S
subramanian100in
In the ISO/IEC 14882:2003 document, in page 492 section '23.2.4.3
vector modifiers', item 1 mentions the following:
"Notes: Causes reallocation if the new size is greater than old
capacity. If no reallocation happens, all the iterators and references
before the insertion point remain valid."
My questions:
---------------------
If reallocation happens, does the above 'Item 1' mean that all the
iterators, references and pointers to elements in the vector, will be
invalidated ?
To know whether reallocation has happened, we first need to store the
old capacity in a variable; then do the modification to the vector;
then check if the new size is greater than the variable value (which
gives the old capacity). Is this how we need to check if reallocation
has happened ? In real world applications, how is this accomplished ?
Kindly explain with some sample code.
Thanks
V.Subramanian
vector modifiers', item 1 mentions the following:
"Notes: Causes reallocation if the new size is greater than old
capacity. If no reallocation happens, all the iterators and references
before the insertion point remain valid."
My questions:
---------------------
If reallocation happens, does the above 'Item 1' mean that all the
iterators, references and pointers to elements in the vector, will be
invalidated ?
To know whether reallocation has happened, we first need to store the
old capacity in a variable; then do the modification to the vector;
then check if the new size is greater than the variable value (which
gives the old capacity). Is this how we need to check if reallocation
has happened ? In real world applications, how is this accomplished ?
Kindly explain with some sample code.
Thanks
V.Subramanian