std::expected<T,E>::and_then
cppreference.net에서 가져옴
| 주 템플릿 |
||
template< class F >
constexpr auto and_then( F&& f ) &;
|
(1) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) const&;
|
(2) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) &&;
|
(3) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) const&&;
|
(4) | (C++23부터) |
void 부분 특수화 |
||
template< class F >
constexpr auto and_then( F&& f ) &;
|
(5) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) const&;
|
(6) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) &&;
|
(7) | (C++23부터) |
template< class F >
constexpr auto and_then( F&& f ) const&&;
|
(8) | (C++23부터) |
*this이 예상 값을 나타내는 경우 f을(를) 호출하고 그 결과를 반환합니다. 그렇지 않으면 std::expected이 포함된 *this 개체를 반환하며, 이는
을(를) 인수로 사용하여 호출됩니다.
f5-8)은(는) 인수 없이 호출됩니다.U주어진 타입
을(를) 다음과 같이 정의합니다:
std::remove_cvref_t<std::invoke_result_t<F, decltype((val))>>1,2)
std::remove_cvref_t<std::invoke_result_t<F, decltype(std::move(val))>>3,4)
std::remove_cvref_t<std::invoke_result_t<F>>5-8)Ustd::expected이 std::is_same_v<U::error_type, E>의 특수화가 아니거나 false이(가)
인 경우 프로그램의 형식이 잘못되었습니다.
1,2)
std::is_constructible_v<E, decltype(error())> 이러한 오버로드는 true이(가) 인 경우에만 오버로드 해결에 참여합니다.3,4)
std::is_constructible_v<E, decltype(std::move(error()))> 이러한 오버로드는 true이(가) 인 경우에만 오버로드 해결에 참여합니다.5,6)
std::is_constructible_v<E, decltype(error())> 이러한 오버로드는 true이(가) 인 경우에만 오버로드 해결에 참여합니다.7,8)
std::is_constructible_v<E, decltype(std::move(error()))> 이러한 오버로드는 true이(가) 매개변수
| f | - | 적합한 함수 또는 Callable 객체로서 std::expected 를 반환하는 |
반환값
| 오버로드 |
has_value()
의 값
|
|
|---|---|---|
| true | false | |
| ( 1,2 ) |
std::
invoke
(
std::
forward
<
F
>
(
f
)
,
val
)
|
U ( std:: unexpect , error ( ) ) |
| ( 3,4 ) |
std::
invoke
(
std::
forward
<
F
>
(
f
)
,std
::
move
(
val
)
)
|
U ( std:: unexpect , std :: move ( error ( ) ) ) |
| ( 5,6 ) | std:: invoke ( std:: forward < F > ( f ) ) | U ( std:: unexpect , error ( ) ) |
| ( 7,8 ) | U ( std:: unexpect , std :: move ( error ( ) ) ) | |
참고 사항
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_expected
|
202211L
|
(C++23) |
std::expected
에 대한 모나딕 함수
|
예제
|
이 섹션은 불완전합니다
이유: 예제가 없음 |
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 3938 | C++23 | 기대값이 value ( ) [1] 로 획득됨 | 다음으로 변경됨 ** this |
| LWG 3973 | C++23 | 기대값이 ** this [2] 로 획득됨 |
다음으로 변경됨
val
|
-
↑
value()는E가 복사 생성 가능해야 하지만 (참조: LWG 이슈 3843 ),operator*는 그렇지 않습니다. - ↑ ** this 는 인수 의존적 탐색 을 유발할 수 있습니다.
참고 항목
|
(C++23)
|
expected
에서 예상치 못한 값을 위한 인플레이스 생성 태그
(태그) |
예상된 값이 존재할 경우 변환된 값을 포함하는
expected
를 반환하고, 그렇지 않으면
expected
자체를 반환함
(public member function) |