foreach over string enum

2011-02-10 Thread Nrgyzer
Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = "file1.ext", file2 = "file2.ext" } I already found this article: http://lists.puremagic.com/pipermail/ digitalmars-d/2007-July/021920.html but it's an enum which contains in

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
Nrgyzer Wrote: > Hey guys, > > I'm trying to iterate over an enumeration which contains strings like > the this: > > enum FileName : string { > file1 = "file1.ext", > file2 = "file2.ext" > } > > I already found this article: http://lists.puremagic.com/pipermail/ > digitalmars-d/2007-July/021920

Re: foreach over string enum

2011-02-10 Thread Nrgyzer
== Auszug aus Jesse Phillips (jessekphillip...@gmail.com)'s Artikel > Nrgyzer Wrote: > > Hey guys, > > > > I'm trying to iterate over an enumeration which contains strings like > > the this: > > > > enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > I already fo

Re: foreach over string enum

2011-02-10 Thread spir
On 02/10/2011 08:22 PM, Jesse Phillips wrote: Nrgyzer Wrote: Hey guys, I'm trying to iterate over an enumeration which contains strings like the this: enum FileName : string { file1 = "file1.ext", file2 = "file2.ext" } I already found this article: http://lists.puremagic.com/pipermail/ digit

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: > On 02/10/2011 08:22 PM, Jesse Phillips wrote: > > enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > void main(string args[]) > > { > > foreach(a; __traits(allMembers, FileName)) > > writeln(mixin("FileName." ~ a)); > > } > > Why t

Re: foreach over string enum

2011-02-10 Thread spir
On 02/10/2011 11:32 PM, Jesse Phillips wrote: enum FileName : string { > > file1 = "file1.ext", > > file2 = "file2.ext" > > } > > > > void main(string args[]) > > { > >foreach(a; __traits(allMembers, FileName)) > >writeln(mixin("FileName." ~ a)); > > } > > Why

Re: foreach over string enum

2011-02-10 Thread Ali Çehreli
I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: > unittest { > auto i = 1; > auto s = "i"; It works if you define s as: enum s = "i"; > writeln(mixin("i")); // compiler happy up to here --> "1" > writeln(mixin(s)); // compiler unhappy --> "Error: argument

Re: foreach over string enum

2011-02-10 Thread spir
On 02/11/2011 01:02 AM, Ali Çehreli wrote: I don't have answers to your other questions. On 02/10/2011 03:25 PM, spir wrote: unittest { auto i = 1; auto s = "i"; It works if you define s as: enum s = "i"; writeln(mixin("i")); // compiler happy up to here --> "1" writeln(mixin(s)); //

Re: foreach over string enum

2011-02-10 Thread Jesse Phillips
spir Wrote: > But in your example the symbol a does not look like a constant, instead it > the > loop variable. Do, how does it work? Magic. No really, the best I can tell is that the compiler will try to run the foreach loop at compile-time if there is something in the body that must be eva

Re: foreach over string enum

2011-02-11 Thread spir
On 02/11/2011 05:27 AM, Jesse Phillips wrote: spir Wrote: But in your example the symbol a does not look like a constant, instead it the loop variable. Do, how does it work? Magic. No really, the best I can tell is that the compiler will try to run the foreach loop at compile-time if there

Re: foreach over string enum

2011-02-20 Thread Daniel Murphy
"Jesse Phillips" wrote in message news:ij2drt$1mq3$1...@digitalmars.com... > > Magic. > > No really, the best I can tell is that the compiler will try to run the > foreach loop at compile-time if there is something in the body that must > be evaluated at compile time. > Actually this happens b