std::expected<T,E>:: and_then
|
メインテンプレート
|
||
|
template
<
class
F
>
constexpr auto and_then ( F && f ) & ; |
(1) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) const & ; |
(2) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) && ; |
(3) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) const && ; |
(4) | (C++23以降) |
|
void
部分特殊化
|
||
|
template
<
class
F
>
constexpr auto and_then ( F && f ) & ; |
(5) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) const & ; |
(6) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) && ; |
(7) | (C++23以降) |
|
template
<
class
F
>
constexpr auto and_then ( F && f ) const && ; |
(8) | (C++23以降) |
*
this
が期待値を表す場合、
f
を呼び出し、その結果を返します。それ以外の場合、
std::expected
オブジェクトを返します。このオブジェクトは、
*
this
の非期待値で初期化された非期待値を含みます。
型
U
が以下のように与えられた場合:
U
が
std::expected
の特殊化でない場合、または
std::
is_same_v
<
U
::
error_type
, E
>
が
false
の場合、プログラムは不適格です。
目次 |
パラメータ
| f | - | 適切な関数または Callable オブジェクトで、 std::expected を返すもの |
戻り値
| オーバーロード |
has_value()
の値
|
|
|---|---|---|
| true | false | |
| ( 1,2 ) |
std::
invoke
(
std::
forward
<
F
>
(
f
)
,
val
)
|
U ( std:: unexpect , error ( ) ) |
| ( 3,4 ) |
std::
invoke
(
std::
forward
<
F
>
(
f
)
,std
::
move
(
val
)
)
|
U ( std:: unexpect , std :: move ( error ( ) ) ) |
| ( 5,6 ) | std:: invoke ( std:: forward < F > ( f ) ) | U ( std:: unexpect , error ( ) ) |
| ( 7,8 ) | U ( std:: unexpect , std :: move ( error ( ) ) ) | |
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_expected
|
202211L
|
(C++23) |
std::expected
のモナド関数
|
例
|
このセクションは不完全です
理由: 例がありません |
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3938 | C++23 | 期待値は value ( ) によって取得されていた [1] | ** this に変更された |
| LWG 3973 | C++23 | 期待値は ** this によって取得されていた [2] |
val
に変更された
|
-
↑
value()はEがコピー構築可能であることを要求する( LWG issue 3843 を参照)。一方でoperator*はこの要求を持たない。 - ↑ ** this は argument-dependent lookup を引き起こす可能性がある。
関連項目
|
(C++23)
|
expected
内の予期しない値に対するインプレース構築タグ
(タグ) |
期待される値が存在する場合は変換された期待値を含む
expected
を返す。それ以外の場合は
expected
自体を返す
(公開メンバ関数) |