Extend the call site default argument expansion mechanism?

jmh530 john.michael.hall at gmail.com
Tue May 15 15:02:36 UTC 2018


On Tuesday, 15 May 2018 at 14:52:46 UTC, Steven Schveighoffer 
wrote:
> [snip]
>
> It seems opDispatch isn't being used in the with statement. 
> That seems like a bug, or maybe a limitation. I'm not sure how 
> "with" works, but I assumed it would try calling as a member, 
> and then if it doesn't work, try the call normally. Probably 
> it's checking to see if it has that member first.
>
> Annoying...
>
> -Steve

Looks like with statements ignore opDispatch.

struct Foo(int x)
{
     auto opDispatch(string s)()
         if (s == "bar")
     {
         return x++;
     }
}


void main()
{
     int y = 0;
     with(Foo!1)
     {
         y = bar; //error: undefined identifier bar
     }
     assert(y == 2);
}


More information about the Digitalmars-d mailing list