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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With