This version works fine:
template<typename T>
struct Foo
{
template<typename U = T>
typename std::enable_if<std::is_same<U,A>::value>::type
bar() { std::cout << "1" << std::endl; }
template<typename U = T>
typename std::enable_if<std::is_same<U,B>::value>::type
bar() { std::cout << "2" << std::endl; }
};
This version fails:
template<typename T>
struct Foo2
{
template<typename U = T, typename V = typename std::enable_if<std::is_same<U,A>::value>::type >
V bar() { std::cout << "1" << std::endl; }
template<typename U = T, typename V = typename std::enable_if<std::is_same<U,B>::value>::type >
V bar() { std::cout << "2" << std::endl; }
};
with:
error: 'template template V Foo2::bar()' cannot be overloaded with 'template template V Foo2::bar()'
The difference between both versions is in the first I use the expression directly, in the second one I create a template default parameter and use that one as return type.
What is the reason to fail in the second example?
std::enable_if
doc. – Gluttonize