fork download
  1. #include <utility>
  2.  
  3. template <int N, typename = void>
  4. struct foo : std::integral_constant<int, -1> {};
  5.  
  6. template <int N>
  7. struct foo<N, typename std::enable_if<(0<=N)&&(N<10)>::type> : std::integral_constant<int, N> {};
  8.  
  9. #include <iostream>
  10. int main()
  11. {
  12. std::cout << foo<-1>::value << '\n';
  13. std::cout << foo<0>::value << '\n';
  14. std::cout << foo<1>::value << '\n';
  15. std::cout << foo<9>::value << '\n';
  16. std::cout << foo<10>::value << '\n';
  17. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
-1
0
1
9
-1