reflection based on my experience so far on compile-time meta-programming in D as a novice user: the problems

mw mingwu at gmail.com
Mon Sep 14 18:53:10 UTC 2020


On Monday, 14 September 2020 at 18:36:53 UTC, H. S. Teoh wrote:
>
> Yep:	https://www.ioccc.org/2005/anon/anon.c

As I said, I'm using the *generated* code:

   cpp -P foo.h > foo.c  // <- this generated code


For a fair comparison, how Steven's *generating* code is more 
superior to read than anon.c?

```
string DECL_TA_FUNC(string TA_FUNC, string[] FUNC_INS, string[] 
FUNC_OUTS)
{
    // this would be easier with string interpolation!
    return format(q{
bool %s(double[] inData, %-(double[] %s,%), %-(%s,%)) {
   %(assert %s.length == inData.length;%)
   int begin, num;
   int lookback = %s_Lookback( %(%s... you get the idea
}}, TA_FUNC, FUNC_OUTS, FUNC_INS, FUNC_OUTS, TA_FUNC, ...);
}

enum MA_INS = [
    "int MA_optInTimePeriod",
    "int TA_MAType optInMAType"
];
enum MA_OUTS = [
    "outMA"
];
mixin(DECL_TA_FUNC(TA_MA, MA_INS, MA_OUTS, somethingElse, 
whatever));
```


More information about the Digitalmars-d mailing list