From: Samuel Krempp (krempp_at_[hidden])
Date: 2001-07-03 11:36:39
> You mean "is strictly equivalent" to the following, right?
> ios_base::fmtflags old_flags(cout.flags());
> (cout << hex << n).flags(old_flags);
exactly, I forgot to unset the flags..
(well, a good example it really is a good thing to have a non-sticky
behaviour ! )
> Ok, so 'x' is not a conversion character or type indicator here, it's just a
> shortcuted form of "non-sticky" 'std::hex' manipulator that will be used to
> change a state of the output stream for the time the argument it corresponds
> to will be printed. What's more, interpretation of 'x' does not depend on
> the actual type of the supposedly affected parameter, e.g. if 'n' is an
I should have given the example with the pair before.
(it's easier to give an example than a formal definition of what is format
> (and http://groups.yahoo.com/group/boost/files/format2/Readme.txt doesn't
> bring a lot of light here, mostly because of intensive mentioning of printf
> and printf-compatibility mode without going into details how it really
> works), but if you know the rules the whole picture looks quite consistent
that's because I was busy finishing work on bind_arg, set_flag, and coping
the Readme.txt is already a bit better, as it gives a (very succinct)
example of behaviour with a user-defined tpye,
and also states clearly what are the effects of the flags on the
I think it should now be already easier to understand the 'big picture',
as you say.
> - I think that's cute :).
> > 2. beyond printf usual field,
> > use its syntax to express formatting option,
> > where the flags' meanings are their most natural interpretations :
> > example : range = make_pair<int,int>( n1, n2);
> > int i;
> > cout << format("%p1$4x %2\n") %range %i;
> > will do the same as
> > cout << hex << setw(4) << range << dec << setw(0)
> > << " " << i << "\n";
> That's a nice example. I believe that you have to save and restore the state
> of the stream before and after each argument's output, instead of resetting
> it to the default one (dec, setw(0), etc.), though.
well, once again, my example is faulty.
the 2 things are not really equivalent, because format indeed restores to
the previous state, not a default state.
In fact, the whole subtlety is to set / restore only what we should, no
more (and no less, but that is not the problem)
Because manipulators passed with % might have changed the stream, and
these changes are supposed to *stay* , even when the argument appears in
several directives. ("%1 %1 %1")
I believe it's actually doing the right thing right now.
(else please let me know..)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk