std::inout_...inout_ptr_t(3)
πΈ NAME πΈ
std::inout_ptr_t::~inout_ptr_t β literally the destructor for std::inout_ptr_t. Thatβs the whole name, bestie. π
β¨ Synopsis β¨
Okay so this is from the C++ Standard Libary manual, page std::inout_...inout_ptr_t(3), and the signature is exactly this:
~inout_ptr_t(); (since C++23)
It resets the adapted Smart object by the value of the modified Pointer object (or the void* object if operator void**() has been called) and the captured arguments. release() may be called on the adapted Smart object if it is not called by the constructor. π«Ά
Letβs define the cast so nobody gets lost:
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,
/*do-release*/denotess.release()if the constructor does not callrelease(), empty otherwise.
Now the destructor behavior, in order:
- If
Smartis a pointer type, the destructor performss = static_cast<Smart>(p);, and the program is ill-formed ifsizeof...(Args) > 0; - otherwise, if
s.reset(static_cast<SP>(p), std::forward<Args>(args)...)is well-formed, the destructor performs
/*do-release*/; 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
/*do-release*/; if (p) { s = Smart(static_cast<SP>(p), std::forward<Args>(args)...); };
- otherwise, the program is ill-formed.
π¨ Bestie, that last βotherwiseβ is not a drill: the program is ill-formed. Periodt.
π Notes π
- The implementation may allocate the storage for the data structure needed for
Smart(e.g. a control block) on construction, in order to leave non-throwing works to the destructor. π - Arguments captured by value are destroyed after resetting. π§Ό
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 3897β Applied to:C++23. Behavior as published: the destructor did not update a raw pointer to the null value. Correct behavior: it does. β
Source: http://cppreference.com Β· Version/date: 2024.06.10 Β· Page: std::inout_...inout_ptr_t(3) β bye bestie, go destroy 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