foreach over string enum
Jesse Phillips
jessekphillips+D at gmail.com
Thu Feb 10 11:22:43 PST 2011
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.html but it's an enum which contains
> integers instead of strings, thus I can't use min- or max-property.
>
> Any suggestions -> thanks in advance!
I'll just be leaving this here, if you need more explanation ask, but maybe you'll understand:
import std.stdio;
enum FileName : string {
file1 = "file1.ext",
file2 = "file2.ext"
}
void main(string args[])
{
foreach(a; __traits(allMembers, FileName))
writeln(mixin("FileName." ~ a));
}
More information about the Digitalmars-d-learn
mailing list