Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::shared_ptr<T>::operator=

      From cppreference.com
      <cpp‎ |memory‎ |shared ptr
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
      std::shared_ptr
      Member functions
      shared_ptr::operator=
      Modifiers
      Observers
      (until C++20*)
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
      functions(until C++26*)
      Helper classes
      Deduction guides(C++17)
       
      shared_ptr& operator=(const shared_ptr& r)noexcept;
      (1)
      template<class Y>
      shared_ptr& operator=(const shared_ptr<Y>& r)noexcept;
      (2)
      shared_ptr& operator=( shared_ptr&& r)noexcept;
      (3)
      template<class Y>
      shared_ptr& operator=( shared_ptr<Y>&& r)noexcept;
      (4)
      template<class Y>
      shared_ptr& operator=(std::auto_ptr<Y>&& r);
      (5)(deprecated in C++11)
      (removed in C++17)
      template<class Y,class Deleter>
      shared_ptr& operator=(std::unique_ptr<Y, Deleter>&& r);
      (6)

      Replaces the managed object with the one managed byr.

      If*this already owns an object and it is the lastshared_ptr owning it, andr is not the same as*this, the object is destroyed through the owned deleter.

      1,2) Shares ownership of the object managed byr. Ifr manages no object,*this manages no object too. Equivalent toshared_ptr<T>(r).swap(*this).
      3,4) Move-assigns ashared_ptr fromr. After the assignment,*this contains a copy of the previous state ofr, andr is empty. Equivalent toshared_ptr<T>(std::move(r)).swap(*this).
      5) Transfers the ownership of the object managed byr to*this. Ifr manages no object,*this manages no object too. After the assignment,*this contains the pointer previously held byr, anduse_count()==1; alsor is empty. Equivalent toshared_ptr<T>(r).swap(*this).
      6) Transfers the ownership of the object managed byr to*this. The deleter associated tor is stored for future deletion of the managed object.r manages no object after the call. Equivalent toshared_ptr<T>(std::move(r)).swap(*this).

      Contents

      [edit]Parameters

      r - another smart pointer to share the ownership to or acquire the ownership from

      [edit]Return value

      *this

      [edit]Notes

      The implementation may meet the requirements without creating a temporaryshared_ptr object.

      [edit]Exceptions

      5,6) May throw implementation-defined exceptions.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      replaces the managed object
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/shared_ptr/operator%3D&oldid=157243"

      [8]ページ先頭

      ©2009-2025 Movatter.jp