Topic: When does vector<T>::push_back (et. al.) invalidate references?


Author: heh@beamtech.com (Howard E. Hinnant)
Date: 1997/06/25
Raw View
Does the standard say anything about the following code?

vector<int> a(5);
...
a.push_back(a[0]);  // Is this dangerous?

The basic question is:  push_back may have to reallocate itself to a
larger size.  Must it take into account that it's argument may be a
reference to itself?  Are references into a invalidated at the point of
entry to push_back, or only at the point of exit, or unspecified by the
standard?

-Howard
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]