Meta-programming - examples

janderson askme at me.com
Sun Feb 11 20:51:16 PST 2007


janderson wrote:
> A couple of people have been asking questions about pseudo-real-life 
> examples for the new compile time code aspects of D.  I ask this 
> question for my interest as well.
> 
> Assuming that we have a good mechanism to process the input how could 
> compile time code improve your every-day proficiency?

What about string enums, this could be done with reflection however you 
could do something like this now:

mixin(
Enum!("Colours",
"Red",
"Blue",
"Green"
));

//Or flags
mixin(
Flags!("Colours",
"Red",
"Blue",
"Green"
));

Colours c;
...
char[] str = ToString(c);

-Joel



More information about the Digitalmars-d mailing list