gcc-4.8 accepts this code, but isn't it wrong since the non-type parameter pack is equivalent to void...
which is illegal?
template <typename T,
typename std::enable_if<std::is_integral<T>::value>::type...>
void test(T) {}
I tried this with clang-3.5 as well which also accepts it. Is this a compiler bug, or am I misunderstanding something?
Full test code below, which uses non-type empty parameter packs to simplify enable_if.
This is almost the same as what's in Flaming Dangerzone's Remastered enable_if except after substitution the pack becomes void...
.
#include <type_traits>
template < typename C >
using enable_if_t = typename std::enable_if<C::value>::type ;
template < typename T, enable_if_t<std::is_integral<T>>... >
void test(T){} // #1
template < typename T, enable_if_t<std::is_floating_point<T>>... >
void test(T){} //#2
int main()
{
test(0); // calls #1
test(0.0); // calls #2
return 0;
}
gcc-4.8 compiles the above code just fine. clang doesn't but that's because it has a different bug http://llvm.org/bugs/show_bug.cgi?id=11723.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…