On 05/07/2012 10:37 PM, Nick Sabalausky wrote:
"Jens Mueller"<[email protected]>  wrote in message
news:[email protected]...
Hi,

from my understanding UFCS is supposed to work with operator overloading.
I.e.
in the following a + b should work

struct Foo {}

Foo opBinary(string op)(Foo lhs, Foo rhs) if (op == "+")
{
    return Foo.init;
}

unittest
{
    Foo a, b;
    a + b; // fails to compile
}

Is UFCS supposed to work with operator overloading, isn't it?

Jens

I don't know why that doesn't work (unless you just need to make it "auto c
= a + b;" so it isn't a "statement has no effect"?), but FWIW that's not an
example of UFCS. UFCS would mean calling your opBinary above like this:

a.opBinary!"+"(b)

Instead of this:

opBinary!"+"(a, b)



 a + b => a.opBinary!"+"(b) => opBinary!"+"(a, b)
       ^                    ^
standard rewrite           UFCS

Reply via email to