[Issue 23353] Add opCallAssign and opCallOpAssign

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 10 10:53:16 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23353

--- Comment #2 from Bolpat <qs.il.paperinik at gmail.com> ---
(In reply to RazvanN from comment #1)
> Can you provide a case where this is useful and is not achievable by the
> current semantics? If opCall returns the a struct by ref and you also define
> an opAssign that should be achievable.

It’s the same argument why properties have setter functions and why
opIndexAssign exists. Any argument carries over immediately.

> Usually, enhancement requests should be accompanied by a concrete use case
> where the lack of feature impedes a specific implementation. Otherwise, it
> is hard to make an argument for the addition of specific features.

Effectively, if obj() returns a proxy type that mimics assignment by reference
(cf. C++ std::vector<bool>::reference) that type is weird. Most importantly, it
breaks meta-programming:

    auto x = obj(a, b);

does not work as intended. It is as if it were

    auto ptr = &obj(a, b);

if opCall returned by reference and x is as if *ptr.

In the past, @safe was an issue. Probably it is solved by DIP 1000, maybe I
missed something.

--


More information about the Digitalmars-d-bugs mailing list