Namespaces
Variants

std::expected<T,E>:: transform_error

From cppreference.net
Utilities library
기본 템플릿
template < class F >
constexpr auto transform_error ( F && f ) & ;
(1) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) const & ;
(2) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) && ;
(3) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) const && ;
(4) (C++23부터)
void 부분 특수화
template < class F >
constexpr auto transform_error ( F && f ) & ;
(5) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) const & ;
(6) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) && ;
(7) (C++23부터)
template < class F >
constexpr auto transform_error ( F && f ) const && ;
(8) (C++23부터)

만약 * this 가 예상치 못한 값을 포함하고 있다면, f * this 의 예상치 못한 값을 인자로 호출하고, f 의 결과로 초기화된 예상치 못한 값을 포함하는 std::expected 객체를 반환합니다. 그렇지 않으면, 예상된 값을 나타내는 std::expected 객체를 반환합니다.

1-4) 기대값은 val 의 기대값으로 초기화됩니다 * this .

주어진 타입 G 는 다음과 같습니다:

1,2) std:: remove_cv_t < std:: invoke_result_t < F, decltype ( error ( ) ) >>
3,4) std:: remove_cv_t < std:: invoke_result_t < F, decltype ( std :: move ( error ( ) ) ) >>
5,6) std:: remove_cv_t < std:: invoke_result_t < F, decltype ( error ( ) ) >>
7,8) std:: remove_cv_t < std:: invoke_result_t < F, decltype ( std :: move ( error ( ) ) ) >>

다음 조건 중 하나라도 충족되면 프로그램의 형식이 잘못되었습니다:

  • G std::unexpected 의 유효한 템플릿 인수가 아닙니다.
  • 다음에 해당하는 선언은 잘못된 형식입니다:
1,2) G g ( std:: invoke ( std:: forward < F > ( f ) , error ( ) ) ) ;
3,4) G g ( std:: invoke ( std:: forward < F > ( f ) , std :: move ( error ( ) ) ) ;
5,6) G g ( std:: invoke ( std:: forward < F > ( f ) , error ( ) ) ) ;
7,8) G g ( std:: invoke ( std:: forward < F > ( f ) , std :: move ( error ( ) ) ) ;


1,2) 이 오버로드는 다음 조건이 std:: is_constructible_v < T, decltype ( ( val ) ) > 일 때만 오버로드 해결에 참여합니다.
3,4) 이 오버로드는 다음 조건이 std:: is_constructible_v < T, decltype ( std :: move ( val ) ) > 일 때만 오버로드 해결에 참여합니다.

목차

매개변수

f - 적절한 함수 또는 Callable 객체로, 호출 시그니처가 비-참조형을 반환하는

반환값

주어진 표현식 expr 는 다음과 같습니다:

1,2) std:: invoke ( std:: forward < F > ( f ) , error ( ) )
3,4) std:: invoke ( std:: forward < F > ( f ) , std :: move ( error ( ) ) )
5,6) std:: invoke ( std:: forward < F > ( f ) , error ( ) )
7,8) std:: invoke ( std:: forward < F > ( f ) , std :: move ( error ( ) ) )

반환 값은 다음과 같이 정의됩니다:

오버로드 has_value() 의 값
true false
( 1,2 ) std:: expected < T, G > ( std:: in_place , val ) std:: expected < T, G >
( std:: unexpect , expr )
( 3,4 ) std:: expected < T, G > ( std:: in_place , std :: move ( val ) )
( 5,6 ) std:: expected < T, G > ( )
( 7,8 )

예제

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 수정된 동작
LWG 3938 C++23 기대값이 value ( ) [1] 로 획득됨 다음으로 변경됨 ** this
LWG 3973 C++23 기대값이 ** this [2] 로 획득됨 다음으로 변경됨 val
  1. value() E 가 복사 생성 가능해야 하지만 (참조: LWG 이슈 3843 ), operator* 는 그렇지 않습니다.
  2. ** this 인수 의존적 탐색 을 유발할 수 있습니다.

참고 항목

예상된 값을 포함하고 있으면 expected 자체를 반환하고, 그렇지 않으면 예상치 못한 값에 대해 주어진 함수의 결과를 반환합니다
(public member function)
예상된 값이 존재하면 변환된 예상된 값을 포함하는 expected 를 반환하고, 그렇지 않으면 expected 자체를 반환합니다
(public member function)