xmllmx xmllmx - 6 days ago 7
C++ Question

Is vector<int>::const_iterator output_iterator?

According to the C++ concepts:


"Any iterator other than input_iterator is an output_iterator."


An
vector<int>::const_iterator
is a
random_access_iterator
, and of course is an
output_iterator
.

However, according to cppref, an
output_iterator
must be writable, while an
vector<int>::const_iterator
cannot.

Is
vector<int>::const_iterator
output_iterator
?


See also: How to check if an iterator is an output_iterator in c++?

Answer

No. vector<int>::const_iterator is a constant iterator ([container.requirements.general]), which means it does not satisfy the requirements of output iterators.

[iterator.requirements.general]/4:

Iterators that further satisfy the requirements of output iterators are called mutable iterators. Nonmutable iterators are referred to as constant iterators.


An vector::const_iterator is a random_access_iterator, and of course is an output_iterator.

This is simply wrong.