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

来自cppreference.com
< cpp‎ | utility‎ | expected
 
 
 
 
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 起)

*this 包含非预期值时返回它,否则返回 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())

[编辑]示例

[编辑]参阅

返回非预期值
(公开成员函数)[编辑]
close