Namespaces
Variants

std:: bad_expected_access

From cppreference.net
Utilities library
헤더 파일에 정의됨 <expected>
template < class E >
class bad_expected_access : public std :: bad_expected_access < void >
(1) (C++23부터)
template <>
class bad_expected_access < void > : public std:: exception
(2) (C++23부터)
1) 예상 객체가 예상치 못한 값을 포함할 때 std::expected::value 에 의해 발생되는 객체 유형을 정의합니다. bad_expected_access<E> 는 예상치 못한 값의 사본을 저장합니다.
2) bad_expected_access < void > 는 다른 모든 bad_expected_access 특수화의 기본 클래스입니다.
std::bad_expected_access 의 모든 멤버 함수는 constexpr 입니다: 상수 표현식 평가 중에 std::bad_expected_access 객체를 생성하고 사용하는 것이 가능합니다.

그러나, std::bad_expected_access 객체는 일반적으로 constexpr 일 수 없습니다. 왜냐하면 동적으로 할당된 저장 공간은 동일한 상수 표현식 평가 내에서 해제되어야 하기 때문입니다.

(C++26부터)

목차

기본 템플릿의 멤버

(constructor)
bad_expected_access 객체를 생성합니다
(public member function)
error
저장된 값을 반환합니다
(public member function)
what
설명 문자열을 반환합니다
(public member function)

std::bad_expected_access:: bad_expected_access

explicit bad_expected_access ( E e ) ;
(C++23부터)
(C++26부터 constexpr)

새로운 bad_expected_access<E> 객체를 생성합니다. 저장된 값을 std::move(e) 로 초기화합니다.

std::bad_expected_access:: error

const E & error ( ) const & noexcept ;
(1) (C++23부터)
(C++26부터 constexpr)
E & error ( ) & noexcept ;
(2) (C++23부터)
(C++26부터 constexpr)
const E && error ( ) const && noexcept ;
(3) (C++23부터)
(C++26부터 constexpr)
E && error ( ) && noexcept ;
(4) (C++23부터)
(C++26부터 constexpr)

저장된 값에 대한 참조를 반환합니다.

std::bad_expected_access:: what

const char * what ( ) const noexcept override ;
(C++23부터)
(C++26부터 constexpr)

설명 문자열을 반환합니다.

반환 값

설명 정보를 포함하는 null로 종료된 문자열에 대한 포인터. 이 문자열은 std::wstring 으로 변환 및 표시하기에 적합합니다. 이 포인터는 최소한 해당 포인터를 얻은 예외 객체가 소멸되거나, 예외 객체의 비상수 멤버 함수(예: 복사 할당 연산자)가 호출되기 전까지는 유효함이 보장됩니다.

상수 평가 중에는 반환된 문자열이 일반 리터럴 인코딩으로 인코딩됩니다.

(C++26부터)

참고

구현체는 what() 을 재정의할 수 있지만, 필수는 아닙니다.

std::bad_expected_access std:: bad_expected_access < void > 로부터 상속됨

bad_expected_access < void > 특수화의 멤버

(생성자)
bad_expected_access < void > 객체를 생성함
(보호된 멤버 함수)
(소멸자)
bad_expected_access < void > 객체를 파괴함
(보호된 멤버 함수)
operator=
bad_expected_access < void > 객체를 대체함
(보호된 멤버 함수)
what
설명 문자열을 반환함
(공개 멤버 함수)

bad_expected_access < void > 의 특수 멤버 함수들은 보호되어 있습니다. 파생 클래스에서만 호출할 수 있습니다.

std:: exception 에서 상속됨

멤버 함수

[virtual]
예외 객체를 파괴함
( std::exception 의 virtual public 멤버 함수)
[virtual]
설명 문자열을 반환함
( std::exception 의 virtual public 멤버 함수)

참고 사항

기능 테스트 매크로 표준 기능
__cpp_lib_constexpr_exceptions 202502L (C++26) constexpr std::bad_expected_access

예제

참고 항목

값을 포함하지 않는 optional에 대한 검증된 접근을 나타내는 예외
(클래스)
variant 값에 대한 잘못된 접근 시 발생하는 예외
(클래스)