digitalmars.D - UFCS and operator overloading
- Jens Mueller (15/15) May 07 2012 Hi,
- Nick Sabalausky (8/24) May 07 2012 I don't know why that doesn't work (unless you just need to make it "aut...
- Gor Gyolchanyan (9/39) May 07 2012 Still, not having non-member operator overloads is very bothersome.
- Timon Gehr (4/34) May 08 2012 a + b => a.opBinary!"+"(b) => opBinary!"+"(a, b)
- Jens Mueller (3/44) May 08 2012 Yes. That's how it should be. I reported it.
- Nick Sabalausky (4/22) May 08 2012 /facepalm
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
May 07 2012
"Jens Mueller" <jens.k.mueller gmx.de> wrote in message news:mailman.391.1336410464.24740.digitalmars-d puremagic.com...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? JensI 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)
May 07 2012
Still, not having non-member operator overloads is very bothersome. On Tue, May 8, 2012 at 12:37 AM, Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> wrote:"Jens Mueller" <jens.k.mueller gmx.de> wrote in message news:mailman.391.1336410464.24740.digitalmars-d puremagic.com....Hi, from my understanding UFCS is supposed to work with operator overloading=cI.e. in the following a + b should work struct Foo {} Foo opBinary(string op)(Foo lhs, Foo rhs) if (op =3D=3D "+") { =C2=A0 =C2=A0return Foo.init; } unittest { =C2=A0 =C2=A0Foo a, b; =C2=A0 =C2=A0a + b; // fails to compile } Is UFCS supposed to work with operator overloading, isn't it? JensI don't know why that doesn't work (unless you just need to make it "auto==3D a + b;" so it isn't a "statement has no effect"?), but FWIW that's no=t anexample of UFCS. UFCS would mean calling your opBinary above like this: a.opBinary!"+"(b) Instead of this: opBinary!"+"(a, b)--=20 Bye, Gor Gyolchanyan.
May 07 2012
On 05/07/2012 10:37 PM, Nick Sabalausky wrote:"Jens Mueller"<jens.k.mueller gmx.de> wrote in message news:mailman.391.1336410464.24740.digitalmars-d puremagic.com...a + b => a.opBinary!"+"(b) => opBinary!"+"(a, b) ^ ^ standard rewrite UFCSHi, 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? JensI 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)
May 08 2012
Timon Gehr wrote:On 05/07/2012 10:37 PM, Nick Sabalausky wrote:Yes. That's how it should be. I reported it. Jens"Jens Mueller"<jens.k.mueller gmx.de> wrote in message news:mailman.391.1336410464.24740.digitalmars-d puremagic.com...a + b => a.opBinary!"+"(b) => opBinary!"+"(a, b) ^ ^ standard rewrite UFCSHi, 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? JensI 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)
May 08 2012
"Timon Gehr" <timon.gehr gmx.ch> wrote in message news:jobo5r$1cf7$1 digitalmars.com...On 05/07/2012 10:37 PM, Nick Sabalausky wrote:/facepalm Yea, I get it now ;)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
May 08 2012