Namespaces
Variants

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

cppreference.net에서 가져옴
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐기됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교체 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
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 객체를 생성합니다.

1) 기본 생성자입니다. T이 (cv 한정 가능한) void가 아닌 경우, 값 초기화된 기댓값을 포함하는 객체를 생성합니다.
생성 후, has_value()는 true을 반환합니다.
이 오버로드는 T이 (cv 한정 가능한) void이거나 std::is_default_constructible_v<T>이 true인 경우에만 오버로드 해결에 참여합니다.
2) 복사 생성자입니다. other.has_value()이 false이면, 새 객체는 직접 초기화된 예상치 못한 값을 포함합니다. 그렇지 않고 other.error()이 (cv 한정 가능한) T가 아니면, 새 객체는 void직접 초기화된 기댓값을 포함합니다. 생성 후, *other는
과 같습니다.has_value() 이 생성자는 다음 경우가 아니면 삭제된 것으로 정의됩니다. other.has_value()
이 (cv 한정 가능한)
  • 이거나, T가 void이고,std::is_copy_constructible_v<T>가 true인 경우.
  • std::is_copy_constructible_v<E> 이 생성자는 다음 경우에 사소한(trivial) 것입니다. true
이 (cv 한정 가능한)
  • 이거나, T가 void이고,std::is_trivially_copy_constructible_v<T>가 true인 경우.
  • std::is_trivially_copy_constructible_v<E>3)true 이동 생성자입니다.
이 이면, 새 객체는 other.has_value()직접 초기화false된 예상치 못한 값을 포함합니다. 그렇지 않고 이 (cv 한정 가능한) 가 아니면, 새 객체는 std::move(other.error())직접 초기화T된 기댓값을 포함합니다.void 생성 후, 는 과 같습니다.std::move(*other) 이 생성자는 다음 경우에만 오버로드 해결에 참여합니다.
has_value()이 (cv 한정 가능한) other.has_value()이거나,
가
  • 이고,T가 void인 경우.std::is_move_constructible_v<T> 이 생성자는 다음 경우에 사소한 것입니다. true가
  • std::is_move_constructible_v<E>이고,true가
인 경우.
  • std::is_trivially_move_constructible_v<T>4,5)true
  • std::is_trivially_move_constructible_v<E>을 true에 대해
(4)로,
  • UF에 대해 std::add_lvalue_reference_t<const U>(5)로 하고,을 U에 대해 (4)로,
  • GF에 대해 const G&(5)로 합니다. G이 이면, 새 객체는 직접 초기화
된 예상치 못한 값을 포함합니다. 그렇지 않고 other.has_value()이 (cv 한정 가능한) false가 아니면, 새 객체는 직접 초기화된 기댓값을 포함합니다.std::forward<GF>(other.error()) 생성 후, T는 void과 같습니다. 이 생성자들 각각은 다음 조건이 각각 충족되는 경우에만 오버로드 해결에 참여합니다. 다음 중 하나: std::forward<UF>(*other)이 (cv 한정 가능한)
이고 has_value()가 other.has_value()이거나,
가
  • 입니다.
    • T는 void입니다.std::is_void_v<U>true이 (cv 한정 가능한)
    • std::is_constructible_v<T, UF>가 아닌 경우, true는 (
  • std::is_constructible_v<E, GF>) true 타입의 어떤 표현식으로부터도 생성 가능하거나 변환 가능하지 않습니다. 즉, 다음 8개 값은 모두
  • 입니다. Tbool는 (T) const 타입의 어떤 표현식으로부터도 생성 가능하지 않습니다. 즉, 다음 4개 값은 모두 std::expected<U, G>입니다. 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>이면 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>
6)explicit 기댓값을 포함하는 객체를 생성하며, std::is_convertible_v<UF, T>직접 초기화std::is_convertible_v<GF, E>(직접 리스트 초기화는 아님)를 통해 false 타입의 객체를 표현식
으로 초기화한 것처럼 초기화됩니다. 생성 후, 는 을 반환합니다.T 이 생성자는 다음 조건이 충족되는 경우에만 오버로드 해결에 참여합니다. std::forward<U>(v)
은 (cv 한정 가능한) has_value()이 아닙니다.true
는
  • T입니다.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인 경우에만 오버로드 해결에 참여합니다.
9) 기댓값을 포함하는 객체를 생성하며, 이 값은 인수 로부터 직접 초기화std::forward<Args>(args)...됩니다.
생성 후, has_value()는 true을 반환합니다.
이 오버로드는 std::is_constructible_v<T, Args...>이 true인 경우에만 오버로드 해결에 참여합니다.
10) 기댓값을 포함하는 객체를 생성하며, 이 값은 인수 로부터 직접 초기화il, std::forward<Args>(args)...됩니다.
생성 후, has_value()는 true을 반환합니다.
이 오버로드는 std::is_constructible_v<T, std::initializer_list<U>&, Args...>이 true인 경우에만 오버로드 해결에 참여합니다.
11) 생성 후 has_value()가 true을 반환하도록 객체를 생성합니다.
12) 예상치 못한 값을 포함하는 객체를 생성하며, 이 값은 인수 로부터 직접 초기화std::forward<Args>(args)...됩니다.
생성 후, has_value()는 false을 반환합니다.
이 오버로드는 std::is_constructible_v<E, Args...>이 true인 경우에만 오버로드 해결에 참여합니다.
13) 예상치 못한 값을 포함하는 객체를 생성하며, 이 값은 인수 로부터 직접 초기화il, std::forward<Args>(args)...됩니다.
생성 후, 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)
예상치 못한 값으로 표현됨
(클래스 템플릿)
인플레이스 생성 태그
(태그)
expected 에서 예상치 못한 값에 대한 인플레이스 생성 태그
(태그)