incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: Problem with vectors and insert
Date Mon, 15 May 2006 18:54:35 GMT
Craig Chariton wrote:
> When using std::vector::insert my understanding is that we should be able to
> insert either a single item or a group of elements.

The requirements on the template overload of insert() are given
in Table 67 of the C++ standard:

   given a sequence (such as vector) a, an iterator p pointing
   into a, and two Input Iterators i and j that form a range
   [i, j) that is not a subrange of [a.begin(), a.end()), the
   expression

     a.insert(p, i, j)

   has the effect of inserting copies of elements in [i, j)
   before p.

> 
> So, using the sample code I used to illustrate this problem, I should be
> able to add another item to that vector (vector b), and then insert that
> vector at the front of the first vector (vector a).   Is this correct?
> 
> Example:
> 
> Vector a:  1,2,3,4
> Vector b:  0,5
> 
> a.insert(a.begin(), b.begin(), b.end());
> 
> I am assuming the result should be 0,5,1,2,3,4
> 
> Is this correct?

Yes. I assume you get a different result (a test case is almost
always better than a verbal description of the expected outcome).
The change I made to resolve STDCXX-179 happens to fix your
original test case but not the underlying problem. Because our
tests suite doesn't detect this bug I quickly wrote a more
exhaustive test program to verify my fix. Unfortunately, it
appears that a bug in this program masked the persistent bug
in vector and that my change didn't fix it. You might notice
that STDCXX-179 has been left in Resolved state (i.e., it's not
Closed yet) until the test suite has been enhanced to exercise
this case. To get an email notification when the status of the
issue has changed (and when the bug has really been fixed) add
yourself to the Jira issue.

Martin

Mime
View raw message