I have the following case that works using std::enable_if
:
template<typename T,
typename std::enable_if<std::is_same<int, T>::value>::type* = nullptr>
void f() { }
template<typename T,
typename std::enable_if<std::is_same<double, T>::value>::type* = nullptr>
void f() { }
Now, I saw in cppreference the new syntax, much cleaner in my opinion : typename = std::enable_if_t<std::is_same<int, T>::value>>
I wanted to port my code :
template<typename T,
typename = std::enable_if_t<std::is_same<int, T>::value>>
void g() { }
template<typename T,
typename = std::enable_if_t<std::is_same<double, T>::value>>
void g() { }
But now GCC (5.2) complains :
error: redefinition of 'template<class T, class> void g()'
void g() { }
Why is that so ? What can I do to have the new, more concise syntax in this case if this is possible ?
enable_if_t
is literallystd::enable_if_t<std::is_same<int, T>::value>* = nullptr
. – Interdependent* = nullptr
. – Negrillo, typename = void
afterenable_if
– Oeildeboeufenable_if_t
@PiotrS. : ok – Groatstypename std::enable_if_t<std::is_same<int, T>::value>* = nullptr
route. 4 characters gained, oh well :p – Groatstypename
in front ofstd::enable_if_t
. More characters gained. – Inverselystd::enable_if_t<std::is_same<int, T>::value, int> = 0
orstd::enable_if_t<std::is_same_v<int, T>, int> = 0
. – Cilium*=0
and not with*=nullptr
. – Groats*=0
. I suppliedint
as the second argument toenable_if_t
instead of the defaultvoid
, so0
is an integer literal, not a null pointer literal. – Cilium