30#ifndef _FORWARD_LIST_H
31#define _FORWARD_LIST_H 1
34#pragma GCC system_header
45#if __glibcxx_ranges_to_container
50namespace std _GLIBCXX_VISIBILITY(default)
52_GLIBCXX_BEGIN_NAMESPACE_VERSION
53_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 : _M_next(__x._M_next)
65 { __x._M_next =
nullptr; }
73 _M_next = __x._M_next;
74 __x._M_next =
nullptr;
87 __begin->_M_next = __end->_M_next;
88 __end->_M_next = _M_next;
91 __begin->_M_next =
nullptr;
97 _M_reverse_after()
noexcept
106 __tail->_M_next = __temp->_M_next;
107 _M_next->_M_next = __keep;
118 template<
typename _Tp>
124 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
128 {
return _M_storage._M_ptr(); }
131 _M_valptr()
const noexcept
132 {
return _M_storage._M_ptr(); }
140 template<
typename _Tp>
146 typedef _Tp value_type;
147 typedef _Tp* pointer;
148 typedef _Tp& reference;
149 typedef ptrdiff_t difference_type;
161 operator*()
const noexcept
162 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
166 operator->()
const noexcept
167 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
170 operator++()
noexcept
172 _M_node = _M_node->_M_next;
177 operator++(
int)
noexcept
180 _M_node = _M_node->_M_next;
190 {
return __x._M_node == __y._M_node; }
192#if __cpp_impl_three_way_comparison < 201907L
198 operator!=(
const _Self& __x,
const _Self& __y)
noexcept
199 {
return __x._M_node != __y._M_node; }
203 _M_next() const noexcept
206 return _Fwd_list_iterator(_M_node->_M_next);
208 return _Fwd_list_iterator(
nullptr);
211 _Fwd_list_node_base* _M_node;
219 template<
typename _Tp>
226 typedef _Tp value_type;
227 typedef const _Tp* pointer;
228 typedef const _Tp& reference;
229 typedef ptrdiff_t difference_type;
240 : _M_node(__iter._M_node) { }
244 operator*()
const noexcept
245 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
249 operator->()
const noexcept
250 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
253 operator++()
noexcept
255 _M_node = _M_node->_M_next;
260 operator++(
int)
noexcept
263 _M_node = _M_node->_M_next;
273 {
return __x._M_node == __y._M_node; }
275#if __cpp_impl_three_way_comparison < 201907L
281 operator!=(
const _Self& __x,
const _Self& __y)
noexcept
282 {
return __x._M_node != __y._M_node; }
286 _M_next() const noexcept
289 return _Fwd_list_const_iterator(_M_node->_M_next);
291 return _Fwd_list_const_iterator(
nullptr);
294 const _Fwd_list_node_base* _M_node;
300 template<
typename _Tp,
typename _Alloc>
304 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
307 struct _Fwd_list_impl
308 :
public _Node_alloc_type
314 : _Node_alloc_type(), _M_head()
317 _Fwd_list_impl(_Fwd_list_impl&&) =
default;
319 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
323 _Fwd_list_impl(_Node_alloc_type&& __a)
324 : _Node_alloc_type(
std::move(__a)), _M_head()
328 _Fwd_list_impl _M_impl;
336 _M_get_Node_allocator()
noexcept
337 {
return this->_M_impl; }
339 const _Node_alloc_type&
340 _M_get_Node_allocator()
const noexcept
341 {
return this->_M_impl; }
360 { _M_erase_after(&_M_impl._M_head,
nullptr); }
367 return std::__to_address(__ptr);
370 template<
typename... _Args>
372 _M_create_node(_Args&&... __args)
374 _Node* __node = this->_M_get_node();
377 ::new ((
void*)__node) _Node;
378 _Node_alloc_traits::construct(_M_get_Node_allocator(),
380 std::forward<_Args>(__args)...);
384 this->_M_put_node(__node);
385 __throw_exception_again;
390 template<
typename... _Args>
395 _M_put_node(_Node* __p)
397 typedef typename _Node_alloc_traits::pointer _Ptr;
438 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
442 "std::forward_list must have a non-const, non-volatile value_type");
443#if __cplusplus > 201703L || defined __STRICT_ANSI__
445 "std::forward_list must have the same value_type as its allocator");
451 typedef typename _Base::_Node _Node;
452 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
458 typedef _Tp value_type;
459 typedef typename _Alloc_traits::pointer pointer;
460 typedef typename _Alloc_traits::const_pointer const_pointer;
461 typedef value_type& reference;
462 typedef const value_type& const_reference;
464 typedef typename _Base::iterator iterator;
466 typedef std::size_t size_type;
467 typedef std::ptrdiff_t difference_type;
468 typedef _Alloc allocator_type;
483 :
_Base(_Node_alloc_type(__al))
492 const __type_identity_t<_Alloc>& __al)
493 :
_Base(_Node_alloc_type(__al))
494 { _M_range_initialize(__list.
begin(), __list.
end()); }
504 std::__make_move_if_noexcept_iterator(__list.begin()),
505 std::__make_move_if_noexcept_iterator(__list.end()));
521 const __type_identity_t<_Alloc>& __al)
522 noexcept(_Node_alloc_traits::_S_always_equal())
537 :
_Base(_Node_alloc_type(__al))
538 { _M_default_initialize(__n); }
550 const _Alloc& __al = _Alloc())
551 :
_Base(_Node_alloc_type(__al))
552 { _M_fill_initialize(__n, __value); }
564 template<
typename _InputIterator,
565 typename = std::_RequireInputIter<_InputIterator>>
567 const _Alloc& __al = _Alloc())
568 :
_Base(_Node_alloc_type(__al))
569 { _M_range_initialize(__first, __last); }
571#if __glibcxx_ranges_to_container
580 template<__detail::__container_compatible_range<_Tp> _Rg>
581 forward_list(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
582 : _Base(_Node_alloc_type(__a))
584 _Node_base* __to = &this->_M_impl._M_head;
585 auto __first = ranges::begin(__rg);
586 const auto __last = ranges::end(__rg);
587 for (; __first != __last; ++__first)
589 __to->_M_next = this->_M_create_node(*__first);
590 __to = __to->_M_next;
602 __list._M_get_Node_allocator()))
603 { _M_range_initialize(__list.
begin(), __list.
end()); }
625 const _Alloc& __al = _Alloc())
626 :
_Base(_Node_alloc_type(__al))
627 { _M_range_initialize(__il.begin(), __il.end()); }
661 noexcept(_Node_alloc_traits::_S_nothrow_move())
663 constexpr bool __move_storage =
664 _Node_alloc_traits::_S_propagate_on_move_assign()
665 || _Node_alloc_traits::_S_always_equal();
666 _M_move_assign(
std::move(__list), __bool_constant<__move_storage>());
697 template<
typename _InputIterator,
698 typename = std::_RequireInputIter<_InputIterator>>
700 assign(_InputIterator __first, _InputIterator __last)
703 _M_assign(__first, __last, __assignable());
706#if __glibcxx_ranges_to_container
711 template<__detail::__container_compatible_range<_Tp> _Rg>
713 assign_range(_Rg&& __rg)
715 static_assert(assignable_from<_Tp&, ranges::range_reference_t<_Rg>>);
717 auto __first = ranges::begin(__rg);
718 const auto __last = ranges::end(__rg);
723 while (__curr != __end && __first != __last)
734 insert_range_after(__prev,
735 ranges::subrange(
std::move(__first), __last));
763 {
assign(__il.begin(), __il.end()); }
768 {
return allocator_type(this->_M_get_Node_allocator()); }
779 {
return iterator(&this->_M_impl._M_head); }
798 {
return iterator(this->_M_impl._M_head._M_next); }
818 {
return iterator(
nullptr); }
867 {
return this->_M_impl._M_head._M_next ==
nullptr; }
887 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
888 return *__front->_M_valptr();
899 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
900 return *__front->_M_valptr();
916 template<
typename... _Args>
917#if __cplusplus > 201402L
925 std::forward<_Args>(__args)...);
926#if __cplusplus > 201402L
952#if __glibcxx_ranges_to_container
968 template<__detail::__container_compatible_range<_Tp> _Rg>
970 prepend_range(_Rg&& __rg)
993 { this->_M_erase_after(&this->_M_impl._M_head); }
1008 template<
typename... _Args>
1011 {
return iterator(this->_M_insert_after(__pos,
1012 std::forward<_Args>(__args)...)); }
1028 {
return iterator(this->_M_insert_after(__pos, __val)); }
1053 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
1070 template<
typename _InputIterator,
1071 typename = std::_RequireInputIter<_InputIterator>>
1074 _InputIterator __first, _InputIterator __last);
1093 {
return insert_after(__pos, __il.begin(), __il.end()); }
1095#if __glibcxx_ranges_to_container
1111 template<__detail::__container_compatible_range<_Tp> _Rg>
1113 insert_range_after(const_iterator __position, _Rg&& __rg)
1115 forward_list __tmp(from_range, std::forward<_Rg>(__rg),
1117 return _M_splice_after(__position, __tmp.before_begin(), __tmp.end());
1140 {
return iterator(this->_M_erase_after(
const_cast<_Node_base*
>
1141 (__pos._M_node))); }
1163 {
return iterator(this->_M_erase_after(
const_cast<_Node_base*
>
1166 (__last._M_node))); }
1183 std::swap(this->_M_impl._M_head._M_next,
1184 __list._M_impl._M_head._M_next);
1185 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1186 __list._M_get_Node_allocator());
1216 resize(size_type __sz,
const value_type& __val);
1228 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1246 if (!__list.empty())
1247 _M_splice_after(__pos, __list.before_begin(), __list.end());
1266 const_iterator __i)
noexcept;
1270 const_iterator __i)
noexcept
1290 { _M_splice_after(__pos, __before, __last); }
1295 { _M_splice_after(__pos, __before, __last); }
1299#ifdef __glibcxx_list_remove_return_type
1300 using __remove_return_type = size_type;
1301# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
1302 __attribute__((__abi_tag__("__cxx20")))
1304 using __remove_return_type = void;
1305# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1320 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1321 __remove_return_type
1322 remove(
const _Tp& __val);
1335 template<
typename _Pred>
1336 __remove_return_type
1349 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1350 __remove_return_type
1354#undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1368 template<
typename _BinPred>
1369 __remove_return_type
1400 template<
typename _Comp>
1404 template<
typename _Comp>
1425 template<
typename _Comp>
1436 { this->_M_impl._M_head._M_reverse_after(); }
1440 template<
typename _InputIterator>
1442 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1447 _M_fill_initialize(size_type __n,
const value_type& __value);
1451 _M_splice_after(const_iterator __pos, const_iterator __before,
1452 const_iterator __last);
1456 _M_default_initialize(size_type __n);
1460 _M_default_insert_after(const_iterator __pos, size_type __n);
1467 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1468 __list._M_impl._M_head._M_next =
nullptr;
1469 std::__alloc_on_move(this->_M_get_Node_allocator(),
1470 __list._M_get_Node_allocator());
1477 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1482 this->
assign(std::make_move_iterator(__list.begin()),
1483 std::make_move_iterator(__list.end()));
1488 template<
typename _InputIterator>
1490 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1493 auto __curr =
begin();
1495 while (__curr != __end && __first != __last)
1502 if (__first != __last)
1504 else if (__curr != __end)
1510 template<
typename _InputIterator>
1512 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1520 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1523 auto __curr =
begin();
1525 while (__curr != __end && __n > 0)
1534 else if (__curr != __end)
1540 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1547#if __cpp_deduction_guides >= 201606
1548 template<
typename _InputIterator,
typename _ValT
1549 =
typename iterator_traits<_InputIterator>::value_type,
1550 typename _Allocator = allocator<_ValT>,
1551 typename = _RequireInputIter<_InputIterator>,
1552 typename = _RequireAllocator<_Allocator>>
1553 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1554 -> forward_list<_ValT, _Allocator>;
1556#if __glibcxx_ranges_to_container
1557 template<ranges::input_range _Rg,
1558 typename _Allocator = allocator<ranges::range_value_t<_Rg>>>
1559 forward_list(from_range_t, _Rg&&, _Allocator = _Allocator())
1560 -> forward_list<ranges::range_value_t<_Rg>, _Allocator>;
1574 template<
typename _Tp,
typename _Alloc>
1580#if __cpp_lib_three_way_comparison
1592 template<
typename _Tp,
typename _Alloc>
1594 inline __detail::__synth3way_t<_Tp>
1599 __y.begin(), __y.end(),
1600 __detail::__synth3way);
1615 template<
typename _Tp,
typename _Alloc>
1618 operator<(
const forward_list<_Tp, _Alloc>& __lx,
1619 const forward_list<_Tp, _Alloc>& __ly)
1620 {
return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
1621 __ly.cbegin(), __ly.cend()); }
1624 template<
typename _Tp,
typename _Alloc>
1627 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
1628 const forward_list<_Tp, _Alloc>& __ly)
1629 {
return !(__lx == __ly); }
1632 template<
typename _Tp,
typename _Alloc>
1635 operator>(
const forward_list<_Tp, _Alloc>& __lx,
1636 const forward_list<_Tp, _Alloc>& __ly)
1637 {
return (__ly < __lx); }
1640 template<
typename _Tp,
typename _Alloc>
1643 operator>=(
const forward_list<_Tp, _Alloc>& __lx,
1644 const forward_list<_Tp, _Alloc>& __ly)
1645 {
return !(__lx < __ly); }
1648 template<
typename _Tp,
typename _Alloc>
1651 operator<=(
const forward_list<_Tp, _Alloc>& __lx,
1652 const forward_list<_Tp, _Alloc>& __ly)
1653 {
return !(__ly < __lx); }
1657 template<
typename _Tp,
typename _Alloc>
1661 noexcept(
noexcept(__lx.swap(__ly)))
1662 { __lx.swap(__ly); }
1664_GLIBCXX_END_NAMESPACE_CONTAINER
1665_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr auto lexicographical_compare_three_way(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
Performs dictionary comparison on ranges.
ISO C++ entities toplevel namespace is std.
is_nothrow_default_constructible
Uniform interface to all allocator types.
A helper basic node class for forward_list. This is just a linked list with nothing inside it....
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
A forward_list::iterator.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list iterator equality comparison.
A forward_list::const_iterator.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list const_iterator equality comparison.
Base class for forward_list.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
__remove_return_type unique(_BinPred __binary_pred)
Remove consecutive elements satisfying a predicate.
iterator begin() noexcept
const_iterator before_begin() const noexcept
void reverse() noexcept
Reverse the elements in list.
forward_list()=default
Creates a forward_list with no elements.
~forward_list() noexcept
The forward_list dtor.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
void swap(forward_list &__list) noexcept
Swaps data with another forward_list.
const_reference front() const
void merge(forward_list &&__list)
Merge sorted lists.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
void sort()
Sort the elements of the list.
iterator before_begin() noexcept
forward_list(const forward_list &__list, const __type_identity_t< _Alloc > &__al)
Copy constructor with allocator argument.
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.
forward_list(const forward_list &__list)
The forward_list copy constructor.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
__remove_return_type remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
const_iterator begin() const noexcept
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
const_iterator cbefore_begin() const noexcept
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
reference emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
iterator insert_after(const_iterator __pos, std::initializer_list< _Tp > __il)
Inserts the contents of an initializer_list into forward_list after the specified iterator.
const_iterator end() const noexcept
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
forward_list(forward_list &&__list, const __type_identity_t< _Alloc > &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
__remove_return_type unique()
Remove consecutive duplicate elements.
void clear() noexcept
Erases all the elements.
__remove_return_type remove(const _Tp &__val)
Remove all elements equal to value.
const_iterator cend() const noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
bool empty() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
forward_list(forward_list &&)=default
The forward_list move constructor.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
void splice_after(const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
const_iterator cbegin() const noexcept
void pop_front()
Removes first element.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
size_type max_size() const noexcept
Uniform interface to all pointer-like types.
One of the comparison functors.
One of the comparison functors.
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++11 allocators.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.