CT filtering of class members

Sjoerd Nijboer dlang at sjoerdnijboer.com
Sun Aug 11 18:59:30 UTC 2019


On Sunday, 11 August 2019 at 16:32:20 UTC, Simen Kjærås wrote:
> [...] Something like this:
>
>     import std.meta : Filter;
>     import std.traits : isFunction;
>     import std.algorithm.searching : canFind;
>
>     enum isNonspecialMemberFunction(string name) = 
> !ctorAndDtor.canFind(name) &&
>                                        
> isFunction!(__traits(getMember, T, name));
>     enum memberFunctions = Filter!(isNonspecialMemberFunction, 
> __traits(derivedMembers, T));
>
> Filter operates on AliasSeqs, not arrays. That's why I restated 
> the __traits(derivedMembers, T) part, but this could just as 
> easily be done by changing this line:
>
>     enum members = [__traits(derivedMembers, T)];
>
> to:
>
>     alias members = __traits(derivedMembers, T);
>
> --
>   Simen

Works beautiful, thank you very much!



More information about the Digitalmars-d-learn mailing list