std::out_ptr_t::~out_ptr_t(3)
π std::out_ptr_t::~out_ptr_t π
okay bestie, welcome to the destructor of std::out_ptr_t β yes, the one from the C++ Standard Library, and yes, it's giving quietly powerful π
β¨ NAME β¨
std::out_ptr_t::~out_ptr_t β literally the destructor of std::out_ptr_t, no notes π
πΈ Synopsis πΈ
~out_ptr_t(); (since C++23)
So here's the vibe: this destructor resets the adapted Smart object using the value of the modified Pointer object (or the void* object if operator void**() has been called) plus the captured arguments. That's the whole main character move, periodt π«Ά
Let's define the cast, because we need the details:
sdenotes the adaptedSmartobject,args...denotes the captured arguments,pdenotes the value of storedPointer, orstatic_cast<Pointer>(*operator void**())ifoperator void**has been called,SPbeSmart::pointer, if it is valid and denotes a type, otherwise,Smart::element_type*, ifSmart::element_typeis valid and denotes a type, otherwise,std::pointer_traits<Smart>::element_type*, ifstd::pointer_traits<Smart>::element_typeis valid and denotes a type, otherwise,Pointer.
ik, that's a whole chain of "otherwise" β it's giving choose-your-own-adventure π but just follow it top to bottom and you'll land on the right type, trust.
If s.reset(static_cast<SP>(p), std::forward<Args>(args)...) is well-formed, the destructor performs:
if (p) s.reset(static_cast<SP>(p), std::forward<Args>(args)...);
otherwise, if std::is_constructible_v<Smart, SP, Args...> is true, the destructor performs:
if (p) s = Smart(static_cast<SP>(p), std::forward<Args>(args)...);
otherwise, the program is ill-formed. π no cap, that's the hard stop β bestie, don't go there.
π¦ Notes π¦
- If
Smartis astd::shared_ptrspecialization, the implementation may allocate the storage for the new control block on construction, in order to leave non-throwing works to the destructor. lowkey iconic of it β¨ - Arguments captured by value are destroyed after resetting. that's the order, respect it π
π reminder:if (p)is doing a lot of heavy lifting in both branches β the reset/assign only happens whenpis truthy. slay.
okay that's the whole page bestie, you ate that π β this was std::out_ptr_t::~out_ptr_t from the C++ Standard Library, brought to you by http://cppreference.com, dated 2024.06.10, and I hope your pointers stay out-ptr'd and your destructors stay well-formed πππ
π¦ 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