Commit 2a7ee2f9 by Paolo Carlini Committed by Paolo Carlini

forward_list.h (_Fwd_list_base<>::_M_insert_after): Move out of line, tweak to…

forward_list.h (_Fwd_list_base<>::_M_insert_after): Move out of line, tweak to return _Fwd_list_node_base*.

2008-10-16  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/forward_list.h (_Fwd_list_base<>::_M_insert_after):
	Move out of line, tweak to return _Fwd_list_node_base*.
	(forward_list<>::insert_after(const_iterator, const _Tp&),
	forward_list<>::insert_after(const_iterator, _Tp&&)): Use it.
	* include/bits/forward_list.tcc (_Fwd_list_base<>::_M_insert_after):
	Define.

	* include/bits/forward_list.h (forward_list<>): Consistently qualify
	calls of base class functions with this->.
	* include/bits/forward_list.tcc (forward_list<>): Likewise.

	* include/bits/forward_list.h: Move some functions out of line...
	* include/bits/forward_list.tcc: ... here.

	* include/bits/forward_list.h (forward_list<>::resize(size_type)): Fix.

From-SVN: r141168
parent e3114905
2008-10-16 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h (_Fwd_list_base<>::_M_insert_after):
Move out of line, tweak to return _Fwd_list_node_base*.
(forward_list<>::insert_after(const_iterator, const _Tp&),
forward_list<>::insert_after(const_iterator, _Tp&&)): Use it.
* include/bits/forward_list.tcc (_Fwd_list_base<>::_M_insert_after):
Define.
* include/bits/forward_list.h (forward_list<>): Consistently qualify
calls of base class functions with this->.
* include/bits/forward_list.tcc (forward_list<>): Likewise.
* include/bits/forward_list.h: Move some functions out of line...
* include/bits/forward_list.tcc: ... here.
* include/bits/forward_list.h (forward_list<>::resize(size_type)): Fix.
2008-10-15 Paolo Carlini <paolo.carlini@oracle.com> 2008-10-15 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h: Remove pointless const qualifiers in * include/bits/forward_list.h: Remove pointless const qualifiers in
......
...@@ -88,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -88,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_reverse_after() _M_reverse_after()
{ {
_Fwd_list_node_base* __tail = this->_M_next; _Fwd_list_node_base* __tail = this->_M_next;
if (! __tail) if (!__tail)
return; return;
while (_Fwd_list_node_base* __temp = __tail->_M_next) while (_Fwd_list_node_base* __temp = __tail->_M_next)
{ {
...@@ -293,7 +293,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -293,7 +293,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Node_alloc_type(), _M_head() : _Node_alloc_type(), _M_head()
{ } { }
explicit
_Fwd_list_impl(const _Node_alloc_type& __a) _Fwd_list_impl(const _Node_alloc_type& __a)
: _Node_alloc_type(__a), _M_head() : _Node_alloc_type(__a), _M_head()
{ } { }
...@@ -347,32 +346,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -347,32 +346,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args> template<typename... _Args>
_Node* _Node*
_M_create_node(_Args&&... __args) _M_create_node(_Args&&... __args)
{ {
_Node* __node = this->_M_get_node(); _Node* __node = this->_M_get_node();
try try
{ {
_M_get_Node_allocator().construct(__node, _M_get_Node_allocator().construct(__node,
std::forward<_Args>(__args)...); std::forward<_Args>(__args)...);
__node->_M_next = 0; __node->_M_next = 0;
} }
catch(...) catch(...)
{ {
this->_M_put_node(__node); this->_M_put_node(__node);
__throw_exception_again; __throw_exception_again;
} }
return __node; return __node;
} }
template<typename... _Args> template<typename... _Args>
void _Fwd_list_node_base*
_M_insert_after(const_iterator __pos, _Args&&... __args) _M_insert_after(const_iterator __pos, _Args&&... __args);
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
}
void void
_M_put_node(_Node* __p) _M_put_node(_Node* __p)
...@@ -583,7 +575,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -583,7 +575,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* elements in the initializer_list @a il. This is linear in * elements in the initializer_list @a il. This is linear in
* il.size(). * il.size().
*/ */
forward_list forward_list&
operator=(std::initializer_list<_Tp> __il) operator=(std::initializer_list<_Tp> __il)
{ {
assign(__il); assign(__il);
...@@ -783,7 +775,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -783,7 +775,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args> template<typename... _Args>
void void
emplace_front(_Args&&... __args) emplace_front(_Args&&... __args)
{ _M_insert_after(cbefore_begin(), std::forward<_Args>(__args)...); } { this->_M_insert_after(cbefore_begin(),
std::forward<_Args>(__args)...); }
/** /**
* @brief Add data to the front of the %forward_list. * @brief Add data to the front of the %forward_list.
...@@ -797,14 +790,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -797,14 +790,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
push_front(const _Tp& __val) push_front(const _Tp& __val)
{ _M_insert_after(cbefore_begin(), __val); } { this->_M_insert_after(cbefore_begin(), __val); }
/** /**
* *
*/ */
void void
push_front(_Tp&& __val) push_front(_Tp&& __val)
{ _M_insert_after(cbefore_begin(), std::move(__val)); } { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
/** /**
* @brief Removes first element. * @brief Removes first element.
...@@ -820,7 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -820,7 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
pop_front() pop_front()
{ _M_erase_after(&this->_M_impl._M_head); } { this->_M_erase_after(&this->_M_impl._M_head); }
/** /**
* @brief Constructs object in %forward_list after the specified * @brief Constructs object in %forward_list after the specified
...@@ -838,7 +831,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -838,7 +831,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args> template<typename... _Args>
iterator iterator
emplace_after(const_iterator __pos, _Args&&... __args) emplace_after(const_iterator __pos, _Args&&... __args)
{ _M_insert_after(__pos, std::forward<_Args>(__args)...); } { return iterator(this->_M_insert_after(__pos,
std::forward<_Args>(__args)...)); }
/** /**
* @brief Inserts given value into %forward_list after specified * @brief Inserts given value into %forward_list after specified
...@@ -854,28 +848,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -854,28 +848,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
iterator iterator
insert_after(const_iterator __pos, const _Tp& __val) insert_after(const_iterator __pos, const _Tp& __val)
{ { return iterator(this->_M_insert_after(__pos, __val)); }
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(__val);
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
return iterator(__to->_M_next);
}
/** /**
* *
*/ */
iterator iterator
insert_after(const_iterator __pos, _Tp&& __val) insert_after(const_iterator __pos, _Tp&& __val)
{ { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(std::move(__val));
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
return iterator(__to->_M_next);
}
/** /**
* @brief Inserts a number of copies of given data into the * @brief Inserts a number of copies of given data into the
...@@ -891,8 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -891,8 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* does not invalidate iterators and references. * does not invalidate iterators and references.
*/ */
void void
insert_after(const_iterator __pos, size_type __n, insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
const _Tp& __val);
/** /**
* @brief Inserts a range into the %forward_list. * @brief Inserts a range into the %forward_list.
...@@ -950,7 +929,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -950,7 +929,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __tmp _Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node); = const_cast<_Fwd_list_node_base*>(__pos._M_node);
if (__tmp) if (__tmp)
return iterator(_Base::_M_erase_after(__tmp)); return iterator(this->_M_erase_after(__tmp));
else else
return end(); return end();
} }
...@@ -979,7 +958,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -979,7 +958,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ {
_Fwd_list_node_base* __tmp _Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node); = const_cast<_Fwd_list_node_base*>(__pos._M_node);
return iterator(_M_erase_after(__tmp, __last._M_node)); return iterator(this->_M_erase_after(__tmp, __last._M_node));
} }
/** /**
...@@ -1010,7 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1010,7 +989,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
resize(size_type __sz) resize(size_type __sz)
{ resize(__sz, _Tp(0)); } { resize(__sz, _Tp()); }
/** /**
* @brief Resizes the %forward_list to the specified number of * @brief Resizes the %forward_list to the specified number of
...@@ -1037,7 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1037,7 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
clear() clear()
{ _M_erase_after(&this->_M_impl._M_head, 0); } { this->_M_erase_after(&this->_M_impl._M_head, 0); }
// 23.2.3.5 forward_list operations: // 23.2.3.5 forward_list operations:
...@@ -1053,17 +1032,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1053,17 +1032,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Requires this != @a x. * Requires this != @a x.
*/ */
void void
splice_after(const_iterator __pos, forward_list&& __list) splice_after(const_iterator __pos, forward_list&& __list);
{
if (!__list.empty() && &__list != this)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
const_iterator __before = __list.cbefore_begin();
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
(__before._M_node));
}
}
/** /**
* @brief Insert element from another %forward_list. * @brief Insert element from another %forward_list.
...@@ -1095,15 +1064,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1095,15 +1064,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/ */
void void
splice_after(const_iterator __pos, forward_list&& __list, splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __before, const_iterator __last) const_iterator __before, const_iterator __last);
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
(__before._M_node),
const_cast<_Fwd_list_node_base*>
(__last._M_node));
}
/** /**
* @brief Remove all elements equal to value. * @brief Remove all elements equal to value.
...@@ -1224,8 +1185,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1224,8 +1185,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Reverse the order of elements in the list in linear time. * Reverse the order of elements in the list in linear time.
*/ */
void void
reverse() reverse();
{ this->_M_impl._M_head._M_reverse_after(); }
}; };
/** /**
...@@ -1241,26 +1201,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1241,26 +1201,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
bool bool
operator==(const forward_list<_Tp, _Alloc>& __lx, operator==(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly);
{
// We don't have size() so we need to walk through both lists
// making sure both iterators are valid.
typename std::forward_list<_Tp, _Alloc>::const_iterator __ix
= __lx.cbegin();
typename std::forward_list<_Tp, _Alloc>::const_iterator __iy
= __ly.cbegin();
while (__ix != __lx.cend() && __iy != __ly.cend())
{
if (*__ix != *__iy)
return false;
++__ix;
++__iy;
}
if (__ix == __lx.cend() && __iy == __ly.cend())
return true;
else
return false;
}
/** /**
* @brief Forward list ordering relation. * @brief Forward list ordering relation.
...@@ -1285,7 +1226,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1285,7 +1226,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline bool inline bool
operator!=(const forward_list<_Tp, _Alloc>& __lx, operator!=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return ! (__lx == __ly); } { return !(__lx == __ly); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
...@@ -1299,14 +1240,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1299,14 +1240,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline bool inline bool
operator>=(const forward_list<_Tp, _Alloc>& __lx, operator>=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return ! (__lx < __ly); } { return !(__lx < __ly); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator<=(const forward_list<_Tp, _Alloc>& __lx, operator<=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly) const forward_list<_Tp, _Alloc>& __ly)
{ return ! (__ly < __lx); } { return !(__ly < __lx); }
/// See std::forward_list::forward_swap(). /// See std::forward_list::forward_swap().
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
......
...@@ -158,6 +158,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -158,6 +158,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
template<typename... _Args>
_Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>::
_M_insert_after(const_iterator __pos, _Args&&... __args)
{
_Fwd_list_node_base* __to
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
_Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
__thing->_M_next = __to->_M_next;
__to->_M_next = __thing;
return __to->_M_next;
}
template<typename _Tp, typename _Alloc>
_Fwd_list_node_base* _Fwd_list_node_base*
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
_M_erase_after(_Fwd_list_node_base* __pos) _M_erase_after(_Fwd_list_node_base* __pos)
...@@ -200,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -200,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __to = &this->_M_impl._M_head; _Fwd_list_node_base* __to = &this->_M_impl._M_head;
for (size_type __i = 0; __i < __n; ++__i) for (size_type __i = 0; __i < __n; ++__i)
{ {
__to->_M_next = _M_create_node(_Tp()); __to->_M_next = this->_M_create_node(_Tp());
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
...@@ -213,7 +227,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -213,7 +227,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __to = &this->_M_impl._M_head; _Fwd_list_node_base* __to = &this->_M_impl._M_head;
for (size_type __i = 0; __i < __n; ++__i) for (size_type __i = 0; __i < __n; ++__i)
{ {
__to->_M_next = _M_create_node(__value); __to->_M_next = this->_M_create_node(__value);
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
...@@ -229,7 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -229,7 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_InputIterator __curr = __first; _InputIterator __curr = __first;
while (__curr != __last) while (__curr != __last)
{ {
__to->_M_next = _M_create_node(*__curr); __to->_M_next = this->_M_create_node(*__curr);
__to = __to->_M_next; __to = __to->_M_next;
++__curr; ++__curr;
} }
...@@ -245,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -245,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__from->_M_next != 0) while (__from->_M_next != 0)
{ {
const _Node* __temp = static_cast<_Node*>(__from->_M_next); const _Node* __temp = static_cast<_Node*>(__from->_M_next);
__to->_M_next = _M_create_node(__temp->_M_value); __to->_M_next = this->_M_create_node(__temp->_M_value);
__from = __from->_M_next; __from = __from->_M_next;
__to = __to->_M_next; __to = __to->_M_next;
} }
...@@ -260,7 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -260,7 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
for (const _Tp* __item = __il.begin(); for (const _Tp* __item = __il.begin();
__item != __il.end(); ++__item) __item != __il.end(); ++__item)
{ {
__to->_M_next = _M_create_node(*__item); __to->_M_next = this->_M_create_node(*__item);
__to = __to->_M_next; __to = __to->_M_next;
} }
} }
...@@ -303,7 +317,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -303,7 +317,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __keep = __to->_M_next; _Fwd_list_node_base* __keep = __to->_M_next;
for (size_type __i = 0; __i < __n; ++__i) for (size_type __i = 0; __i < __n; ++__i)
{ {
__to->_M_next = _M_create_node(__val); __to->_M_next = this->_M_create_node(__val);
__to = __to->_M_next; __to = __to->_M_next;
} }
__to->_M_next = __keep; __to->_M_next = __keep;
...@@ -322,7 +336,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -322,7 +336,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_InputIterator __curr = __first; _InputIterator __curr = __first;
while (__curr != __last) while (__curr != __last)
{ {
__to->_M_next = _M_create_node(*__curr); __to->_M_next = this->_M_create_node(*__curr);
__to = __to->_M_next; __to = __to->_M_next;
++__curr; ++__curr;
} }
...@@ -340,7 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -340,7 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const _Tp* __item = __il.begin(); const _Tp* __item = __il.begin();
while (__item != __il.end()) while (__item != __il.end())
{ {
__to->_M_next = _M_create_node(*__item); __to->_M_next = this->_M_create_node(*__item);
__to = __to->_M_next; __to = __to->_M_next;
++__item; ++__item;
} }
...@@ -369,13 +383,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -369,13 +383,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
forward_list<_Tp, _Alloc>:: forward_list<_Tp, _Alloc>::
splice_after(const_iterator __pos, forward_list&& __list)
{
if (!__list.empty() && &__list != this)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
const_iterator __before = __list.cbefore_begin();
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
(__before._M_node));
}
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __before, const_iterator __last)
{
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
__tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
(__before._M_node),
const_cast<_Fwd_list_node_base*>
(__last._M_node));
}
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
remove(const _Tp& __val) remove(const _Tp& __val)
{ {
_Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head); _Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next)) while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{ {
if (__temp->_M_value == __val) if (__temp->_M_value == __val)
_M_erase_after(__curr); this->_M_erase_after(__curr);
else else
__curr = static_cast<_Node*>(__curr->_M_next); __curr = static_cast<_Node*>(__curr->_M_next);
} }
...@@ -391,7 +434,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -391,7 +434,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next)) while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{ {
if (__pred(__temp->_M_value)) if (__pred(__temp->_M_value))
_M_erase_after(__curr); this->_M_erase_after(__curr);
else else
__curr = static_cast<_Node*>(__curr->_M_next); __curr = static_cast<_Node*>(__curr->_M_next);
} }
...@@ -462,6 +505,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -462,6 +505,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
} }
template<typename _Tp, typename _Alloc>
void
forward_list<_Tp, _Alloc>::
reverse()
{ this->_M_impl._M_head._M_reverse_after(); }
template<typename _Tp, typename _Alloc>
bool
operator==(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
{
// We don't have size() so we need to walk through both lists
// making sure both iterators are valid.
typename std::forward_list<_Tp, _Alloc>::const_iterator __ix
= __lx.cbegin();
typename std::forward_list<_Tp, _Alloc>::const_iterator __iy
= __ly.cbegin();
while (__ix != __lx.cend() && __iy != __ly.cend())
{
if (*__ix != *__iy)
return false;
++__ix;
++__iy;
}
if (__ix == __lx.cend() && __iy == __ly.cend())
return true;
else
return false;
}
_GLIBCXX_END_NAMESPACE // namespace std _GLIBCXX_END_NAMESPACE // namespace std
#endif /* _FORWARD_LIST_TCC */ #endif /* _FORWARD_LIST_TCC */
......
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