retto, вот те продвиннутый вариант| Код | //-------------------------------------------------------------------------------------------------- #include <iostream> #include <iomanip>
//-------------------------------------------------------------------------------------------------- namespace Mpl {
template<class Base, class Derived> struct IsDerived { private: struct YesType { char a[1]; }; struct NoType { char a[10]; };
static YesType deduce(Base*); static NoType deduce(...);
public: enum { value = (sizeof(deduce(static_cast<Derived*>(NULL))) == sizeof(YesType)) }; }; }
template<class B, class D> bool isDerived(D const&) { return (Mpl::IsDerived<B, D>::value != 0)? true : false; }
struct A {}; struct B {}; struct C : A {};
//-------------------------------------------------------------------------------------------------- // // int main(int argc, char const* const argv[]) { B b; C c;
std::cout << std::boolalpha; std::cout << isDerived<A>(b) << std::endl; std::cout << isDerived<A>(c) << std::endl; return 0; } //--------------------------------------------------------------------------------------------------
|
|