This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Shouldn't advance be defined for ostream_iterator?
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: "Neal D. Becker" <nbecker at hns dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Tue, 3 Feb 2004 15:21:25 +0000
- Subject: Re: Shouldn't advance be defined for ostream_iterator?
- References: <bvodet$duj$1@sea.gmane.org>
On Tue, Feb 03, 2004 at 10:07:09AM -0500, Neal D. Becker wrote:
> ostream_iterator has operator++ (nop), but no generic advance. I believe
> advance should be defined:
>
> namespace std {
> template<class T, class charT, class traits, typename dist_t>
> inline void advance (ostream_iterator<T,charT,traits>, dist_t) {}
> };
std::advance() requires an InputIterator, whereas std::ostream_iterator
is a model of the OutputIterator concept, and the description from
http://www.sgi.com/tech/stl/OutputIterator.html says:
[3] Assignment through an Output Iterator x is expected to alternate
with incrementing x, and there must be an assignment through x before
x is ever incremented. Any other order of operations results in
undefined behavior. That is: {*x = t; ++x; *x = t2; ++x} is
acceptable, but {*x = t; ++x; ++x; *x = t2;} is not.
In other words, std::advance(x, 2) is not acceptable.
jon
--
"I was born not knowing and have had only a little time to
change that here and there."
- Feynman