Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > compile-time reflection on enum types?

Reply
Thread Tools

compile-time reflection on enum types?

 
 
IR
Guest
Posts: n/a
 
      10-22-2006
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<MyEnum> instead, 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ENUM server for private ENUM kael UK VOIP 2 02-25-2007 11:54 AM
enum: display elements of an enum specified at runtime Jerminia Java 3 10-07-2005 10:08 PM
enum within an enum - Java 6 06-13-2005 12:51 AM
Including an enum within another enum, possible? mrhicks C Programming 2 06-10-2004 03:00 AM
How to enum an enum? Ernst Murnleitner C++ 5 11-13-2003 11:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57