C++ Logo

std-proposals

Advanced search

Re: [std-proposals] I have a span but I need a container

From: Ivan Matek <libbooze_at_[hidden]>
Date: Tue, 17 Jun 2025 12:48:51 +0200
On Tue, Jun 17, 2025 at 9:53 AM Arthur O'Dwyer via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> However, the thing in this thread is yet again different: it's kind of
> like `is_trivially_const_referenceable_as<T, U>`.
> The problem is, I don't see how the compiler could *ever* infer this kind
> of thing for user-defined types.
>
I absolutely agree, for example in my case there is no way for compiler to
check the function will not delete the raw pointers I gave it( and corrupt
unique_ptr). This working depends on me reading function documentation
where it says it does not modify pointers, and then hacking a way to expose
vector of unique_ptr as vector of pointers.
But to be honest I do not believe this is such a horrible problem, as I
mentioned if library just provides overloads with string_view/span the
issue is solved since those types "erase" container type(although they
obviously work with any region of memory, not just containers).

But I just remembered a talk from CppCon that might interest OP:
https://youtu.be/fglXeSWGVDc?feature=shared&t=780
Basically the String class knows when it is initialized from 'static :)
lifetime char array so it does not allocate it on heap. I presume with ABI
break it is possible to make std::string do this, but I am not sure people
would be delighted about unpredictable branch in some special
member functions.

Received on 2025-06-17 10:49:04