std::expected<T,E>::transform
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |   template< class F > constexpr auto transform( F&& f ) &;  | 
(1) | (C++23 起) | 
|   template< class F > constexpr auto transform( F&& f ) const&;  | 
(2) | (C++23 起) | 
|   template< class F > constexpr auto transform( F&& f ) &&;  | 
(3) | (C++23 起) | 
|   template< class F > constexpr auto transform( F&& f ) const&&;  | 
(4) | (C++23 起) | 
如果 *this 包含期待的值,调用 f 并返回一个包含了其结果的 std::expected 对象;否则,返回一个包含了 error() 的复制的 std::expected 对象。
如果 T 不是(可有 cv 限定的) void ,包含的期待的值( **this )将作为参数传递给 f ;否则 f 不接受任何参数。
令 U 为:
-  如果 
T不是(可有 cv 限定的) void :- 对于重载 (1-2) , std::remove_cv_t<std::invoke_result_t<F, decltype(**this)>> ;
 - 对于重载 (3-4) , std::remove_cv_t<std::invoke_result_t<F, decltype(std::move(**this))>> ;
 
 -  否则 ( 
T是(可有 cv 限定的) void ), std::remove_cv_t<std::invoke_result_t<F>> 。 
U 必须是 std::expected 合法的期待的值类型。具有 U 类型的变量必须能从调用结果构造(但不一定需要是可移动构造)。返回值类型为 std::expected<U, E> 。
1-2) 如果 *this 包含期待的值:
-  如同通过以下方式调用 f :
- 如果 std::is_void_v<T> 为 false , std::invoke(std::forward<F>(f), **this) ;
 - 否则, std::invoke(std::forward<F>(f)) 。
 
 -  然后
-  如果 std::is_void_v<U> 为 false ,返回一个包含期待的值的 
std::expected对象,所含值从调用的结果 直接初始化 ; - 否则,返回 std::expected<U, E>() 。
 
 -  如果 std::is_void_v<U> 为 false ,返回一个包含期待的值的 
 
否则( *this 包含不期待的值),返回 std::expected<U, E>(std::unexpect, error()) 。
这些重载只有在std::is_constructible_v<E, decltype(error())> 为 true 时才会参与重载决议.3-4) 如果 *this 包含期待的值:
-  如同通过以下方式调用 f :
- 如果 std::is_void_v<T> 为 false , std::invoke(std::forward<F>(f), std::move(**this)) ;
 - 否则, std::invoke(std::forward<F>(f)) 。
 
 -  然后
-  如果 std::is_void_v<U> 为 false ,返回一个包含期待的值的 
std::expected对象,所含值从调用的结果 直接初始化 ; - 否则,返回 std::expected<U, E>() 。
 
 -  如果 std::is_void_v<U> 为 false ,返回一个包含期待的值的 
 
否则( *this 包含不期待的值),返回 std::expected<U, E>(std::unexpect, std::move(error())) 。
这些重载只有在std::is_constructible_v<E, decltype(std::move(error()))> 为 true 时才会参与重载决议.参数
| f | - | 适合的函数或 可调用 (Callable) 对象,其返回类型为非引用类型 | 
返回值
一个包含了 f 的结果或不期待的值的 std::expected 对象,如上所述
示例
| 本节未完成 原因:暂无示例  | 
参阅
   若含有期待的值则返回 expected 本身,否则返回含有变换后不期待的值的 expected  (公开成员函数)  |