Remove stuff from a template mixin

Gorge Jingale via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 26 17:55:00 PDT 2016


On Tuesday, 26 July 2016 at 22:23:37 UTC, Jerry wrote:
> On Tuesday, 26 July 2016 at 19:02:32 UTC, Gorge Jingale wrote:
>> I might want to actually use Add internally in B so I can add 
>> some elements behind the scenes, I do not want to expose it to 
>> the outside world though.
>
> There are no way to remove things from an template directly. 
> But you could however generate a new type which does not carry 
> the specified members.
>
> This requires two steps:
> *The member filtering part
> *Generation part
>
> For the masking part take a look at
> https://forum.dlang.org/post/nn8gj8$6s5$1@digitalmars.com
>
> What you basicly do is that you iterate the members and based 
> on some condition filters out the members you don't want.
>
> Then for generating you have to handle functions and fields.
> For fields a string concatenated with other strings fields is 
> probably good enough.
> Something like this:
>      "typeof(" ~ fullyQualifiedName!Aggregate ~ "." ~ 
> memberName ~ ") " ~ member;"

That seems like a lot of work just to remove some elements. 
Creating a whole new template. I think using additive composition 
would be easier and more directly(a few lines of code to split 
the template), and I guess is the more natural way.


More information about the Digitalmars-d-learn mailing list