59 namespace std _GLIBCXX_VISIBILITY(default)
61 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<
typename _Tp,
typename _Alloc>
66 _List_base<_Tp, _Alloc>::
67 _M_clear() _GLIBCXX_NOEXCEPT
69 typedef _List_node<_Tp> _Node;
70 __detail::_List_node_base* __cur = _M_impl._M_node._M_next;
71 while (__cur != &_M_impl._M_node)
73 _Node* __tmp =
static_cast<_Node*
>(__cur);
74 __cur = __tmp->_M_next;
75 _Tp* __val = __tmp->_M_valptr();
76 #if __cplusplus >= 201103L
77 _Node_alloc_traits::destroy(_M_get_Node_allocator(), __val);
79 _Tp_alloc_type(_M_get_Node_allocator()).destroy(__val);
85 #if __cplusplus >= 201103L
86 template<
typename _Tp,
typename _Alloc>
87 template<
typename... _Args>
88 typename list<_Tp, _Alloc>::iterator
90 emplace(const_iterator __position, _Args&&... __args)
92 _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
93 __tmp->_M_hook(__position._M_const_cast()._M_node);
95 return iterator(__tmp);
99 template<
typename _Tp,
typename _Alloc>
100 typename list<_Tp, _Alloc>::iterator
102 #if __cplusplus >= 201103L
103 insert(const_iterator __position,
const value_type& __x)
105 insert(iterator __position,
const value_type& __x)
108 _Node* __tmp = _M_create_node(__x);
109 __tmp->_M_hook(__position._M_const_cast()._M_node);
110 this->_M_inc_size(1);
111 return iterator(__tmp);
114 #if __cplusplus >= 201103L
115 template<
typename _Tp,
typename _Alloc>
116 typename list<_Tp, _Alloc>::iterator
122 list __tmp(__n, __x, get_allocator());
124 splice(__position, __tmp);
127 return __position._M_const_cast();
130 template<
typename _Tp,
typename _Alloc>
131 template<
typename _InputIterator,
typename>
134 insert(const_iterator __position, _InputIterator __first,
135 _InputIterator __last)
137 list __tmp(__first, __last, get_allocator());
141 splice(__position, __tmp);
144 return __position._M_const_cast();
148 template<
typename _Tp,
typename _Alloc>
149 typename list<_Tp, _Alloc>::iterator
151 #if __cplusplus >= 201103L
158 _M_erase(__position._M_const_cast());
173 template<
typename _Tp,
typename _Alloc>
179 #if _GLIBCXX_USE_CXX11_ABI
180 const size_type __len =
size();
181 if (__new_size < __len)
183 if (__new_size <= __len / 2)
186 std::advance(__i, __new_size);
191 ptrdiff_t __num_erase = __len - __new_size;
192 std::advance(__i, -__num_erase);
201 for (__i =
begin(); __i !=
end() && __len < __new_size; ++__i, ++__len)
208 #if __cplusplus >= 201103L
209 template<
typename _Tp,
typename _Alloc>
212 _M_default_append(size_type __n)
217 for (; __i < __n; ++__i)
224 __throw_exception_again;
228 template<
typename _Tp,
typename _Alloc>
235 _M_default_append(__new_size);
240 template<
typename _Tp,
typename _Alloc>
243 resize(size_type __new_size,
const value_type& __x)
247 insert(
end(), __new_size, __x);
252 template<
typename _Tp,
typename _Alloc>
255 resize(size_type __new_size, value_type __x)
257 const_iterator __i = _M_resize_pos(__new_size);
259 insert(
end(), __new_size, __x);
261 erase(__i._M_const_cast(),
end());
265 template<
typename _Tp,
typename _Alloc>
272 #if __cplusplus >= 201103L
273 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
275 auto& __this_alloc = this->_M_get_Node_allocator();
276 auto& __that_alloc = __x._M_get_Node_allocator();
277 if (!_Node_alloc_traits::_S_always_equal()
278 && __this_alloc != __that_alloc)
283 std::__alloc_on_copy(__this_alloc, __that_alloc);
286 _M_assign_dispatch(__x.
begin(), __x.
end(), __false_type());
291 template<
typename _Tp,
typename _Alloc>
297 for (; __i !=
end() && __n > 0; ++__i, --__n)
300 insert(
end(), __n, __val);
305 template<
typename _Tp,
typename _Alloc>
306 template <
typename _InputIterator>
309 _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
312 iterator __first1 =
begin();
313 iterator __last1 =
end();
314 for (; __first1 != __last1 && __first2 != __last2;
315 ++__first1, (void)++__first2)
316 *__first1 = *__first2;
317 if (__first2 == __last2)
318 erase(__first1, __last1);
320 insert(__last1, __first2, __last2);
323 #if __cplusplus > 201703L
324 # define _GLIBCXX20_ONLY(__expr) __expr
326 # define _GLIBCXX20_ONLY(__expr)
329 template<
typename _Tp,
typename _Alloc>
330 typename list<_Tp, _Alloc>::__remove_return_type
334 #if !_GLIBCXX_USE_CXX11_ABI
335 size_type __removed __attribute__((__unused__)) = 0;
337 list __to_destroy(get_allocator());
340 while (__first != __last)
344 if (*__first == __value)
349 __to_destroy.
splice(__to_destroy.
begin(), *
this, __first);
350 #if !_GLIBCXX_USE_CXX11_ABI
351 _GLIBCXX20_ONLY( __removed++ );
358 #if !_GLIBCXX_USE_CXX11_ABI
359 return _GLIBCXX20_ONLY( __removed );
361 return _GLIBCXX20_ONLY( __to_destroy.
size() );
365 template<
typename _Tp,
typename _Alloc>
366 typename list<_Tp, _Alloc>::__remove_return_type
372 if (__first == __last)
373 return _GLIBCXX20_ONLY( 0 );
374 #if !_GLIBCXX_USE_CXX11_ABI
375 size_type __removed __attribute__((__unused__)) = 0;
377 list __to_destroy(get_allocator());
379 while (++__next != __last)
381 if (*__first == *__next)
383 __to_destroy.
splice(__to_destroy.
begin(), *
this, __next);
384 #if !_GLIBCXX_USE_CXX11_ABI
385 _GLIBCXX20_ONLY( __removed++ );
393 #if !_GLIBCXX_USE_CXX11_ABI
394 return _GLIBCXX20_ONLY( __removed );
396 return _GLIBCXX20_ONLY( __to_destroy.
size() );
400 template<
typename _Tp,
typename _Alloc>
403 #if __cplusplus >= 201103L
413 _M_check_equal_allocators(__x);
419 const size_t __orig_size = __x.
size();
421 while (__first1 != __last1 && __first2 != __last2)
422 if (*__first2 < *__first1)
425 _M_transfer(__first1, __first2, ++__next);
430 if (__first2 != __last2)
431 _M_transfer(__last1, __first2, __last2);
433 this->_M_inc_size(__x._M_get_size());
439 this->_M_inc_size(__orig_size - __dist);
440 __x._M_set_size(__dist);
441 __throw_exception_again;
446 template<
typename _Tp,
typename _Alloc>
447 template <
typename _StrictWeakOrdering>
450 #if __cplusplus >= 201103L
451 merge(list&& __x, _StrictWeakOrdering __comp)
453 merge(list& __x, _StrictWeakOrdering __comp)
460 _M_check_equal_allocators(__x);
462 iterator __first1 =
begin();
463 iterator __last1 =
end();
464 iterator __first2 = __x.begin();
465 iterator __last2 = __x.end();
466 const size_t __orig_size = __x.size();
469 while (__first1 != __last1 && __first2 != __last2)
470 if (__comp(*__first2, *__first1))
472 iterator __next = __first2;
473 _M_transfer(__first1, __first2, ++__next);
478 if (__first2 != __last2)
479 _M_transfer(__last1, __first2, __last2);
481 this->_M_inc_size(__x._M_get_size());
487 this->_M_inc_size(__orig_size - __dist);
488 __x._M_set_size(__dist);
489 __throw_exception_again;
494 template<
typename _Tp,
typename _Alloc>
500 if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
501 && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
505 list * __fill = __tmp;
513 for(__counter = __tmp;
514 __counter != __fill && !__counter->
empty();
517 __counter->
merge(__carry);
518 __carry.
swap(*__counter);
520 __carry.
swap(*__counter);
521 if (__counter == __fill)
526 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
527 __counter->
merge(*(__counter - 1));
528 swap( *(__fill - 1) );
532 this->splice(this->
end(), __carry);
533 for (
int __i = 0; __i <
sizeof(__tmp)/
sizeof(__tmp[0]); ++__i)
534 this->splice(this->
end(), __tmp[__i]);
535 __throw_exception_again;
540 template<
typename _Tp,
typename _Alloc>
541 template <
typename _Predicate>
542 typename list<_Tp, _Alloc>::__remove_return_type
546 #if !_GLIBCXX_USE_CXX11_ABI
547 size_type __removed __attribute__((__unused__)) = 0;
549 list __to_destroy(get_allocator());
552 while (__first != __last)
556 if (__pred(*__first))
558 __to_destroy.splice(__to_destroy.begin(), *
this, __first);
559 #if !_GLIBCXX_USE_CXX11_ABI
560 _GLIBCXX20_ONLY( __removed++ );
566 #if !_GLIBCXX_USE_CXX11_ABI
567 return _GLIBCXX20_ONLY( __removed );
569 return _GLIBCXX20_ONLY( __to_destroy.size() );
573 template<
typename _Tp,
typename _Alloc>
574 template <
typename _BinaryPredicate>
575 typename list<_Tp, _Alloc>::__remove_return_type
577 unique(_BinaryPredicate __binary_pred)
579 iterator __first =
begin();
580 iterator __last =
end();
581 if (__first == __last)
582 return _GLIBCXX20_ONLY(0);
583 #if !_GLIBCXX_USE_CXX11_ABI
584 size_type __removed __attribute__((__unused__)) = 0;
586 list __to_destroy(get_allocator());
587 iterator __next = __first;
588 while (++__next != __last)
590 if (__binary_pred(*__first, *__next))
592 __to_destroy.splice(__to_destroy.begin(), *
this, __next);
593 #if !_GLIBCXX_USE_CXX11_ABI
594 _GLIBCXX20_ONLY( __removed++ );
602 #if !_GLIBCXX_USE_CXX11_ABI
603 return _GLIBCXX20_ONLY( __removed );
605 return _GLIBCXX20_ONLY( __to_destroy.size() );
609 #undef _GLIBCXX20_ONLY
611 template<
typename _Tp,
typename _Alloc>
612 template <
typename _StrictWeakOrdering>
615 sort(_StrictWeakOrdering __comp)
618 if (this->_M_impl._M_node._M_next != &this->_M_impl._M_node
619 && this->_M_impl._M_node._M_next->_M_next != &this->_M_impl._M_node)
623 list * __fill = __tmp;
631 for(__counter = __tmp;
632 __counter != __fill && !__counter->
empty();
635 __counter->
merge(__carry, __comp);
636 __carry.
swap(*__counter);
638 __carry.
swap(*__counter);
639 if (__counter == __fill)
644 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
645 __counter->
merge(*(__counter - 1), __comp);
650 this->splice(this->
end(), __carry);
651 for (
int __i = 0; __i <
sizeof(__tmp)/
sizeof(__tmp[0]); ++__i)
652 this->splice(this->
end(), __tmp[__i]);
653 __throw_exception_again;
658 _GLIBCXX_END_NAMESPACE_CONTAINER
659 _GLIBCXX_END_NAMESPACE_VERSION
void resize(size_type __new_size)
Resizes the list to the specified number of elements.
__remove_return_type remove(const _Tp &__value)
Remove all elements equal to value.
void sort()
Sort the elements.
size_type size() const noexcept
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void merge(list &&__x)
Merge sorted lists.
iterator begin() noexcept
_Tp * begin(valarray< _Tp > &__va)
Return an iterator pointing to the first element of the valarray.
bool empty() const noexcept
_Tp * end(valarray< _Tp > &__va)
Return an iterator pointing to one past the last element of the valarray.
void swap(list &__x) noexcept
Swaps data with another list.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into list before specified iterator.
__remove_return_type remove_if(_Predicate)
Remove all elements satisfying a predicate.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
void splice(const_iterator __position, list &&__x) noexcept
Insert contents of another list.
iterator emplace(const_iterator __position, _Args &&...__args)
Constructs object in list before specified iterator.
__remove_return_type unique()
Remove consecutive duplicate elements.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
list & operator=(const list &__x)
List assignment operator.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.