Search code examples
c++c++11iteratormove

move-only input and output iterators


Concerning InputIterator/OutputIterator-s is it consistent to modify their semantics to be move-only? Surely I mean only newly-created custom iterators, not STL ones.

Notes to semantic requirements to ++i and ++r expressions for input and output iterators correspondingly says:

Postcondition: Any copies of the previous value of i are no longer required to be either dereferenceable or to be in the domain of ==.

After this operation r is not required to be incrementable and any copies of the previous value of r are no longer required to be dereferenceable or incrementable.

I think it is safer to prohibit possibility to have a copies of input/output iterators in most cases, but never heard such advice. Is it bad idea?


Solution

  • Input/OutputIterators must first satisfy the Iterator requirement. And that requirement say, from C++14, [iterator.iterators], p2:

    A type X satisfies the Iterator requirements if:

    • X satisfies the CopyConstructible, CopyAssignable, and Destructible requirements (17.6.3.1)

    So no, they cannot be move-only.