study: use checkedint as a drop-in replacement of native long
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Mar 24 17:38:14 UTC 2021
On Wed, Mar 24, 2021 at 05:23:00PM +0000, Q. Schroll via Digitalmars-d wrote:
> On Tuesday, 18 August 2020 at 01:23:01 UTC, Andrei Alexandrescu wrote:
> > Requiring user-defined assignment to `return *this;` was goofy in C++.
> > Requiring user-defined assignment to `return this;` is goofy in D.
> > Assignment should return void and the compiler should take care of it.
>
> Do you mean the compiler should take care of returning *this when
> opAssign returns void? Because there are some use-cases for opAssign
> to return something different than `this`, but I cannot remember at
> the moment what it was. It's a niche case.
I think Andrei meant that opAssign should *always* return void, and the
compiler should always automatically make the RHS of `a = b;` its value.
More precisely:
struct S { ... }
S a, b, c;
return a = b = c;
should be lowered to:
struct S { ... }
S a, b, c;
b.opAssign(c);
a.opAssign(b);
return a;
Having the value of `a = b` return anything other than the RHS of the
assignment is goofy semantics. Since there is only one sensible meaning
of `a = b = c`, the compiler should just automate it instead of
requiring the user to restate the obvious (and potentially making a
mistake or introducing goofy semantics that hurt the readability /
maintainability of the resulting code).
T
--
If you're not part of the solution, you're part of the precipitate.
More information about the Digitalmars-d
mailing list