Terje Sletteb� wrote:
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?
[...]
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.
>
You see, that's what I have implemented back in 2001. You could change braces/separator for each stl container, and it used xalloc()/pword().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:
There's one problem though: I don't remember the syntax of brace
changing, just because I used it a couple of times long ago and then
stopped. Probably, the scope should be more clearly defined:
Edward Diener wrote:
> Al Stevens who writes the C++ column for "Doctor Dobbs Journal" put out a
> persistent template library for C++ containers some time back. It is
> probably on the DDJ web site, although I haven't looked there recently. You
> might want to check that out and see what he did. I will readily admit I
> have not had the need to persist container data in my daily programming but
> I can understand others having that need.
Rozental, Gennadiy wrote:
> I do not see a way how you could implement solution with better
> flexibility/conciseness ratio than copy+ostream_iterator one.
I'm not much interested in persistence (after all, I hope that Robert's
library will take care of that). Likewise, I never needed arbitrary
delimiters, etc. But while developing an algorithm for finding k shortest
paths in a graph, I need to output each path, and have no easy standard way.
One might call this output operators are mostly debugging help, but why not
have standard debugging help?
std::cout << boost::io_format<Map>(",", "[", "]") <<
boost::io_format<MapList>("","","\n") << list << '\n';
This might print:
[1, a]
[2, b]
[3, c]
This example should one case where manipulators are desirable:
vector< vector<int> > v;
cout << v ;
Here, each nested vector better go on a separate line. I suggest:
cout << multiline << v;
where "multiline" manipulator causes each element of the next output container
to go on separate line.
- Volodya
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
