Boost logo

Boost :

Subject: Re: [boost] [format] please add operator String()
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2009-01-09 11:31:27


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");

Sebastian


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