Namespaces
Variants

std:: bad_expected_access

From cppreference.net
Utilities library
定義済みヘッダー <expected>
template < class E >
class bad_expected_access : public std :: bad_expected_access < void >
(1) (C++23以降)
template <>
class bad_expected_access < void > : public std:: exception
(2) (C++23以降)
1) std::expected::value によって、予期しない値を持つexpectedオブジェクトにアクセスする際にスローされるオブジェクトの型を定義します。 bad_expected_access<E> は予期しない値のコピーを保持します。
2) bad_expected_access < void > は、他のすべての bad_expected_access 特殊化の基底クラスです。
std::bad_expected_access のすべてのメンバ関数は constexpr です:定数式の評価中に std::bad_expected_access オブジェクトを作成して使用することが可能です。

ただし、 std::bad_expected_access オブジェクトは一般的に constexpr にはなりません。なぜなら、動的に確保されたストレージはすべて同じ定数式の評価中に解放されなければならないためです。

(C++26以降)

目次

プライマリテンプレートのメンバー

(constructor)
bad_expected_accessオブジェクトを構築する
(public member function)
error
格納された値を返す
(public member function)
what
説明文字列を返す
(public member function)

std::bad_expected_access:: bad_expected_access

explicit bad_expected_access ( E e ) ;
(C++23以降)
(C++26以降 constexpr)

新しい bad_expected_access<E> オブジェクトを構築します。 格納された値を std::move(e) で初期化します。

std::bad_expected_access:: error

const E & error ( ) const & noexcept ;
(1) (C++23以降)
(C++26以降 constexpr)
E & error ( ) & noexcept ;
(2) (C++23以降)
(C++26以降 constexpr)
const E && error ( ) const && noexcept ;
(3) (C++23以降)
(C++26以降 constexpr)
E && error ( ) && noexcept ;
(4) (C++23以降)
(C++26以降 constexpr)

格納された値への参照を返します。

std::bad_expected_access:: what

const char * what ( ) const noexcept override ;
(C++23以降)
(constexpr since C++26)

説明文字列を返します。

戻り値

説明情報を含むヌル終端文字列へのポインタ。この文字列は std::wstring への変換と表示に適しています。ポインタは、少なくとも取得元の例外オブジェクトが破棄されるまで、または例外オブジェクトの非constメンバー関数(コピー代入演算子など)が呼び出されるまで有効であることが保証されています。

定数評価中、返される文字列は通常のリテラルエンコーディングでエンコードされます。

(C++26以降)

注記

実装は what() をオーバーライドすることが許可されていますが、必須ではありません。

std::bad_expected_access std:: bad_expected_access < void > から継承

bad_expected_access < void > 特殊化のメンバー

(コンストラクタ)
bad_expected_access < void > オブジェクトを構築
(protected メンバー関数)
(デストラクタ)
bad_expected_access < void > オブジェクトを破棄
(protected メンバー関数)
operator=
bad_expected_access < void > オブジェクトを置換
(protected メンバー関数)
what
説明文字列を返す
(public メンバー関数)

bad_expected_access < void > の特殊メンバー関数は protected です。派生クラスからのみ呼び出すことができます。

std::exception から継承

メンバ関数

[virtual]
例外オブジェクトを破棄
( std::exception の仮想公開メンバ関数)
[virtual]
説明文字列を返す
( std::exception の仮想公開メンバ関数)

注記

機能テスト マクロ 標準 機能
__cpp_lib_constexpr_exceptions 202502L (C++26) constexpr std::bad_expected_access

関連項目

値を持たないoptionalへのチェック付きアクセスを示す例外
(クラス)
variant の値への不正なアクセス時にスローされる例外
(クラス)