This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Shouldn't advance be defined for ostream_iterator?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]