Why std::shared_ptr
In contrast to std::unique_ptr, which appropriately invokes delete[] in its destructor for arrays, std::shared_ptr lacks a comparable specialization. Consequently, users must manually provide a deleter that correctly deallocates arrays.
Reasons for the Oversight
While the absence of a std::shared_ptr
Recent Developments
Renewed interest in array support for std::shared_ptr has emerged, leading to the creation of a draft technical specification (TS). This TS (n4077.html) proposes a mechanism to extend shared_ptr's functionality to arrays.
Current Status and Future Prospects
The draft TS has been approved as part of C 17, providing official support for array handling in std::shared_ptr. This feature enhancement enables seamless array management and simplifies memory allocation tasks for programmers.
The above is the detailed content of Why Doesn't `std::shared_ptr` Have a Specialization for Array Deletion?. For more information, please follow other related articles on the PHP Chinese website!