M
Marc
Hello,
I was surprised to realize that in the example below, only the first
version is valid, whereas the second is considered a redefinition (which
makes sense, but I hadn't expected it). Giving one of the overloads (but
not the other of course) an extra ",class=void" template parameter makes
it valid again.
What would be your favorite workaround for this limitation?
namespace std {
template<bool,typename=void> struct enable_if{};
template<typename T> struct enable_if<true,T>{typedef T type;};
}
#ifndef BUG
template<class...U>
typename std::enable_if<sizeof...(U)==2>::type
f(U&&...){}
template<class...U>
typename std::enable_if<sizeof...(U)==3>::type
f(U&&...){}
#else
template<class...U,class=typename std::enable_if<sizeof...(U)==2>::type>
void f(U&&...){}
void f(U&&...){}
#endif
int main(){
f(4,5);
f(6,7,8);
}
I was surprised to realize that in the example below, only the first
version is valid, whereas the second is considered a redefinition (which
makes sense, but I hadn't expected it). Giving one of the overloads (but
not the other of course) an extra ",class=void" template parameter makes
it valid again.
What would be your favorite workaround for this limitation?
namespace std {
template<bool,typename=void> struct enable_if{};
template<typename T> struct enable_if<true,T>{typedef T type;};
}
#ifndef BUG
template<class...U>
typename std::enable_if<sizeof...(U)==2>::type
f(U&&...){}
template<class...U>
typename std::enable_if<sizeof...(U)==3>::type
f(U&&...){}
#else
template<class...U,class=typename std::enable_if<sizeof...(U)==2>::type>
void f(U&&...){}
void f(U&&...){}
#endif
int main(){
f(4,5);
f(6,7,8);
}