Getting FieldNameTuple including all base-classes.
drug
drug2004 at bk.ru
Wed May 20 09:13:07 UTC 2020
On 5/20/20 12:03 PM, realhet wrote:
> On Wednesday, 20 May 2020 at 01:18:24 UTC, Paul Backus wrote:
>> On Tuesday, 19 May 2020 at 23:15:45 UTC, realhet wrote:
>> I think what you want is `std.meta.staticMap`. Something like this:
>>
>> alias FieldNameTuple2(T) = staticMap!(FieldNameTuple,
>> BaseClassesTuple!T);
>
> class A { int a, a1; }
> class B : A { int b; }
> class C : B { int c, c1; }
>
> alias AllClasses(T) = Reverse!(AliasSeq!(T, BaseClassesTuple!T[0..$-1]));
> alias AllFieldNames(T) = staticMap!(FieldNameTuple, AllClasses!T);
>
> void main(){
> static foreach(T; "ABC") mixin("AllFieldNames!"~T~".stringof.writeln;");
> }
>
> That statticMap unlike the normal map, it also joins the AliasSeq at the
> end. Just what I needed.
>
> Thank You!
Just in case - you can avoid mixin using:
```D
static foreach(T; AliasSeq!(A, B, C))
AllFieldNames!T.stringof.writeln;
```
https://run.dlang.io/is/Q6omgL
More information about the Digitalmars-d-learn
mailing list