Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-12-04 13:18:40

Yes - it appears to be very convenient,

(though is it something of an indictment of the language that it should be

I can confirm that with MS VC 7.1 and the indispensible Boost unit_test library.

boost::ostream_iterator and std::ostream_iterator work the same.

                ostringstream oss;
                copy(vs.begin(), vs.end(), boost::ostream_iterator(oss, " "));
                BOOST_CHECK_EQUAL(oss.str(), "this is a test ");
                ostringstream oss;
                copy(vs.begin(), vs.end(), std::ostream_iterator<string>(oss, " "));
                BOOST_CHECK_EQUAL(oss.str(), "this is a test ");

In practice one would only have to write

using boost::ostream_iterator; // Using boost and std causes trouble!

copy(vi.begin(), vi.end(), ostream_iterator(cout, "\n "));


Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of John Torjo
| Sent: Tuesday, December 02, 2003 2:38 AM
| To: Boost mailing list
| Subject: [boost] why no boost::ostream_itearator?
| Dear boosters,
| 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.
| This should not be necessary since it can be deduced at the time of writing.
| I wrote a small helper. Any interest in adding it to boost?

Boost list run by bdawes at, gregod at, cpdaniel at, john at