Trying to forward unwrapped opDispatch names to alias this

aliak something at something.com
Tue Feb 20 16:31:30 UTC 2018


On Tuesday, 20 February 2018 at 16:12:17 UTC, Adam D. Ruppe wrote:
> On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote:
>> T is the wrapped type. So if T has a member (in the example 
>> it's the built in field "max") then forward that.
>
> Oh, I see what you mean.
>
> So the problem is that built in types don't have "members" per 
> se, they have "magic". The built in properties don't count to 
> `hasMember`. You could probably do `if(__traits(compiles, 
> mixin("a." ~ member))` though.
>
>> I assume this should work because rules for alias this (as I 
>> understand) are to basically try if there's a member name that 
>> resolves the call, else forward to alias this.
>
> yeah, just built in properties/members don't pass the same 
> existence checks so that's confusing your template constraint.

I believe the same happens if it's not a built in property. You 
can replace B!int with B!S and have S contains a function "f" 
(for instance), then whether or the not constraint on opDispatch 
is:

__traits(compiles, mixin("t." ~ name))
or
hasMember(T, name)

You still get:

b.p.writeln; // Error: no property 'p' for type 'B!(S)'




More information about the Digitalmars-d-learn mailing list