operator==, !=, <, <=, >, >=, <=> (std::optional)
|
ヘッダーで定義
<optional>
|
||
|
二つの
optional
オブジェクトを比較
|
||
|
template
<
class
T,
class
U
>
constexpr bool operator == ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(1) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator ! = ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(2) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator < ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(3) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator <= ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(4) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator > ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(5) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator >= ( const optional < T > & lhs, const optional < U > & rhs ) ; |
(6) | (C++17以降) |
|
template
<
class
T,
std::
three_way_comparable_with
<
T
>
U
>
constexpr
std::
compare_three_way_result_t
<
T, U
>
|
(7) | (C++20以降) |
optional
オブジェクトと
nullopt
を比較する
|
||
|
template
<
class
T
>
constexpr bool operator == ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(8) | (C++17以降) |
|
template
<
class
T
>
constexpr bool operator == ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(9) |
(C++17以降)
(C++20以前) |
|
template
<
class
T
>
constexpr bool operator ! = ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(10) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator ! = ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(11) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator < ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(12) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator < ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(13) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator <= ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(14) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator <= ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(15) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator > ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(16) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator > ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(17) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator >= ( const optional < T > & opt, std:: nullopt_t ) noexcept ; |
(18) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr bool operator >= ( std:: nullopt_t , const optional < T > & opt ) noexcept ; |
(19) |
(C++17以降)
(C++20まで) |
|
template
<
class
T
>
constexpr
std::
strong_ordering
|
(20) | (C++20以降) |
optional
オブジェクトと値を比較する
|
||
|
template
<
class
T,
class
U
>
constexpr bool operator == ( const optional < T > & opt, const U & value ) ; |
(21) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator == ( const U & value, const optional < T > & opt ) ; |
(22) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator ! = ( const optional < T > & opt, const U & value ) ; |
(23) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator ! = ( const U & value, const optional < T > & opt ) ; |
(24) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator < ( const optional < T > & opt, const U & value ) ; |
(25) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator < ( const U & value, const optional < T > & opt ) ; |
(26) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator <= ( const optional < T > & opt, const U & value ) ; |
(27) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator <= ( const U & value, const optional < T > & opt ) ; |
(28) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator > ( const optional < T > & opt, const U & value ) ; |
(29) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator > ( const U & value, const optional < T > & opt ) ; |
(30) | (C++17以降) |
|
template
<
class
T,
class
U
>
constexpr bool operator >= ( const optional < T > & opt, const U & value ) ; |
(31) | (C++17以降) |
|
template
<
class
U,
class
T
>
constexpr bool operator >= ( const U & value, const optional < T > & opt ) ; |
(32) | (C++17以降) |
|
template
<
class
T,
std::
three_way_comparable_with
<
T
>
U
>
constexpr
std::
compare_three_way_result_t
<
T, U
>
|
(33) | (C++20以降) |
optional
オブジェクトに対する比較操作を実行します。
optional
オブジェクト、
lhs
と
rhs
を比較する。格納された値は、
lhs
と
rhs
の両方が値を保持している場合にのみ(
T
の対応する演算子を使用して)比較される。それ以外の場合、
- lhs は、 lhs と rhs の両方が値を保持していない場合に限り、 rhs と 等しい と見なされる。
- lhs は、 rhs が値を保持しており、 lhs が値を保持していない場合に限り、 rhs より 小さい と見なされる。
|
対応する式 * lhs @ * rhs が不適格であるか、その結果が bool に変換できない場合、プログラムは不適格となる。 |
(C++26まで) |
|
このオーバーロードは、対応する式 * lhs @ * rhs が適格であり、かつその結果が bool に変換可能な場合にのみ、オーバーロード解決に参加する。 |
(C++26以降) |
nullopt
と比較する。値を含まない
optional
との比較における
(1-6)
と等価。
|
|
(C++20以降) |
T
の対応する演算子を使用して)
opt
が値を含む場合にのみ行われます。それ以外の場合、
opt
は
より小さい
と見なされます
value
よりも。
|
対応する式 * opt @ value または value @ * opt (オペランドの位置による)が不適格であるか、その結果が bool に変換できない場合、プログラムは不適格である。 |
(C++26まで) |
|
このオーバーロードは、以下の条件が全て満たされる場合にのみオーバーロード解決に参加する:
|
(C++26以降) |
目次 |
パラメータ
| lhs, rhs, opt | - |
比較対象の
optional
オブジェクト
|
| value | - | 格納されている値と比較する値 |
戻り値
( lhs. has_value ( ) == false ? true : * lhs == * rhs )
( lhs. has_value ( ) == false ? false : * lhs ! = * rhs )
例外
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202403L
|
(C++26) | std::optional の制約付き比較演算子 |
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2945 | C++17 | compare-with-Tの場合のテンプレートパラメータ順序が一貫していない | 一貫性を持たせた |