Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Olaf van der Spek (ml_at_[hidden])
Date: 2017-01-03 09:23:33


On Tue, Jan 3, 2017 at 3:16 PM, Christof Donat <cd_at_[hidden]> wrote:
> Hin
>
> Am 03.01.2017 14:20, schrieb Olaf van der Spek:
>>
>> On Tue, Jan 3, 2017 at 2:19 PM, Christof Donat <cd_at_[hidden]> wrote:
>>>
>>> Am 01.01.2017 00:21, schrieb Andrey Semashev:
>>>>
>>>>
>>>> throw std::runtime_error(format(std::string()) << "Error " << 47);
>>>
>>>
>>>
>>> How would that differ from
>>>
>>> throw std::runtime_error((std::ostringstream{} << "Error " <<
>>> 47).str());
>>
>>
>> Simpler syntax, better performance
>
>
> I see the chances for better performance, but for the syntax I don't really
> see
> any remarkable improvements.

The extra parentheses and the .str() part are annoying.. same goes for
boost::format.

How about this one?

throw std::runtime_error("Error "s << 47);

> If performance matters, I'd try with boost::spirit::karma. The syntax will

Performance matters but it's not the only thing that matters.
What solution do you think someone new to C++ understands better?

> If you have multiple places like that in your code, I guess, you'd like to
> wrap it
> into a generic function and you have a similar API to the "append()"
> proposal. Now
> I see, how it might be useful, thanks. I think, append() should rely on
> karma
> generators then, instead of yet another int to string implementation,
> because we
> only already have five dozens.

It's an implementation detail but yes, it might be useful.

-- 
Olaf

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk