C++ Logo

sg16

Advanced search

Re: [isocpp-sg16] std::format and charN_t

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 01 Jul 2024 22:52:23 +0200
On Monday 1 July 2024 12:01:49 CEST Tiago Freire via SG16 wrote:
> Not sure that it would be possible to make it to C++26. You can try to
> pre-allocate, but the question is how much? For that it would require a
> 2-pass solution, the first pass figures out the required size, the
> allocation would happen in the middle, the second pass would fulfill the
> conversion keeping the promise of the first pass.

There's a third alternative, which is what we use in Qt: we estimate the
maximum possible size and request that. Once we've transcoded, we tell the
container how much was actually used, which truncates the output to that size
before continuing the formatting operation.

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

Received on 2024-07-01 20:52:32