Boost logo

Boost Users :

Subject: Re: [Boost-users] copy a range to ostream
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2012-01-29 10:03:09


Hi,

2012/1/29 Neal Becker <ndbecker2_at_[hidden]>:
> With all the nice boost libraries, is there a modern idiom to copy a range to an
> ostream?
>
> I was thinking range/algorithm/copy could be useful.  What I'd really like to do
> is:
>
> std::vector<some type> x;
>
> range::copy (x, std::cout);
>
> Of course there would also need to be a way to specify formatting, at least
> insertion of whitespace.
>

copy() will always take iterator as output destination so both problems
(copying to ostream and formatting) are easily fixed by using iterator that
is designed for this job:

range::copy(x, std::ostream_iterator<int>(std::cout,", "));

-- 
Szymon Gatner
The Lordz Games Studio
www.thelordzgamesstudio.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net