|
Boost : |
Subject: Re: [boost] Variadic append for std::string
From: Christof Donat (cd_at_[hidden])
Date: 2017-01-03 09:48:42
Hi,
Am 03.01.2017 15:23, schrieb Olaf van der Spek:
> On Tue, Jan 3, 2017 at 3:16 PM, Christof Donat <cd_at_[hidden]> wrote:
> The extra parentheses and the .str() part are annoying.. same goes for
> boost::format.
I see. For me that is not a big issue, but people are different.
> How about this one?
>
> throw std::runtime_error("Error "s << 47);
Uh. How does that work with
std::cout << "Error "s << 47;
Will that be
(std::cout << "Error "s) << 47;
or
std::cout << ("Error "s << 47);
Also I'd expect a std::string to behave like a stream then and try to
use e.g. manipulators. Maybe that would be acceptable with a different
operator. e.g. like in SQL:
throw std::runtime_error("Error "s || 47);
Now this is explicit:
std::cout << "Error "s || 47; // versus
std::cout << "Error "s << 47;
But then again this might behave surprisingly:
throw std::runtime_error("Error "s || 47 || 11);
I still don't feel comfortable with it.
>> 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?
I think, mixing the notion of strings and streams, but not for e.g.
manipulators would confuse people a lot. I am a big fan of overloading
operators and expression templates, wherever they improve the expression
of intent. In this particular case my gut feeling tells me, that it will
harm the expression of intent more often, than it will improve.
Christof
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk