digitalmars.D - Feature Request: foreach over an enum
- stonecobra <scott stonecobra.com> Jun 04 2004
- J Anderson <REMOVEanderson badmama.com.au> Jun 04 2004
- "Matthew" <matthew.hat stlsoft.dot.org> Jun 04 2004
- Sean Kelly <sean f4.ca> Jun 05 2004
- stonecobra <scott stonecobra.com> Jun 06 2004
Hi,
In helping kris with the mango package (the log administrator servlet
specifically), I came across the need to iterate over the values of an emum:
enum Level {Trace=0, Info, Warn, Error, Fatal, None};
So, I go about coding like so:
for (int i = Logger.Level.min; i < Logger.Level.max + 1; i++)
{
... //do stuff here with Level[i]
}
Why not add the ability to foreach, so that iteration is nicer:
foreach(Level l; Level)
{
... //do stuff with l
{
Wouldn't you just love to handle enums like this. I believe iteration
over enums is a pretty common thing.
Thanks
Scott Sanders
Jun 04 2004
stonecobra wrote:Hi, In helping kris with the mango package (the log administrator servlet specifically), I came across the need to iterate over the values of an emum: enum Level {Trace=0, Info, Warn, Error, Fatal, None}; So, I go about coding like so: for (int i = Logger.Level.min; i < Logger.Level.max + 1; i++) { ... //do stuff here with Level[i] } Why not add the ability to foreach, so that iteration is nicer: foreach(Level l; Level) { ... //do stuff with l { Wouldn't you just love to handle enums like this. I believe iteration over enums is a pretty common thing. Thanks Scott Sanders
That would be nice. -- -Anderson: http://badmama.com.au/~anderson/
Jun 04 2004
Wouldn't you just love to handle enums like this. I believe iteration over enums is a pretty common thing. Thanks Scott Sanders
That would be nice.
I can't immediately see a problem with it. As long as none transpires, count my vote.
Jun 04 2004
In article <c9r1o4$27nd$1 digitaldaemon.com>, stonecobra says...Wouldn't you just love to handle enums like this. I believe iteration over enums is a pretty common thing.
I've never had a need to iterate over an enum, but I agree that it's a nice feature. Unless there's some bizarre consequence I haven't thought of it has my vote. Sean
Jun 05 2004
I think that a shortened syntax would reduce the redundancy :)
How about:
foreach(Level l)
{
...
}
That way a single argument would have to be an Enum.
Scott
stonecobra wrote:
foreach(Level l; Level)
{
... //do stuff with l
{
Jun 06 2004









"Matthew" <matthew.hat stlsoft.dot.org> 