30#ifndef _FORWARD_LIST_H
31#define _FORWARD_LIST_H 1
33#pragma GCC system_header
45namespace std _GLIBCXX_VISIBILITY(default)
47_GLIBCXX_BEGIN_NAMESPACE_VERSION
48_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
59 : _M_next(__x._M_next)
60 { __x._M_next =
nullptr; }
68 _M_next = __x._M_next;
69 __x._M_next =
nullptr;
82 __begin->_M_next = __end->_M_next;
83 __end->_M_next = _M_next;
86 __begin->_M_next =
nullptr;
92 _M_reverse_after()
noexcept
101 __tail->_M_next = __temp->_M_next;
102 _M_next->_M_next = __keep;
113 template<
typename _Tp>
119 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
123 {
return _M_storage._M_ptr(); }
126 _M_valptr()
const noexcept
127 {
return _M_storage._M_ptr(); }
135 template<
typename _Tp>
141 typedef _Tp value_type;
142 typedef _Tp* pointer;
143 typedef _Tp& reference;
144 typedef ptrdiff_t difference_type;
156 operator*()
const noexcept
157 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
161 operator->()
const noexcept
162 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
165 operator++()
noexcept
167 _M_node = _M_node->_M_next;
172 operator++(
int)
noexcept
175 _M_node = _M_node->_M_next;
185 {
return __x._M_node == __y._M_node; }
187#if __cpp_impl_three_way_comparison < 201907L
193 operator!=(
const _Self& __x,
const _Self& __y)
noexcept
194 {
return __x._M_node != __y._M_node; }
198 _M_next() const noexcept
201 return _Fwd_list_iterator(_M_node->_M_next);
203 return _Fwd_list_iterator(
nullptr);
206 _Fwd_list_node_base* _M_node;
214 template<
typename _Tp>
221 typedef _Tp value_type;
222 typedef const _Tp* pointer;
223 typedef const _Tp& reference;
224 typedef ptrdiff_t difference_type;
235 : _M_node(__iter._M_node) { }
239 operator*()
const noexcept
240 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
244 operator->()
const noexcept
245 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
248 operator++()
noexcept
250 _M_node = _M_node->_M_next;
255 operator++(
int)
noexcept
258 _M_node = _M_node->_M_next;
268 {
return __x._M_node == __y._M_node; }
270#if __cpp_impl_three_way_comparison < 201907L
276 operator!=(
const _Self& __x,
const _Self& __y)
noexcept
277 {
return __x._M_node != __y._M_node; }
281 _M_next() const noexcept
284 return _Fwd_list_const_iterator(_M_node->_M_next);
286 return _Fwd_list_const_iterator(
nullptr);
289 const _Fwd_list_node_base* _M_node;
295 template<
typename _Tp,
typename _Alloc>
299 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
302 struct _Fwd_list_impl
303 :
public _Node_alloc_type
309 : _Node_alloc_type(), _M_head()
312 _Fwd_list_impl(_Fwd_list_impl&&) =
default;
314 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
318 _Fwd_list_impl(_Node_alloc_type&& __a)
319 : _Node_alloc_type(
std::move(__a)), _M_head()
323 _Fwd_list_impl _M_impl;
331 _M_get_Node_allocator()
noexcept
332 {
return this->_M_impl; }
334 const _Node_alloc_type&
335 _M_get_Node_allocator()
const noexcept
336 {
return this->_M_impl; }
355 { _M_erase_after(&_M_impl._M_head,
nullptr); }
362 return std::__to_address(__ptr);
365 template<
typename... _Args>
367 _M_create_node(_Args&&... __args)
369 _Node* __node = this->_M_get_node();
372 ::new ((
void*)__node)
_Node;
373 _Node_alloc_traits::construct(_M_get_Node_allocator(),
379 this->_M_put_node(__node);
380 __throw_exception_again;
385 template<
typename... _Args>
390 _M_put_node(
_Node* __p)
392 typedef typename _Node_alloc_traits::pointer _Ptr;
433 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
437 "std::forward_list must have a non-const, non-volatile value_type");
438#if __cplusplus > 201703L || defined __STRICT_ANSI__
440 "std::forward_list must have the same value_type as its allocator");
447 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
453 typedef _Tp value_type;
456 typedef value_type& reference;
457 typedef const value_type& const_reference;
461 typedef std::size_t size_type;
462 typedef std::ptrdiff_t difference_type;
463 typedef _Alloc allocator_type;
478 :
_Base(_Node_alloc_type(__al))
487 const __type_identity_t<_Alloc>& __al)
488 :
_Base(_Node_alloc_type(__al))
489 { _M_range_initialize(__list.
begin(), __list.
end()); }
499 std::__make_move_if_noexcept_iterator(__list.begin()),
500 std::__make_move_if_noexcept_iterator(__list.end()));
503 forward_list(forward_list&& __list, _Node_alloc_type&& __al,
506 : _Base(
std::move(__list), _Node_alloc_type(__al), true_type{})
516 const __type_identity_t<_Alloc>& __al)
517 noexcept(_Node_alloc_traits::_S_always_equal())
532 :
_Base(_Node_alloc_type(__al))
533 { _M_default_initialize(__n); }
545 const _Alloc& __al = _Alloc())
546 :
_Base(_Node_alloc_type(__al))
547 { _M_fill_initialize(__n, __value); }
559 template<
typename _InputIterator,
560 typename = std::_RequireInputIter<_InputIterator>>
562 const _Alloc& __al = _Alloc())
563 :
_Base(_Node_alloc_type(__al))
564 { _M_range_initialize(__first, __last); }
573 __list._M_get_Node_allocator()))
574 { _M_range_initialize(__list.
begin(), __list.
end()); }
596 const _Alloc& __al = _Alloc())
597 :
_Base(_Node_alloc_type(__al))
598 { _M_range_initialize(__il.begin(), __il.end()); }
632 noexcept(_Node_alloc_traits::_S_nothrow_move())
634 constexpr bool __move_storage =
635 _Node_alloc_traits::_S_propagate_on_move_assign()
636 || _Node_alloc_traits::_S_always_equal();
637 _M_move_assign(
std::move(__list), __bool_constant<__move_storage>());
668 template<
typename _InputIterator,
669 typename = std::_RequireInputIter<_InputIterator>>
671 assign(_InputIterator __first, _InputIterator __last)
674 _M_assign(__first, __last, __assignable());
701 {
assign(__il.begin(), __il.end()); }
706 {
return allocator_type(this->_M_get_Node_allocator()); }
717 {
return iterator(&this->_M_impl._M_head); }
736 {
return iterator(this->_M_impl._M_head._M_next); }
805 {
return this->_M_impl._M_head._M_next ==
nullptr; }
825 __glibcxx_requires_nonempty();
826 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
827 return *__front->_M_valptr();
838 __glibcxx_requires_nonempty();
839 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
840 return *__front->_M_valptr();
856 template<
typename... _Args>
857#if __cplusplus > 201402L
866#if __cplusplus > 201402L
906 { this->_M_erase_after(&this->_M_impl._M_head); }
921 template<
typename... _Args>
924 {
return iterator(this->_M_insert_after(__pos,
941 {
return iterator(this->_M_insert_after(__pos, __val)); }
966 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
983 template<
typename _InputIterator,
984 typename = std::_RequireInputIter<_InputIterator>>
987 _InputIterator __first, _InputIterator __last);
1006 {
return insert_after(__pos, __il.begin(), __il.end()); }
1028 (__pos._M_node))); }
1053 (__last._M_node))); }
1070 std::swap(this->_M_impl._M_head._M_next,
1071 __list._M_impl._M_head._M_next);
1072 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1073 __list._M_get_Node_allocator());
1103 resize(size_type __sz,
const value_type& __val);
1115 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1133 if (!__list.empty())
1134 _M_splice_after(__pos, __list.before_begin(), __list.end());
1152 splice_after(const_iterator __pos, forward_list&& __list,
1153 const_iterator __i)
noexcept;
1156 splice_after(const_iterator __pos, forward_list& __list,
1157 const_iterator __i)
noexcept
1177 { _M_splice_after(__pos, __before, __last); }
1182 { _M_splice_after(__pos, __before, __last); }
1186#ifdef __glibcxx_list_remove_return_type
1187 using __remove_return_type = size_type;
1188# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
1189 __attribute__((__abi_tag__("__cxx20")))
1191 using __remove_return_type = void;
1192# define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1207 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1208 __remove_return_type
1209 remove(
const _Tp& __val);
1222 template<
typename _Pred>
1223 __remove_return_type
1236 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1237 __remove_return_type
1241#undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1255 template<
typename _BinPred>
1256 __remove_return_type
1287 template<
typename _Comp>
1289 merge(forward_list&& __list, _Comp __comp);
1291 template<
typename _Comp>
1293 merge(forward_list& __list, _Comp __comp)
1312 template<
typename _Comp>
1323 { this->_M_impl._M_head._M_reverse_after(); }
1327 template<
typename _InputIterator>
1329 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1334 _M_fill_initialize(size_type __n,
const value_type& __value);
1338 _M_splice_after(const_iterator __pos, const_iterator __before,
1339 const_iterator __last);
1343 _M_default_initialize(size_type __n);
1347 _M_default_insert_after(const_iterator __pos, size_type __n);
1354 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1355 __list._M_impl._M_head._M_next =
nullptr;
1356 std::__alloc_on_move(this->_M_get_Node_allocator(),
1357 __list._M_get_Node_allocator());
1362 _M_move_assign(forward_list&& __list, false_type)
1364 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1369 this->
assign(std::make_move_iterator(__list.begin()),
1370 std::make_move_iterator(__list.end()));
1375 template<
typename _InputIterator>
1377 _M_assign(_InputIterator __first, _InputIterator __last, true_type)
1380 auto __curr =
begin();
1382 while (__curr != __end && __first != __last)
1389 if (__first != __last)
1391 else if (__curr != __end)
1397 template<
typename _InputIterator>
1399 _M_assign(_InputIterator __first, _InputIterator __last, false_type)
1407 _M_assign_n(size_type __n,
const _Tp& __val, true_type)
1410 auto __curr =
begin();
1412 while (__curr != __end && __n > 0)
1421 else if (__curr != __end)
1427 _M_assign_n(size_type __n,
const _Tp& __val, false_type)
1434#if __cpp_deduction_guides >= 201606
1435 template<
typename _InputIterator,
typename _ValT
1436 =
typename iterator_traits<_InputIterator>::value_type,
1437 typename _Allocator = allocator<_ValT>,
1438 typename = _RequireInputIter<_InputIterator>,
1439 typename = _RequireAllocator<_Allocator>>
1440 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1441 -> forward_list<_ValT, _Allocator>;
1454 template<
typename _Tp,
typename _Alloc>
1460#if __cpp_lib_three_way_comparison
1472 template<
typename _Tp,
typename _Alloc>
1474 inline __detail::__synth3way_t<_Tp>
1479 __y.begin(), __y.end(),
1480 __detail::__synth3way);
1495 template<
typename _Tp,
typename _Alloc>
1498 operator<(
const forward_list<_Tp, _Alloc>& __lx,
1499 const forward_list<_Tp, _Alloc>& __ly)
1500 {
return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
1501 __ly.cbegin(), __ly.cend()); }
1504 template<
typename _Tp,
typename _Alloc>
1507 operator!=(
const forward_list<_Tp, _Alloc>& __lx,
1508 const forward_list<_Tp, _Alloc>& __ly)
1509 {
return !(__lx == __ly); }
1512 template<
typename _Tp,
typename _Alloc>
1515 operator>(
const forward_list<_Tp, _Alloc>& __lx,
1516 const forward_list<_Tp, _Alloc>& __ly)
1517 {
return (__ly < __lx); }
1520 template<
typename _Tp,
typename _Alloc>
1523 operator>=(
const forward_list<_Tp, _Alloc>& __lx,
1524 const forward_list<_Tp, _Alloc>& __ly)
1525 {
return !(__lx < __ly); }
1528 template<
typename _Tp,
typename _Alloc>
1531 operator<=(
const forward_list<_Tp, _Alloc>& __lx,
1532 const forward_list<_Tp, _Alloc>& __ly)
1533 {
return !(__ly < __lx); }
1537 template<
typename _Tp,
typename _Alloc>
1541 noexcept(
noexcept(__lx.swap(__ly)))
1542 { __lx.swap(__ly); }
1544_GLIBCXX_END_NAMESPACE_CONTAINER
1545_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 _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
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.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
static constexpr pointer allocate(_Alloc &__a, size_type __n)
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
static constexpr size_type max_size(const _Alloc &__a) noexcept
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.