std::expected<T,E>::expected
ja.cppreference.net より
constexpr expected();
|
(1) | (C++23以上) |
constexpr expected( const expected& other );
|
(2) | (C++23以上) |
constexpr expected( expected&& other ) noexcept(/* see below */);
|
(3) | (C++23以上) |
template< class U, class G >
constexpr explicit(/* see below */) expected( const expected<U, G>& other );
|
(4) | (C++23以上) |
template< class U, class G >
constexpr explicit(/* see below */) expected( expected<U, G>&& other );
|
(5) | (C++23以上) |
template< class U = std::remove_cv_t<T> >
constexpr explicit(!std::is_convertible_v<U, T>) expected( U&& v );
|
(6) | (C++23以上) (T は cv void ではない) |
template< class G >
constexpr explicit(!std::is_convertible_v<const G&, E>)
expected( const std::unexpected<G>& e );
|
(7) | (C++23以上) |
template< class G >
constexpr explicit(!std::is_convertible_v<G, E>)
expected( std::unexpected<G>&& e );
|
(8) | (C++23以上) |
template< class... Args >
constexpr explicit expected( std::in_place_t, Args&&... args );
|
(9) | (C++23以上) (T は cv void ではない) |
template< class U, class... Args >
constexpr explicit expected( std::in_place_t,
std::initializer_list<U> il, Args&&... args );
|
(10) | (C++23以上) (T は cv void ではない) |
constexpr explicit expected( std::in_place_t ) noexcept;
|
(11) | (C++23以上) (T は cv void) |
template< class... Args >
constexpr explicit expected( std::unexpect_t, Args&&... args );
|
(12) | (C++23以上) |
template< class U, class... Args >
constexpr explicit expected( std::unexpect_t,
std::initializer_list<U> il, Args&&... args );
|
(13) | (C++23以上) |
新しい expected オブジェクトを構築する。
構築後、
has_value() は true を返します。 このオーバーロードは、
T が(CV修飾された可能性のある)void であるか、std::is_default_constructible_v<T> が true である場合にのみ、オーバーロード解決に参加します。2) コピーコンストラクタ。
other.has_value() が false の場合、新しいオブジェクトは予期しない値を持ち、それは 直接初期化 により other.error() から初期化されます。 そうでなく、T が(CV修飾された可能性のある)void でない場合、新しいオブジェクトは期待値を持ち、それは 直接初期化 により *other から初期化されます。 構築後、
has_value() は other.has_value() と等しくなります。 このコンストラクタは、以下の場合を除き削除されたものとして定義されます:
Tが(CV修飾された可能性のある)voidであるか、またはstd::is_copy_constructible_v<T>がtrueであり、かつstd::is_copy_constructible_v<E>がtrueであること。
このコンストラクタは、以下の場合にトリビアルです:
Tが(CV修飾された可能性のある)voidであるか、またはstd::is_trivially_copy_constructible_v<T>がtrueであり、かつstd::is_trivially_copy_constructible_v<E>がtrueであること。
3) ムーブコンストラクタ。
other.has_value() が false の場合、新しいオブジェクトは予期しない値を持ち、それは 直接初期化 により std::move(other.error()) から初期化されます。 そうでなく、T が(CV修飾された可能性のある)void でない場合、新しいオブジェクトは期待値を持ち、それは 直接初期化 により std::move(*other) から初期化されます。 構築後、
has_value() は other.has_value() と等しくなります。 このコンストラクタは、以下の場合にのみオーバーロード解決に参加します:
Tが(CV修飾された可能性のある)voidであるか、またはstd::is_move_constructible_v<T>がtrueであり、かつstd::is_move_constructible_v<E>がtrueであること。
このコンストラクタは、以下の場合にトリビアルです:
std::is_trivially_move_constructible_v<T>がtrueであり、かつstd::is_trivially_move_constructible_v<E>がtrueであること。
4,5)
UFをstd::add_lvalue_reference_t<const U>(4) の場合は 、U(5) の場合は とし、GFをconst G&(4) の場合は 、G(5) の場合は とする。
other.has_value() が false の場合、新しいオブジェクトは予期しない値を持ち、それは 直接初期化 により std::forward<GF>(other.error()) から初期化されます。 そうでなく、T が(CV修飾された可能性のある)void でない場合、新しいオブジェクトは期待値を持ち、それは 直接初期化 により std::forward<UF>(*other) から初期化されます。 構築後、
has_value() は other.has_value() と等しくなります。 これらのコンストラクタはそれぞれ、以下の条件が満たされる場合にのみオーバーロード解決に参加します:
- 次のいずれか:
Tが(CV修飾された可能性のある)voidであり、かつstd::is_void_v<U>がtrueである。またはstd::is_constructible_v<T, UF>がtrueである。
std::is_constructible_v<E, GF>はtrueである。Tが(CV修飾された可能性のある)boolでない場合、Tは(可能性としてconstが付加された)std::expected<U, G>型の任意の式から構築可能または変換可能ではない。すなわち、以下の8つの値はすべてfalseである:std::is_constructible_v<T, std::expected<U, G>&std::is_constructible_v<T, std::expected<U, G>std::is_constructible_v<T, const std::expected<U, G>&std::is_constructible_v<T, const std::expected<U, G>std::is_convertible_v<std::expected<U, G>&, T>std::is_convertible_v<std::expected<U, G>, T>std::is_convertible_v<const std::expected<U, G>&, T>std::is_convertible_v<const std::expected<U, G>, T>
std::unexpected<E>は(可能性としてconstが付加された)std::expected<U, G>型の任意の式から構築可能ではない。すなわち、以下の4つの値はすべてfalseである:std::is_constructible_v<std::unexpected<E>, std::expected<U, G>&std::is_constructible_v<std::unexpected<E>, std::expected<U, G>std::is_constructible_v<std::unexpected<E>, const std::expected<U, G>&std::is_constructible_v<std::unexpected<E>, const std::expected<U, G>
これらのコンストラクタは、
explicit または std::is_convertible_v<UF, T> が std::is_convertible_v<GF, E> である場合、false になる。6) 期待値を含むオブジェクトを構築します。期待値は、直接初期化(ただし直接リスト初期化ではない)により、式
T で std::forward<U>(v) 型のオブジェクトを初期化するかのように初期化されます。 構築後、
has_value() は true を返します。 このコンストラクタは、以下の条件が満たされる場合にのみオーバーロード解決に参加します:
Tは(CV修飾された可能性のある)voidではない。std::is_same_v<std::remove_cvref_t<U>, std::in_place_t>はfalseである。std::is_same_v<expected, std::remove_cvref_t<U>>はfalseである。std::is_constructible_v<T, U>はtrueである。std::remove_cvref_t<U>はstd::unexpectedの特殊化ではない。Tが(CV修飾された可能性のある)boolである場合、std::remove_cvref_t<U>はstd::expectedの特殊化ではない。
7,8)
GF を const G&(7) の場合は 、G(8) の場合は とする。 予期しない値を含むオブジェクトを構築します。その値は 直接初期化 により std::forward<GF>(e.error()) から初期化されます。 構築後、
has_value() は false を返します。 これらのオーバーロードは、
std::is_constructible_v<E, GF> が true である場合にのみオーバーロード解決に参加します。 構築後、
has_value() は true を返します。 このオーバーロードは、
std::is_constructible_v<T, Args...> が true である場合にのみオーバーロード解決に参加します。 構築後、
has_value() は true を返します。 このオーバーロードは、
std::is_constructible_v<T, std::initializer_list<U>&, Args...> が true である場合にのみオーバーロード解決に参加します。 構築後、
has_value() は false を返します。 このオーバーロードは、
std::is_constructible_v<E, Args...> が true である場合にのみオーバーロード解決に参加します。 構築後、
has_value() は false を返します。 このオーバーロードは、
std::is_constructible_v<E, std::initializer_list<U>&, Args...> が true である場合にのみオーバーロード解決に参加します。パラメータ
| other | - |
別の
expected
オブジェクト。その含まれる値がコピーされる
|
| e | - |
std::unexpected
オブジェクト。その含まれる値がコピーされる
|
| v | - | 含まれる値を初期化するための値 |
| args | - | 含まれる値を初期化するための引数 |
| il | - | 含まれる値を初期化するための初期化子リスト |
例外
例
|
このセクションは不完全です
理由: 例がありません |
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3886 | C++23 |
overload
(
6
)
のデフォルトテンプレート引数は
T
であった
|
以下のように変更された std:: remove_cv_t < T > |
関連項目
|
(C++23)
|
予期しない値として表現される
(クラステンプレート) |
|
インプレース構築タグ
(タグ) |
|
|
(C++23)
|
expectedにおける予期しない値のインプレース構築タグ
(タグ) |