diff options
author | Doug Gilbert <dgilbert@us.ibm.com> | 2012-03-05 17:24:31 -0600 |
---|---|---|
committer | Bradley W. Bishop <bradleyb@us.ibm.com> | 2012-03-06 23:00:55 -0600 |
commit | 630f7ba9928d0cd9a6e80a0635269dc83c9ecd64 (patch) | |
tree | 49d4e58c14976a7f2609d09776c1d1dd2098f2e8 | |
parent | c556e10089a39c5fbb67073c4355c0a9d0981920 (diff) | |
download | talos-hostboot-630f7ba9928d0cd9a6e80a0635269dc83c9ecd64.tar.gz talos-hostboot-630f7ba9928d0cd9a6e80a0635269dc83c9ecd64.zip |
Add return of an iterator to the vector erase function to match the stl standard.
Change-Id: I383a147976bb6203f6426c22279f9ad6dc80b46e
RTC: 37922
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/722
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Reviewed-by: Bradley W. Bishop <bradleyb@us.ibm.com>
-rw-r--r-- | src/include/vector | 17 | ||||
-rw-r--r-- | src/usr/testcore/lib/stltest.H | 33 |
2 files changed, 45 insertions, 5 deletions
diff --git a/src/include/vector b/src/include/vector index 4d52d8a44..4827116dc 100644 --- a/src/include/vector +++ b/src/include/vector @@ -505,24 +505,30 @@ namespace std /** * Remove an element from the container * @param[in] position iterator, position of element to remove + * @return new location of the element that followed the last + * element erased, or end() if the operation erased + * the last element in the sequence. * @pre begin() <= position < end() * @post All previously obtained iterators are invalid. */ __attribute__ ((always_inline)) - void erase(iterator position) + iterator erase(iterator position) { - erase(position,position+1); + return erase(position,position+1); } /** * Remove a slice of elements from the container * @param[in] first iterator, postion of the first element to remove * @param[in] last iterator, postion of the last element + 1 to remove + * @return new location of the element that followed the last + * element erased, or end() if the operation erased + * the last element in the sequence. * @pre begin() <= first,last <= end(), first < last. * @post All previously obtained iterators are invalid. * @note The element pointed to be last is not deleted. */ - void erase(iterator first, iterator last) + iterator erase(iterator first, iterator last) { assert(last >= first); assert(first >= iv_start); @@ -530,12 +536,13 @@ namespace std assert(last > iv_start); assert(last <= iv_finish); - first = copy(last,iv_finish,first); - while(first != iv_finish) + last = copy(last,iv_finish,first); + while(last != iv_finish) { --iv_finish; iv_finish->~T(); } + return first; } diff --git a/src/usr/testcore/lib/stltest.H b/src/usr/testcore/lib/stltest.H index f2bea98c5..ddd2bb46e 100644 --- a/src/usr/testcore/lib/stltest.H +++ b/src/usr/testcore/lib/stltest.H @@ -261,5 +261,38 @@ class STLTest : public CxxTest::TestSuite } } + + void testVector() + { + std::vector<int> v; + v.reserve(100); + + for(int i = 0; i < 100; ++i) + { + v.push_back(i); + } + + std::vector<int>::iterator itr = v.begin(); + std::advance(itr, 50); + if(*itr != 50) + { + TS_FAIL("Vector iterator not pointing at the right value. %d",*itr); + } + + itr = v.erase(itr); + if(v.size() != 99) + { + TS_FAIL("Vector is not correct size after erase. %d",v.size()); + } + if(*itr != 51) + { + TS_FAIL("Vector::erase did not erase the correct element. %d",*itr); + } + itr = v.erase(itr,v.end()); + if(itr != v.end()) + { + TS_FAIL("Vector erase to end not at end()"); + } + } }; #endif |