I'm already fairly sure what I'm about to ask isn't possible without creating my own enum implamentation, but I thought it was worth putting it out there in case there's something I've missed, because it would simplify a situation I come across quite often both at work and in my own projects.
Basically, I would like a generic way of returning a list of all enums in an enum class, or at least a generic way of returning all positive enums up until an enum-specific but otherwise pre-determined point. Ok, that last idea was confusing, so I'll post pseudo code of what I mean below...
A way of setting a specific enum "key?" that is used to return the number of positive enums up until the given key:
template<typename EnumType>
std::vector<EnumType> getFullEnumList()
{
std::vector<EnumType> fullEnumList;
for (enumIndex = 0; enumIndex < EnumType::NumEnums; enumIndex++)
fullEnumList.push_back(static_cast<EnumType>(enumIndex));
return fullEnumList;
}
I'm guessing this wouldn't be a practical thing to implement as stated above because the compiler doesn't care what I've called each enum class value, only it's value and class type... that all that compiler deals with in the final compilation stages right?
My first idea I guess would involve some kind of:
EnumClass::size()
...function, which I already know doesn't exist, but I don't currently know enough about the specifics of an enum class to understand why this wouldn't be possible to implement in future c++ iterations... I'm guessing it's either not possible, or it would be an undesirable extra overhead in most enum class use cases, otherwise they'd have implemented it years ago...
But to narrow down to my actual question, on top of the extra knowledge nuggets you guys could furnish me with regarding the above musings, is there some generic way of doing this I haven't thought of?
Cheers in advance for your insights,
Pete