fork download
  1. #include <functional>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. #define DEVICE_A 0
  6. #define DEVICE_B 1
  7. //..
  8. #define DEVICE_N 50
  9.  
  10. #define COMPANY_A 0
  11. #define COMPANY_B 1
  12. #define COMPANY_C 2
  13. #define COMPANY_D 2
  14. //..
  15. #define COMPANY_N 50
  16.  
  17. int main ()
  18. {
  19. int giCompany = COMPANY_B;
  20. int giDevice = DEVICE_A;
  21. int randomValue_1 = 5;
  22. int randomValue_2 = 7;
  23. std::vector<std::pair<std::function<bool(int, int)>, std::function<void()>>> operations =
  24. {
  25. {
  26. [] (int company, int device) {return company == COMPANY_A || company == COMPANY_B || company != COMPANY_C && device == DEVICE_A;},
  27. [&] {std::cout << "First case " << randomValue_1 << '\n';}
  28. },
  29. {
  30. [] (int company, int device) {return company == COMPANY_D;},
  31. [&] {std::cout << "Second case " << randomValue_2 << '\n';}
  32. },
  33. };
  34.  
  35. for (auto const& pair: operations)
  36. {
  37. if (pair.first (giCompany, giDevice))
  38. {
  39. pair.second ();
  40. }
  41. }
  42. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
First case 5