I read in an article on OutputIterator
that we only can dereference it as lvalue. My question is about operator++
which increments the iterator by one position.
So,
*it++ = t
would be
{*it = t; ++it; }
https://www.sgi.com/tech/stl/OutputIterator.html
Now, I am assuming that operator++
would be overloaded in such a fashion that it would increment OutputIterator
by one position.
ostream_iterator
is also an OutputIterator
and implements all the requirements of OutputIterator
.
Then why is operator++
implemented as shown 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/
That shows operator++
does nothing.
Does dereferencing the output operator assign a new value and advance it by one position? Without using operator++
?
If so, then why do we need to implement operator++
?
The use of this operator is formal . An OutputIterator
must support the ++
-operator regardless if it has any effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.