std::expected<T,E>::~expected
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::expected
expected::~expected
constexpr ~expected();
(since C++23)
[edit] Main template destructor
Destroys the contained value:
- If
has_value()
is true, destroys the expected value. - Otherwise, destroys the unexpected value.
This destructor is trivial if std::is_trivially_destructible_v <T> and std::is_trivially_destructible_v <E> are both true.
[edit] void partial specialization destructor
If has_value()
is false, destroys the unexpected value.
This destructor is trivial if std::is_trivially_destructible_v <E> is true.
[edit] Example
Run this code
#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}; }
Output:
~Error : 37 ~Error : 13 ~Value : 42