Naruto
11/28/2014 - 10:47 AM

enum class iterator test

enum class iterator test

// clang++ -std=c++11 ./enum_test.cpp
#include <iostream>
#include <type_traits>

enum class COLOR :int
{
  Blue = 0,
  Red,
  Green,
  Purple,
  Last,
  First=Blue,
};

inline COLOR operator++( COLOR& x ) { return x = (COLOR)(std::underlying_type<COLOR>::type(x) + 1); }
inline COLOR operator*( COLOR& x ) { return x; }
inline COLOR begin( COLOR& x ) { return COLOR::First; }
inline COLOR end( COLOR& x ) { return COLOR::Last; }

int main(int argc, char **argv) {
  for(auto c : COLOR()) {
    int x = static_cast<int>(c);
    std::cout << x << std::endl;
  }
  return 0;
}