给出了C++ 11代码:
#include <type_traits>
enum Enum { EnumValue };
template <typename>
struct Pred { constexpr static bool const value = true; };
template <
typename T,
typename ::std::enable_if<
Pred<T>::value,
Enum
>::type = EnumValue>
class Huh {};
template <typename T>
constexpr bool f(Huh<T> const &) noexcept { return true; }
static_assert(f(Huh<int>()), "");
我从GCC 7.3.0中得到以下错误消息:
test.cpp:19:27: error: no matching function for call to 'f(Huh<int>)'
static_assert(f(Huh<int>()), "");
^
test.cpp:17:16: note: candidate: template<class T> constexpr bool f(const Huh<T>&)
constexpr bool f(Huh<T> const &) noexcept { return true; }
^
test.cpp:17:16: note: template argument deduction/substitution failed:
test.cpp:19:27: note: template argument '(type)0' does not match 'EnumValue'
static_assert(f(Huh<int>()), "");
^
如果我使用
int
和
0
而不是
Enum
EnumValue
,错误消失。
为什么枚举失败?