Re: Not allowed to globally overload operators?

2021-07-20 Thread Tejas via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 18:32:26 UTC, Ali Çehreli wrote: On 7/19/21 11:20 PM, Tejas wrote: > trying to create the spaceship operator of C++ Just to make sure, D's opCmp returns an int. That new C++ operator was added to provide the same semantics. Ali I know. As I already mentioned, I

Re: Not allowed to globally overload operators?

2021-07-20 Thread Ali Çehreli via Digitalmars-d-learn
On 7/20/21 11:49 AM, H. S. Teoh wrote: > On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: >> On 7/19/21 11:20 PM, Tejas wrote: >> >>> trying to create the spaceship operator of C++ >> >> Just to make sure, D's opCmp returns an int. That new C++ operator was >

Re: Not allowed to globally overload operators?

2021-07-20 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 18:49:07 UTC, H. S. Teoh wrote: On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 7/19/21 11:20 PM, Tejas wrote: > trying to create the spaceship operator of C++ Just to make sure, D's opCmp returns an int. That new C++ operato

Re: Not allowed to globally overload operators?

2021-07-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 7/19/21 11:20 PM, Tejas wrote: > > > trying to create the spaceship operator of C++ > > Just to make sure, D's opCmp returns an int. That new C++ operator was > added to provide the same semantics. [...] F

Re: Not allowed to globally overload operators?

2021-07-20 Thread Ali Çehreli via Digitalmars-d-learn
On 7/19/21 11:20 PM, Tejas wrote: > trying to create the spaceship operator of C++ Just to make sure, D's opCmp returns an int. That new C++ operator was added to provide the same semantics. Ali

Re: Not allowed to globally overload operators?

2021-07-19 Thread Tejas via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 06:34:45 UTC, vit wrote: On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote: ... Initially, I was trying to create the spaceship operator of C++, but we aren't allowed to create new operators ... D has spaceship operator: opCmp (https://dlang.org/spec/operator

Re: Not allowed to globally overload operators?

2021-07-19 Thread Tejas via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 06:30:56 UTC, Mike Parker wrote: On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote: Why isn't it working by default? Initially, I was trying to create the spaceship operator of C++, but we aren't allowed to create new operators, it seems. Then I just wanted to

Re: Not allowed to globally overload operators?

2021-07-19 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote: Why isn't it working by default? Initially, I was trying to create the spaceship operator of C++, but we aren't allowed to create new operators, it seems. Then I just wanted to verify whether we can even overload an operator globally, but

Re: Not allowed to globally overload operators?

2021-07-19 Thread vit via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote: ... Initially, I was trying to create the spaceship operator of C++, but we aren't allowed to create new operators ... D has spaceship operator: opCmp (https://dlang.org/spec/operatoroverloading.html#compare).

Not allowed to globally overload operators?

2021-07-19 Thread Tejas via Digitalmars-d-learn
The following doesn't work: ```d import std; int opBinary(string s:"+")(int a, int b){ int result; ab? (result = 1): (result = 0); return result; } void main(){ int f = 1 + 5; writeln(f); } ``` It outputs 6 But if I manually write it as ```d int f = opBinary!"+"(1,5); ``` It w