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 包含非預期值,那麼以 *this 的非預期值作為實參調用 f 並返回一個包含預期值的 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()));
目錄 |
[編輯] 參數
f | - | 適合的函數或可調用 (Callable) 對象,它的返回類型不是引用類型 |
[編輯] 返回值
給定表達式 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) |
[編輯] 示例
本節未完成 原因:暫無示例 |
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 出版時的行為 | 正確行為 |
---|---|---|---|
LWG 3938 | C++23 | 通過 value() 獲取預期值[1] | 改成 **this |
LWG 3973 | C++23 | 通過 **this 獲取預期值[2] | 改成 val
|
[編輯] 參閱
若 expected 含有預期值則返回其自身,否則返回給定的函數在非預期值上的結果 (公開成員函數) | |
若存在預期值則返回含有變換後的預期值的 expected ,否則返回 expected 本身 (公開成員函數) |