UDA + Pegged AST Hack

Philippe Sigaud philippe.sigaud at gmail.com
Wed Nov 28 14:19:37 PST 2012


> I made two, but not as cool as yours: http://dpaste.dzfl.pl/32536704


I like this one :)

I think this part:

static T readArgs(T)(string[] args)
{
T ret;
pragma(msg, "getopt(args"~buildGetOptArguments!(T, "ret")~");");
mixin("getopt(args"~buildGetOptArguments!(T, "ret")~");");
 return ret;
}


Could be slightly simplified somewhat. Try passing 'ret' as an alias. That
way, buildGetOptArguments should be able to create the "ret" string by
itself, like this:


private static string buildGetOptArguments(T, alias instance)()
{
    enum string instanceName = instance.stringof; // for example
...

And I'd have buildGetOptArguments return the "getopt(args" ... ")" part
also.
Which gives:

T readArgs(T)(string[] args)
{
T ret;
pragma(msg, buildGetOptArguments!(T, ret));
mixin(buildGetOptArguments!(T, ret)~";");
 return ret;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121128/4e2906e4/attachment.html>


More information about the Digitalmars-d mailing list