Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |utility‎ |expected
       
       
      Utilities library
       
       
      constexpr ~expected();
      (since C++23)

      [edit]Main template destructor

      Destroys the contained value:

      • Ifhas_value() istrue, destroys the expected value.
      • Otherwise, destroys the unexpected value.

      This destructor is trivial ifstd::is_trivially_destructible_v<T> andstd::is_trivially_destructible_v<E> are bothtrue.

      [edit]void partial specialization destructor

      Ifhas_value() isfalse, destroys the unexpected value.

      This destructor is trivial ifstd::is_trivially_destructible_v<E> istrue.

      [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
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/expected/%7Eexpected&oldid=183125"

      [8]ページ先頭

      ©2009-2025 Movatter.jp