Boost logo

Boost Users :

Subject: [Boost-users] [Format] No implicit conversion to string?
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-02-12 23:35:21

It's shown prominently in the docs that a boost::format object can be sent to an ostream.

     cout << format("%2% %1%") % 36 % 77;

But, there is no easy way to use it where a plain string is needed. E.g.

     throw runtime_error ( format("%2% %1%") % 36 % 77 );

One must use extra parens and a named function, either

     throw runtime_error ( (format("%2% %1%") % 36 % 77).str() );
     throw runtime_error ( str(format("%2% %1%") % 36 % 77) );

either of which detracts from the expression.

Is there any good reason why an implicit conversion operator to the matching string class
was omitted? I'd like to find out if there is some reason, before looking into submitting
an update.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at