This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: GCC STL implementation bug?
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: apamecha at houston dot geoquest dot slb dot com
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 24 Sep 2003 03:01:54 +0200
- Subject: Re: GCC STL implementation bug?
Not a bug.
You have to call vec_in.reserve(2*vec_in.size()); before your copy().
See, f.i., this section in the Errata of Josuttis book:
*Page 273, Section 7.4.2
*In iter/backins.cpp there is a nasty problem with the following statement:
copy (coll.begin(), coll.end(), /// source /
back_inserter(coll)); /// destination/
Because the back inserter inserts elements into a vector, these
insertions might invalidate all other iterators referring to the same
vector. Thus, the algorithm invalidates the passed source iterators
while running. To avoid this behavior, you have to reserve enough space
so that the reallocation won't happen. So, insert before the statement
above:
/// reserve enough memory to avoid reallocation/
coll.reserve (2*coll.size());
Paolo.