On Wed, Jan 24, 2024 at 11:13 AM Jonathan Wakely via Std-Proposals <std-proposals@lists.isocpp.org> wrote:


On Wed, 24 Jan 2024 at 15:37, Jan Schultke via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
This has already been proposed in P1046: Automatically Generate More
Operators, although with explicit = default. It didn't go further than
allowing defaulting ->.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1046r2.html

I like the idea, but a strong reason against it is that you can also
default operator++(int) in terms of operator+, with no prefix
increment involved. You'd have to make a very strong case for
hardcoding a specific implementation in the core language instead of
letting the user decide.

Doing it that way is only valid for random access iterators (or more precisely, ones which provide operator+ which usually means random access) and is vanishingly rare in my experience. I would have no problem whatsoever saying that the default definition does the obvious thing, and if you want to define it differently you just have to write it by hand.

Also, the implementation that calls operator+ is extremely unlikely to ever be preferable to the one that uses prefix operator++. You have to make a copy in both cases.
 

--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals


--
Brian Bi