C++ Logo

sg16

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 03 Jul 2024 06:37:56 +0200
On Tuesday 2 July 2024 17:01:52 CEST Thiago Macieira via SG16 wrote:
> Therefore, when formating a QLatin1StringView or QString onto a
> std::string, we will have to:
> 1) allocate a QByteArray of the maximum size (which is 2x the size of the
> latin1 string or 3x the codepoint count of the UTF-16 one)
> 2) transcode onto it
> 3) shrink in to size
> 4) allocate a std::string of the correct size
> 5) copy onto it
> 6) deallocate the QByteArray
> 7) use std::formatter<std::string>, which memcpy's it to the destination
> std::string

Oops, correcting the brainfreeze here: we don't need to copy onto a
std::string in order to format it to the output. We have std::string_view.
Therefore, steps 4 and 5 don't exist, and 7 reading directly from the QBA
buffer is before 6.

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

Received on 2024-07-03 04:38:04