bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ 3.0.4: std::vector<...>.erase (iterator): preconditions?


From: Benjamin Kaufman
Subject: Re: g++ 3.0.4: std::vector<...>.erase (iterator): preconditions?
Date: Thu, 04 Apr 2002 22:30:34 +0000 (GMT)

According to the SGI STL programmers guide, you're assumption is incorrect.
The description of erase(iterator pos) is:  Erases the element at position pos.
There is no element to erase at v.end()

Most programs would use v.end() as a condition to terminate a loop - before
attempting to erase it.

Ben
   

On Thu, 04 Apr 2002 01:18:39 +0200, address@hidden (Peter
Müller) wrote:

>Hi,
>
>#include <vector>
>int main ()
>{
>    std::vector<int> v;
>    v.erase (v.end ());
>}
>
>dumps core in g++ 3.0.4. IMHO erase (end ()) is perfectly legal and
>may frequently occur. Furthermore v.erase(v.end ()) must be equivalent
>to v.erase (v.end (), v.end ()).
>
> From the header file I cannot
>see this:
>
>g++-v3/bits/stl_vector.h:
>     378   iterator erase(iterator __position) {
>     379     if (__position + 1 != end())
>     380       copy(__position + 1, end(), __position);
>     381     --_M_finish;
>     382     destroy(_M_finish);
>     383     return __position;
>     384   }
>     385   iterator erase(iterator __first, iterator __last) {
>     386     iterator __i(copy(__last, end(), __first));
>     387     destroy(__i, end());
>     388     _M_finish = _M_finish - (__last - __first);
>     389     return __first;
>     390   }
>
>Any suggestions? All I could find about the preconditions of the
>iterator argument was "v.begin () <= iterator <= v.end ()" in
>some popular C++ textbook.
>
>TIA
>
>Peter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]