std::expected<T,E>::transform_error
來自 cppreference.com
主模板 |
||
template< class F > constexpr auto transform_error( F&& f ) &; |
(1) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) const&; |
(2) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) &&; |
(3) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) const&&; |
(4) | (C++23 起) |
void 偏特化 |
||
template< class F > constexpr auto transform_error( F&& f ) &; |
(5) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) const&; |
(6) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) &&; |
(7) | (C++23 起) |
template< class F > constexpr auto transform_error( F&& f ) const&&; |
(8) | (C++23 起) |
如果 *this 包含一個非預期值,則呼叫 f,並將 *this 的非預期值作為引數,返回一個包含非預期值的 std::expected
物件,該非預期值用 f 的結果初始化。否則,返回一個表示預期值的 std::expected
物件。
給定型別 G
為
1,2) std::remove_cv_t<std::invoke_result_t<F, decltype(error())>>
3,4) std::remove_cv_t<std::invoke_result_t<F, decltype(std::move(error()))>>
5,6) std::remove_cv_t<std::invoke_result_t<F, decltype(error())>>
7,8) std::remove_cv_t<std::invoke_result_t<F, decltype(std::move(error()))>>
如果滿足以下任何條件,程式將不正確:
-
G
不是std::unexpected
的有效模板引數。 - 以下相應的宣告格式錯誤:
1,2) G g(std::invoke(std::forward<F>(f), error()));
3,4) G g(std::invoke(std::forward<F>(f), std::move(error()));
5,6) G g(std::invoke(std::forward<F>(f), error()));
7,8) G g(std::invoke(std::forward<F>(f), std::move(error()));
目錄 |
[edit] 引數
f | - | 一個合適的函式或可呼叫 (Callable) 物件,其呼叫簽名返回一個非引用型別 |
[edit] 返回值
給定表示式 expr 為
1,2) std::invoke(std::forward<F>(f), error())
3,4) std::invoke(std::forward<F>(f), std::move(error()))
5,6) std::invoke(std::forward<F>(f), error())
7,8) std::invoke(std::forward<F>(f), std::move(error()))
返回值定義如下:
過載 | has_value() 的值 | |
---|---|---|
true | false | |
(1,2) | std::expected<T, G>(std::in_place, val )
|
std::expected<T, G> (std::unexpect, expr) |
(3,4) | std::expected<T, G>(std::in_place, std::move(val ))
| |
(5,6) | std::expected<T, G>() | |
(7,8) |
[edit] 示例
本節不完整 原因:無示例 |
[edit] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 3938 | C++23 | 期望值透過 value()[1] 獲得 | 更改為 **this |
LWG 3973 | C++23 | 期望值透過 **this[2] 獲得 | 更改為 val |
[edit] 參閱
如果 `expected` 包含一個預期值,則返回 `expected` 本身;否則,返回給定函式對非預期值的結果。 (public member function) | |
如果預期值存在,返回包含轉換後的預期值的 expected ;否則返回 expected 自身(public member function) |