Does Boost Ranges have a built-in way to cout the elements easily, for example separated by comma or space?
I am of course aware that I could loop over them and print them separately, but it seems to me that this should be built in somehow (like printing a vector in scripting languages).
In an example program I saw, the author copied the range to cout:
boost::copy(range, ostream_iterator(cout, ” “))
Looks ugly to me. Is this idiomatic?
EDIT: A solution for std iterators would also be acceptable.
EDIT2:
What I want to do is this:
cout << range;
But I don’t think that works.
So what I am hoping for is something like this (Python inspired):
cout << range.join(", ");
or perhaps with a range adaptor.
cout << (range | stringify(", "));
I don’t believe it’s ever been really finished/polished, but that’s the intent of Boost.Explore.
Personally, I’ve just gotten used to using
std::copy. For this sort of thing, aninfix_ostream_iteratorcan be quite helpful at times. For example, something like this:As it stands, this has
operator<<taking a vector, but it would be relatively trivial to have it take a range instead.