public
Created

  • Download Gist
gistfile1.d
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import std.stdio;
import std.conv;
 
auto makeType(T, string X)()
{
mixin("enum makeTypeTemp" ~ " : " ~ "T" ~ " { " ~ X ~ " }");
makeTypeTemp temp;
return temp;
}
 
template choice(T, string X)
{
alias typeof({ auto x = makeType!(T, X); return x; }()) choice;
}
 
alias choice!(bool, "yes, no") Redraw;
alias choice!(int, "red, green, blue") Color;
 
void paint(Redraw redraw, Color color = Color.blue)
{
if (redraw == Redraw.yes)
{
writefln("Painting %s pixels.", to!string(color));
}
else
{
writefln("Not painting %s pixels.", to!string(color));
}
}
 
void main()
{
paint(Redraw.yes);
paint(Redraw.no, Color.red);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.