On Monday, 19 February 2018 at 08:28:22 UTC, aliak wrote:
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.

There is a related ticket,
However, not exactly facing this question.

It seems, that currently opDispatch replaces alias this... (?)
Nevertheless, not only T is the wrapped type, but also A with the alias. What to do, if both members have a property with the same name? And why?

Reply via email to