From: Karl Nelson (kenelson_at_[hidden])
Date: 2002-01-29 14:23:41
> > This gets a lot harder when you start throwing in
> > manipulators unfortunately.
> > That is why I am switching to a groupable format like...
> > cout << format( fstr, 1.0, group(hex,width(10),16), "bob");
> > rather than
> > cout << format(fstr) % 1.0 % hex % width(10) % 16 % "bob" ;
> I definitely like the grouping format for local manipulators. For
> persistent manipulators, however, it is not appropriate. We need both.
Why should their be persistent manipulators in a format stream.
They don't make sense because they can get moved up when reordered.
Consider if I allow persistent manipulators and just have a simple
cout << format( fstr) % 16 % hex % 16;
Okay so if fstr is " =  base 16" thus we print
"16 = 10 base 16". But if manipulators are persistent if
someone attempts to reverse the order in some translation they
write " ???? 16 = ", this implies
cout << hex<<16 " ???? 16 = " << 16;
Thus we print "10 ???? 16 = 10". Ouch, not what we want.
Thus no manipulators should be persistent.
> > In the first the positionally nature is there. Plus you can now
> > see the manipulators are only to the one argument.
> > It also is good in that you can group arguments in reasonable ways...
> > cout << format(" Change is %d", group( c>0?'+':'-', c) );
> > Thus both the char and the int get placed in the position 1.
> Clever idea. I like it.
> Only the %d confuses the issue. I would expect the %d to be applied to each
> argument, meaning for c=3 you would get: " Change is 433". This is a good
> example of why is it best of avoid type specifiers unless you really want to
> override the current format specified by the manipulator context (e.g.
> override decimal with hex or vice verse).
I take this argument a completely different way. Yes, type specifiers
should not convert types, but rather they simply should not be taken
I take the type as being very general.
x - stream is hex (any numbers in it are shown as hex)
d - stream is decimal (any numbers in it are shown as decimal)
s - string literal (stream defaults)
Thus %d on group(c>0?'+':'-',c) is "<< dec << '+' << 3".
We don't try to convert the argument. It is also almost impossible
to do because, we would have to force the types to fix basic types
to interpret them.
cout << format("%.2f") % complex<int>(0,0);
How would you know to convert 0 to float(0.0) so we get the
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk