我在和斯芬娜玩,发现我无法解释的行为。
这个
compiles fine
以下内容:
template<typename Integer,
std::enable_if_t<std::is_integral<Integer>::value>* = nullptr>
void foo(Integer) {}
template<typename Floating,
std::enable_if_t<std::is_floating_point<Floating>::value>* = nullptr>
void foo(Floating) {}
当这个(
nullptr
0
template<typename Integer,
std::enable_if_t<std::is_integral<Integer>::value>* = 0>
void foo(Integer) {}
template<typename Floating,
std::enable_if_t<std::is_floating_point<Floating>::value>* = 0>
void foo(Floating) {}
gives me a compile error
prog.cpp: In function âint main()â: prog.cpp:13:10: error: no matching function for call to âfoo(int)â
foo(3);
^ prog.cpp:5:6: note: candidate: template<class Integer, std::enable_if_t<std::is_integral<_Tp>::value>* <anonymous> > void foo(Integer) void foo(Integer) {}
^~~ prog.cpp:5:6: note: template argument deduction/substitution failed: prog.cpp:4:64: error: could not convert template argument â0â to âstd::enable_if_t<true, void>* {aka void*}â
std::enable_if_t<std::is_integral<Integer>::value>* = 0>
^ prog.cpp:9:6: note: candidate: template<class Floating, std::enable_if_t<std::is_floating_point<_Tp>::value>* <anonymous> > void foo(Floating) void foo(Floating) {}
^~~ prog.cpp:9:6: note: template argument deduction/substitution failed: prog.cpp:8:71: note: invalid template non-type parameter
std::enable_if_t<std::is_floating_point<Floating>::value>* = 0>
^
enable_if_t
void
void* = 0