operator==, !=, <, <=, >, >=, <=> (std::optional)
|
Definiert im 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
>
|
(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
|
(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 nur dann verglichen (unter Verwendung des entsprechenden Operators von
T
), wenn sowohl
lhs
als auch
rhs
Werte enthalten. Andernfalls gilt:
- lhs wird als gleich rhs betrachtet, genau dann, wenn sowohl lhs als auch rhs keinen Wert enthalten.
- lhs wird als kleiner als rhs betrachtet, genau dann, wenn rhs einen Wert enthält und lhs keinen.
|
Falls der entsprechende Ausdruck * lhs @ * rhs ungültig ist oder sein Ergebnis nicht in bool konvertierbar ist, ist das Programm ungültig. |
(bis C++26) |
|
Diese Überladung nimmt nur an der Überladungsauflösung teil, wenn der entsprechende Ausdruck * lhs @ * rhs gültig ist und sein Ergebnis in bool konvertierbar ist. |
(seit C++26) |
nullopt
. Entspricht
(1-6)
beim Vergleich mit einem
optional
, das keinen Wert enthält.
|
Die
|
(since C++20) |
T
), wenn
opt
einen Wert enthält. Andernfalls wird
opt
als
kleiner als
value
betrachtet.
|
Falls der entsprechende Ausdruck * opt @ value oder value @ * opt (abhängig von der Position der Operanden) fehlerhaft ist oder sein Ergebnis nicht in bool konvertierbar ist, ist das Programm fehlerhaft. |
(bis C++26) |
|
Diese Überladung nimmt nur dann an der Überladungsauflösung teil, wenn alle folgenden Bedingungen erfüllt sind:
|
(seit C++26) |
Inhaltsverzeichnis |
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 |