Re: [boost] Variadic append for std::string
On Dec 28, 2016 7:20 PM, "Yakov Galka"
One frequently needs to append stuff to strings, but the standard way (s += "A" + "B" + to_string(42)) isn't optimal due to temporaries.
Can't we already write it through (((s += "A") += "B") += to_string(42))? This is the time I think that assignment operators, other than =, should have had left associativitiy... pity they don't. I think what's desired here is a two-pass approach in which append() or concat() or whatever first figures out the final length required, allocates that much storage, then appends into it with no further expansion. When we say it should understand two kinds of string_view, etc., I assume that the catch-all case for each arg would be "anything that can be treated as a range of char_type."
On Thu, Dec 29, 2016 at 1:43 AM, Nat Goodspeed
I think what's desired here is a two-pass approach in which append() or concat() or whatever first figures out the final length required, allocates that much storage, then appends into it with no further expansion.
When we say it should understand two kinds of string_view, etc., I assume that the catch-all case for each arg would be "anything that can be treated as a range of char_type."
Sounds good.. but if you've got an input range (not readable twice) then you can no longer apply the two-pass optimization. The interface certainly allows it. -- Olaf
participants (2)
-
Nat Goodspeed
-
Olaf van der Spek