Home >Backend Development >C++ >Why Isn't There a std::shared_ptr Specialization in C ?
std::shared_ptr
The C standard library contains a specialization of std::unique_ptr for arrays, which correctly calls delete[] from its destructor. However, a similar specialization is notably absent for std::shared_ptr. This behavior requires users to manually provide a deleter that explicitly calls delete[].
Is this omission an oversight or intentional?
Reason for Absence
The C Library Working Group (LWG) has considered the possibility of a std::shared_ptr
Specifically, arithmetic operations on std::shared_ptr
Recent Developments
Informally, the topic has once again gained traction within the LWG, and a prototype has been developed. While there is potential for this feature to become a valuable tool, its inclusion in the standard remains uncertain.
Current Status
As of C 11, a std::shared_ptr
Update (2017)
The C 17 standard includes support for arrays in std::shared_ptr (case 3 of shared_ptr::shared_ptr()).
The above is the detailed content of Why Isn't There a std::shared_ptr Specialization in C ?. For more information, please follow other related articles on the PHP Chinese website!