I used to believe that 'typedef' is not automatically inherited. But the code snap below suggests something different.
#include <iostream>
#include <type_traits>
struct A
{
typedef int X;
};
struct A_
{
typedef char X;
};
struct B : A {};
struct B_ : A, A_ {};
template< typename ... Ts >
using void_t = void;
template< typename T, typename = void >
struct has_typedef_X : std::false_type {};
template< typename T >
struct has_typedef_X< T, void_t<typename T::X> > : std::true_type {};
int main()
{
std::cout << std::boolalpha;
std::cout << has_typedef_X<A>::value << std::endl;
std::cout << has_typedef_X<A_>::value << std::endl;
std::cout << has_typedef_X<B>::value << std::endl;
std::cout << has_typedef_X<B_>::value << std::endl;
return 0;
}
The output is 'true true true false'.
But in my point of view, 'has_typedef_X<B>::value
' giving 'true' implies that in struct B, X is 'typedef'ed.
So if anyone can please explain this problem or correct me?
A online version is available at http://melpon.org/wandbox/permlink/iwZ6eZ3PoBPgyFBj [URL corrected]