std::expected<T,E>:: expected
|
Hauptvorlage
|
||
|
constexpr
expected
(
)
;
|
(1) | (seit C++23) |
|
constexpr
expected
(
const
expected
&
other
)
;
|
(2) | (seit C++23) |
|
constexpr
expected
(
expected
&&
other
)
noexcept
(
/* siehe unten */
)
;
|
(3) | (seit C++23) |
|
template
<
class
U,
class
G
>
constexpr expected ( const expected < U, G > & other ) ; |
(4) |
(seit C++23)
(bedingt explizit) |
|
template
<
class
U,
class
G
>
constexpr expected ( expected < U, G > && other ) ; |
(5) |
(seit C++23)
(bedingt explizit) |
|
template
<
class
U
=
std::
remove_cv_t
<
T
>
>
constexpr explicit ( ! std:: is_convertible_v < U, T > ) expected ( U && v ) ; |
(6) | (seit C++23) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(7) | (seit C++23) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(8) | (seit C++23) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: in_place_t , Args && ... args ) ; |
(9) | (seit C++23) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(10) | (seit C++23) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: unexpect_t , Args && ... args ) ; |
(11) | (seit C++23) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(12) | (seit C++23) |
|
void
Partielle Spezialisierung
|
||
|
constexpr
expected
(
)
;
|
(13) | (seit C++23) |
|
constexpr
expected
(
const
expected
&
other
)
;
|
(14) | (seit C++23) |
|
constexpr
expected
(
expected
&&
other
)
noexcept ( std:: is_nothrow_move_constructible_v < E > ) ; |
(15) | (seit C++23) |
|
template
<
class
U,
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(16) | (seit C++23) |
|
template
<
class
U,
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(17) | (seit C++23) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(18) | (seit C++23) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(19) | (seit C++23) |
|
constexpr
explicit
expected
(
std::
in_place_t
)
;
|
(20) | (seit C++23) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: unexpect_t , Args && ... args ) ; |
(21) | (seit C++23) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(22) | (seit C++23) |
Konstruiert ein neues
expected
-Objekt.
Inhaltsverzeichnis |
Parameter
| other | - |
ein weiteres
expected
Objekt, dessen enthaltene Werte kopiert werden
|
| e | - |
std::unexpected
Objekt, dessen enthaltene Werte kopiert werden
|
| v | - | Wert, mit dem der enthaltene Wert initialisiert wird |
| args | - | Argumente, mit denen der enthaltene Wert initialisiert wird |
| il | - | Initialisierungsliste, mit der der enthaltene Wert initialisiert wird |
Effekte
Primäre Template-Konstruktoren
| Overload |
Initialisierungs-
methode |
Initialisierer für... |
has_value()
nach Konstruktion |
|
|---|---|---|---|---|
| der erwartete Wert | der unerwartete Wert | |||
| ( 1 ) | Wert | (leer) | - | true |
| ( 2 ) |
Direkte Initialisierung
(Nicht-Liste) |
* other | other. error ( ) |
other.
has_value
(
)
|
| ( 3 ) | std :: move ( * other ) | std :: move ( other. error ( ) ) | ||
| ( 4 ) |
std::
forward
<
const
U
&
>
( * other ) |
std::
forward
<
const
G
&
>
( other. error ( ) ) |
||
| ( 5 ) | std:: forward < U > ( * other ) |
std::
forward
<
G
>
( other. error ( ) ) |
||
| ( 6 ) | std:: forward < U > ( v ) | - | true | |
| ( 7 ) | - |
std::
forward
<
const
G
&
>
( e. error ( ) ) |
false | |
| ( 8 ) | std:: forward < G > ( e. error ( ) ) | |||
| ( 9 ) | std:: forward < Args > ( args ) ... | - | true | |
| ( 10 ) |
il,
std:: forward < Args > ( args ) ... |
|||
| ( 11 ) | - | std:: forward < Args > ( args ) ... | false | |
| ( 12 ) |
il,
std:: forward < Args > ( args ) ... |
|||
void Partielle Spezialisierungskonstruktoren
| Überladung | Initialisierungsmethode | Initialisierer für den unerwarteten Wert |
has_value()
nach Konstruktion
|
|---|---|---|---|
| ( 13 ) | N/A | - | true |
| ( 14 ) | Direkt (nicht-Liste) | rhs. error ( ) |
other.
has_value
(
)
|
| ( 15 ) | std :: move ( rhs. error ) | ||
| ( 16 ) | std:: forward < const G & > ( rhs. error ( ) ) | ||
| ( 17 ) | std:: forward < G > ( rhs. error ( ) ) | ||
| ( 18 ) | std:: forward < const G & > ( e. error ( ) ) | false | |
| ( 19 ) | std:: forward < G > ( e. error ( ) ) | ||
| ( 20 ) | N/A | - | true |
| ( 21 ) | Direkt (nicht-Liste) | std:: forward < Args > ( args ) ... | false |
| ( 22 ) | il, std:: forward < Args > ( args ) ... |
Einschränkungen und ergänzende Informationen
Primäre Template-Konstruktoren
- Für Überladung (4) , std:: is_constructible_v < T, const U & > und std:: is_constructible_v < E, const G & > sind beide true .
- Für Überladung (5) , std:: is_constructible_v < T, U > und std:: is_constructible_v < E, G > beide true sind.
-
Wenn
Tnicht (möglicherweise cv-qualifiziert) bool ist, sind die folgenden 8 Werte alle 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 >
-
Die folgenden 4 Werte sind alle
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 >>
- std:: is_same_v < std:: remove_cvref_t < U > , std:: in_place_t > ist false .
- std:: is_same_v < std:: expected < T, E > , std:: remove_cvref_t < U >> ist false .
- std:: is_constructible_v < T, U > ist true .
-
std::
remove_cvref_t
<
U
>
ist keine Spezialisierung von
std::unexpected. -
Falls
T(möglicherweise cv-qualifiziertes) bool ist, std:: remove_cvref_t < U > ist keine Spezialisierung vonstd::expected.
void Partielle Spezialisierungskonstruktoren
- Für Überladung (16) , std:: is_constructible_v < E, const G & > ist true .
- Für Überladung (17) , std:: is_constructible_v < E, G > ist true .
- std:: is_void_v < U > ist true .
-
Die folgenden 4 Werte sind alle
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 >>
Exceptions
Primäre Template-Konstruktoren
&& std:: is_nothrow_move_constructible_v < E > )
void Partielle Spezialisierungskonstruktoren
Beispiel
|
Dieser Abschnitt ist unvollständig
Grund: Kein Beispiel |
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrigiertes Verhalten |
|---|---|---|---|
| LWG 3886 | C++23 |
das Standard-Template-Argument von overload
(
6
)
war
T
|
geändert zu std:: remove_cv_t < T > |
Siehe auch
|
(C++23)
|
dargestellt als ein unerwarteter Wert
(Klassen-Template) |
|
In-Place-Konstruktions-Tag
(Tag) |
|
|
(C++23)
|
In-Place-Konstruktions-Tag für unerwartete Werte in
expected
(Tag) |