[cfe-commits] [libcxx] r111745 - in /libcxx/trunk: include/forward_list test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp
Howard Hinnant
hhinnant at apple.com
Sat Aug 21 13:58:44 PDT 2010
Author: hhinnant
Date: Sat Aug 21 15:58:44 2010
New Revision: 111745
URL: http://llvm.org/viewvc/llvm-project?rev=111745&view=rev
Log:
US 117
Modified:
libcxx/trunk/include/forward_list
libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp
libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp
Modified: libcxx/trunk/include/forward_list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/forward_list?rev=111745&r1=111744&r2=111745&view=diff
==============================================================================
--- libcxx/trunk/include/forward_list (original)
+++ libcxx/trunk/include/forward_list Sat Aug 21 15:58:44 2010
@@ -97,8 +97,8 @@
InputIterator first, InputIterator last);
iterator insert_after(const_iterator p, initializer_list<value_type> il);
- void erase_after(const_iterator p);
- void erase_after(const_iterator first, const_iterator last);
+ iterator erase_after(const_iterator p);
+ iterator erase_after(const_iterator first, const_iterator last);
void swap(forward_list& x);
@@ -568,8 +568,8 @@
iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
{return insert_after(__p, __il.begin(), __il.end());}
- void erase_after(const_iterator __p);
- void erase_after(const_iterator __f, const_iterator __l);
+ iterator erase_after(const_iterator __p);
+ iterator erase_after(const_iterator __f, const_iterator __l);
void swap(forward_list& __x) {base::swap(__x);}
@@ -1033,7 +1033,7 @@
}
template <class _Tp, class _Alloc>
-void
+typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
{
__node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
@@ -1042,17 +1042,18 @@
__node_allocator& __a = base::__alloc();
__node_traits::destroy(__a, addressof(__n->__value_));
__node_traits::deallocate(__a, __n, 1);
+ return iterator(__p->__next_);
}
template <class _Tp, class _Alloc>
-void
+typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
{
+ __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
if (__f != __l)
{
__node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
__node_pointer __n = __p->__next_;
- __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
if (__n != __e)
{
__p->__next_ = __e;
@@ -1066,6 +1067,7 @@
} while (__n != __e);
}
}
+ return iterator(__e);
}
template <class _Tp, class _Alloc>
Modified: libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp?rev=111745&r1=111744&r2=111745&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp Sat Aug 21 15:58:44 2010
@@ -9,7 +9,7 @@
// <forward_list>
-// void erase_after(const_iterator first, const_iterator last);
+// iterator erase_after(const_iterator first, const_iterator last);
#include <forward_list>
#include <cassert>
@@ -22,7 +22,8 @@
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
- c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4));
+ C::iterator i = c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4));
+ assert(i == next(c.cbefore_begin(), 4));
assert(distance(c.begin(), c.end()) == 10);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
@@ -35,7 +36,8 @@
assert(*next(c.begin(), 8) == 8);
assert(*next(c.begin(), 9) == 9);
- c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5));
+ i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5));
+ assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 8);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
@@ -46,7 +48,8 @@
assert(*next(c.begin(), 6) == 8);
assert(*next(c.begin(), 7) == 9);
- c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3));
+ i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3));
+ assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 8);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
@@ -57,7 +60,8 @@
assert(*next(c.begin(), 6) == 8);
assert(*next(c.begin(), 7) == 9);
- c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9));
+ i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9));
+ assert(i == c.end());
assert(distance(c.begin(), c.end()) == 5);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
@@ -65,14 +69,17 @@
assert(*next(c.begin(), 3) == 5);
assert(*next(c.begin(), 4) == 6);
- c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2));
+ i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2));
+ assert(i == c.begin());
assert(distance(c.begin(), c.end()) == 4);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 4);
assert(*next(c.begin(), 2) == 5);
assert(*next(c.begin(), 3) == 6);
- c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5));
+ i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5));
+ assert(i == c.begin());
+ assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
}
Modified: libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp?rev=111745&r1=111744&r2=111745&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp Sat Aug 21 15:58:44 2010
@@ -9,7 +9,7 @@
// <forward_list>
-// void erase_after(const_iterator p);
+// iterator erase_after(const_iterator p);
#include <forward_list>
#include <cassert>
@@ -22,29 +22,35 @@
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
- c.erase_after(next(c.cbefore_begin(), 4));
+ C::iterator i = c.erase_after(next(c.cbefore_begin(), 4));
+ assert(i == c.end());
assert(distance(c.begin(), c.end()) == 4);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 3);
- c.erase_after(next(c.cbefore_begin(), 0));
+ i = c.erase_after(next(c.cbefore_begin(), 0));
+ assert(i == c.begin());
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 2);
assert(*next(c.begin(), 2) == 3);
- c.erase_after(next(c.cbefore_begin(), 1));
+ i = c.erase_after(next(c.cbefore_begin(), 1));
+ assert(i == next(c.begin()));
assert(distance(c.begin(), c.end()) == 2);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 3);
- c.erase_after(next(c.cbefore_begin(), 1));
+ i = c.erase_after(next(c.cbefore_begin(), 1));
+ assert(i == c.end());
assert(distance(c.begin(), c.end()) == 1);
assert(*next(c.begin(), 0) == 1);
- c.erase_after(next(c.cbefore_begin(), 0));
+ i = c.erase_after(next(c.cbefore_begin(), 0));
+ assert(i == c.begin());
+ assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
}
More information about the cfe-commits
mailing list