CTFE mixin template internal storage/scope (intermediary data) `exclude` keyword
Hipreme
msnmancini at hotmail.com
Thu Dec 1 11:31:00 UTC 2022
Would like to say if it is possible we could have a mixin
template internal storage for CTFE .
So, a common problem I have been having in mixin template is
mixing inside a class scope. Which does not allow you to define
intermediary data (as this intermediary data will be included in
the class). A common solution to that is to create a helper
function, and you actually call inside mixin template and do a
mixin such as:
```d
mixin template MyMixin(A)
{
mixin(MyMixinImpl!A);
}
```
I don't know much about the internals, but I would like to know
if would be possible to do something like that:
```d
mixin template MyMixin(A)
{
static foreach(mem; __traits(allMembers, A))
{
exclude {
enum _isConst = isConst!(__traits(getMember, A, mem));
enum _isRef = isRef!(__traits(getMember, A, mem));
//non template execution for isConst
enum funcAttributes = __traits(getFunctionAttributes,
__traits(getMember, A, mem);
enum _isConst2 = funcAttributes.has("const");
enum _isRef2 = funcAttributes.has("ref");
}
static if(_isConst && _isRef){}
else static if(_isRef){}
else static if(_isConst){}
}
}
```
I don't know much about the compilers, but I believe that having
some way to store those intermediary steps better than generating
a mixin(CTFEForTheMixinCode), and remembering what Feep said
about creating template functions completely within itself by
making cache (such as using is() instead of isPointer!T) would be
made a lot easier to do.
More information about the Digitalmars-d
mailing list