Date: Sat, 23 Aug 2025 08:45:50 +0200
On 2025-08-23 at 08:15, organicoman via Std-Proposals wrote:
>
>
>
> The direct answer to "why is it not a reference" is the same as for why
> we have "*this" - these features were added to the language early, long
> before we even had references.
>
> C++ has a long history of not removing existing parts of the language,
> but instead add new alternatives. This is one of those cases - delete
> uses a pointer, because it always has.
>
> But if we change it from a copy to a reference, it won't break anything.
> The call sites will be the same, and the function signature is
> compatible. So?
>
It will break things, like programs with overloaded "operator new" and
"operator delete", that will now have the wrong signature.
The chosen solution was to add owning pointers, like unique_ptr and
shared_ptr, and then avoid direct use of new and delete. They are still
there - unchanged to support old programs - but with much less use in
modern C++.
>
>
>
> The direct answer to "why is it not a reference" is the same as for why
> we have "*this" - these features were added to the language early, long
> before we even had references.
>
> C++ has a long history of not removing existing parts of the language,
> but instead add new alternatives. This is one of those cases - delete
> uses a pointer, because it always has.
>
> But if we change it from a copy to a reference, it won't break anything.
> The call sites will be the same, and the function signature is
> compatible. So?
>
It will break things, like programs with overloaded "operator new" and
"operator delete", that will now have the wrong signature.
The chosen solution was to add owning pointers, like unique_ptr and
shared_ptr, and then avoid direct use of new and delete. They are still
there - unchanged to support old programs - but with much less use in
modern C++.
Received on 2025-08-23 06:45:55