fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<typename t_find>
  6. bool contains(const t_find& i_find)
  7. {
  8. return false;
  9. }
  10.  
  11. template<typename t_find, typename... t_rest>
  12. bool contains(const t_find& i_find, t_find&& i_head, t_rest&&... i_rest)
  13. {
  14. return i_find == i_head ? true : contains(i_find, std::forward<t_rest>(i_rest)...);
  15. }
  16.  
  17. template<typename t_find, typename t_head, typename... t_rest>
  18. bool contains(const t_find& i_find, t_head&& i_head, t_rest&&... i_rest)
  19. {
  20. return contains(i_find, std::forward<t_rest>(i_rest)...);
  21. }
  22.  
  23. int main() {
  24. printf("contains 0: %i\n", contains(0, 1,2,3,4) ? 1 : 0);
  25. printf("contains 1: %i\n", contains(1, 1,2,3,4) ? 1 : 0);
  26. printf("contains 2: %i\n", contains(2, 1,2,3,4) ? 1 : 0);
  27. printf("contains 3: %i\n", contains(3, 1,2,3,4) ? 1 : 0);
  28. printf("contains 4: %i\n", contains(4, 1,2,3,4) ? 1 : 0);
  29. printf("contains 5: %i\n", contains(5, 1,2,3,4) ? 1 : 0);
  30. // your code goes here
  31. return 0;
  32. }
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