Title
`std::nullopt_t` should be comparable
Status
new
Section
[optional.nullopt]
Submitter
Barry Revzin

Created on 2025-12-21.00:00:00 last changed 1 week ago

Messages

Date: 2025-12-21.00:00:00

`std::nullopt_t` currently has no comparison operators. This prevents perfectly reasonable code from working, like `ranges::find(v, nullopt)` where `v` is a vector<optional<T>>, for no good reason.

Additionally, optional<T> has the full set of comparisons. But optional<T> is conceptually a variant<nullopt_t, T>, which wouldn't be comparable... because of `nullopt_t`. Other empty types like tuple<> and `monostate` are also comparable.

Proposed resolution: Add a defaulted member operator<=> to `nullopt_t`.

History
Date User Action Args
2025-12-21 00:00:00admincreate