Re: enum -> STL container
barcaroller wrote:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:fc72qu$ish$1@news.datemas.de...
What's "the contents of an enum"? Is that like "all the constants
in my current scope" or "all macros currently defined in the module"?
I'm asking because the enumerators defined inside an enumeration type
are essentially that, a set of named constants that all have some
specific type (and values), there is no specific order or containment
relationship between them or between them and the enumeration.
The enum contains a list of integers (constants). Something like
enum { MIN, ONE=13, TWO=45, THREE=55, MAX }
It contains a "list of integers" as much as a function declaration
contains the list of arguments or a class definition contains a list
of member declarations. There is no such thing at the _run-time_.
It all exists in the source code, and ONLY in the source code.
Basically, a bunch of "#defines". The only guarantee is that they
are in ascending order.
Really? Where did that guarantee come from?
enum { foo = 3, bar = 2, foobar = 1 };
I want to move them into an STL container so
Whom "them"? What does your container look like?
that I can iterate over them without having to use a switch statement
every time. My guess is that I would have to use at least one switch
statement to move them into the STL container.
<shrug> I would like to see that...
What you need is a duplication of your enum declaration in an array.
enum { MIN, ONE=13, TWO=45, THREE=55, MAX };
int const enum_copies[] = {MIN, ONE, TWO, THREE, MAX};
std::list<int> my_enum(enum_copies, enum_copies + 5);
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask