Is there an inconsistency in the C++17 standard regarding std::map::iterator?

Viewed 94

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:

  1. All container iterators are supposed to satisfy ForwardIterator.
  2. For an iterator It satisfying ForwardIterator, std::iterator_traits<It>::reference has to be either value_type& – if It is mutable – or const value_type& – if It is constant.
  3. The notion “It is mutable” is defined as “It also satisfies OutputIterator”, while “constant” means non-mutable.
  4. In order to satisfy OutputIterator, the expression *it = o should be valid for o being 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?

0 Answers
Related