C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 16 Jun 2025 16:12:42 -0700
On Monday, 16 June 2025 16:01:45 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> The key here is that the make-believe container must be 'const' --
> meaning that you can't edit its elements, can't resize it, and very
> importantly, you can't move from it.

Not just const. It must be a const-ref, because otherwise in some platforms
with callee-destroy code, it would try to destroy the pretender.

> Is there any possibility we could have something like this in the
> Standard? It can be implemented without an ABI break. I can implement
> it in a day or two for all the major C++ standard libraries. . .
> Dinkumware, Microsoft, libstdc++, libc++. It's not much work.

Probably not.

> In my own program I'll be using this strategy to pretend that a
> constexpr char array is a wxString object.

Or, instead of asking for a pretend, how about asking for a non-allocating
mode of the container? QString and QByteArray have fromRawData(). Though of
course that requires an ABI break to enable, because all destroyers must be
aware of the need to not destroy.

But if a break was acceptable, then this could also be done with a different
allocator template parameter. Which is probably why this request has little
chance of being accepted. The Standard usually does not care about old
implementations that can't be updated and must be tricked. There is and has
been a perfectly good solution for this.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Platform & System Engineering

Received on 2025-06-16 23:12:48