std::expected<T,E>::operator->, std::expected<T,E>::operator*

来自cppreference.com
< cpp‎ | utility‎ | expected
 
 
 
 
主模板
constexpr const T* operator->() const noexcept;
(1) (C++23 起)
constexpr T* operator->() noexcept;
(2) (C++23 起)
constexpr const T& operator*() const& noexcept;
(3) (C++23 起)
constexpr T& operator*() & noexcept;
(4) (C++23 起)
constexpr const T&& operator*() const&& noexcept;
(5) (C++23 起)
constexpr T&& operator*() && noexcept;
(6) (C++23 起)
void 部分特化
constexpr void operator*() const noexcept;
(7) (C++23 起)

访问 *this 含有的预期值。

1,2) 返回指向预期值的指针。
3-6) 返回到预期值的引用。
7) 没有返回值。

如果 has_value()false,那么行为未定义。

(C++26 前)

如果 has_value()false,那么:

  • 如果实现是硬化实现,那么就会发生契约违背。并且契约违背处理函数在“观察”求值语义下返回时行为未定义。
  • 如果实现不是硬化实现,那么行为未定义。
(C++26 起)

目录

[编辑] 返回值

1,2) std::addressof(val )
3,4) val
5,6) std::move(val )

[编辑] 注解

这些运算符不会检查 expected 是否表示预期值,用户可以使用 has_value()operator bool() 手动检查。或者,需要访问检查时也可以使用 value()