Shouldn't advance be defined for ostream_iterator?
Jonathan Wakely
cow@compsoc.man.ac.uk
Tue Feb 3 15:21:00 GMT 2004
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
More information about the Libstdc++
mailing list