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 verify whether we can even overload an
operator globally, but even that seems to be failing, atleast
for me.
From the docs:
Operator overloading is accomplished by rewriting operators
whose operands are class or struct objects into calls to
specially named members.
https://dlang.org/spec/operatoroverloading.html
Note the word "members".
Ack. I remember reading the spec but have forgotten that detail
multiple times now.
See also:
https://dlang.org/articles/rationale.html#why-no-global-operator-functions
Well, this is new. **sigh** Guess I'll have to find another way
to implement spaceship then. I don't disagree with the rationale,
but it is a little inconvenient in my case.