Boost logo

Boost :

From: Jason House (jhouse_at_[hidden])
Date: 2003-02-05 11:01:30


Terje Slettebø wrote:

> > It should handle maps and pairs
> > reasonably well. I think that I have the same complaints about this as
> > io_manip
> >
> > The saving of information to the stream means that you can affect all
> > future output...
> >
> > For instance, if you have a type
> > map<custom_object, list<string> >
> >
> > and custom_object's stream output uses io_format<list<string> >, then
> > you are going to run into trouble if it wants a different formatting.
>
> Right. That's a consequence of this. As you say too, I don't know any
> obvious alternatives, though.
>

I thought of one thing that might work reasonably well.

How about making ++io_format< T > save the current format in a stack.
and having io_format< T>-- restore the previously queuued format

so, then something like

> > std::cout << ++io_format<char (&)[3]>("\n|","|\n","|")--
> > << ++io_format<char (&)[3][3]>("-------","-------","-------")--
> > << board << '\n';

would save and restore the formating for char(&)[3][3] and char(&)[3] and never
stomp on anything else.

The net effect is that you can optionally add the extra few characters and prevent
stomping on other code that is displaying your class.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk