fork(40) download
  1. #include <iostream>
  2. enum class COLOR
  3. {
  4. Blue,
  5. Red,
  6. Green,
  7. Purple,
  8. First=Blue,
  9. Last=Purple
  10. };
  11.  
  12. inline COLOR operator++( COLOR& x ) { return x = (COLOR)(std::underlying_type<COLOR>::type(x) + 1); }
  13. COLOR operator*(COLOR c) {return c;}
  14. COLOR begin(COLOR r) {return COLOR::First;}
  15. COLOR end(COLOR r) {COLOR l=COLOR::Last; return ++l;}
  16.  
  17. std::ostream& operator<<(std::ostream& o, COLOR x) {
  18. return o << std::underlying_type<COLOR>::type(x);
  19. }
  20.  
  21.  
  22. int main() {
  23. for(auto c : COLOR()) {
  24. std::cout << c << '\n';
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
0
1
2
3