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 起) | 
如果 *this 包含不期待的值,调用 f 并返回一个包含了其结果的 std::expected 对象;否则,返回一个包含了 **this 的复制的 std::expected 对象。包含的不期待的值( error() )将作为参数传递给 f 。
令 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()))>> 。
 
G 必须是 std::unexpected 的合法模板参数。具有 G 类型的变量必须能从调用结果构造(但不一定需要是可移动构造)。返回值类型为 std::expected<T, G> 。
1-2) 如果 *this 包含期待的值:
- 如果 std::is_void_v<T> 为 false ,返回 std::expected<T, G>(std::in_place, **this) ;
 - 否则,返回 std::expected<T, G>() 。
 
否则( *this 包含不期待的值),返回一个包含不期待的值的 std::expected<T, G> 对象,所含值从 std::invoke(std::forward<F>(f), error()) 直接初始化 。
这些重载只有在 std::is_void_v<T> 或 std::is_constructible_v<T, decltype(**this)> 为 true 时才会参与重载决议 。3-4) 如果 *this 包含期待的值:
- 如果 std::is_void_v<T> 为 false ,返回 std::expected<T, G>(std::in_place, std::move(**this)) ;
 - 否则,返回 std::expected<T, G>() 。
 
否则( *this 包含不期待的值),返回一个包含不期待的值的 std::expected<T, G> 对象,所含值从 std::invoke(std::forward<F>(f), std::move(error())) 直接初始化 。
这些重载只有在 std::is_void_v<T> 或 std::is_constructible_v<T, decltype(std::move(**this))> 为 true 时才会参与重载决议 。参数
| f | - | 适合的函数或 可调用 (Callable) 对象,其返回类型为非引用类型 | 
返回值
一个包含了 f 的结果或不期待的值的 std::expected 对象,如上所述
示例
| 本节未完成 原因:暂无示例  | 
参阅
   若 expected 含有期待的值则返回其自身,否则返回给定的函数在不期待的值上的结果 (公开成员函数)  | |
   若期待的值存在则返回含有变换后期待的值的 expected ,否则返回 expected 本身 (公开成员函数)  |