30 #ifndef _FORWARD_LIST_H 31 #define _FORWARD_LIST_H 1 33 #pragma GCC system_header 45 namespace 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;
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
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) { }
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
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); }
361 auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
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(),
375 std::forward<_Args>(__args)...);
379 this->_M_put_node(__node);
380 __throw_exception_again;
385 template<
typename... _Args>
387 _M_insert_after(const_iterator __pos, _Args&&... __args);
390 _M_put_node(_Node* __p)
392 typedef typename _Node_alloc_traits::pointer _Ptr;
394 _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
433 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
436 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
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()); }
498 insert_after(cbefore_begin(),
499 std::__make_move_if_noexcept_iterator(__list.begin()),
500 std::__make_move_if_noexcept_iterator(__list.end()));
516 const __type_identity_t<_Alloc>& __al)
517 noexcept(_Node_alloc_traits::_S_always_equal())
519 typename _Node_alloc_traits::is_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); }
572 : _Base(_Node_alloc_traits::_S_select_on_copy(
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); }
727 {
return const_iterator(&this->_M_impl._M_head); }
736 {
return iterator(this->_M_impl._M_head._M_next); }
746 {
return const_iterator(this->_M_impl._M_head._M_next); }
756 {
return iterator(
nullptr); }
766 {
return const_iterator(
nullptr); }
776 {
return const_iterator(this->_M_impl._M_head._M_next); }
786 {
return const_iterator(&this->_M_impl._M_head); }
796 {
return const_iterator(
nullptr); }
805 {
return this->_M_impl._M_head._M_next ==
nullptr; }
813 {
return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
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 864 this->_M_insert_after(cbefore_begin(),
865 std::forward<_Args>(__args)...);
866 #if __cplusplus > 201402L 883 { this->_M_insert_after(cbefore_begin(), __val); }
889 push_front(_Tp&& __val)
890 { this->_M_insert_after(cbefore_begin(),
std::move(__val)); }
906 { this->_M_erase_after(&this->_M_impl._M_head); }
921 template<
typename... _Args>
924 {
return iterator(this->_M_insert_after(__pos,
925 std::forward<_Args>(__args)...)); }
941 {
return iterator(this->_M_insert_after(__pos, __val)); }
947 insert_after(const_iterator __pos, _Tp&& __val)
948 {
return iterator(this->_M_insert_after(__pos,
std::move(__val))); }
966 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
983 template<
typename _InputIterator,
984 typename = std::_RequireInputIter<_InputIterator>>
986 insert_after(const_iterator __pos,
987 _InputIterator __first, _InputIterator __last);
1006 {
return insert_after(__pos, __il.begin(), __il.end()); }
1027 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1028 (__pos._M_node))); }
1050 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1052 const_cast<_Node_base*>
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());
1088 resize(size_type __sz);
1103 resize(size_type __sz,
const value_type& __val);
1115 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1133 if (!__list.
empty())
1138 splice_after(const_iterator __pos,
forward_list& __list) noexcept
1139 { splice_after(__pos,
std::move(__list)); }
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
1158 { splice_after(__pos,
std::move(__list), __i); }
1176 const_iterator __before, const_iterator __last) noexcept
1177 { _M_splice_after(__pos, __before, __last); }
1181 const_iterator __before, const_iterator __last) noexcept
1182 { _M_splice_after(__pos, __before, __last); }
1186 #ifdef __glibcxx_list_remove_return_type // C++20 && HOSTED 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
1224 remove_if(_Pred __pred);
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
1257 unique(_BinPred __binary_pred);
1287 template<
typename _Comp>
1291 template<
typename _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());
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)
1379 auto __prev = before_begin();
1380 auto __curr =
begin();
1382 while (__curr != __end && __first != __last)
1389 if (__first != __last)
1390 insert_after(__prev, __first, __last);
1391 else if (__curr != __end)
1392 erase_after(__prev, __end);
1397 template<
typename _InputIterator>
1399 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1402 insert_after(cbefore_begin(), __first, __last);
1407 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1409 auto __prev = before_begin();
1410 auto __curr =
begin();
1412 while (__curr != __end && __n > 0)
1420 insert_after(__prev, __n, __val);
1421 else if (__curr != __end)
1422 erase_after(__prev, __end);
1427 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1430 insert_after(cbefore_begin(), __n, __val);
1434 #if __cpp_deduction_guides >= 201606 1435 template<
typename _InputIterator,
typename _ValT
1438 typename = _RequireInputIter<_InputIterator>,
1439 typename = _RequireAllocator<_Allocator>>
1440 forward_list(_InputIterator, _InputIterator, _Allocator = _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>
1480 __detail::__synth3way);
1495 template<
typename _Tp,
typename _Alloc>
1498 operator<(const forward_list<_Tp, _Alloc>& __lx,
1504 template<
typename _Tp,
typename _Alloc>
1509 {
return !(__lx == __ly); }
1512 template<
typename _Tp,
typename _Alloc>
1517 {
return (__ly < __lx); }
1520 template<
typename _Tp,
typename _Alloc>
1525 {
return !(__lx < __ly); }
1528 template<
typename _Tp,
typename _Alloc>
1531 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1533 {
return !(__ly < __lx); }
1534 #endif // three-way comparison 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
1548 #endif // _FORWARD_LIST_H Forward iterators support a superset of input iterator operations.
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.
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...
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Base class for forward_list.
Uniform interface to all pointer-like types.
forward_list(const forward_list &__list, const __type_identity_t< _Alloc > &__al)
Copy constructor with allocator argument.
iterator before_begin() noexcept
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
The standard allocator, as per C++03 [20.4.1].
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list const_iterator equality comparison.
const_iterator cbefore_begin() const noexcept
is_nothrow_default_constructible
void merge(forward_list &&__list)
Merge sorted lists.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
const_iterator cbegin() const noexcept
ISO C++ entities toplevel namespace is std.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
~forward_list() noexcept
The forward_list dtor.
size_type max_size() const noexcept
void swap(forward_list &__list) noexcept
Swaps data with another forward_list.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
A forward_list::const_iterator.
Traits class for iterators.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
forward_list(forward_list &&__list, const __type_identity_t< _Alloc > &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
const_iterator end() const noexcept
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
Uniform interface to all allocator types.
void clear() noexcept
Erases all the elements.
forward_list(const forward_list &__list)
The forward_list copy constructor.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
A forward_list::iterator.
void reverse() noexcept
Reverse the elements in list.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list iterator equality comparison.
void pop_front()
Removes first element.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
const_iterator before_begin() const noexcept
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
reference emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
bool empty() const noexcept
One of the comparison functors.
void sort()
Sort the elements of the list.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
const_iterator begin() const noexcept
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
__remove_return_type unique()
Remove consecutive duplicate elements.
const_reference front() const
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
One of the comparison functors.
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.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
const_iterator cend() const noexcept
iterator begin() noexcept
Uniform interface to C++98 and C++11 allocators.