I have a class
template <typename T>
struct Trait { typedef std::false_type IsGood; };
template <>
struct Trait<int> { typedef std::true_type IsGood; };
A call like this fails to compile on MSVC 2010
template <typename T, typename Enable = void> class Foo;
template <typename T>
class Foo <T, std::enable_if<typename Trait<T>::IsGood::value>::type>
{};
// This fails as well
template <typename T>
class Foo <T, typename std::enable_if<Trait<T>::IsGood::value>::type>
{};
// And this fails horribly
template <typename T>
class Foo <T, typename std::enable_if<typename Trait<T>::IsGood::value>::type>
{};
while
template <typename T>
class Foo <T, typename std::enable_if<std::is_same<std::true_type,
typename Trait<T>::IsGood>::value>::type>
{};
works — why?
The error message is:
main.cpp(12): error C2039: 'type' : is not a member of 'std::tr1::enable_if<_Test>'
with
[
_Test=false
]
main.cpp(12): error C2146: syntax error : missing ',' before identifier 'type'
main.cpp(12): error C2065: 'type' : undeclared identifier
main.cpp(13): error C2976: 'Foo' : too few template arguments
You’re using
typenameat wrong place. This is correct:Now it compiles fine: http://ideone.com/0SwO9
But you’re using
typenameas:Trait<T>::IsGood::valueis not a type, So you cannot applytypenameon it.GCC error message is very much clear:
See yourself : http://ideone.com/9ujJv