Home > Backend Development > C++ > body text

Why Doesn't `std::shared_ptr` Have a Specialization for Arrays in C ?

DDD
Release: 2024-11-20 16:18:16
Original
789 people have browsed it

Why Doesn't `std::shared_ptr` Have a Specialization for Arrays in C  ?

Specialization of std::shared_ptr

In C , std::unique_ptr has a template specialization for handling arrays, which appropriately invokes delete[] in its destructor. However, no such specialization exists for std::shared_ptr.

Why the Absence?

Initially, the oversight was likely due to time constraints, as the LWG (C committee) had many other pressing matters. However, the lack of a formal proposal also played a role.

Recent Developments

Informal discussions have brought the issue back to the forefront, and prototypes have been implemented. However, a formal proposal is still pending. Some LWG members believe that array support for std::shared_ptr would be a valuable addition.

Current Status

As of C 14, there is no built-in specialization for std::shared_ptr. To handle arrays, one must provide a custom deleter that calls delete[].

Update

In 2014, a draft Technical Specification (TS) was proposed to add array support to std::shared_ptr. This proposal has been implemented in C 17.

The above is the detailed content of Why Doesn't `std::shared_ptr` Have a Specialization for Arrays in C ?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template