operator==(std::expected)
| プライマリテンプレート |
||
template< class T2, class E2 >
requires (!std::is_void_v<T2>)
friend constexpr bool operator==( const expected& lhs,
const std::expected<T2, E2>& rhs );
|
(1) | (C++23以降) |
template< class E2 >
friend constexpr bool operator==( const expected& lhs,
const std::unexpected<E2>& unex );
|
(2) | (C++23以降) |
template< class T2 >
friend constexpr bool operator==( const expected& lhs, const T2& val );
|
(3) | (C++23以降) |
void部分特殊化 |
||
template< class T2, class E2 >
requires std::is_void_v<T2>
friend constexpr bool operator==( const expected& lhs,
const std::expected<T2, E2>& rhs );
|
(4) | (C++23以降) |
template< class E2 >
friend constexpr bool operator==( const expected& lhs,
const std::unexpected<E2>& unex );
|
(5) | (C++23以降) |
std::expectedオブジェクトに対して比較演算を実行します。
lhsとrhsが等しい期待値を保持しているか、両方が等しい予期しない値を保持している場合に限り、オブジェクトは等しいと比較されます。
|
以下の式のいずれかが ill-formed であるか、その結果が |
(C++26未満) |
|
このオーバーロードは、以下の式がすべて well-formed であり、その結果が |
(C++26以降) |
*lhs == *rhslhs.error() == rhs.error()
lhsがunex.error()と等しい予期しない値を含む場合に限り、オブジェクトは等しいと比較されます。
|
式 |
(C++26未満) |
|
このオーバーロードは、式 |
(C++26以降) |
lhsがvalと等しい期待値を含む場合に限り、オブジェクトは等しいと比較されます。
|
式 |
(C++26未満) |
|
このオーバーロードは、以下の条件がすべて満たされる場合にのみ、オーバーロード解決に参加します。
|
(C++26以降) |
lhsとrhsの両方が期待値を表すか、両方が等しい予期しない値を含む場合に限り、オブジェクトは等しいと比較されます。
|
式 |
(C++26未満) |
|
このオーバーロードは、式 |
(C++26以降) |
lhsがunex.error()と等しい予期しない値を含む場合に限り、オブジェクトは等しいと比較されます。
|
式 |
(C++26未満) |
|
このオーバーロードは、式 |
(C++26以降) |
これらの関数は通常の非修飾または修飾名前探索では可視ではなく、引数依存の名前探索によってのみ、std::expected<T, E>が引数の関連クラスである場合に見つけることができます。
!=演算子はから合成されます。
operator==
パラメータ
| lhs, rhs | - | std::expected 比較対象のオブジェクト |
| unex | - | std::unexpected lhs と比較する値 |
| val | - | lhs に含まれる期待値と比較する値 |
戻り値
( lhs. has_value ( ) ? * lhs == * rhs : lhs. error ( ) == rhs. error ( ) )
lhs. has_value ( ) || static_cast < bool > ( lhs. error ( ) == rhs. error ( ) )
例外
比較がスローするタイミングと内容をスローします。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_constrained_equality
|
202411L
|
(C++26) | std::expected の制約付き比較演算子 |
例
#include <expected> #include <iostream> #include <string_view> using namespace std::string_view_literals; int main() { auto x1{"\N{GREEN HEART}"sv}; auto x2{"\N{CROSS MARK}"sv}; std::expected<std::string_view, int> e1{x1}, e2{x1}, e3{x2}; std::unexpected u1{13}; std::cout << "Overload (1):\n" << e1.value() << (e1 == e2 ? " == " : " != ") << *e2 << '\n' << e1.value() << (e1 != e3 ? " != " : " == ") << *e3 << "\n\n"; std::cout << "Overload (2):\n" << e1.value() << (e1 == u1 ? " == " : " != ") << u1.error() << '\n'; e1 = std::unexpected{13}; std::cout << e1.error() << (e1 == u1 ? " == " : " != ") << u1.error() << '\n'; e1 = std::unexpected{31}; std::cout << e1.error() << (e1 != u1 ? " != " : " == ") << u1.error() << '\n'; std::cout << "Overload (3):\n" << *e1 << (e1 == x1 ? " == " : " != ") << x1 << '\n' << *e1 << (e1 != x2 ? " != " : " == ") << x2 << "\n\n"; }
出力:
Overload (1): 💚 == 💚 💚 != ❌ Overload (2): 💚 != 13 13 == 13 31 != 13 Overload (3): 💚 == 💚 💚 != ❌
関連項目
|
(C++23)
|
std::unexpected
オブジェクトを比較する
(関数テンプレート) |