fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <int First, int... Numbers>
  5. inline bool in_impl(int n)
  6. {
  7. return n == First || in_impl<Numbers...>(n);
  8. }
  9.  
  10. template <>
  11. inline bool in_impl<int(0)>(int n)
  12. {
  13. return false;
  14. }
  15.  
  16. template <int... Numbers>
  17. inline bool in(int n)
  18. {
  19. return in_impl<Numbers..., int(0)>(n);
  20. }
  21.  
  22. enum E { E1, E2, E3, E4 };
  23.  
  24. int main() {
  25. std::cout << in<3, 5, 7, 9>(4) << '\n';
  26. std::cout << in<3, 5, 7, 9>(5) << '\n';
  27. std::cout << in<E2, E4>(E1) << '\n';
  28. std::cout << in<E2, E4>(E2) << '\n';
  29. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
0
1
0
1