operator==, !=, <, <=, >, >=, <=>(std::optional)
| Definiert in der Header-Datei <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> |
(7) | (seit C++20) |
| Vergleiche ein optional-Objekt mit 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 |
(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> |
(33) | (seit C++20) |
Führt Vergleichsoperationen auf optional-Objekten aus.
optional-Objekte, lhs und rhs. Die enthaltenen Werte werden (mittels des entsprechenden Operators von T) verglichen, nur wenn sowohl lhs als auch rhs Werte enthalten. Andernfalls gilt:- lhs ist *gleich* rhs genau dann, wenn weder lhs noch rhs einen Wert enthalten.
- lhs ist *kleiner als* rhs genau dann, wenn rhs einen Wert enthält und lhs nicht.
|
Wenn der entsprechende Ausdruck *lhs @ *rhs ill-formed ist oder sein Ergebnis nicht in bool konvertierbar ist, ist das Programm ill-formed. |
(bis C++26) |
|
Diese Überladung nimmt nur an der Overload-Auflösung teil, wenn der entsprechende Ausdruck *lhs @ *rhs gut gebildet ist und sein Ergebnis in bool konvertierbar ist. |
(seit C++26) |
nullopt. Äquivalent zu (1-6), wenn mit einem optional verglichen wird, das keinen Wert enthält.|
Die Operatoren |
(seit C++20) |
T) verglichen, nur wenn opt einen Wert enthält. Andernfalls gilt opt als *kleiner als* value.|
Wenn der entsprechende Ausdruck *opt @ value oder value @ *opt (je nach Position der Operanden) ill-formed ist oder sein Ergebnis nicht in bool konvertierbar ist, ist das Programm ill-formed. |
(bis C++26) |
|
Dieser Überladung nimmt nur an der Überladungsauflösung teil, wenn alle folgenden Bedingungen erfüllt sind:
|
(seit C++26) |
Inhalt |
[bearbeiten] Parameter
| lhs, rhs, opt | - | ein zu vergleichendes optional-Objekt |
| value | - | ein Wert, mit dem der enthaltene Wert verglichen wird |
[bearbeiten] Rückgabewert
(lhs.has_value() == false ? true : *lhs == *rhs)
(lhs.has_value() == false ? false : *lhs != *rhs)
[bearbeiten] Ausnahmen
[bearbeiten] Hinweise
| Feature-Test-Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_constrained_equality |
202403L |
(C++26) | beschränkte Vergleichsoperatoren für std::optional |
[bearbeiten] Fehlerberichte
Die folgenden Verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | angewendet auf | Verhalten wie veröffentlicht | Korrigiertes Verhalten |
|---|---|---|---|
| LWG 2945 | C++17 | Reihenfolge der Template-Parameter inkonsistent für compare-with-T-Fälle | konsistent gemacht |