Commit 33913cfa by Paolo Carlini Committed by Paolo Carlini

forward_list.h (forward_list<>::erase_after): Change signature per N2988, return void; simplify.

2009-11-13  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/forward_list.h (forward_list<>::erase_after):
	Change signature per N2988, return void; simplify.
	(_Fwd_list_base<>::_M_erase_after): Likewise return void.
	(forward_list<>::~forward_list): Do not call _M_erase_after
	unnecessarily, the base class destructor already does it.
	(forward_list<>::splice_after(const_iterator position,
	forward_list&&, const_iterator i): Check position != i and
	position != ++i.
	* include/bits/forward_list.tcc (_Fwd_list_base<>::
	_M_erase_after(typename _Node_base::_Pointer): Simplify.
	(_Fwd_list_base<>::_M_erase_after(typename _Node_base::_Pointer,
	typename _Node_base::_Pointer): Fix (remove the correct range
	of element) and simplify (update __pos->_M_next at the end).
	* testsuite/23_containers/forward_list/modifiers/3.cc: Adjust
	and extend.
	* testsuite/23_containers/forward_list/ext_pointer/
	modifiers/3.cc: Likewise.
	* testsuite/23_containers/forward_list/requirements/dr438/
	assign_neg.cc: Tweak dg-error line numbers.
	* testsuite/23_containers/forward_list/requirements/dr438/
	insert_neg.cc: Likewise.
	* testsuite/23_containers/forward_list/requirements/dr438/
	constructor_1_neg.cc: Likewise.
	* testsuite/23_containers/forward_list/requirements/dr438/
	constructor_2_neg.cc: Likewise.

From-SVN: r154174
parent 870875e6
2009-11-13 Paolo Carlini <paolo.carlini@oracle.com> 2009-11-13 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h (forward_list<>::erase_after):
Change signature per N2988, return void; simplify.
(_Fwd_list_base<>::_M_erase_after): Likewise return void.
(forward_list<>::~forward_list): Do not call _M_erase_after
unnecessarily, the base class destructor already does it.
(forward_list<>::splice_after(const_iterator position,
forward_list&&, const_iterator i): Check position != i and
position != ++i.
* include/bits/forward_list.tcc (_Fwd_list_base<>::
_M_erase_after(typename _Node_base::_Pointer): Simplify.
(_Fwd_list_base<>::_M_erase_after(typename _Node_base::_Pointer,
typename _Node_base::_Pointer): Fix (remove the correct range
of element) and simplify (update __pos->_M_next at the end).
* testsuite/23_containers/forward_list/modifiers/3.cc: Adjust
and extend.
* testsuite/23_containers/forward_list/ext_pointer/
modifiers/3.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
assign_neg.cc: Tweak dg-error line numbers.
* testsuite/23_containers/forward_list/requirements/dr438/
insert_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_1_neg.cc: Likewise.
* testsuite/23_containers/forward_list/requirements/dr438/
constructor_2_neg.cc: Likewise.
2009-11-13 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/algorithm: Include <utility>, per UK-300. * include/std/algorithm: Include <utility>, per UK-300.
* include/bits/stl_algobase.h: Don't do it here. * include/bits/stl_algobase.h: Don't do it here.
......
...@@ -350,10 +350,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -350,10 +350,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_put_node(typename _Node::_Pointer __p) _M_put_node(typename _Node::_Pointer __p)
{ _M_get_Node_allocator().deallocate(__p, 1); } { _M_get_Node_allocator().deallocate(__p, 1); }
typename _Node_base::_Pointer void
_M_erase_after(typename _Node_base::_Pointer __pos); _M_erase_after(typename _Node_base::_Pointer __pos);
typename _Node_base::_Pointer void
_M_erase_after(typename _Node_base::_Pointer __pos, _M_erase_after(typename _Node_base::_Pointer __pos,
typename _Node_base::_Pointer __last); typename _Node_base::_Pointer __last);
}; };
...@@ -529,7 +529,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -529,7 +529,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @brief The forward_list dtor. * @brief The forward_list dtor.
*/ */
~forward_list() ~forward_list()
{ _M_erase_after(&this->_M_impl._M_head, 0); } { }
/** /**
* @brief The %forward_list assignment operator. * @brief The %forward_list assignment operator.
...@@ -871,7 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -871,7 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
insert_after(const_iterator __pos, size_type __n, const _Tp& __val) insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
{ {
forward_list __tmp(__n, __val, this->get_allocator()); forward_list __tmp(__n, __val, this->get_allocator());
this->splice_after(__pos, std::move(__tmp)); splice_after(__pos, std::move(__tmp));
} }
/** /**
...@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -893,7 +893,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_InputIterator __first, _InputIterator __last) _InputIterator __first, _InputIterator __last)
{ {
forward_list __tmp(__first, __last, this->get_allocator()); forward_list __tmp(__first, __last, this->get_allocator());
this->splice_after(__pos, std::move(__tmp)); splice_after(__pos, std::move(__tmp));
} }
/** /**
...@@ -913,14 +913,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -913,14 +913,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
insert_after(const_iterator __pos, std::initializer_list<_Tp> __il) insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
{ {
forward_list __tmp(__il, this->get_allocator()); forward_list __tmp(__il, this->get_allocator());
this->splice_after(__pos, std::move(__tmp)); splice_after(__pos, std::move(__tmp));
} }
/** /**
* @brief Removes the element pointed to by the iterator following * @brief Removes the element pointed to by the iterator following
* @c pos. * @c pos.
* @param pos Iterator pointing to element to be erased. * @param pos Iterator pointing before element to be erased.
* @return An iterator pointing to the next element (or end()).
* *
* This function will erase the element at the given position and * This function will erase the element at the given position and
* thus shorten the %forward_list by one. * thus shorten the %forward_list by one.
...@@ -932,14 +931,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -932,14 +931,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* is itself a pointer, the pointed-to memory is not touched in * is itself a pointer, the pointed-to memory is not touched in
* any way. Managing the pointer is the user's responsibility. * any way. Managing the pointer is the user's responsibility.
*/ */
iterator void
erase_after(const_iterator __pos) erase_after(const_iterator __pos)
{ {
_Node_base* __tmp = __const_pointer_cast<_Node_base*>(__pos._M_node); _Node_base* __tmp = __const_pointer_cast<_Node_base*>(__pos._M_node);
if (__tmp) this->_M_erase_after(__tmp);
return iterator(this->_M_erase_after(__tmp));
else
return end();
} }
/** /**
...@@ -948,8 +944,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -948,8 +944,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* erased. * erased.
* @param last Iterator pointing to one past the last element to be * @param last Iterator pointing to one past the last element to be
* erased. * erased.
* @return An iterator pointing to the element pointed to by @a last
* prior to erasing (or end()).
* *
* This function will erase the elements in the range @a * This function will erase the elements in the range @a
* (pos,last) and shorten the %forward_list accordingly. * (pos,last) and shorten the %forward_list accordingly.
...@@ -961,11 +955,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -961,11 +955,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* pointed-to memory is not touched in any way. Managing the pointer * pointed-to memory is not touched in any way. Managing the pointer
* is the user's responsibility. * is the user's responsibility.
*/ */
iterator void
erase_after(const_iterator __pos, iterator __last) erase_after(const_iterator __pos, const_iterator __last)
{ {
_Node_base* __tmp = __const_pointer_cast<_Node_base*>(__pos._M_node); _Node_base* __tmpp = __const_pointer_cast<_Node_base*>(__pos._M_node);
return iterator(this->_M_erase_after(__tmp, &*__last._M_node)); _Node_base* __tmpl = __const_pointer_cast<_Node_base*>(__last._M_node);
this->_M_erase_after(__tmpp, __tmpl);
} }
/** /**
...@@ -1044,7 +1039,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1044,7 +1039,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* @brief Insert element from another %forward_list. * @brief Insert element from another %forward_list.
* @param pos Iterator referencing the element to insert after. * @param pos Iterator referencing the element to insert after.
* @param list Source list. * @param list Source list.
* @param it Iterator referencing the element before the element * @param i Iterator referencing the element before the element
* to move. * to move.
* *
* Removes the element in list @a list referenced by @a i and * Removes the element in list @a list referenced by @a i and
...@@ -1052,10 +1047,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1052,10 +1047,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
splice_after(const_iterator __pos, forward_list&& __list, splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __it) const_iterator __i)
{ {
this->splice_after(__pos, std::forward<forward_list>(__list), const_iterator __j = __i;
__it, __it._M_next()); ++__j;
if (__pos == __i || __pos == __j)
return;
splice_after(__pos, std::move(__list), __i, __j);
} }
/** /**
......
...@@ -113,42 +113,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -113,42 +113,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
typename _Fwd_list_base<_Tp, _Alloc>::_Node_base::_Pointer void
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(typename _Node_base::_Pointer __pos) _M_erase_after(typename _Node_base::_Pointer __pos)
{ {
typename _Node::_Pointer __curr typename _Node::_Pointer __curr
= __static_pointer_cast<typename _Node::_Pointer>(__pos->_M_next); = __static_pointer_cast<typename _Node::_Pointer>(__pos->_M_next);
if (__curr) __pos->_M_next = __curr->_M_next;
{ _M_get_Node_allocator().destroy(__curr);
typename _Node_base::_Pointer __next = __curr->_M_next; _M_put_node(__curr);
__pos->_M_next = __next;
_M_get_Node_allocator().destroy(__curr);
_M_put_node(__curr);
}
return __pos;
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
typename _Fwd_list_base<_Tp, _Alloc>::_Node_base::_Pointer void
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(typename _Node_base::_Pointer __pos, _M_erase_after(typename _Node_base::_Pointer __pos,
typename _Node_base::_Pointer __last) typename _Node_base::_Pointer __last)
{ {
typename _Node::_Pointer __curr typename _Node::_Pointer __curr
= __static_pointer_cast<typename _Node::_Pointer>(__pos->_M_next); = __static_pointer_cast<typename _Node::_Pointer>(__pos->_M_next);
while (__curr) while (__curr != __last)
{ {
typename _Node::_Pointer __temp = __curr; typename _Node::_Pointer __temp = __curr;
__curr = __static_pointer_cast<typename _Node::_Pointer> __curr = __static_pointer_cast<typename _Node::_Pointer>
(__curr->_M_next); (__curr->_M_next);
_M_get_Node_allocator().destroy(__temp); _M_get_Node_allocator().destroy(__temp);
_M_put_node(__temp); _M_put_node(__temp);
__pos->_M_next = __curr;
if (__temp == __last)
break;
} }
return __pos; __pos->_M_next = __last;
} }
// Called by the range constructor to implement [23.1.1]/9 // Called by the range constructor to implement [23.1.1]/9
......
...@@ -43,10 +43,7 @@ test01() ...@@ -43,10 +43,7 @@ test01()
++pos; ++pos;
VERIFY(*pos == 1); VERIFY(*pos == 1);
std::forward_list<int, _ExtPtr_allocator<int> >::iterator fl.erase_after(pos);
next = fl.erase_after(pos);
VERIFY(*next == 1);
VERIFY(*pos == 1); VERIFY(*pos == 1);
++pos; ++pos;
...@@ -78,14 +75,20 @@ test02() ...@@ -78,14 +75,20 @@ test02()
++stop; ++stop;
VERIFY(*stop == 4); VERIFY(*stop == 4);
std::forward_list<int, _ExtPtr_allocator<int> >::iterator fl.erase_after(pos, stop);
next = fl.erase_after(pos, stop);
VERIFY(*next == 1);
VERIFY(*pos == 1); VERIFY(*pos == 1);
++pos; ++pos;
VERIFY(*pos == 5); VERIFY(*pos == 4);
VERIFY(std::distance(fl.begin(), fl.end()) == 8);
fl.erase_after(pos, fl.end());
VERIFY(++pos == fl.end());
VERIFY(std::distance(fl.begin(), fl.end()) == 3);
fl.erase_after(fl.before_begin(), pos);
VERIFY(std::distance(fl.begin(), fl.end()) == 0);
VERIFY(fl.empty());
} }
int int
......
...@@ -37,8 +37,7 @@ test01() ...@@ -37,8 +37,7 @@ test01()
++pos; ++pos;
VERIFY(*pos == 1); VERIFY(*pos == 1);
std::forward_list<int>::iterator next = fl.erase_after(pos); fl.erase_after(pos);
VERIFY(*next == 1);
VERIFY(*pos == 1); VERIFY(*pos == 1);
++pos; ++pos;
...@@ -65,12 +64,20 @@ test02() ...@@ -65,12 +64,20 @@ test02()
++stop; ++stop;
VERIFY(*stop == 4); VERIFY(*stop == 4);
std::forward_list<int>::iterator next = fl.erase_after(pos, stop); fl.erase_after(pos, stop);
VERIFY(*next == 1);
VERIFY(*pos == 1); VERIFY(*pos == 1);
++pos; ++pos;
VERIFY(*pos == 5); VERIFY(*pos == 4);
VERIFY(std::distance(fl.begin(), fl.end()) == 8);
fl.erase_after(pos, fl.end());
VERIFY(++pos == fl.end());
VERIFY(std::distance(fl.begin(), fl.end()) == 3);
fl.erase_after(fl.before_begin(), pos);
VERIFY(std::distance(fl.begin(), fl.end()) == 0);
VERIFY(fl.empty());
} }
int int
......
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-error "no matching" "" { target *-*-* } 1197 }
// { dg-excess-errors "" } // { dg-excess-errors "" }
// Copyright (C) 2009 Free Software Foundation // Copyright (C) 2009 Free Software Foundation
......
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-error "no matching" "" { target *-*-* } 1197 }
// { dg-excess-errors "" } // { dg-excess-errors "" }
// Copyright (C) 2009 Free Software Foundation // Copyright (C) 2009 Free Software Foundation
......
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-error "no matching" "" { target *-*-* } 1197 }
// { dg-excess-errors "" } // { dg-excess-errors "" }
// Copyright (C) 2009 Free Software Foundation // Copyright (C) 2009 Free Software Foundation
......
// { dg-do compile } // { dg-do compile }
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-error "no matching" "" { target *-*-* } 1198 } // { dg-error "no matching" "" { target *-*-* } 1197 }
// { dg-excess-errors "" } // { dg-excess-errors "" }
// Copyright (C) 2009 Free Software Foundation // Copyright (C) 2009 Free Software Foundation
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment