I used enable_ifin this rough order with various versions of GCC (prior to 5.2):
template< bool b, std::enable_if_t< b >... >
void fn() { std::cout << 1 << std::endl; }
template< bool b, std::enable_if_t< !b >... >
void fn() { std::cout << 2 << std::endl; }
fn< true >();
fn< false >();
But, as it turns out, Clang 3.7 does not accept this (the "fn" call is ambiguous ").
Q1. Who is right and why?
There are, of course, other ways to do this, but I kinda don't like it
template< bool b >
std::enable_if_t< b, void > fa() { std::cout << 1 << std::endl; }
and its ilk in order to make the normal parts of the function signature less readable, and
template< bool b, std::enable_if_t< b, int > = 0 >
void fd() { std::cout << 1 << std::endl; }
to include irrelevant elements (types and values).
Q2. What other (correct, more readable, less hacker / weird) ways to use enable_if/ enable_if_tare there?
source
share