Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-02-04 14:10:18


>From: "Jason House" <jhouse_at_[hidden]>

> Terje Slettebø wrote:
> > and given this:
> >
> > int main()
> > {
> > char board[3][3]=
> > {
> > {'O','X','O'},
> > {'X','X','O'},
> > {'O','O','X'}
> > };
> >
> > std::cout << io_format<char (&)[3]>("\n|","|\n","|")
> > << io_format<char (&)[3][3]>("-------","-------","-------")
> > << board << '\n';
> > }
> >
> > we get:
> >
> > -------
> > |O|X|O|
> > -------
> > |X|X|O|
> > -------
> > |O|O|X|
> > -------
>
> Hey, that's pretty cool. I'm glad to see the ability to format items
> inside of a container as well.

I'm glad you like. :) Yes, it applies operator<< recursively, using
overloading, and any format settings for the given type, so for the outer
array, it matches the second format above, and for the inner it matches the
first one.

> 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.

Regards,

Terje


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