Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |utility‎ |expected
       
       
      Utilities library
       
       
      Primary template
      template<class...Args>
      constexpr T& emplace( Args&&...args)noexcept;
      (1)(since C++23)
      template<class U,class...Args>
      constexpr T& emplace(std::initializer_list<U> il, Args&&...args)noexcept;
      (2)(since C++23)
      void partial specialization
      constexprvoid emplace()noexcept;
      (3)(since C++23)

      Constructs an expected value in-place. After the call,has_value() returns true.

      1) Destroys the contained value, thendirect-initializes the expected value contained in*this withstd::forward<Args>(args)....
      This overload participates in overload resolution only ifstd::is_nothrow_constructible_v<T, Args...> istrue.
      2) Destroys the contained value, then direct-initializes the expected value contained in*this withil andstd::forward<Args>(args)....
      This overload participates in overload resolution only ifstd::is_nothrow_constructible_v<T,std::initializer_list<U>&, Args...> istrue.
      3) If*this contains an unexpected value, destroys that value.

      Contents

      [edit]Parameters

      args - the arguments to pass to the constructor
      il - the initializer list to pass to the constructor

      [edit]Return value

      1)*std::construct_at(std::addressof(val),std::forward<Args>(args)...)
      2)*std::construct_at(std::addressof(val), il,std::forward<Args>(args)...)

      [edit]Notes

      If the construction ofT is potentially-throwing,operator= can be used instead.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      assigns contents
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/expected/emplace&oldid=173295"

      [8]ページ先頭

      ©2009-2025 Movatter.jp