If I do
struct A{};
struct C:private A{};
typedef char (&yes)[1];
typedef char (&no)[2];
template
struct Host
{
operato
Do you have access to a compiler with C++11 support?
If so, you can combine Chad's use of static_cast
with decltype
to create a very simple type trait implementation (as demonstrated in this question). As per Jonathan Wakely's suggestion, the references have been replaced with pointers to avoid false positives when D
defines an operator B&()
.
template struct AnyReturn { typedef void type; };
template
struct is_base_of: std::false_type {};
template
struct is_base_of( std::declval() ) ) >::type
>: std::true_type {};
When using gcc 4.7:
struct Base {};
struct PublicDerived : public Base {};
struct PrivateDerived : private Base {};
int main()
{
std::cout << is_base_of ::value << std::endl; // prints 1
std::cout << is_base_of ::value << std::endl; // prints 0
return 0;
}