|
|
Member functions | ||||
Observers | ||||
Iterators | ||||
(C++26) | ||||
(C++26) | ||||
Monadic operations | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
Modifiers | ||||
Non-member functions | ||||
operator==operator!=operator<operator<=operator>operator>=operator<=> (C++20) | ||||
Deduction guides | ||||
Helper classes | ||||
Helper objects | ||||
Defined in header <optional> | ||
Compare two optional objects | ||
template<class T,class U> constexprbool operator==(const optional<T>& lhs,const optional<U>& rhs); | (1) | (since C++17) |
template<class T,class U> constexprbool operator!=(const optional<T>& lhs,const optional<U>& rhs); | (2) | (since C++17) |
template<class T,class U> constexprbool operator<(const optional<T>& lhs,const optional<U>& rhs); | (3) | (since C++17) |
template<class T,class U> constexprbool operator<=(const optional<T>& lhs,const optional<U>& rhs); | (4) | (since C++17) |
template<class T,class U> constexprbool operator>(const optional<T>& lhs,const optional<U>& rhs); | (5) | (since C++17) |
template<class T,class U> constexprbool operator>=(const optional<T>& lhs,const optional<U>& rhs); | (6) | (since C++17) |
template<class T,std::three_way_comparable_with<T> U> constexprstd::compare_three_way_result_t<T, U> | (7) | (since C++20) |
Compare an optional object with anullopt | ||
template<class T> constexprbool operator==(const optional<T>& opt,std::nullopt_t)noexcept; | (8) | (since C++17) |
template<class T> constexprbool operator==(std::nullopt_t,const optional<T>& opt)noexcept; | (9) | (since C++17) (until C++20) |
template<class T> constexprbool operator!=(const optional<T>& opt,std::nullopt_t)noexcept; | (10) | (since C++17) (until C++20) |
template<class T> constexprbool operator!=(std::nullopt_t,const optional<T>& opt)noexcept; | (11) | (since C++17) (until C++20) |
template<class T> constexprbool operator<(const optional<T>& opt,std::nullopt_t)noexcept; | (12) | (since C++17) (until C++20) |
template<class T> constexprbool operator<(std::nullopt_t,const optional<T>& opt)noexcept; | (13) | (since C++17) (until C++20) |
template<class T> constexprbool operator<=(const optional<T>& opt,std::nullopt_t)noexcept; | (14) | (since C++17) (until C++20) |
template<class T> constexprbool operator<=(std::nullopt_t,const optional<T>& opt)noexcept; | (15) | (since C++17) (until C++20) |
template<class T> constexprbool operator>(const optional<T>& opt,std::nullopt_t)noexcept; | (16) | (since C++17) (until C++20) |
template<class T> constexprbool operator>(std::nullopt_t,const optional<T>& opt)noexcept; | (17) | (since C++17) (until C++20) |
template<class T> constexprbool operator>=(const optional<T>& opt,std::nullopt_t)noexcept; | (18) | (since C++17) (until C++20) |
template<class T> constexprbool operator>=(std::nullopt_t,const optional<T>& opt)noexcept; | (19) | (since C++17) (until C++20) |
template<class T> constexprstd::strong_ordering | (20) | (since C++20) |
Compare an optional object with a value | ||
template<class T,class U> constexprbool operator==(const optional<T>& opt,const U& value); | (21) | (since C++17) |
template<class U,class T> constexprbool operator==(const U& value,const optional<T>& opt); | (22) | (since C++17) |
template<class T,class U> constexprbool operator!=(const optional<T>& opt,const U& value); | (23) | (since C++17) |
template<class U,class T> constexprbool operator!=(const U& value,const optional<T>& opt); | (24) | (since C++17) |
template<class T,class U> constexprbool operator<(const optional<T>& opt,const U& value); | (25) | (since C++17) |
template<class U,class T> constexprbool operator<(const U& value,const optional<T>& opt); | (26) | (since C++17) |
template<class T,class U> constexprbool operator<=(const optional<T>& opt,const U& value); | (27) | (since C++17) |
template<class U,class T> constexprbool operator<=(const U& value,const optional<T>& opt); | (28) | (since C++17) |
template<class T,class U> constexprbool operator>(const optional<T>& opt,const U& value); | (29) | (since C++17) |
template<class U,class T> constexprbool operator>(const U& value,const optional<T>& opt); | (30) | (since C++17) |
template<class T,class U> constexprbool operator>=(const optional<T>& opt,const U& value); | (31) | (since C++17) |
template<class U,class T> constexprbool operator>=(const U& value,const optional<T>& opt); | (32) | (since C++17) |
template<class T,std::three_way_comparable_with<T> U> constexprstd::compare_three_way_result_t<T, U> | (33) | (since C++20) |
Performs comparison operations onoptional
objects.
optional
objects,lhs andrhs. The contained values are compared (using the corresponding operator ofT
) only if bothlhs andrhs contain values. Otherwise,If the corresponding expression*lhs @*rhs is ill-formed or its result is not convertible tobool, the program is ill-formed. | (until C++26) |
This overload participates in overload resolution only if the corresponding expression*lhs @*rhs is well-formed and its result is convertible tobool. | (since C++26) |
nullopt
. Equivalent to(1-6) when comparing to anoptional
that does not contain a value.The | (since C++20) |
T
) only ifopt contains a value. Otherwise,opt is consideredless thanvalue.If the corresponding expression*opt @ value orvalue @*opt (depending on the positions of the operands) is ill-formed or its result is not convertible tobool, the program is ill-formed. | (until C++26) |
This overload participates in overload resolution only if all following conditions are satisfied:
| (since C++26) |
Contents |
lhs, rhs, opt | - | anoptional object to compare |
value | - | value to compare to the contained value |
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_constrained_equality | 202403L | (C++26) | constrained comparison operators forstd::optional |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2945 | C++17 | order of template parameters inconsistent for compare-with-T cases | made consistent |