Will macros just be syntactic sugar?
Don Clugston
dac at nospam.com.au
Wed Apr 25 03:45:02 PDT 2007
Davidl wrote:
> macro macroname(Token... tokens)
> {
> static if (tokens[0].ID != Token.LParen)
> pragma(error, `( expected`);
:
> alias token[1] arg0;
> alias token[5] arg1;
> alias token[7] arg2;
> alias token[9] arg3;
> arg0[arg1] = arg2 + arg3;
> }
>
> caller could call the macro with :
>
> macroname(arg0)[arg1] := arg2 + arg3;
I don't think that's much nicer than
mixin(macroname("arg0[arg1]:= arg2+ arg3"));
which works in DMD 1.012. The static if/Token properties can be done via
a CTFE library. If structs were allowed in CTFE functions, the code
wouldn't even be too ugly.
More information about the Digitalmars-d
mailing list