std::shared_ptr::operator=(3)
β¨ std::shared_ptr::operator= (3) β bestie edition π
okay so this is the glow-up of the std::shared_ptr::operator= page from the C++ Standard Libary manual (yes, βLibaryβ β thatβs literally how the page spells it π). Itβs giving overload (3) main character energy, but the page actually covers a whole little family of assignment operators, and we are keeping every single one. no cap.
πΈ NAME
std::shared_ptr::operator= β std::shared_ptr::operator=
π Synopsis
shared_ptr& operator=( const shared_ptr& r ) noexcept; (1)
template< class Y > (2)
shared_ptr& operator=( const shared_ptr<Y>& r ) noexcept;
shared_ptr& operator=( shared_ptr&& r ) noexcept; (3)
template< class Y > (4)
shared_ptr& operator=( shared_ptr<Y>&& r ) noexcept;
template< class Y > (5)
(deprecated in C++11)
shared_ptr& operator=( std::auto_ptr<Y>&& r );
(removed in C++17)
template< class Y, class Deleter > (6)
shared_ptr& operator=( std::unique_ptr<Y, Deleter>&& r );
Replaces the managed object with the one managed by r. π«Ά
If*thisalready owns an object and it is the lastshared_ptrowning it, andris not the same as*this, the object is destroyed through the owned deleter. π
- (1), (2) β Shares ownership of the object managed by
r. Ifrmanages no object,*thismanages no object too. Equivalent toshared_ptr<T>(r).swap(*this). β¨ - (3), (4) β Move-assigns a
shared_ptrfromr. After the assignment,*thiscontains a copy of the previous state ofr, andris empty. Equivalent toshared_ptr<T>(std::move(r)).swap(*this). π₯ - (5) β Transfers the ownership of the object managed by
rto*this. Ifrmanages no object,*thismanages no object too. After the assignment,*thiscontains the pointer previously held byr, anduse_count() == 1; alsoris empty. Equivalent toshared_ptr<T>(r).swap(*this). π¦ - (6) β Transfers the ownership of the object managed by
rto*this. The deleter associated toris stored for future deletion of the managed object.rmanages no object after the call. Equivalent toshared_ptr<T>(std::move(r)).swap(*this). π
π Parameters
rβ another smart pointer to share the ownership to or acquire the ownership from.
π«Ά Return value
*this β thatβs the vibe. π
π§ Notes
The implementation may meet the requirements without creating a temporary shared_ptr object. iconic, honestly β¨
π Exceptions
5,6β May throw implementation-defined exceptions.
π Example
This section is incomplete Reason: no example
π See also
resetβ replaces the managed object (public member function)
π·οΈ Category
- Todo no example
okay thatβs the whole page, bestie. source vibes: http://cppreference.com, dated 2024.06.10, and the footer is literally std::shared_ptr::operator=(3). mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms