fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. using namespace std;
  5.  
  6. #define EXPAND_VALUES(action) \
  7. action (1, SUNDAY, "Sunday") \
  8. action (2, MONDAY, "Monday") \
  9. action (3, TUESDAY, "Tuesday") \
  10. action (4, WEDNESDAY, "Wednesday") \
  11. action (5, THURSDAY, "Thursday") \
  12. action (6, FRIDAY, "Friday") \
  13. action (7, SATURDAY, "Saturday")
  14.  
  15. #define DEF_ENUM(i,v,s) v = i,
  16. enum class Days : int { EXPAND_VALUES(DEF_ENUM) };
  17. #undef DEF_ENUM
  18.  
  19. #define DEF_MAP(i,v,s) {i, Days::v},
  20. std::map<int, Days> WeekMap { EXPAND_VALUES(DEF_MAP) };
  21. #undef DEF_MAP
  22.  
  23. #define DEF_STR_MAP(i,v,s) {Days::v, s},
  24. std::map<Days, std::string> WeekStrMap { EXPAND_VALUES(DEF_STR_MAP) };
  25. #undef DEF_STR_MAP
  26.  
  27. int main() {
  28. cout << WeekMap.size() << endl;
  29. for (auto const & e : WeekMap)
  30. cout << e.first << " -> " << int(e.second) << endl;
  31. cout << WeekStrMap.size() << endl;
  32. for (auto const & e : WeekStrMap)
  33. cout << int(e.first) << " -> " << e.second << endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
7
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
7
1 -> Sunday
2 -> Monday
3 -> Tuesday
4 -> Wednesday
5 -> Thursday
6 -> Friday
7 -> Saturday