On Friday, 12 June 2015 at 14:22:45 UTC, Jacob Carlborg wrote:
On 2015-06-12 10:06, Tofu Ninja wrote:
Also a feature that would make this perfect is macro template arguments.

Something like

void templateFunction(macro a)()
{
     int x = 5;
     return mixin(a);
}

Essentially, the expression in the argument would be converted to an
expression macro.

Calling templateFunction!(x + x)() would return 10

Why would you want this over string mixins?
For one, it looks a lot cleaner.
Also as its not a string, it cant be changed and the parser need not re-parse it when it gets mixed in, which could be faster than normal
string mixins.
Also it would allow for mixin macros to look something similar to c++ macros only with the mixin keyword in front of it. Would keep the whole
thing clean looking.

Example assert doing c style return error codes.

mixin macro cassert(macro expression, alias errorcode)
{
     if(!(mixin(expression))) return errorcode;
}

... some other piece of code that returns null on error ...
mixin cassert(x == 3, null);

This starts to look like AST macros to me.

But without the AST ;) never actually have to deal with ast's but still has a lot of its functionality in a simpler form.

Reply via email to