Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::optional<T>::swap

      From cppreference.com
      <cpp‎ |experimental‎ |optional
       
       
       
       
       
      void swap( optional& other)noexcept(/* see below */);
      (library fundamentals TS)

      Swaps the contents with those ofother.

      • If neither*this norother contain a value, the function has no effect.
      • If only one of*this andother contains a value (let's call this objectin and the otherun), the contained value ofun isdirect-initialized fromstd::move(*in), followed by destruction of the contained value ofin as if byin.val->T::~T(). After this call,in does not contain a valueun contains a value.
      • If both*this andother contain values, the contained values are exchanged by callingusingstd::swap; swap(**this,*other).T lvalues must satisfySwappable.

      Contents

      [edit]Parameters

      other - theoptional object to exchange the contents with

      [edit]Return value

      (none)

      [edit]Exceptions

      noexcept specification:  
      noexcept(std::is_nothrow_move_constructible<T>::value&&
                 noexcept(swap(std::declval<T&>(),std::declval<T&>())))

      In the case of thrown exception, the states of the contained values of*this andother are determined by the exception safety guarantees ofswap of typeT orT's move constructor, whichever is called. For both*this andother, if the object contained a value, it is left containing a value, and the other way round.

      [edit]See also

      specializes thestd::swap algorithm
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/optional/swap&oldid=155042"

      [8]ページ先頭

      ©2009-2025 Movatter.jp