简体   繁体   中英

Input and output iterators are swappable?

Input iterators Output Iterators

  1. 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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM