operator==, !=, <, <=, >, >=, <=>(std::optional)
| Definiert in Header <optional>
|
||
| Vergleiche zwei optional-Objekte |
||
template< class T, class U >
constexpr bool operator==( const optional<T>& lhs, const optional<U>& rhs );
|
(1) | (seit C++17) |
template< class T, class U >
constexpr bool operator!=( const optional<T>& lhs, const optional<U>& rhs );
|
(2) | (seit C++17) |
template< class T, class U >
constexpr bool operator<( const optional<T>& lhs, const optional<U>& rhs );
|
(3) | (seit C++17) |
template< class T, class U >
constexpr bool operator<=( const optional<T>& lhs, const optional<U>& rhs );
|
(4) | (seit C++17) |
template< class T, class U >
constexpr bool operator>( const optional<T>& lhs, const optional<U>& rhs );
|
(5) | (seit C++17) |
template< class T, class U >
constexpr bool operator>=( const optional<T>& lhs, const optional<U>& rhs );
|
(6) | (seit C++17) |
template< class T, std::three_way_comparable_with<T> U >
constexpr std::compare_three_way_result_t<T, U>
operator<=>( const optional<T>& lhs, const optional<U>& rhs );
|
(7) | (seit C++20) |
| Vergleiche ein optional-Objekt mit einem nullopt |
||
template< class T >
constexpr bool operator==( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(8) | (seit C++17) |
template< class T >
constexpr bool operator==( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(9) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator!=( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(10) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator!=( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(11) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator<( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(12) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator<( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(13) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator<=( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(14) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator<=( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(15) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator>( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(16) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator>( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(17) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator>=( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(18) | (seit C++17) (bis C++20) |
template< class T >
constexpr bool operator>=( std::nullopt_t, const optional<T>& opt ) noexcept;
|
(19) | (seit C++17) (bis C++20) |
template< class T >
constexpr std::strong_ordering
operator<=>( const optional<T>& opt, std::nullopt_t ) noexcept;
|
(20) | (seit C++20) |
| Vergleiche ein optional-Objekt mit einem Wert |
||
template< class T, class U >
constexpr bool operator==( const optional<T>& opt, const U& value );
|
(21) | (seit C++17) |
template< class U, class T >
constexpr bool operator==( const U& value, const optional<T>& opt );
|
(22) | (seit C++17) |
template< class T, class U >
constexpr bool operator!=( const optional<T>& opt, const U& value );
|
(23) | (seit C++17) |
template< class U, class T >
constexpr bool operator!=( const U& value, const optional<T>& opt );
|
(24) | (seit C++17) |
template< class T, class U >
constexpr bool operator<( const optional<T>& opt, const U& value );
|
(25) | (seit C++17) |
template< class U, class T >
constexpr bool operator<( const U& value, const optional<T>& opt );
|
(26) | (seit C++17) |
template< class T, class U >
constexpr bool operator<=( const optional<T>& opt, const U& value );
|
(27) | (seit C++17) |
template< class U, class T >
constexpr bool operator<=( const U& value, const optional<T>& opt );
|
(28) | (seit C++17) |
template< class T, class U >
constexpr bool operator>( const optional<T>& opt, const U& value );
|
(29) | (seit C++17) |
template< class U, class T >
constexpr bool operator>( const U& value, const optional<T>& opt );
|
(30) | (seit C++17) |
template< class T, class U >
constexpr bool operator>=( const optional<T>& opt, const U& value );
|
(31) | (seit C++17) |
template< class U, class T >
constexpr bool operator>=( const U& value, const optional<T>& opt );
|
(32) | (seit C++17) |
template< class T, std::three_way_comparable_with<T> U >
constexpr std::compare_three_way_result_t<T, U>
operator<=>( const optional<T>& opt, const U& value );
|
(33) | (seit C++20) |
Führt Vergleichsoperationen auf optional-Objekten durch.
optional-Objekte, lhs und rhs. Die enthaltenen Werte werden verglichen (unter Verwendung des entsprechenden Operators von T) nur wenn sowohl lhs als auch rhs Werte enthalten. Andernfalls
wird lhsals gleich zurhsbetrachtet, genau dann, wenn beidelhsundrhskeinen Wert enthalten.lhswird als kleiner alsrhsbetrachtet, genau dann, wennrhseinen Wert enthält undlhsnicht.
@ den entsprechenden Vergleichsoperator für jede dieser Funktionen:
|
Falls der entsprechende Ausdruck |
(bis C++26) |
|
Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn der entsprechende Ausdruck |
(seit C++26) |
opt mit einem nullopt. Äquivalent zu (1-6) beim Vergleich mit einem optional, das keinen Wert enthält.
|
Die Operatoren |
(seit C++20) |
opt mit einem value. Die Werte werden verglichen (unter Verwendung des entsprechenden Operators von T) nur wenn opt einen Wert enthält. Andernfalls wird opt als kleiner als value betrachtet.@ den entsprechenden Vergleichsoperator für jede dieser Funktionen:
|
Falls der entsprechende Ausdruck |
(bis C++26) |
|
Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn alle folgenden Bedingungen erfüllt sind:
|
(seit C++26) |
Parameter
| lhs, rhs, opt | - |
ein
optional
Objekt zum Vergleichen
|
| value | - | Wert zum Vergleich mit dem enthaltenen Wert |
Rückgabewert
( lhs. has_value ( ) == false ? true : * lhs == * rhs )
( lhs. has_value ( ) == false ? false : * lhs ! = * rhs )
Exceptions
Hinweise
| Feature-Test Makro | Wert | Std | Funktion |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | Eingeschränkte Vergleichsoperatoren für std::optional |
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrektes Verhalten |
|---|---|---|---|
| LWG 2945 | C++17 | Reihenfolge der Template-Parameter inkonsistent für Compare-with-T-Fälle | konsistent gemacht |