C++ Logo


Advanced search

Re: nullptr_t and nullopt_t should both have operator<=> and operator== to enable the *_with concepts

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 8 Jul 2021 11:08:14 +0200

On 08/07/2021 07:15, Justin Bassett via Std-Proposals wrote:
> Adding relational operators to nullptr and nullopt have no harm, but let
> these types meet the *_with concepts as they should.

Thank you very much for this. Indeed singular values that are comparable
for (in)equality do already model strong_ordering, so C++ should just
reflect that in the language/library (with the provision that we don't
want to introduce things like `nullptr < ptr`). nullopt_t isn't already
comparable but it doesn't make much sense for it not to be.

Just a couple of notes:

* you may want to target EWG (as well as LEWG) as you're proposing
changes to the language;

* in some cases the changes bring us a step closer to satisfying the
comparison concepts, but still those won't be satisfied due to other
(pre-existing) issues. For instance

std::three_way_comparable_with<std::unique_ptr<X>, std::nullptr_t>

is still false/unsatisfied because `std::unique_ptr` isn't copiable.
Mut.mut. for `std::optional<some_move_only_type>` and `nullopt_t`, and
also `std::equality_comparable_with` -- all of this stems from
`std::common_reference_t`. Probably worth just adding as a note.

Thank you again,

Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2021-07-08 04:08:21