Commit 4d54539c by Benjamin Kosnik Committed by Benjamin Kosnik

stl_list.h: Formatting tweaks.


2003-12-18  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/stl_list.h: Formatting tweaks.
	* include/bits/list.tcc: Same.

From-SVN: r74795
parent 91d39d71
2003-12-18 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/stl_list.h: Formatting tweaks.
* include/bits/list.tcc: Same.
2003-12-18 Matt Austern <austern@apple.com> 2003-12-18 Matt Austern <austern@apple.com>
* include/bits/demangle.h: Fix allocator type correctness, * include/bits/demangle.h: Fix allocator type correctness,
......
...@@ -66,7 +66,7 @@ namespace __gnu_norm ...@@ -66,7 +66,7 @@ namespace __gnu_norm
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
_List_base<_Tp,_Alloc>:: _List_base<_Tp,_Alloc>::
__clear() _M_clear()
{ {
typedef _List_node<_Tp> _Node; typedef _List_node<_Tp> _Node;
_Node* __cur = static_cast<_Node*>(this->_M_node._M_next); _Node* __cur = static_cast<_Node*>(this->_M_node._M_next);
...@@ -92,7 +92,8 @@ namespace __gnu_norm ...@@ -92,7 +92,8 @@ namespace __gnu_norm
this->_M_node._M_next = __x._M_node._M_next; this->_M_node._M_next = __x._M_node._M_next;
this->_M_node._M_prev = __x._M_node._M_prev; this->_M_node._M_prev = __x._M_node._M_prev;
this->_M_node._M_next->_M_prev = this->_M_node._M_prev->_M_next = &this->_M_node; this->_M_node._M_prev->_M_next = &this->_M_node;
this->_M_node._M_next->_M_prev = this->_M_node._M_prev->_M_next;
__x._M_node._M_next = __x._M_node._M_prev = &__x._M_node; __x._M_node._M_next = __x._M_node._M_prev = &__x._M_node;
} }
} }
...@@ -101,7 +102,8 @@ namespace __gnu_norm ...@@ -101,7 +102,8 @@ namespace __gnu_norm
__x._M_node._M_next = this->_M_node._M_next; __x._M_node._M_next = this->_M_node._M_next;
__x._M_node._M_prev = this->_M_node._M_prev; __x._M_node._M_prev = this->_M_node._M_prev;
__x._M_node._M_next->_M_prev = __x._M_node._M_prev->_M_next = &__x._M_node; __x._M_node._M_prev->_M_next = &__x._M_node;
__x._M_node._M_next->_M_prev = __x._M_node._M_prev->_M_next;
this->_M_node._M_next = this->_M_node._M_prev = &this->_M_node; this->_M_node._M_next = this->_M_node._M_prev = &this->_M_node;
} }
else else
...@@ -109,8 +111,10 @@ namespace __gnu_norm ...@@ -109,8 +111,10 @@ namespace __gnu_norm
std::swap(this->_M_node._M_next,__x._M_node._M_next); std::swap(this->_M_node._M_next,__x._M_node._M_next);
std::swap(this->_M_node._M_prev,__x._M_node._M_prev); std::swap(this->_M_node._M_prev,__x._M_node._M_prev);
this->_M_node._M_next->_M_prev = this->_M_node._M_prev->_M_next = &this->_M_node; this->_M_node._M_prev->_M_next = &this->_M_node;
__x._M_node._M_next->_M_prev = __x._M_node._M_prev->_M_next = &__x._M_node; this->_M_node._M_next->_M_prev = this->_M_node._M_prev->_M_next;
__x._M_node._M_prev->_M_next = &__x._M_node;
__x._M_node._M_next->_M_prev = __x._M_node._M_prev->_M_next;
} }
} }
...@@ -196,11 +200,13 @@ namespace __gnu_norm ...@@ -196,11 +200,13 @@ namespace __gnu_norm
template <typename _InputIterator> template <typename _InputIterator>
void void
list<_Tp,_Alloc>:: list<_Tp,_Alloc>::
_M_assign_dispatch(_InputIterator __first2, _InputIterator __last2, __false_type) _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
__false_type)
{ {
iterator __first1 = begin(); iterator __first1 = begin();
iterator __last1 = end(); iterator __last1 = end();
for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) for (; __first1 != __last1 && __first2 != __last2;
++__first1, ++__first2)
*__first1 = *__first2; *__first1 = *__first2;
if (__first2 == __last2) if (__first2 == __last2)
erase(__first1, __last1); erase(__first1, __last1);
...@@ -276,10 +282,12 @@ namespace __gnu_norm ...@@ -276,10 +282,12 @@ namespace __gnu_norm
__List_base_reverse(_List_node_base* __p) __List_base_reverse(_List_node_base* __p)
{ {
_List_node_base* __tmp = __p; _List_node_base* __tmp = __p;
do { do
{
std::swap(__tmp->_M_next, __tmp->_M_prev); std::swap(__tmp->_M_next, __tmp->_M_prev);
__tmp = __tmp->_M_prev; // Old next node is now prev. __tmp = __tmp->_M_prev; // Old next node is now prev.
} while (__tmp != __p); }
while (__tmp != __p);
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
......
...@@ -104,11 +104,9 @@ namespace __gnu_norm ...@@ -104,11 +104,9 @@ namespace __gnu_norm
_List_node_base* _M_node; _List_node_base* _M_node;
_List_iterator_base(_List_node_base* __x) _List_iterator_base(_List_node_base* __x)
: _M_node(__x) : _M_node(__x) { }
{ }
_List_iterator_base() _List_iterator_base() { }
{ }
/// Walk the %list forward. /// Walk the %list forward.
void void
...@@ -152,20 +150,17 @@ namespace __gnu_norm ...@@ -152,20 +150,17 @@ namespace __gnu_norm
typedef _List_node<_Tp> _Node; typedef _List_node<_Tp> _Node;
_List_iterator(_Node* __x) _List_iterator(_Node* __x)
: _List_iterator_base(__x) : _List_iterator_base(__x) { }
{ }
_List_iterator() _List_iterator() { }
{ }
_List_iterator(const iterator& __x) _List_iterator(const iterator& __x)
: _List_iterator_base(__x._M_node) : _List_iterator_base(__x._M_node) { }
{ }
// Must downcast from List_node_base to _List_node to get to _M_data.
reference reference
operator*() const operator*() const
{ return static_cast<_Node*>(_M_node)->_M_data; } { return static_cast<_Node*>(_M_node)->_M_data; }
// Must downcast from List_node_base to _List_node to get to _M_data.
pointer pointer
operator->() const operator->() const
...@@ -207,25 +202,29 @@ namespace __gnu_norm ...@@ -207,25 +202,29 @@ namespace __gnu_norm
* See bits/stl_deque.h's _Deque_base for an explanation. * See bits/stl_deque.h's _Deque_base for an explanation.
* @endif * @endif
*/ */
template <typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
class _List_base class _List_base
: public _Alloc::template rebind<_List_node<_Tp> >::other : public _Alloc::template rebind<_List_node<_Tp> >::other
{ {
protected: protected:
// NOTA BENE // NOTA BENE
// The stored instance is not actually of "allocator_type"'s type. // The stored instance is not actually of "allocator_type"'s
// Instead we rebind the type to Allocator<List_node<Tp>>, which // type. Instead we rebind the type to
// according to [20.1.5]/4 should probably be the same. // Allocator<List_node<Tp>>, which according to [20.1.5]/4
// List_node<Tp> is not the same size as Tp (it's two pointers // should probably be the same. List_node<Tp> is not the same
// larger), and specializations on Tp may go unused because // size as Tp (it's two pointers larger), and specializations on
// List_node<Tp> is being bound instead. // Tp may go unused because List_node<Tp> is being bound
// instead.
// //
// We put this to the test in the constructors and in get_allocator, // We put this to the test in the constructors and in
// where we use conversions between allocator_type and // get_allocator, where we use conversions between
// _Node_Alloc_type. The conversion is required by table 32 in [20.1.5]. // allocator_type and _Node_Alloc_type. The conversion is
// required by table 32 in [20.1.5].
typedef typename _Alloc::template rebind<_List_node<_Tp> >::other typedef typename _Alloc::template rebind<_List_node<_Tp> >::other
_Node_Alloc_type; _Node_Alloc_type;
_List_node_base _M_node;
_List_node<_Tp>* _List_node<_Tp>*
_M_get_node() _M_get_node()
{ return _Node_Alloc_type::allocate(1); } { return _Node_Alloc_type::allocate(1); }
...@@ -234,11 +233,11 @@ namespace __gnu_norm ...@@ -234,11 +233,11 @@ namespace __gnu_norm
_M_put_node(_List_node<_Tp>* __p) _M_put_node(_List_node<_Tp>* __p)
{ _Node_Alloc_type::deallocate(__p, 1); } { _Node_Alloc_type::deallocate(__p, 1); }
_List_node_base _M_node;
public: public:
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
allocator_type get_allocator() const
allocator_type
get_allocator() const
{ return allocator_type(*static_cast<const _Node_Alloc_type*>(this)); } { return allocator_type(*static_cast<const _Node_Alloc_type*>(this)); }
_List_base(const allocator_type& __a) _List_base(const allocator_type& __a)
...@@ -250,18 +249,16 @@ namespace __gnu_norm ...@@ -250,18 +249,16 @@ namespace __gnu_norm
// This is what actually destroys the list. // This is what actually destroys the list.
~_List_base() ~_List_base()
{ { _M_clear(); }
__clear();
}
void void
__clear(); _M_clear();
}; };
/** /**
* @brief A standard container with linear time access to elements, and * @brief A standard container with linear time access to elements,
* fixed time insertion/deletion at any point in the sequence. * and fixed time insertion/deletion at any point in the sequence.
* *
* @ingroup Containers * @ingroup Containers
* @ingroup Sequences * @ingroup Sequences
...@@ -327,13 +324,14 @@ namespace __gnu_norm ...@@ -327,13 +324,14 @@ namespace __gnu_norm
typedef typename _Base::allocator_type allocator_type; typedef typename _Base::allocator_type allocator_type;
protected: protected:
// Note that pointers-to-_Node's can be ctor-converted to iterator types. // Note that pointers-to-_Node's can be ctor-converted to
// iterator types.
typedef _List_node<_Tp> _Node; typedef _List_node<_Tp> _Node;
/** @if maint /** @if maint
* One data member plus two memory-handling functions. If the _Alloc * One data member plus two memory-handling functions. If the
* type requires separate instances, then one of those will also be * _Alloc type requires separate instances, then one of those
* included, accumulated from the topmost parent. * will also be included, accumulated from the topmost parent.
* @endif * @endif
*/ */
using _Base::_M_node; using _Base::_M_node;
...@@ -351,7 +349,8 @@ namespace __gnu_norm ...@@ -351,7 +349,8 @@ namespace __gnu_norm
_M_create_node(const value_type& __x) _M_create_node(const value_type& __x)
{ {
_Node* __p = this->_M_get_node(); _Node* __p = this->_M_get_node();
try { try
{
std::_Construct(&__p->_M_data, __x); std::_Construct(&__p->_M_data, __x);
} }
catch(...) catch(...)
...@@ -364,15 +363,16 @@ namespace __gnu_norm ...@@ -364,15 +363,16 @@ namespace __gnu_norm
/** /**
* @if maint * @if maint
* Allocates space for a new node and default-constructs a new instance * Allocates space for a new node and default-constructs a new
* of @c value_type in it. * instance of @c value_type in it.
* @endif * @endif
*/ */
_Node* _Node*
_M_create_node() _M_create_node()
{ {
_Node* __p = this->_M_get_node(); _Node* __p = this->_M_get_node();
try { try
{
std::_Construct(&__p->_M_data); std::_Construct(&__p->_M_data);
} }
catch(...) catch(...)
...@@ -452,8 +452,8 @@ namespace __gnu_norm ...@@ -452,8 +452,8 @@ namespace __gnu_norm
* No explicit dtor needed as the _Base dtor takes care of * No explicit dtor needed as the _Base dtor takes care of
* things. The _Base dtor only erases the elements, and note * things. The _Base dtor only erases the elements, and note
* that if the elements themselves are pointers, the pointed-to * that if the elements themselves are pointers, the pointed-to
* memory is not touched in any way. Managing the pointer is the * memory is not touched in any way. Managing the pointer is
* user's responsibilty. * the user's responsibilty.
*/ */
/** /**
...@@ -488,9 +488,9 @@ namespace __gnu_norm ...@@ -488,9 +488,9 @@ namespace __gnu_norm
* This function fills a %list with copies of the elements in the * This function fills a %list with copies of the elements in the
* range [@a first,@a last). * range [@a first,@a last).
* *
* Note that the assignment completely changes the %list and that the * Note that the assignment completely changes the %list and
* resulting %list's size is the same as the number of elements assigned. * that the resulting %list's size is the same as the number of
* Old data may be lost. * elements assigned. Old data may be lost.
*/ */
template<typename _InputIterator> template<typename _InputIterator>
void void
...@@ -536,7 +536,7 @@ namespace __gnu_norm ...@@ -536,7 +536,7 @@ namespace __gnu_norm
*/ */
const_iterator const_iterator
end() const end() const
{ return const_cast<_Node *>(static_cast<const _Node*>(&this->_M_node)); } { return const_cast<_Node*>(static_cast<const _Node*>(&this->_M_node)); }
/** /**
* Returns a read/write reverse iterator that points to the last * Returns a read/write reverse iterator that points to the last
...@@ -614,8 +614,8 @@ namespace __gnu_norm ...@@ -614,8 +614,8 @@ namespace __gnu_norm
// element access // element access
/** /**
* Returns a read/write reference to the data at the first element of the * Returns a read/write reference to the data at the first
* %list. * element of the %list.
*/ */
reference reference
front() { return *begin(); } front() { return *begin(); }
...@@ -707,8 +707,8 @@ namespace __gnu_norm ...@@ -707,8 +707,8 @@ namespace __gnu_norm
* @param x Data to be inserted. * @param x Data to be inserted.
* @return An iterator that points to the inserted data. * @return An iterator that points to the inserted data.
* *
* This function will insert a copy of the given value before the * This function will insert a copy of the given value before
* specified location. Due to the nature of a %list this * the specified location. Due to the nature of a %list this
* operation can be done in constant time, and does not * operation can be done in constant time, and does not
* invalidate iterators and references. * invalidate iterators and references.
*/ */
...@@ -742,8 +742,9 @@ namespace __gnu_norm ...@@ -742,8 +742,9 @@ namespace __gnu_norm
* first,@a last) into the %list before the location specified by * first,@a last) into the %list before the location specified by
* @a position. * @a position.
* *
* Due to the nature of a %list this operation can be done in constant * Due to the nature of a %list this operation can be done in
* time, and does not invalidate iterators and references. * constant time, and does not invalidate iterators and
* references.
*/ */
template<typename _InputIterator> template<typename _InputIterator>
void void
...@@ -819,7 +820,7 @@ namespace __gnu_norm ...@@ -819,7 +820,7 @@ namespace __gnu_norm
* Managing the pointer is the user's responsibilty. * Managing the pointer is the user's responsibilty.
*/ */
void void
clear() { _Base::__clear(); } clear() { _Base::_M_clear(); }
// [23.2.2.4] list operations // [23.2.2.4] list operations
/** /**
...@@ -882,8 +883,9 @@ namespace __gnu_norm ...@@ -882,8 +883,9 @@ namespace __gnu_norm
* Removes every element in the list equal to @a value. * Removes every element in the list equal to @a value.
* Remaining elements stay in list order. Note that this * Remaining elements stay in list order. Note that this
* function only erases the elements, and that if the elements * function only erases the elements, and that if the elements
* themselves are pointers, the pointed-to memory is not touched * themselves are pointers, the pointed-to memory is not
* in any way. Managing the pointer is the user's responsibilty. * touched in any way. Managing the pointer is the user's
* responsibilty.
*/ */
void void
remove(const _Tp& __value); remove(const _Tp& __value);
...@@ -895,8 +897,8 @@ namespace __gnu_norm ...@@ -895,8 +897,8 @@ namespace __gnu_norm
* Removes every element in the list for which the predicate * Removes every element in the list for which the predicate
* returns true. Remaining elements stay in list order. Note * returns true. Remaining elements stay in list order. Note
* that this function only erases the elements, and that if the * that this function only erases the elements, and that if the
* elements themselves are pointers, the pointed-to memory is not * elements themselves are pointers, the pointed-to memory is
* touched in any way. Managing the pointer is the user's * not touched in any way. Managing the pointer is the user's
* responsibilty. * responsibilty.
*/ */
template<typename _Predicate> template<typename _Predicate>
...@@ -907,11 +909,11 @@ namespace __gnu_norm ...@@ -907,11 +909,11 @@ namespace __gnu_norm
* @brief Remove consecutive duplicate elements. * @brief Remove consecutive duplicate elements.
* *
* For each consecutive set of elements with the same value, * For each consecutive set of elements with the same value,
* remove all but the first one. Remaining elements stay in list * remove all but the first one. Remaining elements stay in
* order. Note that this function only erases the elements, and * list order. Note that this function only erases the
* that if the elements themselves are pointers, the pointed-to * elements, and that if the elements themselves are pointers,
* memory is not touched in any way. Managing the pointer is the * the pointed-to memory is not touched in any way. Managing
* user's responsibilty. * the pointer is the user's responsibilty.
*/ */
void void
unique(); unique();
...@@ -920,13 +922,13 @@ namespace __gnu_norm ...@@ -920,13 +922,13 @@ namespace __gnu_norm
* @brief Remove consecutive elements satisfying a predicate. * @brief Remove consecutive elements satisfying a predicate.
* @param BinaryPredicate Binary predicate function or object. * @param BinaryPredicate Binary predicate function or object.
* *
* For each consecutive set of elements [first,last) that satisfy * For each consecutive set of elements [first,last) that
* predicate(first,i) where i is an iterator in [first,last), * satisfy predicate(first,i) where i is an iterator in
* remove all but the first one. Remaining elements stay in list * [first,last), remove all but the first one. Remaining
* order. Note that this function only erases the elements, and * elements stay in list order. Note that this function only
* that if the elements themselves are pointers, the pointed-to * erases the elements, and that if the elements themselves are
* memory is not touched in any way. Managing the pointer is the * pointers, the pointed-to memory is not touched in any way.
* user's responsibilty. * Managing the pointer is the user's responsibilty.
*/ */
template<typename _BinaryPredicate> template<typename _BinaryPredicate>
void void
...@@ -937,9 +939,9 @@ namespace __gnu_norm ...@@ -937,9 +939,9 @@ namespace __gnu_norm
* @param x Sorted list to merge. * @param x Sorted list to merge.
* *
* Assumes that both @a x and this list are sorted according to * Assumes that both @a x and this list are sorted according to
* operator<(). Merges elements of @a x into this list in sorted * operator<(). Merges elements of @a x into this list in
* order, leaving @a x empty when complete. Elements in this * sorted order, leaving @a x empty when complete. Elements in
* list precede elements in @a x that are equal. * this list precede elements in @a x that are equal.
*/ */
void void
merge(list& __x); merge(list& __x);
...@@ -947,12 +949,13 @@ namespace __gnu_norm ...@@ -947,12 +949,13 @@ namespace __gnu_norm
/** /**
* @brief Merge sorted lists according to comparison function. * @brief Merge sorted lists according to comparison function.
* @param x Sorted list to merge. * @param x Sorted list to merge.
* @param StrictWeakOrdering Comparison function definining sort order. * @param StrictWeakOrdering Comparison function definining
* sort order.
* *
* Assumes that both @a x and this list are sorted according to * Assumes that both @a x and this list are sorted according to
* StrictWeakOrdering. Merges elements of @a x into this list in * StrictWeakOrdering. Merges elements of @a x into this list
* sorted order, leaving @a x empty when complete. Elements in * in sorted order, leaving @a x empty when complete. Elements
* this list precede elements in @a x that are equivalent * in this list precede elements in @a x that are equivalent
* according to StrictWeakOrdering(). * according to StrictWeakOrdering().
*/ */
template<typename _StrictWeakOrdering> template<typename _StrictWeakOrdering>
...@@ -1047,7 +1050,8 @@ namespace __gnu_norm ...@@ -1047,7 +1050,8 @@ namespace __gnu_norm
void void
_M_transfer(iterator __position, iterator __first, iterator __last) _M_transfer(iterator __position, iterator __first, iterator __last)
{ {
if (__position != __last) { if (__position != __last)
{
// Remove [first, last) from its old position. // Remove [first, last) from its old position.
__last._M_node->_M_prev->_M_next = __position._M_node; __last._M_node->_M_prev->_M_next = __position._M_node;
__first._M_node->_M_prev->_M_next = __last._M_node; __first._M_node->_M_prev->_M_next = __last._M_node;
...@@ -1083,7 +1087,8 @@ namespace __gnu_norm ...@@ -1083,7 +1087,8 @@ namespace __gnu_norm
const_iterator __i1 = __x.begin(); const_iterator __i1 = __x.begin();
const_iterator __i2 = __y.begin(); const_iterator __i2 = __y.begin();
while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) { while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
{
++__i1; ++__i1;
++__i2; ++__i2;
} }
......
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