Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki MarkupReallocation can occur when a member function modifies its container. Modifying member functions include {{reserve()}} and {{resize()}}, {{push_back()}}, {{pop_back()}}, {{erase()}}, {{clear()}}, {{insert()}}, and others. In addition, assignment operations and modifying algorithms can also cause reallocation. When a container reallocates its elements, their addresses change. Consequently, the values of existing iterators are invalidated \[Kalev 99\]. Using invalid iterators yields undefined results.

Non-compliant Code Example 1

...

Code Block
double data[5] = { 2.3, 3.7, 1.4, 0.8, 9.6 };
deque<double> d;

transform(data, data+5,
    inserter(d,d.begin()),
    bind2nd(plus<int>(), 41));

...

  • Meyers 01 Item 43: Prefer algorithm calls to hand-written loops.
  • Sutter 04 Item 84: Prefer algorithm calls to handwritten loops.
  • Kalev 99 ANSI/ISO C++ Professional Programmer's Handbook.

...