std::out_ptr_t::~out_ptr_t(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… 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:

  • s denotes the adapted Smart object,
  • args... denotes the captured arguments,
  • p denotes the value of stored Pointer, or static_cast<Pointer>(*operator void**()) if operator void** has been called,
  • SP be
    • Smart::pointer, if it is valid and denotes a type, otherwise,
    • Smart::element_type*, if Smart::element_type is valid and denotes a type, otherwise,
    • std::pointer_traits<Smart>::element_type*, if std::pointer_traits<Smart>::element_type is 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 Smart is a std::shared_ptr specialization, 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 when p is 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