>From: "Vladimir Prus" <[EMAIL PROTECTED]>

> after having to output std::vector to stream again and again using custom
> solution, I started to wonder why we don't have a solution in boost.
> Does it makes sense to include operators<< for vectors, sets, etc?
>
> I was thinking about
>
>    <boost/io/vector.hpp>
>    <boost/io/set.hpp>
>
> and so on. There are basically two approaches:
>
> 1. Operators use fixed format: bracked list with commas between values for
>     vector, for example.
> 2. Manipulators are provided to set brackets and separators.
>
> I had implemented the second approach some time ago, but it turned out
that
> was overkill. So, 1) looks better now.

If this is done as a library, then I think it's best not to have hard-coded
brackets and separators. One might use an xalloc() value for each type to
output. For example something like:

typedef std::pair<int,char> Map;
typedef std::vector<Map> MapList;

MapList list;

// Fill container

std::cout << boost::io_format<Map>(",", "[", "]") <<
boost::io_format<MapList>("","","\n") << list << '\n';

This might print:

[1, a]
[2, b]
[3, c]


Regards,

Terje

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to