|
Boost : |
Subject: Re: [boost] Variadic append for std::string
From: Olaf van der Spek (ml_at_[hidden])
Date: 2017-01-03 07:45:44
On Tue, Jan 3, 2017 at 1:32 PM, Andrey Semashev
<andrey.semashev_at_[hidden]> wrote:
>> Yes, as manually calling reserve beforehand is always possible.
>> How to optimally implement this is still an open question but that's
>> kind of an implementation detail.
>
>
> But you would have to either overallocate memory or perform the formatting
> to determine its length.
True
> And while overallocating might be possible for
> standard types such as integers and FP numbers (assuming C-locale format),
> that does not seem possible for user's types. Or are you not planning to
> support user-defined types?
Supporting such types in one big call to sprint would be nice but it
does complicate the proposal.
One could always call sprint(s, <udt>) 'manually'. Or maybe the
two-argument version could be the extension point.
Maybe a sprint_max_size(s, <udt>) could be used (if defined) to
estimate the size required.
> My intent was to format into a local/preallocated buffer, without any
> additional allocations, but I assume that won't work because `std::array` is
> lacking APIs for insertion. That probably means that you have to define a
> concept of the possible target, what operations it must support.
Right, if we opt for a generic version. It would again complicate the
proposal though.
-- Olaf
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk