xmllmx xmllmx - 9 days ago 5
C++ Question

Is vector<int>::const_iterator an output_iterator?

According to the C++ concepts:


Any iterator other than input_iterator is an output_iterator.


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

However, according to cppreference.com, an
output_iterator
must be writable, while a
vector<int>::const_iterator
is not.

Is
vector<int>::const_iterator
an
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.