Boost logo

Boost :

From: Daryle Walker (dwalker07_at_[hidden])
Date: 2003-04-23 03:06:48


On Tuesday, April 22, 2003, at 2:07 PM, Peter Dimov wrote:

> Giovanni Bajo wrote:
>> - No class boost::format. No function boost::format. It's just
>> template <typename T> std::string operator%(std::string, T whatever),
>> and you inject it into your global namespace (a clash is _very_,
>> _very_ unlikely). That's all you need: a function that lets you
>> format a single parameter into a string and get the new string as
>> result. In a perfect world, I'd like that operator% to be defined
>> into namespace std.
>
> Very appealing... but doesn't work, for me, at least.
>
> "%1% %3%" % 5 % 6 % 7; // should yield "5 7"

The first part of that expression would be like:

        whatever operator %( char const *p1, int p2 );

I don't think Giovanni's expected "char const [N]"-to-std::string
conversion will occur, killing his idea. (Also, the function prototype
I gave above isn't legal since you can't overload operators without at
least one user-defined operand type. This is probably the cause of
Peter's errors.)

Even if the conversions did work, I don't like it. I don't think you
should define operators for types you don't have control over. The
main reason is that you'll screw up the authors if they decide to add
such an operator later.

Daryle


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