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.
This is an option:
#define COLORS {red, green , blue}
enum Color COLORS;
static std::set<Color> color_set() {
return COLORS;
}
#undef COLORS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With