Title
iterator and const_iterator should have the same value type
Status
cd1
Section
[container.requirements]
Submitter
Matt Austern

Created on 2001-05-17.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

This belongs as a container requirement, rather than an iterator requirement, because the whole notion of iterator/const_iterator pairs is specific to containers' iterator.

It is existing practice that (for example) iterator_traits<list<int>::const_iterator>::value_type is "int", rather than "const int". This is consistent with the way that const pointers are handled: the standard already requires that iterator_traits<const int*>::value_type is int.

Date: 2010-10-21.18:28:33

Proposed resolution:

In Table 65 ("Container Requirements"), change the return type for X::iterator to "iterator type whose value type is T". Change the return type for X::const_iterator to "constant iterator type whose value type is T".

Date: 2001-05-17.00:00:00

It's widely assumed that, if X is a container, iterator_traits<X::iterator>::value_type and iterator_traits<X::const_iterator>::value_type should both be X::value_type. However, this is nowhere stated. The language in Table 65 is not precise about the iterators' value types (it predates iterator_traits), and could even be interpreted as saying that iterator_traits<X::const_iterator>::value_type should be "const X::value_type".

Related issue: 279.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2230
2010-10-21 18:28:33adminsetmessages: + msg2229
2001-05-17 00:00:00admincreate