C++ Logo

std-proposals

Advanced search

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

From: Justin Bassett <jbassett271_at_[hidden]>
Date: Wed, 7 Jul 2021 22:15:40 -0700
Hello,

Please see the attached proposal. The abstract makes a good summary:

nullopt_t can be three-way compared to optional. However, because there is
> no operator<=> or operator== between nullopt_ts, optional is not
> *comparison_relation*_with nullopt_t where *comparison_relation*_with is
> any of equality_comparable_with, totally_ordered_with, or
> three_way_comparable_with. Adding a trivial operator<=> for nullopt_t
> allows *comparison_relation*_with to support optional + nullopt_t. The
> same holds true with nullptr_t and unique_ptr<T> and shared_ptr<T>.
>

To expand a little bit more, in isolation, relational operators for nullptr
and nullopt can easily be made, but they would have no use. However, when
considered in the context of smart_ptr<T> and optional<T> respectively, the
cross-type relations operator@(foo<T>, nullfoo_t)s need operator@(foo<T>,
foo<T>) and also operator@(nullfoo_t, nullfoo_t) before we can meet the
respective *_with concept. Adding relational operators to nullptr and
nullopt have no harm, but let these types meet the *_with concepts as they
should.

Thanks,
Justin Bassett

Received on 2021-07-08 00:15:59