Trying to forward unwrapped opDispatch names to alias this

aliak something at something.com
Mon Feb 19 08:28:22 UTC 2018


On Monday, 19 February 2018 at 01:00:23 UTC, Adam D. Ruppe wrote:
> On Monday, 19 February 2018 at 00:42:05 UTC, aliak wrote:
>> struct B(T) {
>>     T t;
>>     A a;
>>     alias a this;
>>     auto opDispatch(string name)() if (hasMember!(T, name)) {
>>         return mixin("t." ~ name);
>
> Did you perhaps mean `A` instead of `T` here? cuz in your code 
> T is int, not the struct.

I don't think I did :p

T is the wrapped type. So if T has a member (in the example it's 
the built in field "max") then forward that. If member not there 
then I figured the alias this would be used. I.e. in the example 
b.p should call A.p.

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.


More information about the Digitalmars-d-learn mailing list