1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <type_traits>
template <typename T, bool IsClass>
struct RealType;
template <typename T>
struct RealType <T, true>
{
typedef typename T::IntT VeryRealType;
};
template <typename T>
struct RealType <T, false>
{
typedef T VeryRealType;
};
template <typename T>
struct MaClasse
{
typename RealType<T, std::is_class<T>::value>::VeryRealType monMembre; // long, n'est-ce pas ?
};
struct Foo
{
typedef int IntT;
};
int main()
{
std::is_class<int>::value; // OK
std::is_class<Foo>::value; // OK
MaClasse<int> MonInstance_1; // KO !!!
MaClasse<Foo> MonInstance_2; // OK
std::conditional<true, Foo::IntT, int> MonInstance_3;
std::conditional<false, Foo::IntT, int> MonInstance_4;
} |