|
Boost : |
From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2003-04-22 08:14:36
Peter Dimov <pdimov_at_[hidden]> 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"
It pretty much depends on the semantic you give to the positional operators.
My personal implementation of operator%() is: go through the string, look
for the positional format with the lowest number, and format it. So "%1%
%3%" is the same of "%1% %300%" or "%100% %300%".
But if you want to a have a semantic like the one you're proposing, you
could still decrement each position while you go through the string.
"%1% %3%" % 5 % 6 % 7 => "5 %2%" % 6 % 7 => "5 %1%" % 7 => "5 7".
Also, I personally don't allow multiple formatting of the same parameter:
"%1% %1%" % 5 % 6 gives "5 6" in my implementation, but it's a trivial
change as well.
Giovanni Bajo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk