59 namespace std _GLIBCXX_VISIBILITY(default)
61 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
63 template<
typename _Tp,
typename _Alloc>
65 _List_base<_Tp, _Alloc>::
66 _M_clear() _GLIBCXX_NOEXCEPT
68 typedef _List_node<_Tp> _Node;
69 __detail::_List_node_base* __cur = _M_impl._M_node._M_next;
70 while (__cur != &_M_impl._M_node)
72 _Node* __tmp =
static_cast<_Node*
>(__cur);
73 __cur = __tmp->_M_next;
74 _Tp* __val = __tmp->_M_valptr();
75 #if __cplusplus >= 201103L 76 _Node_alloc_traits::destroy(_M_get_Node_allocator(), __val);
78 _Tp_alloc_type(_M_get_Node_allocator()).destroy(__val);
84 #if __cplusplus >= 201103L 85 template<
typename _Tp,
typename _Alloc>
86 template<
typename... _Args>
87 typename list<_Tp, _Alloc>::iterator
91 _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
92 __tmp->_M_hook(__position._M_const_cast()._M_node);
98 template<
typename _Tp,
typename _Alloc>
101 #if __cplusplus >= 201103L 104 insert(
iterator __position,
const value_type& __x)
107 _Node* __tmp = _M_create_node(__x);
108 __tmp->_M_hook(__position._M_const_cast()._M_node);
109 this->_M_inc_size(1);
113 #if __cplusplus >= 201103L 114 template<
typename _Tp,
typename _Alloc>
121 list __tmp(__n, __x, get_allocator());
123 splice(__position, __tmp);
126 return __position._M_const_cast();
129 template<
typename _Tp,
typename _Alloc>
130 template<
typename _InputIterator,
typename>
134 _InputIterator __last)
136 list __tmp(__first, __last, get_allocator());
140 splice(__position, __tmp);
143 return __position._M_const_cast();
147 template<
typename _Tp,
typename _Alloc>
150 #if __cplusplus >= 201103L 157 _M_erase(__position._M_const_cast());
172 template<
typename _Tp,
typename _Alloc>
178 #if _GLIBCXX_USE_CXX11_ABI 179 const size_type __len = size();
180 if (__new_size < __len)
182 if (__new_size <= __len / 2)
190 ptrdiff_t __num_erase = __len - __new_size;
200 for (__i =
begin(); __i !=
end() && __len < __new_size; ++__i, ++__len)
207 #if __cplusplus >= 201103L 208 template<
typename _Tp,
typename _Alloc>
216 for (; __i < __n; ++__i)
223 __throw_exception_again;
227 template<
typename _Tp,
typename _Alloc>
234 _M_default_append(__new_size);
239 template<
typename _Tp,
typename _Alloc>
242 resize(size_type __new_size,
const value_type& __x)
246 insert(
end(), __new_size, __x);
251 template<
typename _Tp,
typename _Alloc>
254 resize(size_type __new_size, value_type __x)
258 insert(
end(), __new_size, __x);
260 erase(__i._M_const_cast(),
end());
264 template<
typename _Tp,
typename _Alloc>
271 #if __cplusplus >= 201103L 272 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
274 auto& __this_alloc = this->_M_get_Node_allocator();
275 auto& __that_alloc = __x._M_get_Node_allocator();
276 if (!_Node_alloc_traits::_S_always_equal()
277 && __this_alloc != __that_alloc)
282 std::__alloc_on_copy(__this_alloc, __that_alloc);
285 _M_assign_dispatch(__x.
begin(), __x.
end(), __false_type());
290 template<
typename _Tp,
typename _Alloc>
296 for (; __i !=
end() && __n > 0; ++__i, --__n)
299 insert(
end(), __n, __val);
304 template<
typename _Tp,
typename _Alloc>
305 template <
typename _InputIterator>
313 for (; __first1 != __last1 && __first2 != __last2;
314 ++__first1, ++__first2)
315 *__first1 = *__first2;
316 if (__first2 == __last2)
317 erase(__first1, __last1);
319 insert(__last1, __first2, __last2);
322 template<
typename _Tp,
typename _Alloc>
330 while (__first != __last)
334 if (*__first == __value)
346 if (__extra != __last)
350 template<
typename _Tp,
typename _Alloc>
357 if (__first == __last)
360 while (++__next != __last)
362 if (*__first == *__next)
370 template<
typename _Tp,
typename _Alloc>
373 #if __cplusplus >= 201103L 383 _M_check_equal_allocators(__x);
389 while (__first1 != __last1 && __first2 != __last2)
390 if (*__first2 < *__first1)
393 _M_transfer(__first1, __first2, ++__next);
398 if (__first2 != __last2)
399 _M_transfer(__last1, __first2, __last2);
401 this->_M_inc_size(__x._M_get_size());
406 template<
typename _Tp,
typename _Alloc>
407 template <
typename _StrictWeakOrdering>
410 #if __cplusplus >= 201103L 411 merge(
list&& __x, _StrictWeakOrdering __comp)
413 merge(
list& __x, _StrictWeakOrdering __comp)
420 _M_check_equal_allocators(__x);
426 while (__first1 != __last1 && __first2 != __last2)
427 if (__comp(*__first2, *__first1))
430 _M_transfer(__first1, __first2, ++__next);
435 if (__first2 != __last2)
436 _M_transfer(__last1, __first2, __last2);
438 this->_M_inc_size(__x._M_get_size());
443 template<
typename _Tp,
typename _Alloc>
449 if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
450 && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
454 list * __fill = __tmp;
461 for(__counter = __tmp;
462 __counter != __fill && !__counter->
empty();
465 __counter->
merge(__carry);
466 __carry.
swap(*__counter);
468 __carry.
swap(*__counter);
469 if (__counter == __fill)
474 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
475 __counter->
merge(*(__counter - 1));
476 swap( *(__fill - 1) );
480 template<
typename _Tp,
typename _Alloc>
481 template <
typename _Predicate>
488 while (__first != __last)
492 if (__pred(*__first))
498 template<
typename _Tp,
typename _Alloc>
499 template <
typename _BinaryPredicate>
506 if (__first == __last)
509 while (++__next != __last)
511 if (__binary_pred(*__first, *__next))
519 template<
typename _Tp,
typename _Alloc>
520 template <
typename _StrictWeakOrdering>
523 sort(_StrictWeakOrdering __comp)
526 if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
527 && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
531 list * __fill = __tmp;
538 for(__counter = __tmp;
539 __counter != __fill && !__counter->
empty();
542 __counter->
merge(__carry, __comp);
543 __carry.
swap(*__counter);
545 __carry.
swap(*__counter);
546 if (__counter == __fill)
551 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
552 __counter->
merge(*(__counter - 1), __comp);
557 _GLIBCXX_END_NAMESPACE_CONTAINER
iterator begin() noexcept
void swap(list &__x) noexcept
Swaps data with another list.
void unique()
Remove consecutive duplicate elements.
void resize(size_type __new_size)
Resizes the list to the specified number of elements.
void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
bool empty() const noexcept
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
void splice(const_iterator __position, list &&__x) noexcept
Insert contents of another list.
void merge(list &&__x)
Merge sorted lists.
list & operator=(const list &__x)
List assignment operator.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into list before specified iterator.
void remove(const _Tp &__value)
Remove all elements equal to value.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void remove_if(_Predicate)
Remove all elements satisfying a predicate.
ISO C++ entities toplevel namespace is std.
void sort()
Sort the elements.
iterator emplace(const_iterator __position, _Args &&...__args)
Constructs object in list before specified iterator.