fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. template<class T> struct __arr_contains
  7. {
  8. const T& container;
  9. __arr_contains(const T& c) : container(c) {}
  10. };
  11.  
  12. template<class T, class V> bool operator+(V&& val, __arr_contains<T> c)
  13. {
  14. return std::find(c.container.begin(), c.container.end(), val)
  15. != c.container.end();
  16. }
  17.  
  18. struct __arr_check
  19. {
  20. __arr_check() {}
  21. template<class T> __arr_contains<T> operator*(const T& arr)
  22. { return __arr_contains<T>(arr); }
  23. };
  24.  
  25. #define in +__arr_check()*
  26.  
  27. int main() {
  28. vector<int> v{ 1,2,3,4,5 };
  29. if (3 in v)
  30. {
  31. cout << "yep";
  32. }
  33. else
  34. cout << "nope";
  35. return 0;
  36. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
yep