std::expected<T,E>:: expected
|
기본 템플릿
|
||
|
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 expected ( const expected < U, G > & other ) ; |
(4) |
(C++23부터)
(조건부 explicit) |
|
template
<
class
U,
class
G
>
constexpr expected ( expected < U, G > && other ) ; |
(5) |
(C++23부터)
(조건부 explicit) |
|
template
<
class
U
=
std::
remove_cv_t
<
T
>
>
constexpr explicit ( ! std:: is_convertible_v < U, T > ) expected ( U && v ) ; |
(6) | (C++23 이후) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(7) | (C++23 이후) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(8) | (C++23 이후) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: in_place_t , Args && ... args ) ; |
(9) | (C++23 이후) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(10) | (C++23 이후) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: unexpect_t , Args && ... args ) ; |
(11) | (C++23 이후) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(12) | (C++23 이후) |
|
void
부분 특수화
|
||
|
constexpr
expected
(
)
;
|
(13) | (C++23부터) |
|
constexpr
expected
(
const
expected
&
other
)
;
|
(14) | (C++23 이후) |
|
constexpr
expected
(
expected
&&
other
)
noexcept ( std:: is_nothrow_move_constructible_v < E > ) ; |
(15) | (C++23 이후) |
|
template
<
class
U,
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(16) | (C++23 이후) |
|
template
<
class
U,
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(17) | (C++23부터) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
const
G
&
, E
>
)
|
(18) | (C++23 이후) |
|
template
<
class
G
>
constexpr
explicit
(
!
std::
is_convertible_v
<
G, E
>
)
|
(19) | (C++23 이후) |
|
constexpr
explicit
expected
(
std::
in_place_t
)
;
|
(20) | (C++23 이후) |
|
template
<
class
...
Args
>
constexpr explicit expected ( std:: unexpect_t , Args && ... args ) ; |
(21) | (C++23 이후) |
|
template
<
class
U,
class
...
Args
>
constexpr
explicit
|
(22) | (C++23 이후) |
새로운
expected
객체를 생성합니다.
목차 |
매개변수
| other | - |
다른
expected
객체로, 포함된 값이 복사됨
|
| e | - |
std::unexpected
객체로, 포함된 값이 복사됨
|
| v | - | 포함된 값을 초기화하는 데 사용되는 값 |
| args | - | 포함된 값을 초기화하는 데 사용되는 인수들 |
| il | - | 포함된 값을 초기화하는 데 사용되는 초기화 리스트 |
효과
기본 템플릿 생성자
| 오버로드 |
초기화
방식 |
초기화 대상... |
has_value()
생성 후 상태 |
|
|---|---|---|---|---|
| 기대값 | 예상치 못한 값 | |||
| ( 1 ) | 값 | (비어 있음) | - | true |
| ( 2 ) |
직접 초기화
(비-리스트) |
* 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 부분 특수화 생성자
| 오버로드 | 초기화 방식 | 예상치 못한 값(unexpected value)에 대한 초기화자 |
has_value()
생성 후 값
|
|---|---|---|---|
| ( 13 ) | 해당 없음 | - | true |
| ( 14 ) | 직접 초기화 (비리스트) | 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 ) | 해당 없음 | - | true |
| ( 21 ) | 직접 초기화 (비리스트) | std:: forward < Args > ( args ) ... | false |
| ( 22 ) | il, std:: forward < Args > ( args ) ... |
제약 조건 및 보충 정보
기본 템플릿 생성자
- 오버로드 (4) 의 경우, std:: is_constructible_v < T, const U & > 와 std:: is_constructible_v < E, const G & > 가 모두 true 입니다.
- 오버로드 (5) 에 대해, std:: is_constructible_v < T, U > 와 std:: is_constructible_v < E, G > 가 모두 true 입니다.
-
만약
T가 (cv 한정자를 포함할 수 있는) bool 이 아니라면, 다음 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 >
-
다음 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 >>
- std:: is_same_v < std:: remove_cvref_t < U > , std:: in_place_t > 가 false 인 경우.
- std:: is_same_v < std:: expected < T, E > , std:: remove_cvref_t < U >> 가 false 인 경우.
- std:: is_constructible_v < T, U > 가 true 인 경우.
-
std::
remove_cvref_t
<
U
>
가
std::unexpected의 특수화(specialization)가 아닌 경우. -
만약
T가 (possibly cv-qualified) bool 인 경우, std:: remove_cvref_t < U > 가std::expected의 특수화(specialization)가 아닌 경우.
void 부분 특수화 생성자
- 오버로드 (16) 의 경우, std:: is_constructible_v < E, const G & > 가 true 입니다.
- 오버로드 (17) 의 경우, std:: is_constructible_v < E, G > 가 true 입니다.
- std:: is_void_v < U > 가 true 입니다.
-
다음 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 >>
예외
기본 템플릿 생성자
&& std:: is_nothrow_move_constructible_v < E > )
void 부분 특수화 생성자
예제
|
이 섹션은 불완전합니다
이유: 예시가 없음 |
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 3886 | C++23 |
overload
의 기본 템플릿 인수
(
6
)
가
T
였음
|
std:: remove_cv_t < T > 로 변경됨 |
참고 항목
|
(C++23)
|
예상치 못한 값으로 표현됨
(클래스 템플릿) |
|
인플레이스 생성 태그
(태그) |
|
|
(C++23)
|
expected
에서 예상치 못한 값에 대한 인플레이스 생성 태그
(태그) |