Boost logo

Boost :

Subject: Re: [boost] [format] please add operator String()
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-01-10 05:47:58


Sebastian Redl skrev:
> Thorsten Ottosen wrote:
>> Hi,
>>
>> In code like this:
>>
>> std::string columns() const
>> {
>> return (boost::format("%7s, %7s, %7s, %7s")
>> % "testCost" % "optimalEcr" % "efficiecyEcr" %
>> "testCostEcr").str();
>> }
>>
>> it is very annoying to have to put () around the whole expression and
>> then call .str() (Just imagine that we are creating a string on the
>> fly to a function).
>>
>> Therefore I suggest that we add
>>
>> operator string_type() const { return str(); }
>>
>> to the interface of basic_format<>.
>>
>> Any comments?
> You could write it as
>
> return boost::str(boost::format("%7s, %7s, %7s, %7s")
> % "testCost" % "optimalEcr" % "efficiecyEcr" %
> "testCostEcr");
>

yes, which is hardly any better than the above. Why is such a function
even there?

I my mind formatting is so closely tied to strings that I don't see any
problem in the implicit conversion. IIRC, String.Format in other
langauages return a String.

-Thorsten


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