Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2017-01-03 07:32:24

On 01/03/17 13:14, Olaf van der Spek wrote:
> On Sun, Jan 1, 2017 at 12:21 AM, Andrey Semashev
> <andrey.semashev_at_[hidden]> wrote:
>> If formatting is required I would prefer to be required to spell my intent
>> more clearly, like this:
>> print(s, 47);
> I'd expect print to output to cout.. wouldn't you?
> sprint then?

sprint works for me as well.

>> Also, I'm not clear enough about the intended use cases of the proposed
>> library. Is the goal just to optimize memory allocation?
> No, the goal is also to provide a better and simpler way to handle integers.
>> Is that at all
>> possible when formatting is involved?
> 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. 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?

>> I think, something with one line capability like that would be useful. Would
>> the library allow something like this?
>> Would the library support targets other than std::string?
> Yes, probably.
>> E.g. would I be
>> able to format into an `std::array< char, 10 >`?
> No, as array is fixed-size you can't append to it..
> vector<char> might work though.

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

Boost list run by bdawes at, gregod at, cpdaniel at, john at