iterate over enum name:value pairs
Jay Norwood
jayn at prismnet.com
Sun Dec 8 16:18:41 PST 2013
On Sunday, 8 December 2013 at 22:30:25 UTC, bearophile wrote:
>
> Try:
>
> member.writeln;
>
> Bye,
> bearophile
yeah, that's pretty nice.
module main;
import std.stdio;
void main()
{
struct Suit {string nm; int val; int val2; string shortNm;};
static Suit[5] suits = [
{"spades",1,6,"spd"},
{"hearts",4,10,"hrt"},
{"hearts2",4,10,"hrt2"},
{"diamonds",10,16,"dmd"},
{"clubs",11,17,"clb"}
];
foreach (immutable member; suits)
{
member.writeln();
}
}
output:
immutable(Suit)("spades", 1, 6, "spd")
immutable(Suit)("hearts", 4, 10, "hrt")
immutable(Suit)("hearts2", 4, 10, "hrt2")
immutable(Suit)("diamonds", 10, 16, "dmd")
immutable(Suit)("clubs", 11, 17, "clb")
More information about the Digitalmars-d-learn
mailing list