Pre / post increment operator on OutputIterator

I read in an article about OutputIterator

that we can only dereference it as an lvalue. My question is about operator++

which increments an iterator by one position.

So,

*it++ = t 

      

will be

{*it = t; ++it; }

      

https://www.sgi.com/tech/stl/OutputIterator.html

Now I am assuming it operator++

will be overloaded in such a way that it will increment OutputIterator

by one position.

ostream_iterator

also is OutputIterator

and implements all requirements OutputIterator

.

Then why operator++

implemented as below in ostream_iterator

?

ostream_iterator<T,charT,traits>& operator++() { return *this; }
ostream_iterator<T,charT,traits>& operator++(int) { return *this; }

      

http://www.cplusplus.com/reference/iterator/ostream_iterator/

This shows that operator++

it does nothing.

Does dereferencing an output statement assign a new value and advance it one position? Without use operator++

?

If so, why do we need to implement operator++

?

+3


source to share


1 answer


The use of this operator is formal . OutputIterator

must support the ++

-operator, regardless of whether it has an effect.



+5


source







All Articles