Namensräume
Varianten
Aktionen

operator==, !=, <, <=, >, >=(std::experimental::optional)

Von cppreference.com
 
 
 
 
 
Definiert im Header <experimental/optional>
Vergleicht zwei optional Objekte
template< class T >
constexpr bool operator==( const optional<T>& lhs, const optional<T>& rhs );
(1) (library fundamentals TS)
template< class T >
constexpr bool operator!=( const optional<T>& lhs, const optional<T>& rhs );
(2) (library fundamentals TS)
template< class T >
constexpr bool operator<( const optional<T>& lhs, const optional<T>& rhs );
(3) (library fundamentals TS)
template< class T >
constexpr bool operator<=( const optional<T>& lhs, const optional<T>& rhs );
(4) (library fundamentals TS)
template< class T >
constexpr bool operator>( const optional<T>& lhs, const optional<T>& rhs );
(5) (library fundamentals TS)
template< class T >
constexpr bool operator>=( const optional<T>& lhs, const optional<T>& rhs );
(6) (library fundamentals TS)
Vergleicht ein optional Objekt mit nullopt
template< class T >
constexpr bool operator==( const optional<T>& opt, std::nullopt_t ) noexcept;
(7) (library fundamentals TS)
template< class T >
constexpr bool operator==( std::nullopt_t, const optional<T>& opt ) noexcept;
(8) (library fundamentals TS)
template< class T >
constexpr bool operator!=( const optional<T>& opt, std::nullopt_t ) noexcept;
(9) (library fundamentals TS)
template< class T >
constexpr bool operator!=( std::nullopt_t, const optional<T>& opt ) noexcept;
(10) (library fundamentals TS)
template< class T >
constexpr bool operator<( const optional<T>& opt, std::nullopt_t ) noexcept;
(11) (library fundamentals TS)
template< class T >
constexpr bool operator<( std::nullopt_t, const optional<T>& opt ) noexcept;
(12) (library fundamentals TS)
template< class T >
constexpr bool operator<=( const optional<T>& opt, std::nullopt_t ) noexcept;
(13) (library fundamentals TS)
template< class T >
constexpr bool operator<=( std::nullopt_t, const optional<T>& opt ) noexcept;
(14) (library fundamentals TS)
template< class T >
constexpr bool operator>( const optional<T>& opt, std::nullopt_t ) noexcept;
(15) (library fundamentals TS)
template< class T >
constexpr bool operator>( std::nullopt_t, const optional<T>& opt ) noexcept;
(16) (library fundamentals TS)
template< class T >
constexpr bool operator>=( const optional<T>& opt, std::nullopt_t ) noexcept;
(17) (library fundamentals TS)
template< class T >
constexpr bool operator>=( std::nullopt_t, const optional<T>& opt ) noexcept;
(18) (library fundamentals TS)
Vergleicht ein optional Objekt mit einem T
template< class T >
constexpr bool operator==( const optional<T>& opt, const T& value );
(19) (library fundamentals TS)
template< class T >
constexpr bool operator==( const T& value, const optional<T>& opt );
(20) (library fundamentals TS)
template< class T >
constexpr bool operator!=( const optional<T>& opt, const T& value );
(21) (library fundamentals TS)
template< class T >
constexpr bool operator!=( const T& value, const optional<T>& opt );
(22) (library fundamentals TS)
template< class T >
constexpr bool operator<( const optional<T>& opt, const T& value );
(23) (library fundamentals TS)
template< class T >
constexpr bool operator<( const T& value, const optional<T>& opt );
(24) (library fundamentals TS)
template< class T >
constexpr bool operator<=( const optional<T>& opt, const T& value );
(25) (library fundamentals TS)
template< class T >
constexpr bool operator<=( const T& value, const optional<T>& opt );
(26) (library fundamentals TS)
template< class T >
constexpr bool operator>( const optional<T>& opt, const T& value );
(27) (library fundamentals TS)
template< class T >
constexpr bool operator>( const T& value, const optional<T>& opt );
(28) (library fundamentals TS)
template< class T >
constexpr bool operator>=( const optional<T>& opt, const T& value );
(29) (library fundamentals TS)
template< class T >
constexpr bool operator>=( const T& value, const optional<T>& opt );
(30) (library fundamentals TS)

Führt Vergleichsoperationen für optional Objekte durch.

1-6) Vergleicht zwei optional Objekte, lhs und rhs. Die enthaltenen Werte werden verglichen (mithilfe von operator== für (1,2) und operator< für (3-6)), nur wenn sowohl lhs als auch rhs Werte enthalten. Andernfalls,
  • lhs ist *gleich* rhs genau dann, wenn weder lhs noch rhs einen Wert enthalten.
  • lhs wird als *kleiner als* rhs betrachtet, wenn und nur wenn rhs einen Wert enthält und lhs dies nicht tut.
7-18) Vergleicht opt mit einem nullopt. Äquivalent zu (1-6) beim Vergleichen mit einem optional, das keinen Wert enthält.
19-30) Vergleicht opt mit einem value. Die Werte werden verglichen (mithilfe von operator== für (19-22) und operator< für (23-30)), nur wenn opt einen Wert enthält. Andernfalls wird opt als *kleiner als* value betrachtet.

[edit] Parameter

lhs, rhs, opt - ein zu vergleichendes optional Objekt
value - zu vergleichender Wert für den enthaltenen Wert
Typanforderungen
-
T muss die Anforderungen von EqualityComparable erfüllen, um Überladungen (1,2) zu verwenden.

[edit] Rückgabewert

1) Wenn bool(lhs) != bool(rhs), gibt false zurück.
Andernfalls, wenn bool(lhs) == false (und somit auch bool(rhs) == false), gibt true zurück.
Andernfalls gibt *lhs == *rhs zurück.
2) Gibt !(lhs == rhs) zurück.
3) Wenn bool(rhs) == false gibt false zurück.
Andernfalls, wenn bool(lhs) == false, gibt true zurück.
Andernfalls gibt *x < *y zurück.
4) Gibt !(rhs < lhs) zurück.
5) Gibt rhs < lhs zurück.
6) Gibt !(lhs < rhs) zurück.
7,8) Gibt !opt zurück.
9,10) Gibt bool(opt) zurück.
11) Gibt false zurück.
12) Gibt bool(opt) zurück.
13) Gibt !opt zurück.
14) Gibt true zurück.
15) Gibt bool(opt) zurück.
16) Gibt false zurück.
17) Gibt true zurück.
18) Gibt !opt zurück.
19) Gibt bool(opt) ? *opt == value : false zurück.
20) Gibt bool(opt) ? value == *opt : false zurück.
21) Gibt bool(opt) ? !(*opt == value) : true zurück.
22) Gibt bool(opt) ? !(value == *opt) : true zurück.
23) Gibt bool(opt) ? *opt < value : true zurück.
24) Gibt bool(opt) ? value < *opt : false zurück.
25) Gibt !(opt > value) zurück.
26) Gibt !(value > opt) zurück.
27) Gibt bool(opt) ? value < *opt : false zurück.
28) Gibt bool(opt) ? *opt < value : true zurück.
29) Gibt !(opt < value) zurück.
30) Gibt !(value < opt) zurück.

[edit] Ausnahmen

1-6) (keine)
19-30) (keine)