59namespace std _GLIBCXX_VISIBILITY(default)
61_GLIBCXX_BEGIN_NAMESPACE_VERSION
62_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<
typename _Tp,
typename _Alloc>
69 typedef typename _Node_traits::_Node _Node;
70 typedef typename _Node_traits::_Node_base _Node_base;
71 typename _Node_base::_Base_ptr __cur = _M_impl._M_node._M_next;
72 while (__cur != _M_impl._M_node._M_base())
74 _Node& __tmp =
static_cast<_Node&
>(*__cur);
75 __cur = __tmp._M_next;
76 this->_M_destroy_node(__tmp._M_node_ptr());
80#if __cplusplus >= 201103L
81 template<
typename _Tp,
typename _Alloc>
82 template<
typename... _Args>
83 typename list<_Tp, _Alloc>::iterator
85 emplace(const_iterator __position, _Args&&... __args)
88 __tmp->_M_hook(__position._M_const_cast()._M_node);
90 return iterator(__tmp->_M_base());
94 template<
typename _Tp,
typename _Alloc>
95 typename list<_Tp, _Alloc>::iterator
97#if __cplusplus >= 201103L
98 insert(const_iterator __position,
const value_type& __x)
100 insert(iterator __position,
const value_type& __x)
104 __tmp->_M_hook(__position._M_const_cast()._M_node);
105 this->_M_inc_size(1);
106 return iterator(__tmp->_M_base());
109#if __cplusplus >= 201103L
110 template<
typename _Tp,
typename _Alloc>
111 typename list<_Tp, _Alloc>::iterator
113 insert(const_iterator __position, size_type __n,
const value_type& __x)
118 iterator __it = __tmp.
begin();
119 splice(__position, __tmp);
122 return __position._M_const_cast();
125 template<
typename _Tp,
typename _Alloc>
126 template<
typename _InputIterator,
typename>
127 typename list<_Tp, _Alloc>::iterator
129 insert(const_iterator __position, _InputIterator __first,
130 _InputIterator __last)
135 iterator __it = __tmp.
begin();
136 splice(__position, __tmp);
139 return __position._M_const_cast();
143 template<
typename _Tp,
typename _Alloc>
144 typename list<_Tp, _Alloc>::iterator
146#if __cplusplus >= 201103L
147 erase(const_iterator __position)
noexcept
149 erase(iterator __position)
152 iterator __ret = iterator(__position._M_node->_M_next);
153 _M_erase(__position._M_const_cast());
168 template<
typename _Tp,
typename _Alloc>
169 typename list<_Tp, _Alloc>::const_iterator
174#if _GLIBCXX_USE_CXX11_ABI
176 if (__new_size < __len)
178 if (__new_size <= __len / 2)
186 ptrdiff_t __num_erase = __len - __new_size;
196 for (__i =
begin(); __i !=
end() && __len < __new_size; ++__i, ++__len)
203#if __cplusplus >= 201103L
204 template<
typename _Tp,
typename _Alloc>
212 for (; __i < __n; ++__i)
219 __throw_exception_again;
223 template<
typename _Tp,
typename _Alloc>
226 resize(size_type __new_size)
228 const_iterator __i = _M_resize_pos(__new_size);
230 _M_default_append(__new_size);
235 template<
typename _Tp,
typename _Alloc>
238 resize(size_type __new_size,
const value_type& __x)
240 const_iterator __i = _M_resize_pos(__new_size);
247 template<
typename _Tp,
typename _Alloc>
252 const_iterator __i = _M_resize_pos(__new_size);
254 insert(
end(), __new_size, __x);
256 erase(__i._M_const_cast(),
end());
260 template<
typename _Tp,
typename _Alloc>
267#if __cplusplus >= 201103L
268 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
270 auto& __this_alloc = this->_M_get_Node_allocator();
271 auto& __that_alloc = __x._M_get_Node_allocator();
272 if (!_Node_alloc_traits::_S_always_equal()
273 && __this_alloc != __that_alloc)
278 std::__alloc_on_copy(__this_alloc, __that_alloc);
281 _M_assign_dispatch(__x.
begin(), __x.
end(), __false_type());
286 template<
typename _Tp,
typename _Alloc>
292 for (; __i !=
end() && __n > 0; ++__i, --__n)
295 insert(
end(), __n, __val);
300 template<
typename _Tp,
typename _Alloc>
301 template <
typename _InputIterator>
304 _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
307 iterator __first1 =
begin();
308 iterator __last1 =
end();
309 for (; __first1 != __last1 && __first2 != __last2;
310 ++__first1, (void)++__first2)
311 *__first1 = *__first2;
312 if (__first2 == __last2)
313 erase(__first1, __last1);
315 insert(__last1, __first2, __last2);
318#if __cplusplus > 201703L
319# define _GLIBCXX20_ONLY(__expr) __expr
321# define _GLIBCXX20_ONLY(__expr)
324 template<
typename _Tp,
typename _Alloc>
325 typename list<_Tp, _Alloc>::__remove_return_type
327 remove(
const value_type& __value)
329#if !_GLIBCXX_USE_CXX11_ABI
330 size_type __removed __attribute__((__unused__)) = 0;
333 iterator __first =
begin();
334 iterator __last =
end();
335 while (__first != __last)
337 iterator __next = __first;
339 if (*__first == __value)
344 __to_destroy.
splice(__to_destroy.
begin(), *
this, __first);
345#if !_GLIBCXX_USE_CXX11_ABI
346 _GLIBCXX20_ONLY( __removed++ );
353#if !_GLIBCXX_USE_CXX11_ABI
354 return _GLIBCXX20_ONLY( __removed );
356 return _GLIBCXX20_ONLY( __to_destroy.
size() );
360 template<
typename _Tp,
typename _Alloc>
361 typename list<_Tp, _Alloc>::__remove_return_type
365 iterator __first =
begin();
366 iterator __last =
end();
367 if (__first == __last)
368 return _GLIBCXX20_ONLY( 0 );
369#if !_GLIBCXX_USE_CXX11_ABI
370 size_type __removed __attribute__((__unused__)) = 0;
373 iterator __next = __first;
374 while (++__next != __last)
376 if (*__first == *__next)
378 __to_destroy.
splice(__to_destroy.
begin(), *
this, __next);
379#if !_GLIBCXX_USE_CXX11_ABI
380 _GLIBCXX20_ONLY( __removed++ );
388#if !_GLIBCXX_USE_CXX11_ABI
389 return _GLIBCXX20_ONLY( __removed );
391 return _GLIBCXX20_ONLY( __to_destroy.
size() );
395 template<
typename _Tp,
typename _Alloc>
398#if __cplusplus >= 201103L
408 _M_check_equal_allocators(__x);
410 iterator __first1 =
begin();
411 iterator __last1 =
end();
412 iterator __first2 = __x.
begin();
413 iterator __last2 = __x.
end();
415 const _Finalize_merge __fin(*
this, __x, __first2);
417 while (__first1 != __last1 && __first2 != __last2)
418 if (*__first2 < *__first1)
420 iterator __next = __first2;
421 _M_transfer(__first1, __first2, ++__next);
426 if (__first2 != __last2)
428 _M_transfer(__last1, __first2, __last2);
434 template<
typename _Tp,
typename _Alloc>
435 template <
typename _StrictWeakOrdering>
438#if __cplusplus >= 201103L
439 merge(
list&& __x, _StrictWeakOrdering __comp)
441 merge(
list& __x, _StrictWeakOrdering __comp)
448 _M_check_equal_allocators(__x);
450 iterator __first1 =
begin();
451 iterator __last1 =
end();
452 iterator __first2 = __x.
begin();
453 iterator __last2 = __x.
end();
455 const _Finalize_merge __fin(*
this, __x, __first2);
457 while (__first1 != __last1 && __first2 != __last2)
458 if (__comp(*__first2, *__first1))
460 iterator __next = __first2;
461 _M_transfer(__first1, __first2, ++__next);
466 if (__first2 != __last2)
468 _M_transfer(__last1, __first2, __last2);
474 template<
typename _Tp,
typename _Alloc>
484 typedef __list::_Scratch_list<typename _Node_traits::_Node_base>
495 _Scratch_list __carry;
496 _Scratch_list __tmp[64];
497 _Scratch_list* __fill = __tmp;
498 _Scratch_list* __counter;
500 typename _Scratch_list::template _Ptr_cmp<iterator, void> __ptr_comp;
506 __carry._M_take_one(
begin()._M_node);
508 for(__counter = __tmp;
509 __counter != __fill && !__counter->empty();
513 __counter->merge(__carry, __ptr_comp);
514 __carry.swap(*__counter);
516 __carry.swap(*__counter);
517 if (__counter == __fill)
522 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
523 __counter->merge(__counter[-1], __ptr_comp);
524 __fill[-1].swap(this->_M_impl._M_node);
529 __carry._M_put_all(
end()._M_node);
530 for (
int __i = 0; __i <
sizeof(__tmp)/
sizeof(__tmp[0]); ++__i)
531 __tmp[__i]._M_put_all(
end()._M_node);
532 __throw_exception_again;
537 template<
typename _Tp,
typename _Alloc>
538 template <
typename _Predicate>
539 typename list<_Tp, _Alloc>::__remove_return_type
543#if !_GLIBCXX_USE_CXX11_ABI
544 size_type __removed __attribute__((__unused__)) = 0;
547 iterator __first =
begin();
548 iterator __last =
end();
549 while (__first != __last)
551 iterator __next = __first;
553 if (__pred(*__first))
555 __to_destroy.
splice(__to_destroy.
begin(), *
this, __first);
556#if !_GLIBCXX_USE_CXX11_ABI
557 _GLIBCXX20_ONLY( __removed++ );
563#if !_GLIBCXX_USE_CXX11_ABI
564 return _GLIBCXX20_ONLY( __removed );
566 return _GLIBCXX20_ONLY( __to_destroy.
size() );
570 template<
typename _Tp,
typename _Alloc>
571 template <
typename _BinaryPredicate>
572 typename list<_Tp, _Alloc>::__remove_return_type
574 unique(_BinaryPredicate __binary_pred)
576 iterator __first =
begin();
577 iterator __last =
end();
578 if (__first == __last)
579 return _GLIBCXX20_ONLY(0);
580#if !_GLIBCXX_USE_CXX11_ABI
581 size_type __removed __attribute__((__unused__)) = 0;
584 iterator __next = __first;
585 while (++__next != __last)
587 if (__binary_pred(*__first, *__next))
589 __to_destroy.
splice(__to_destroy.
begin(), *
this, __next);
590#if !_GLIBCXX_USE_CXX11_ABI
591 _GLIBCXX20_ONLY( __removed++ );
599#if !_GLIBCXX_USE_CXX11_ABI
600 return _GLIBCXX20_ONLY( __removed );
602 return _GLIBCXX20_ONLY( __to_destroy.
size() );
606#undef _GLIBCXX20_ONLY
608 template<
typename _Tp,
typename _Alloc>
609 template <
typename _StrictWeakOrdering>
612 sort(_StrictWeakOrdering __comp)
619 typedef __list::_Scratch_list<typename _Node_traits::_Node_base>
622 _Scratch_list __carry;
623 _Scratch_list __tmp[64];
624 _Scratch_list* __fill = __tmp;
625 _Scratch_list* __counter;
627 typename _Scratch_list::
628 template _Ptr_cmp<iterator, _StrictWeakOrdering> __ptr_comp
635 __carry._M_take_one(
begin()._M_node);
637 for(__counter = __tmp;
638 __counter != __fill && !__counter->empty();
642 __counter->merge(__carry, __ptr_comp);
643 __carry.swap(*__counter);
645 __carry.swap(*__counter);
646 if (__counter == __fill)
651 for (__counter = __tmp + 1; __counter != __fill; ++__counter)
652 __counter->merge(__counter[-1], __ptr_comp);
653 __fill[-1].swap(this->_M_impl._M_node);
658 __carry._M_put_all(
end()._M_node);
659 for (
size_t __i = 0; __i <
sizeof(__tmp)/
sizeof(__tmp[0]); ++__i)
660 __tmp[__i]._M_put_all(
end()._M_node);
661 __throw_exception_again;
666_GLIBCXX_END_NAMESPACE_CONTAINER
667_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
ISO C++ entities toplevel namespace is std.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr void advance(_InputIterator &__i, _Distance __n)
A generalization of pointer arithmetic.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void resize(size_type __new_size)
Resizes the list to the specified number of elements.
iterator insert(const_iterator __position, const value_type &__x)
Inserts given value into list before specified iterator.
void sort()
Sort the elements.
iterator begin() noexcept
iterator emplace(const_iterator __position, _Args &&... __args)
Constructs object in list before specified iterator.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
list & operator=(const list &__x)
List assignment operator.
__remove_return_type unique()
Remove consecutive duplicate elements.
size_type size() const noexcept
void merge(list &&__x)
Merge sorted lists.
_Node_ptr _M_create_node(_Args &&... __args)
__remove_return_type remove(const _Tp &__value)
Remove all elements equal to value.
list()=default
Creates a list with no elements.
__remove_return_type remove_if(_Predicate)
Remove all elements satisfying a predicate.
void splice(const_iterator __position, list &&__x) noexcept
Insert contents of another list.
iterator erase(const_iterator __position) noexcept
Remove element at given position.
bool empty() const noexcept
See bits/stl_deque.h's _Deque_base for an explanation.