correct info on object element reference invalidation

This commit is contained in:
Dmitry Arkhipov 2025-02-27 14:52:29 +03:00
parent e3531d3210
commit 13d95270e9

View File

@ -35,14 +35,14 @@ class key_value_pair;
This is an associative container whose elements This is an associative container whose elements
are key/value pairs with unique keys. are key/value pairs with unique keys.
\n
The elements are stored contiguously; iterators are The elements are stored contiguously; iterators are
ordinary pointers, allowing random access pointer ordinary pointers, allowing random access pointer
arithmetic for retrieving elements. arithmetic for retrieving elements.
In addition, the container maintains an internal In addition, the container maintains an internal
index to speed up find operations, reducing the index to speed up find operations, reducing the
average complexity for most lookups and insertions. average complexity for most lookups and insertions.
\n
Reallocations are usually costly operations in terms of Reallocations are usually costly operations in terms of
performance, as elements are copied and the internal performance, as elements are copied and the internal
index must be rebuilt. The @ref reserve function can index must be rebuilt. The @ref reserve function can
@ -871,7 +871,7 @@ public:
allocated. Otherwise, the call has no effect. allocated. Otherwise, the call has no effect.
The number of elements and therefore the The number of elements and therefore the
@ref size() of the container is not changed. @ref size() of the container is not changed.
\n
If new memory is allocated, all iterators If new memory is allocated, all iterators
including any past-the-end iterators, and all including any past-the-end iterators, and all
references to the elements are invalidated. references to the elements are invalidated.
@ -969,6 +969,8 @@ public:
are two keys within the range that are equal to each other, only the are two keys within the range that are equal to each other, only the
first will be inserted. first will be inserted.
@n
Insertion may result in rehashing of the container. In that case all Insertion may result in rehashing of the container. In that case all
iterators and references are invalidated. Otherwise, they are not iterators and references are invalidated. Otherwise, they are not
affected. affected.
@ -1353,12 +1355,11 @@ public:
Returns a reference to the value that is mapped Returns a reference to the value that is mapped
to a key equivalent to key, performing an insertion to a key equivalent to key, performing an insertion
of a null value if such key does not already exist. of a null value if such key does not already exist.
\n
If an insertion occurs and results in a rehashing of If an insertion occurs and results in a rehashing of the container, all
the container, all iterators are invalidated. Otherwise iterators including any past-the-end iterators, and all references to
iterators are not affected. References are not the elements are invalidated. Otherwise, no iterators or references are
invalidated. Rehashing occurs only if the new invalidated.
number of elements is greater than @ref capacity().
@par Complexity @par Complexity
Constant on average, worst case linear in @ref size(). Constant on average, worst case linear in @ref size().