K
K. Frank
Hello Group!
I believe that if I insert a key / value pair into a
std::unordered_map, and then take a pointer to the
inserted value, that pointer will remain valid after
subsequent calls to insert and erase.
(I understand that erasing a value will invalidate the
pointer to that specific value. But I believe that
other pointers will not be invalidated.)
I would like to check whether or not this belief is correct.
I believe that the standard says this, but the language
is not really clear to me.
(unordered_map is the case of interest to me, but I
believe that this is true for all of the so-called
associative containers.)
From the draft standard (n3485, pg. 723):
Point 9 of 23.2.4 [associative.reqmts] states:
9 The insert and emplace members shall not affect the
validity of iterators and references to the container,
and the erase members shall invalidate only iterators
and references to the erased elements.
The language is a little terse. It speaks of references,
but not pointers, and of "references to the container,"
rather than references to elements of (or values in) the
container.
Do I have it right that pointers to values in an
unordered_map will remain valid?
Thanks.
K. Frank
I believe that if I insert a key / value pair into a
std::unordered_map, and then take a pointer to the
inserted value, that pointer will remain valid after
subsequent calls to insert and erase.
(I understand that erasing a value will invalidate the
pointer to that specific value. But I believe that
other pointers will not be invalidated.)
I would like to check whether or not this belief is correct.
I believe that the standard says this, but the language
is not really clear to me.
(unordered_map is the case of interest to me, but I
believe that this is true for all of the so-called
associative containers.)
From the draft standard (n3485, pg. 723):
Point 9 of 23.2.4 [associative.reqmts] states:
9 The insert and emplace members shall not affect the
validity of iterators and references to the container,
and the erase members shall invalidate only iterators
and references to the erased elements.
The language is a little terse. It speaks of references,
but not pointers, and of "references to the container,"
rather than references to elements of (or values in) the
container.
Do I have it right that pointers to values in an
unordered_map will remain valid?
Thanks.
K. Frank