I am a bit confused about the C++17 standard named requirements regarding iterators; it seems to me that std::map::iterator violates the requirements. From the standard, I gather the following:
- All container iterators are supposed to satisfy ForwardIterator.
- For an iterator
Itsatisfying ForwardIterator,std::iterator_traits<It>::referencehas to be eithervalue_type&– ifItis mutable – orconst value_type&– ifItis constant. - The notion “
Itis mutable” is defined as “Italso satisfies OutputIterator”, while “constant” means non-mutable. - In order to satisfy OutputIterator, the expression
*it = oshould be valid forobeing of a type writable to the iterator; there has to be a nonempty set of such types.
Now, std::iterator_traits<std::map::iterator>::reference is value_type& (without const), but the iterator does not satisfy the OutputIterator requirements – as value_type of map::iterator is std::pair<const Key, Value>, we can never assign to *it.
So, the question is, am I overlooking some part of the standard that deals with this inconsistency? Or am I interpreting the standard requirements wrong?