opDispatch and UFCS

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 11 17:30:27 PDT 2016


On Thursday, 12 May 2016 at 00:04:43 UTC, Adam D. Ruppe wrote:
> On Wednesday, 11 May 2016 at 23:46:48 UTC, John Colvin wrote:
>> Bug? Or am I misunderstanding how these two features are 
>> supposed to interact?
>
> I'm not sure what you actually expected there, but I'd note 
> that in general, opDispatch will always be preferred over UFCS, 
> just like any other member access, so if you have an 
> unrestricted opDispatch, you basically disable ufcs on the type.

I think I was hoping that the opDispatch wouldn't compile in the 
second case and it would therefore fail-over to UFCS.

std.typecons.Proxy (and therefore Typedef) seems to get around 
this:

import std.typecons;

alias Blah = Typedef!(int);

void foo(Blah a){}

void main()
{
	Blah.init.foo;
}

work fine.


More information about the Digitalmars-d-learn mailing list