Ideally I would like a following examples to work, but I guess some of it is not implementable in C++.
{
typedef StrongEnum<Red=0, Green=1, Blue=2> Color; // not a C++ syntax
Color c = Color::Red; // static const
Color d; //error: default constructor is private
Color d = c;
Color e = Color::OfInt(5); // ifdef DEBUG - Runtime error: Enum out of range
int sum = 0;
// I do have these macros, but separate for each enum - FOREACH_COLOR(c)
FOREACH_ENUM (Color c) {
sum += c.ToInt ();
}
ArrayMap<Color, string> map; // Internally this is const size array, possible
map [Color::Red] = "red"; // because Color have static const Limit = 3 inisde.
// Advanced: EnumPair does bitpacking.
// currently I implement it manually for every pair of Enum's I need.
typedef EnumPair <door=Color, window=Color> ColorPair; // I guess I can't get this, can I?
ColorPair pair (door = Color::Red, window = Color::Green); // I guess I can't give the labels here or one line above, can I?
Color w = pair.window;
Color w = pair.window ();
}
I use them a lot and currently I I write each one from the scratch. I am aware that a complete generic solution is a dream, so I welcome any partial solutions. Maybe somebody created a library or a code generator?
Update 1:
This and this questions are related. I'm investigating which issues can be solved with them.