fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <memory>
  5.  
  6. struct in
  7. {
  8. std::shared_ptr<void> ptr;
  9. size_t hash_type;
  10. void add_strings(){}
  11.  
  12.  
  13. template<typename T, typename... Args>
  14. void add_strings(T value, Args... args) {
  15. std::vector<T> &vec = *(std::vector<T>*)ptr.get();
  16. vec.push_back(value);
  17. add_strings(args...);
  18. }
  19.  
  20. template<typename... Args>
  21. void add_strings(char const*const value_ptr, Args... args) {
  22. std::vector<std::string> &vec = *(std::vector<std::string>*)ptr.get();
  23. vec.push_back(std::string(value_ptr));
  24. add_strings(args...);
  25. }
  26.  
  27. template<typename... Args>
  28. in(char const*const value_ptr, Args... args) {
  29. hash_type = typeid(std::string).hash_code();
  30. ptr = std::make_shared<std::vector<std::string>>(0);
  31. add_strings(value_ptr, args...);
  32. }
  33.  
  34. template<typename T, typename... Args>
  35. in(T value, Args... args) {
  36. hash_type = typeid(T).hash_code();
  37. ptr = std::make_shared<std::vector<T>>(0);
  38. add_strings(value, args...);
  39. }
  40. };
  41.  
  42. template<typename T>
  43. bool operator==(T const& str, in const& val) {
  44. if(val.hash_type == typeid(T).hash_code())
  45. {
  46. std::vector<T> &vec = *(std::vector<T>*)val.ptr.get();
  47. for(auto &i : vec)
  48. {
  49. if(i == str)
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. // -----------------------------------------------------
  56.  
  57. int main(void)
  58. {
  59. std::string lang, country = "GB";
  60.  
  61. if (country == in ("US","GB","AU"))
  62. {
  63. lang="en";
  64. }
  65.  
  66. if (country == in (1,2,3))
  67. {
  68. lang="hz";
  69. }
  70.  
  71. int a, b = 10;
  72.  
  73. if (b == in (1,2,10,3))
  74. {
  75. lang += " +100500";
  76. }
  77.  
  78. std::cout << "lang = " << lang << std::endl;
  79.  
  80. return 0;
  81. }
  82.  
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
lang = en +100500