我正在尝试为非字符数组部分专门化一个特征:
template<typename T>
struct is_container : std::false_type {};
template<typename T, unsigned N>
struct is_container<T[N]>
: std::enable_if<!std::is_same<T, char>::value, std::true_type>::type {};
Visual Studio 2010 给了我一个 C2039(type
不是enable_if
...的元素)。但是,SFINAE 不应该只是在这里触底而不是给出编译器错误吗?或者 SFINAE 不适用于这种情况?
当然,我可以将 non-char 和 char 的特化分开:
template<typename T>
struct is_container : std::false_type {};
template<typename T, unsigned N>
struct is_container<T[N]> : std::true_type {};
template<unsigned N>
struct is_container<char[N]> : std::false_type {};
但我真的很想知道为什么 SFINAE 在这种特殊情况下不起作用。