Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 04, 2004 Feature Request: foreach over an enum | ||||
---|---|---|---|---|
| ||||
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 |
June 05, 2004 Re: Feature Request: foreach over an enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to stonecobra | 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/ |
June 05, 2004 Re: Feature Request: foreach over an enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | > > 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.
|
June 05, 2004 Re: Feature Request: foreach over an enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to stonecobra | 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 |
June 07, 2004 Re: Feature Request: foreach over an enum | ||||
---|---|---|---|---|
| ||||
Posted in reply to stonecobra | 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
> {
>
|
Copyright © 1999-2021 by the D Language Foundation