Date: Tue, 14 Apr 2026 17:04:37 +0800
I think it can work on pointers to (an array of) non-trivially-destructible
objects. Maybe nobody finds a real usage scenario for this, thus no one has
proposed it?
On Tue, 14 Apr 2026 at 16:47, Marcin Jaczewski via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> If I have a pointer that I can call `delete[]` on it, then why does
> the standard not allow
> getting the size of this storage aside in case of deleting it?
> like:
>
> ```
> auto* p = new Foo[100]{};
> auto size = std::get_allocated_elements(p);
> delete[] p;
> assert(size == 100);
> ```
>
> Only case where I could see this not working is `new char[]` as it could
> skip
> this metadata as no destructor call is needed for elements.
>
> There are other limitations that prevent the standard to have it?
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
objects. Maybe nobody finds a real usage scenario for this, thus no one has
proposed it?
On Tue, 14 Apr 2026 at 16:47, Marcin Jaczewski via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> If I have a pointer that I can call `delete[]` on it, then why does
> the standard not allow
> getting the size of this storage aside in case of deleting it?
> like:
>
> ```
> auto* p = new Foo[100]{};
> auto size = std::get_allocated_elements(p);
> delete[] p;
> assert(size == 100);
> ```
>
> Only case where I could see this not working is `new char[]` as it could
> skip
> this metadata as no destructor call is needed for elements.
>
> There are other limitations that prevent the standard to have it?
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
-- Yongwei Wu URL: http://wyw.dcweb.cn/
Received on 2026-04-14 09:04:51
