fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<int i_find, int... i_rest>
  5. struct contains;
  6.  
  7. template<int i_find, int i_head, int... i_rest>
  8. struct contains<i_find, i_head, i_rest...> : contains<i_find, i_rest...> {};
  9.  
  10. template<int i_find, int... i_rest>
  11. struct contains<i_find, i_find, i_rest...> : std::true_type {};
  12.  
  13. template<int i_find>
  14. struct contains<i_find> : std::false_type {};
  15.  
  16. int main() {
  17. printf("contains 0: %i\n", contains<0, 1,2,3,4>() ? 1 : 0);
  18. printf("contains 1: %i\n", contains<1, 1,2,3,4>() ? 1 : 0);
  19. printf("contains 2: %i\n", contains<2, 1,2,3,4>() ? 1 : 0);
  20. printf("contains 3: %i\n", contains<3, 1,2,3,4>() ? 1 : 0);
  21. printf("contains 4: %i\n", contains<4, 1,2,3,4>() ? 1 : 0);
  22. printf("contains 5: %i\n", contains<5, 1,2,3,4>() ? 1 : 0);
  23. // your code goes here
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
contains 0: 0
contains 1: 1
contains 2: 1
contains 3: 1
contains 4: 1
contains 5: 0