Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
template< class TFunctor >
inline void CallWithType( const TFunctor &rcFunctor, int nTypeDescriptor );
...
template< class TObject >
inline bool IsKindOf( int nTypeDescriptor )
{
return CallWithType( IsKindOfHelper< TObject >(), nTypeDescriptor );
}
// TypeDescriptor is virtual func, which returns descriptor of the real object type.
// Implementation shown in previous example (you don't need to write this function by hands)
if( IsKindOf< ISettable >( TypeDescriptor() ) )
// IsWrapperApplicable converts nType to the real type TObject using CallWithType,
// calls WrapperTraits::CSomeWrapper::MakeWrappedType< TObject >::type metafunction
// in order to resolve wrapped type, then calls MakeDescriptor for this type.
return MakeWrappedType< WrapperTraits::CSomeWrapper >( nType ) );
Шаблонная магия, паттерн CallWithType