std::weak_ptr::operator=(3)
Hey bestie! Welcome to the std::weak_ptr::operator=(3) page from the C++ Standard Libary manual πβ¨ (yes, βLibaryβ is exactly how the manual name is spelled up there β we respect the typo, no cap).
π NAME π
std::weak_ptr::operator= β std::weak_ptr::operator=. Thatβs it, thatβs the name. Sheβs self-titled and honestly? Main character energy π.
πΈ Synopsis πΈ
Okay so there are five overloads, all chillinβ since C++11 and all noexcept. Hereβs the exact lineup, bestie:
weak_ptr& operator=( const weak_ptr& r ) noexcept; (1) (since C++11)
template< class Y > (2) (since C++11)
weak_ptr& operator=( const weak_ptr<Y>& r ) noexcept;
template< class Y > (3) (since C++11)
weak_ptr& operator=( const shared_ptr<Y>& r ) noexcept;
weak_ptr& operator=( weak_ptr&& r ) noexcept; (4) (since C++11)
template< class Y > (5) (since C++11)
weak_ptr& operator=( weak_ptr<Y>&& r ) noexcept;
The vibe of the whole thing: replaces the managed object with the one managed by r. The object is shared with r. If r manages no object, *this manages no object too. Periodt. π
Specifically:
- Overloads
1-3)β equivalent tostd::weak_ptr<T>(r).swap(*this). - Overloads
4,5)β equivalent tostd::weak_ptr<T>(std::move(r)).swap(*this).
π Parameters π
rβ smart pointer to share an object with π
π«Ά Return value π«Ά
*this. Thatβs the whole return value. She gives herself back. Iconic.
π Notes π
Implementation tea β: the implementation may meet the requirements without creating a temporary weak_ptr object. No extra temp needed, lowkey efficient.
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Yes bestie, retroactive glow-ups are real.
- DR LWG 2315 β applied to C++11. Behavior as published:
move semantic was not enabled for weak_ptr. Correct behavior:enabled.
π See also π
constructorβ creates a newweak_ptr(public member function) β¨swapβ swaps the managed objects (public member function) π
Thatβs the whole page, bestie π«Ά β brought to you by http://cppreference.com, dated 2024.06.10, and filed under std::weak_ptr::operator=(3). Go forth and assign responsibly πβ¨
π¦ 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