std::expected<T,E>::operator bool, std::expected<T,E>::has_value

来自cppreference.com
< cpp‎ | utility‎ | expected
 
 
 
 
constexpr explicit operator bool() const noexcept;
(1) (C++23 起)
constexpr bool has_value() const noexcept;
(2) (C++23 起)

检查 *this 是否表示预期值。

目录

[编辑] 返回值

has_val

[编辑] 注解

一个 std::expected 对象永远不会无值。如果 has_value() 返回 true,那么可以用 operator*() 访问预期值;否则,可以用 error() 访问非预期值。

[编辑] 示例

[编辑] 参阅

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