aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2008-10-16 10:23:00 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2008-10-16 10:23:00 +0000
commit2a7ee2f9893f7eeb1c330c4e042e3c7d56c6edaf (patch)
treeb48bb4762d64c13f15b109e0ad9cc38c69d6683d /libstdc++-v3
parente311490551f3889e6a3e5da09c8fb3ca50778f42 (diff)
downloadgcc-2a7ee2f9893f7eeb1c330c4e042e3c7d56c6edaf.zip
gcc-2a7ee2f9893f7eeb1c330c4e042e3c7d56c6edaf.tar.gz
gcc-2a7ee2f9893f7eeb1c330c4e042e3c7d56c6edaf.tar.bz2
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog18
-rw-r--r--libstdc++-v3/include/bits/forward_list.h139
-rw-r--r--libstdc++-v3/include/bits/forward_list.tcc93
3 files changed, 141 insertions, 109 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 3786322..14aeec0 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,21 @@
+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>
* include/bits/forward_list.h: Remove pointless const qualifiers in
diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h
index 5e8cfec..88a6017 100644
--- a/libstdc++-v3/include/bits/forward_list.h
+++ b/libstdc++-v3/include/bits/forward_list.h
@@ -88,7 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_reverse_after()
{
_Fwd_list_node_base* __tail = this->_M_next;
- if (! __tail)
+ if (!__tail)
return;
while (_Fwd_list_node_base* __temp = __tail->_M_next)
{
@@ -293,7 +293,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Node_alloc_type(), _M_head()
{ }
- explicit
_Fwd_list_impl(const _Node_alloc_type& __a)
: _Node_alloc_type(__a), _M_head()
{ }
@@ -347,32 +346,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args>
_Node*
_M_create_node(_Args&&... __args)
- {
- _Node* __node = this->_M_get_node();
- try
- {
- _M_get_Node_allocator().construct(__node,
- std::forward<_Args>(__args)...);
- __node->_M_next = 0;
- }
- catch(...)
- {
- this->_M_put_node(__node);
- __throw_exception_again;
- }
- return __node;
- }
+ {
+ _Node* __node = this->_M_get_node();
+ try
+ {
+ _M_get_Node_allocator().construct(__node,
+ std::forward<_Args>(__args)...);
+ __node->_M_next = 0;
+ }
+ catch(...)
+ {
+ this->_M_put_node(__node);
+ __throw_exception_again;
+ }
+ return __node;
+ }
template<typename... _Args>
- void
- _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;
- }
+ _Fwd_list_node_base*
+ _M_insert_after(const_iterator __pos, _Args&&... __args);
void
_M_put_node(_Node* __p)
@@ -583,7 +575,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* elements in the initializer_list @a il. This is linear in
* il.size().
*/
- forward_list
+ forward_list&
operator=(std::initializer_list<_Tp> __il)
{
assign(__il);
@@ -783,7 +775,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args>
void
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.
@@ -797,14 +790,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
void
push_front(const _Tp& __val)
- { _M_insert_after(cbefore_begin(), __val); }
+ { this->_M_insert_after(cbefore_begin(), __val); }
/**
*
*/
void
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.
@@ -820,7 +813,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
void
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
@@ -838,7 +831,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename... _Args>
iterator
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
@@ -854,28 +848,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
iterator
insert_after(const_iterator __pos, const _Tp& __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);
- }
+ { return iterator(this->_M_insert_after(__pos, __val)); }
/**
*
*/
iterator
insert_after(const_iterator __pos, _Tp&& __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);
- }
+ { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
/**
* @brief Inserts a number of copies of given data into the
@@ -891,8 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* does not invalidate iterators and references.
*/
void
- insert_after(const_iterator __pos, size_type __n,
- const _Tp& __val);
+ insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
/**
* @brief Inserts a range into the %forward_list.
@@ -950,7 +929,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __tmp
= const_cast<_Fwd_list_node_base*>(__pos._M_node);
if (__tmp)
- return iterator(_Base::_M_erase_after(__tmp));
+ return iterator(this->_M_erase_after(__tmp));
else
return end();
}
@@ -979,7 +958,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
_Fwd_list_node_base* __tmp
= 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)
*/
void
resize(size_type __sz)
- { resize(__sz, _Tp(0)); }
+ { resize(__sz, _Tp()); }
/**
* @brief Resizes the %forward_list to the specified number of
@@ -1037,7 +1016,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
void
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:
@@ -1053,17 +1032,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Requires this != @a x.
*/
void
- 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));
- }
- }
+ splice_after(const_iterator __pos, forward_list&& __list);
/**
* @brief Insert element from another %forward_list.
@@ -1095,15 +1064,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
void
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));
- }
+ const_iterator __before, const_iterator __last);
/**
* @brief Remove all elements equal to value.
@@ -1224,8 +1185,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Reverse the order of elements in the list in linear time.
*/
void
- reverse()
- { this->_M_impl._M_head._M_reverse_after(); }
+ reverse();
};
/**
@@ -1241,26 +1201,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
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;
- }
+ const forward_list<_Tp, _Alloc>& __ly);
/**
* @brief Forward list ordering relation.
@@ -1285,7 +1226,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline bool
operator!=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
- { return ! (__lx == __ly); }
+ { return !(__lx == __ly); }
/// Based on operator<
template<typename _Tp, typename _Alloc>
@@ -1299,14 +1240,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline bool
operator>=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
- { return ! (__lx < __ly); }
+ { return !(__lx < __ly); }
/// Based on operator<
template<typename _Tp, typename _Alloc>
inline bool
operator<=(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)
- { return ! (__ly < __lx); }
+ { return !(__ly < __lx); }
/// See std::forward_list::forward_swap().
template<typename _Tp, typename _Alloc>
diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc
index a7fabf8..7ae4f23 100644
--- a/libstdc++-v3/include/bits/forward_list.tcc
+++ b/libstdc++-v3/include/bits/forward_list.tcc
@@ -158,6 +158,20 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
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_base<_Tp, _Alloc>::
_M_erase_after(_Fwd_list_node_base* __pos)
@@ -200,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
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;
}
}
@@ -213,7 +227,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __to = &this->_M_impl._M_head;
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;
}
}
@@ -229,7 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_InputIterator __curr = __first;
while (__curr != __last)
{
- __to->_M_next = _M_create_node(*__curr);
+ __to->_M_next = this->_M_create_node(*__curr);
__to = __to->_M_next;
++__curr;
}
@@ -245,7 +259,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (__from->_M_next != 0)
{
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;
__to = __to->_M_next;
}
@@ -260,7 +274,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
for (const _Tp* __item = __il.begin();
__item != __il.end(); ++__item)
{
- __to->_M_next = _M_create_node(*__item);
+ __to->_M_next = this->_M_create_node(*__item);
__to = __to->_M_next;
}
}
@@ -303,7 +317,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Fwd_list_node_base* __keep = __to->_M_next;
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->_M_next = __keep;
@@ -322,7 +336,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_InputIterator __curr = __first;
while (__curr != __last)
{
- __to->_M_next = _M_create_node(*__curr);
+ __to->_M_next = this->_M_create_node(*__curr);
__to = __to->_M_next;
++__curr;
}
@@ -340,7 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
const _Tp* __item = __il.begin();
while (__item != __il.end())
{
- __to->_M_next = _M_create_node(*__item);
+ __to->_M_next = this->_M_create_node(*__item);
__to = __to->_M_next;
++__item;
}
@@ -369,13 +383,42 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Alloc>
void
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)
{
_Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{
if (__temp->_M_value == __val)
- _M_erase_after(__curr);
+ this->_M_erase_after(__curr);
else
__curr = static_cast<_Node*>(__curr->_M_next);
}
@@ -391,7 +434,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
while (_Node* __temp = static_cast<_Node*>(__curr->_M_next))
{
if (__pred(__temp->_M_value))
- _M_erase_after(__curr);
+ this->_M_erase_after(__curr);
else
__curr = static_cast<_Node*>(__curr->_M_next);
}
@@ -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
#endif /* _FORWARD_LIST_TCC */