constexpr const T* operator->() const noexcept; // (1)
constexpr T* operator->() noexcept; // (2)
概要
保持している正常値のメンバにアクセスする。
事前条件
has_value() == true
戻り値
正常値へのポインタ。
例外
投げない
例
#include <expected>
#include <iostream>
#include <string>
int main()
{
std::expected<std::string, int> x = "Hello";
std::cout << x->size() << std::endl;
std::expected<std::string, int> y = std::unexpected{42};
//std::cout << y->size() << std::endl;
// エラー値を保持する y に対する operator-> 呼び出しは未定義動作
}
出力
5
バージョン
言語
- C++23
処理系
- Clang: 16.0
- GCC: 12.1
- ICC: ??
- Visual C++: ??