From: Samuel Krempp (krempp_at_[hidden])
Date: 2001-06-29 20:06:41
The short form of positional arguments is now implemented, as "%N "
That is, you need to put a space after the number, that gets eaten.
format("%1 bla") % BLA gives : BLAbla
This extra space is necessary to support both syntaxes.
The conversion to string is also here (although conversion operators are
rarely appreciated, I think it is quite safe here)
Sample usage now (v1.4) :
string s = format(" %5 . %5$=6s . le format %5 , c'%3 %1 %2 .\n")
%"le" %"bonheur" %"est" %"trop" * setfill('_') %"bref";
cerr << s;
assert( s == " bref. _bref_ . le format bref, c'est le bonheur.\n");
( of course usage "cout << format(.." is still here)
> > the "format-is-a-function" approach has big problems :
> > . limited number of arguments. ("well, who cares..")
> True, however, so far I've never hit that limit. Anyway, there is a
> simple workaround: format("%1..%9", arg1,...,format("%1..."))
> Just embed another format in the last argument. So it's not a real
> limit, just kind of annoying (considering you even hit it).
I never use more than a few args either..
but I think the real problem is the loss of generality.
For those apps with i18n, the format string cant be sliced in pieces
without losing half of the "positional parameters" benefits..
> > . if you want good passing of arguments (ie not copy by value, but
> > passing T& / const T&),
> > you need to define 2^10 functions.. (!)
> You must know something I don't. With the version I've been using, all
> arguments are passed to the constructor as const T&, and I've only got 9
> constructors. Why do you need the non-const variations?
that's the point, as long as you dont need a non-const version, fine.
But it sounds strange to impose this restriction
"only objects with const operator<< defined are formattable".
(even if needing to modify the object at print-time sounds like
Since boost aims at very general libraries, I think this was a cause for
the halt on this approach of boost::format.
At least it was one of the issues raised at the last format thread.
else, the function approach has some possibilities that can't be beaten by
passing arguments through an operator !
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk