How to elegantly put all enums into a std::set
c++, enums, stdset
Solution
This is an option:
#define COLORS {red, green , blue}
enum Color COLORS;
static std::set<Color> color_set() {
return COLORS;
}
#undef COLORS
Problem
I have an enum and I want to put them all in the set( and then remove some with set_intersection algorithm, but that is offtopic). All works great except Im stuck on step 1. :) If I have(real class has enum with higher cardinality) ``` class MyClass { enum Color{red, green , blue} }; ``` How would I init a `std::set<MyClass::Color>` to contain all enums. I can obviously manually insert them one by one, do a for loop with casting since they are consecutive and start from 0 (I think that is required if I dont use = in enum definition), but Im looking for a more elegant way. EDIT: I prefer C++03 solution if possible because current instance of problem requires it, but if not C++11 is good to know too.