Input iterators Output Iterators
- Swappable: The value pointed to by these iterators can be exchanged or swapped.
In these two links it's stated that the value pointed to by input iterators or output iterators can be exchanged or swapped. I'm not sure what they mean. In case of input iterators how would you change the value pointed to when you can't assign to them? In case of output iterators, how would you know what value to write when you can't read values?
Also it's stated that the output iterators cannot be compared for equality. Why?
It's not saying you can swap the values using those iterators, nor indeed swap the values at all. Or, if it is saying that, it is wrong.
Swappability is a requirement on the iterator type; this is just one of a few core rules for iterators ([iterator.iterators/2.1]
).
As for comparing output iterators for equality, that statement is at least partially false. Output iterators are not required to support equality checks, but still may ([iterator.concept.output/1]
). Where they can't, it's because there is no logical way to implement that. For example, off the top off my head, an ostream_iterator
seems likely to fall into this category, because where does it "point"? How do you represent that?
So the website is, at best, misleading (at worst it is plain wrong), but that's why we do not learn C++ from random websites.