Namespaces
Variants

std::expected<T,E>::error_or

来自 zh.cppreference.net
 
 
 
 
template< class G = E > 
constexpr E error_or( G&& default_value ) const&;
(1) (C++23 起)
template< class G = E > 
constexpr E error_or( G&& default_value ) &&;
(2) (C++23 起)

如果存在非预期值,则返回该错误值,否则返回 default_value。

1) 如果 std::is_copy_constructible_v<E> 或 std::is_convertible_v<G, E> 是 false,则程序非良构。
2) 如果 std::is_move_constructible_v<E> 或 std::is_convertible_v<G, E> 是 false,则程序非良构。

参数

default_value - 当 * this 不包含意外值时使用的值
类型要求

返回值

1) has_value ( ) ? std:: forward < G > ( default_value ) : error ( )
2) has_value ( ) ? std:: forward < G > ( default_value ) : std :: move ( error ( ) )

示例

参见

返回非预期值
(公开成员函数)
若存在预期值则返回该值,否则返回另一值
(公开成员函数)