|
Boost : |
From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2003-04-23 03:45:59
Daryle Walker <dwalker07_at_[hidden]> wrote:
>> 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 think you misread what Peter was trying to say. He was implying that,
without a format class, you can't keep track of how many formatting items
you have applied to your string, so you can't skip the '6' in the above
example. My answer was to modify the input string by decrementing the
positions within the string every time, until they reach zero and get
formatted.
> 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.)
The conversion to string does occur, I tried it in real code, you just need
a string context:
void Foo(std::string m)
{ cout << m; }
Foo("This %s work - %u" % "does" % 123)
It does not work in contexts not explicitally asking for a string, like
stream.operator<<() (which I believe it's a template). My guess was that you
could fix it by providing a global operator<<(ostream&, string) which would
simply call ostream.operator<<(), but I never tried it.
Giovanni Bajo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk