Specialization of std::shared_ptr
The C Standard Library includes a specialized template for std::unique_ptr that appropriately invokes delete[] in its destructor. However, a similar specialization is absent for std::shared_ptr, necessitating the use of a custom deleter to correctly deallocate arrays.
Reason for the Lack of Specialization
Initially, the omission of std::shared_ptr
Ultimately, the absence of a proposal for std::shared_ptr
Current Status
Despite the lack of a specialized template, C 17 introduced partial array support for shared_ptr, as specified in the shared_ptr::shared_ptr() method's third case. This update allows for the creation and destruction of arrays using shared_ptr, albeit without the convenience of a dedicated specialization.
Future Prospects
The draft TS (Technical Specification) N4077 outlined a potential path towards array support in shared_ptr, and this feature was eventually incorporated into C 17. The continued development of C may bring further enhancements to this area, offering additional flexibility and expressiveness for array management using shared pointers.
The above is the detailed content of Why Doesn't `std::shared_ptr` Have a Specialization for Array Types?. For more information, please follow other related articles on the PHP Chinese website!