У меня есть класс
template <typename T>
struct Trait { typedef std::false_type IsGood; };
template <>
struct Trait<int> { typedef std::true_type IsGood; };
Вызов, подобный этому, не компилируется в 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>
{};
, а
template <typename T>
class Foo <T, typename std::enable_if<std::is_same<std::true_type,
typename Trait<T>::IsGood>::value>::type>
{};
работает - почему?
Сообщение об ошибке:
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