C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Should postfix increment and decrement operators be automatically obtainable from their prefix versions?

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 24 Jan 2024 16:12:10 +0000
On Wed, 24 Jan 2024 at 15:37, Jan Schultke via Std-Proposals <
std-proposals_at_[hidden]> 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.

Received on 2024-01-24 16:13:26