Home >Backend Development >C++ >Why Isn't There a std::shared_ptr Specialization in C ?

Why Isn't There a std::shared_ptr Specialization in C ?

DDD
DDDOriginal
2024-11-10 06:48:03991browse

Why Isn't There a std::shared_ptr Specialization in C  ?

std::shared_ptr Specialization

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 specialization, but controversy surrounding additional features prevented its inclusion.

Specifically, arithmetic operations on std::shared_ptr were proposed but were met with opposition. Ultimately, the lack of an official proposal and prioritization led to the feature's exclusion from the standard.

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 specialization has not been standardized. However, there is an ongoing draft TS proposal (N4077) that introduces array support for 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!

Statement:
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