This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.
iterator
and const_iterator
Section: 23.2.7 [associative.reqmts] Status: C++11 Submitter: Alisdair Meredith Opened: 2009-03-12 Last modified: 2016-01-28
Priority: Not Prioritized
View other active issues in [associative.reqmts].
View all other issues in [associative.reqmts].
View all issues with C++11 status.
Discussion:
Addresses UK 238 [CD1]
Leaving it unspecified whether or not iterator
and const_iterator
are the
same type is dangerous, as user code may or may not violate the One
Definition Rule by providing overloads for
both types. It is probably too late to specify a single behaviour, but
implementors should document what to expect. Observing that problems can be
avoided by users restricting themselves to using const_iterator
, add a note to that effect.
Suggest Change 'unspecified' to 'implementation defined'.
[ Summit: ]
Agree with issue. Agree with adding the note but not with changing the normative text. We believe the note provides sufficient guidance.
[ Batavia (2009-05): ]
We agree with the proposed resolution. Move to Tentatively Ready.
Proposed resolution:
In 23.2.7 [associative.reqmts] p6, add:
-6-
iterator
of an associative container meets the requirements of theBidirectionalIterator
concept. For associative containers where the value type is the same as the key type, bothiterator
andconst_iterator
are constant iterators. It is unspecified whether or notiterator
andconst_iterator
are the same type. [Note:iterator
andconst_iterator
have identical semantics in this case, anditerator
is convertible toconst_iterator
. Users can avoid violating the One Definition Rule by always usingconst_iterator
in their function parameter lists -- end note]