[Format] No implicit conversion to string?
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() ); or 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. —John
From: mpbecey7gu@snkmail.com
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() ); or 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.
—John
I've also wondered about this. I also find having to use str() inconvenient. Regards, Nate
On 2/12/2012 10:57 PM, Nathan Ridge wrote:
I've also wondered about this. I also find having to use str() inconvenient.
Regards, Nate
It seems to not bother anything when I added the operator. I submitted it as Ticket #6553. Now who should I lobby to "accept" it and take the next steps? —John
It seems to not bother anything when I added the operator. I submitted it as Ticket #6553.
Now who should I lobby to "accept" it and take the next steps?
There was a discussion on this subj a few years ago: http://lists.boost.org/Archives/boost/2005/03/83322.php I believe nothing changed since then...
participants (3)
-
Igor R
-
John M. Dlugosz
-
Nathan Ridge