Three‐way comparison operators

Synopses

Declared in <beman/optional/optional.hpp>

Compares two nullopt_t objects.

constexpr
std::strong_ordering
operator<=>(
    nullopt_t lhs,
    nullopt_t rhs) noexcept;

Three‐way comparison of two optionals.

template<
    typename T,
    std::three_way_comparable_with<T> U>
constexpr
std::compare_three_way_result_t<T, U>
operator<=>(
    optional<T> const& lhs,
    optional<U> const& rhs);

Three‐way comparison of an optional against nullopt.

template<class T>
constexpr
std::strong_ordering
operator<=>(
    optional<T> const& lhs,
    nullopt_t rhs) noexcept;

Three‐way comparison of an optional against a value.

template<
    typename T,
    typename U>
requires (!is_derived_from_optional<U>) && std::three_way_comparable_with<T, U>
constexpr
std::compare_three_way_result_t<T, U>
operator<=>(
    optional<T> const& x,
    U const& v);

Return Value

  • Always std::strong_ordering::equivalent, since all nullopt_t objects compare equal.

  • The comparison category; a disengaged optional orders before any engaged one.

  • equivalent if lhs is disengaged, otherwise greater.

  • The comparison category; a disengaged optional orders before v.

Parameters

Name

Description

lhs

The left‐hand nullopt_t object.

rhs

The right‐hand nullopt_t object.

x

The optional operand.

v

The value operand.

Created with MrDocs