Hi,
I'm trying to store values of an enum type in a std::bitset
container, in a contiguous manner.
eg.
typedef enum
{
meValue1 = 0xbaad,
meValue2 = 0xbeef,
meValue3 = 0xdead,
meValue4 = 0xbeef
} MyEnum;
should be stored in a std::bitset<3(due to the duplicate value
0xbeef).
I don't consider using a std::set<MyEnuminstead, because I would
then be lacking std::bitset facilities such as flip() and set() that
work on the whole set of values.
My goal is to provide some kind of "enumset" template container that
would store only legal values of it's parametrized enum type.
Of course there is the solution to manually map each enum value to a
bit index (and the other way around too), but I'd like to automate
this if possible (which I didn't achieve so far).
The ideal would be to have compile-time reflection on the enum type,
but searching on the web yielded no relevant results so I guess I'm
in a deadend as far as a (value <=bit index) automatic mapping is
concerned.
Another idea was to make the std::bitset large enough to handle
_all_ possible values between minimum and maximum values of the
enum. But this seems impractical with enums that have large
differences between their min and max value.
eg. for MyEnum : 0xbaad to 0xdead would be 9217 bits ie. 1153 bytes
(but we really need only 1 byte, as we have 3 distinct values).
Any suggestions are welcome, I'm kinda stuck ATM. :(
--
IR