std::expected<T,E>:: ~expected
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
|
expected::~expected
|
||||
| Observers | ||||
| Monadic operations | ||||
| Modifiers | ||||
| Non-member functions | ||||
| Helper classes | ||||
|
constexpr
~expected
(
)
;
|
(C++23以降) | |
メインテンプレートデストラクタ
保持されている値を破棄します:
-
has_value()が true の場合、期待値を破棄します。 - それ以外の場合、非期待値を破棄します。
このデストラクタは、 std:: is_trivially_destructible_v < T > と std:: is_trivially_destructible_v < E > の両方が true の場合、自明です。
void 部分特殊化デストラクタ
has_value()
が
false
の場合、unexpected値を破棄します。
このデストラクタは、 std:: is_trivially_destructible_v < E > が true の場合、トリビアルです。
例
#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