C++ Logo

std-proposals

Advanced search

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

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 23 Jun 2025 16:51:05 -0400
On Mon, Jun 23, 2025 at 2:24 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> To keep the "object model" people happy, there could be a standard library type as follows:
>
> std::basic_string_nocopy;
>
> Its constructor could be:
>
> template<size_t N>
> consteval basic_string_nocopy( value_type const (&arg)[N] );
>
> And it could have a member function called "str" which returns a reference to a const std::string.
>
> The standard could simply mandate that when the string_nocopy object is created, an std::string object is also created, and the lifetime of the std::string object is the same as the lifetime of the string_nocopy object. Furthermore the standard could mandate that explicitly calling the std::string destructor on the enclosed std::string object is undefined behavior, just in case any wild west gun slinger tries something like:
>
> string_nocopy obj("Hello");
> string const &s = obj.str();
> const_cast<string&>(s)->~string();

I don't see how this addresses any of the problems with the proposal.
The proposal is not specific to `std::string`; that's just an example.
Furthermore, I don't see how this would be used even within the
example you gave.

Received on 2025-06-23 20:51:22