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();
(C++23부터)

메인 템플릿 소멸자

포함된 값을 파괴합니다:

  • 만약 has_value() 가 true 이면, 기대값을 파괴합니다.
  • 그렇지 않으면, 예상치 못한 값을 파괴합니다.

이 소멸자는 std:: is_trivially_destructible_v < T > 와 std:: is_trivially_destructible_v < E > 가 모두 true 인 경우 trivial합니다.

void 부분 특수화 소멸자

만약 has_value() 가 false 인 경우, 예상치 못한 값을 파괴합니다.

이 소멸자는 std:: is_trivially_destructible_v < E > 가 true 일 때 trivial합니다.

예제

#include <expected>
#include <print>
void info(auto name, int x)
{
    std::println("{} : {}", name, x);
}
struct Value
{
    int o{};
    ~Value() { info(__func__, o); }
};
struct Error
{
    int e{};
    ~Error() { info(__func__, e); }
};
int main()
{
    std::expected<Value, Error> e1{42};
    std::expected<Value, Error> e2{std::unexpect, 13};
    std::expected<void, Error> e3{std::unexpect, 37};
}

출력:

~Error : 37
~Error : 13
~Value : 42