Alias template param - Undefined Identifier

Chris Williams yoreanon-chrisw at yahoo.co.jp
Tue Mar 18 17:07:02 PDT 2014


On Tuesday, 18 March 2014 at 23:33:12 UTC, bearophile wrote:
> Chris Williams:
>
>> But I also like to know how most-effectively to write a 
>> C-style macro in D, so it seemed worth checking what the state 
>> of the art is.
>
> This is an antipattern :-)
>
> Bye,
> bearophile

As are goto, pointers, and conditional compilation. That doesn't 
mean that there aren't cases where those are the best solution, 
because other solutions would be longer and more convoluted or 
too inefficient.

In Python, I could write a wrapping function that I could apply 
(using decorators) to each function with this behavior, based on 
the presence of a UDA.

I could roughly build something like that for D, but the whole 
framework for it would be far more convoluted and harder to 
maintain than a simple three line macro. ...probably something 
along the lines of making all of my functions a static function 
in a struct, which I then pass into a template which processes 
UDAs to generate functions at the top with the same names as the 
originals in the struct, which call the struct variants. It's 
also a longer to write and debug.

Unfortunately, at the moment, I don't believe that there's any 
way to use UDAs to process a file and generate interceptors -- 
which would be the sort of pattern that we'd like.


More information about the Digitalmars-d-learn mailing list