digitalmars.D - Feature Request: foreach over an enum
- stonecobra (18/18) Jun 04 2004 Hi,
- J Anderson (4/23) Jun 04 2004 That would be nice.
- Matthew (2/8) Jun 04 2004 I can't immediately see a problem with it. As long as none transpires, c...
- Sean Kelly (5/7) Jun 05 2004 I've never had a need to iterate over an enum, but I agree that it's a n...
- stonecobra (9/14) Jun 06 2004 I think that a shortened syntax would reduce the redundancy :)
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
I can't immediately see a problem with it. As long as none transpires, count my vote.Wouldn't you just love to handle enums like this. I believe iteration over enums is a pretty common thing. Thanks Scott SandersThat would be nice.
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> 