Contextual metaprogramming, query the parent type.

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Feb 4 09:41:57 UTC 2022


Let's say you create a type for constrained integers so that 
```Int!(-2,128)``` can only hold values in the range [-2,128]. 
The Int type then has to decide whether it should store this in a 
*ubyte* with a -2 adjustment or store it in an *short*. Basically 
a space vs speed tradeoff.

In this situation the parent struct holding a field of the 
```Int!(-2,128)``` type might provide information about this, but 
explicitly doing an ```Int!(-2,128, Context)``` is tedious.

So, what if you could write a template that queries the 
containing type and then either produces  ```IntFast!(-2,128)``` 
or  ```IntCompact!(-2,128)``` types?

Seems to me that this should be possible and could make 
metaprogramming more powerful, but I don't think it is possible 
now? Or am I wrong?




More information about the Digitalmars-d mailing list