Boost logo

Boost :

From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2003-12-05 07:36:13


Ron,

> > I browsed the sandbox, but could not find a simpler ostream_iterator.
> > The thing is that I don't like the fact that when writing using an
> > ostream_iterator I have to provide the value_type I'm writing.
> > This is both tedios and error prone.
> >
> > Example:
> >
> > std::copy( vs.begin(), vs.end(),
> > std::ostream_iterator<std::string>(std::cout, " "));
> > ^^^ tedious and error prone.
> >
> At least from my perspective, the only thing I tend to use
> ostream_iterator for is to stream a container of stuff to std::cout, or
> the like, as you do above. A while back I wrote some helpers so that
> the syntax becomes more like:
>
>
> std::cout << "Stuff follows:\n" << stream_range(vs.begin(),vs.end(),",")
> << "\n";
>
> I like this a lot better, though I must admit that ostream_iterator is a
> little more flexible. But I usually use this kind of thing for
> debugging or personal programming projects.

I've taken a similar tack with:

s << range_streamer( vs.begin(), vs.end(), "{", "," "}" );

See the thread: http://thread.gmane.org/gmane.comp.lib.boost.user/4465

from the boost.user mailing list archive which includes the implementation.

-----------------
Jeff Flinn
Applied Dynamics, International


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