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;
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(),
375 std::forward<_Args>(__args)...);
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>>
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()); }
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())
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)
673 typedef is_assignable<_Tp&, decltype(*__first)> __assignable;
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
865 std::forward<_Args>(__args)...);
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,
925 std::forward<_Args>(__args)...)); }
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());
1153 const_iterator __i) noexcept;
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 // 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
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)
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>
1457 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1458 const forward_list<_Tp, _Alloc>& __ly);
1460 #if __cpp_lib_three_way_comparison
1472 template<
typename _Tp,
typename _Alloc>
1474 inline __detail::__synth3way_t<_Tp>
1475 operator<=>(
const forward_list<_Tp, _Alloc>& __x,
1476 const forward_list<_Tp, _Alloc>& __y)
1478 return std::lexicographical_compare_three_way(__x.begin(), __x.end(),
1479 __y.begin(), __y.end(),
1480 __detail::__synth3way);
1495 template<
typename _Tp,
typename _Alloc>
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>
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