C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Unary operator | (absolute value of)

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 23 Nov 2023 21:03:30 -0500
On Thu, Nov 23, 2023 at 7:13 PM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Thursday, 23 November 2023 14:43:55 PST Rik van der Brugghen via Std-
> Proposals wrote:
> > Hi.
> >
> > Maybe suggested before, but would be great with
> >
> > a = |b; // a = abs (b)
> >
>
> And since we *have* abs(), how often do we need this? Adding an operator to
> the language is a VERY high bar, there must be a strong reason for this. What
> would it allow one to do that can't be done with the library as it is?
>
> Operator <=> is the only operator we've added since C++ was first standardised.
> It was added because the three-way comparison needed to be a language feature
> so we could have the other relational operators synthesised from it, otherwise
> we could have simply done with a library solution with extension points.

To be completely fair, there are two other operators. The user-defined
literal operator and `operator co_await`. But your point is otherwise
valid, as at least some parts of these are things that have to be part
of the language.

Received on 2023-11-24 02:03:54