30 #ifndef _FORWARD_LIST_H
31 #define _FORWARD_LIST_H 1
33 #pragma GCC system_header
44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
66 __begin->_M_next = __end->_M_next;
67 __end->_M_next = _M_next;
76 _M_reverse_after() noexcept
85 __tail->_M_next = __temp->_M_next;
86 _M_next->_M_next = __keep;
97 template<
typename _Tp>
103 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
107 {
return _M_storage._M_ptr(); }
110 _M_valptr()
const noexcept
111 {
return _M_storage._M_ptr(); }
119 template<
typename _Tp>
125 typedef _Tp value_type;
126 typedef _Tp* pointer;
127 typedef _Tp& reference;
128 typedef ptrdiff_t difference_type;
140 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
144 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
149 _M_node = _M_node->_M_next;
157 _M_node = _M_node->_M_next;
162 operator==(
const _Self& __x)
const
163 {
return _M_node == __x._M_node; }
166 operator!=(
const _Self& __x)
const
167 {
return _M_node != __x._M_node; }
186 template<
typename _Tp>
193 typedef _Tp value_type;
194 typedef const _Tp* pointer;
195 typedef const _Tp& reference;
196 typedef ptrdiff_t difference_type;
207 : _M_node(__iter._M_node) { }
211 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
215 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
220 _M_node = _M_node->_M_next;
228 _M_node = _M_node->_M_next;
233 operator==(
const _Self& __x)
const
234 {
return _M_node == __x._M_node; }
237 operator!=(
const _Self& __x)
const
238 {
return _M_node != __x._M_node; }
255 template<
typename _Tp>
259 {
return __x._M_node == __y._M_node; }
264 template<
typename _Tp>
268 {
return __x._M_node != __y._M_node; }
273 template<
typename _Tp,
typename _Alloc>
278 typedef typename _Alloc_traits::template rebind<_Tp>::other
281 typedef typename _Alloc_traits::template
282 rebind<_Fwd_list_node<_Tp>>::other _Node_alloc_type;
286 struct _Fwd_list_impl
287 :
public _Node_alloc_type
292 : _Node_alloc_type(), _M_head()
295 _Fwd_list_impl(
const _Node_alloc_type& __a)
296 : _Node_alloc_type(__a), _M_head()
299 _Fwd_list_impl(_Node_alloc_type&& __a)
300 : _Node_alloc_type(std::move(__a)), _M_head()
304 _Fwd_list_impl _M_impl;
312 _M_get_Node_allocator() noexcept
313 {
return *
static_cast<_Node_alloc_type*
>(&this->_M_impl); }
315 const _Node_alloc_type&
316 _M_get_Node_allocator()
const noexcept
317 {
return *
static_cast<const _Node_alloc_type*
>(&this->_M_impl); }
328 : _M_impl(std::move(__lst._M_get_Node_allocator()))
330 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
331 __lst._M_impl._M_head._M_next = 0;
335 { _M_erase_after(&_M_impl._M_head, 0); }
346 template<
typename... _Args>
348 _M_create_node(_Args&&... __args)
350 _Node* __node = this->_M_get_node();
353 _Tp_alloc_type __a(_M_get_Node_allocator());
355 ::new ((
void*)__node)
_Node();
356 _Alloc_traits::construct(__a, __node->_M_valptr(),
357 std::forward<_Args>(__args)...);
361 this->_M_put_node(__node);
362 __throw_exception_again;
367 template<
typename... _Args>
372 _M_put_node(
_Node* __p)
374 typedef typename _Node_alloc_traits::pointer _Ptr;
413 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
420 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
421 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
427 typedef _Tp value_type;
428 typedef typename _Alloc_traits::pointer pointer;
429 typedef typename _Alloc_traits::const_pointer const_pointer;
430 typedef value_type& reference;
431 typedef const value_type& const_reference;
435 typedef std::size_t size_type;
436 typedef std::ptrdiff_t difference_type;
437 typedef _Alloc allocator_type;
447 :
_Base(_Node_alloc_type(__al))
456 :
_Base(_Node_alloc_type(__al))
457 { _M_range_initialize(__list.
begin(), __list.
end()); }
465 noexcept(_Node_alloc_traits::_S_always_equal())
466 :
_Base(std::move(__list), _Node_alloc_type(__al))
478 :
_Base(_Node_alloc_type(__al))
479 { _M_default_initialize(__n); }
491 const _Alloc& __al = _Alloc())
492 :
_Base(_Node_alloc_type(__al))
493 { _M_fill_initialize(__n, __value); }
505 template<
typename _InputIterator,
506 typename = std::_RequireInputIter<_InputIterator>>
508 const _Alloc& __al = _Alloc())
509 :
_Base(_Node_alloc_type(__al))
510 { _M_range_initialize(__first, __last); }
519 __list._M_get_Node_allocator()))
520 { _M_range_initialize(__list.
begin(), __list.
end()); }
532 :
_Base(std::move(__list)) { }
543 const _Alloc& __al = _Alloc())
544 :
_Base(_Node_alloc_type(__al))
545 { _M_range_initialize(__il.begin(), __il.end()); }
577 constexpr
bool __move_storage =
578 _Node_alloc_traits::_S_propagate_on_move_assign()
579 || _Node_alloc_traits::_S_always_equal();
580 _M_move_assign(std::move(__list),
612 template<
typename _InputIterator,
613 typename = std::_RequireInputIter<_InputIterator>>
615 assign(_InputIterator __first, _InputIterator __last)
617 typedef is_assignable<_Tp, decltype(*__first)> __assignable;
618 _M_assign(__first, __last, __assignable());
633 { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
645 {
assign(__il.begin(), __il.end()); }
650 {
return allocator_type(this->_M_get_Node_allocator()); }
660 {
return iterator(&this->_M_impl._M_head); }
677 {
return iterator(this->_M_impl._M_head._M_next); }
739 {
return this->_M_impl._M_head._M_next == 0; }
757 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
758 return *__front->_M_valptr();
768 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
769 return *__front->_M_valptr();
785 template<
typename... _Args>
789 std::forward<_Args>(__args)...); }
810 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
826 { this->_M_erase_after(&this->_M_impl._M_head); }
841 template<
typename... _Args>
844 {
return iterator(this->_M_insert_after(__pos,
845 std::forward<_Args>(__args)...)); }
861 {
return iterator(this->_M_insert_after(__pos, __val)); }
868 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
886 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
903 template<
typename _InputIterator,
904 typename = std::_RequireInputIter<_InputIterator>>
907 _InputIterator __first, _InputIterator __last);
926 {
return insert_after(__pos, __il.begin(), __il.end()); }
947 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
970 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
972 const_cast<_Node_base*>
973 (__last._M_node))); }
987 noexcept(_Node_alloc_traits::_S_nothrow_swap())
989 std::swap(this->_M_impl._M_head._M_next,
990 __list._M_impl._M_head._M_next);
991 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
992 __list._M_get_Node_allocator());
1022 resize(size_type __sz,
const value_type& __val);
1034 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1052 if (!__list.empty())
1053 _M_splice_after(__pos, __list.before_begin(), __list.end());
1072 const_iterator __i);
1095 { _M_splice_after(__pos, __before, __last); }
1099 const_iterator __before, const_iterator __last)
1100 { _M_splice_after(__pos, __before, __last); }
1114 remove(
const _Tp& __val);
1127 template<
typename _Pred>
1157 template<
typename _BinPred>
1159 unique(_BinPred __binary_pred);
1176 {
merge(std::move(__list)); }
1189 template<
typename _Comp>
1193 template<
typename _Comp>
1196 {
merge(std::move(__list), __comp); }
1214 template<
typename _Comp>
1225 { this->_M_impl._M_head._M_reverse_after(); }
1229 template<
typename _InputIterator>
1231 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1236 _M_fill_initialize(size_type __n,
const value_type& __value);
1240 _M_splice_after(const_iterator __pos, const_iterator __before,
1241 const_iterator __last);
1245 _M_default_initialize(size_type __n);
1249 _M_default_insert_after(const_iterator __pos, size_type __n);
1256 std::swap(this->_M_impl._M_head._M_next,
1257 __list._M_impl._M_head._M_next);
1258 std::__alloc_on_move(this->_M_get_Node_allocator(),
1259 __list._M_get_Node_allocator());
1266 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1271 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1272 std::__make_move_if_noexcept_iterator(__list.end()));
1277 template<
typename _InputIterator>
1279 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1282 auto __curr =
begin();
1284 while (__curr != __end && __first != __last)
1291 if (__first != __last)
1293 else if (__curr != __end)
1299 template<
typename _InputIterator>
1301 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1309 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1312 auto __curr =
begin();
1314 while (__curr != __end && __n > 0)
1323 else if (__curr != __end)
1329 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1346 template<
typename _Tp,
typename _Alloc>
1348 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1349 const forward_list<_Tp, _Alloc>& __ly);
1363 template<
typename _Tp,
typename _Alloc>
1365 operator<(const forward_list<_Tp, _Alloc>& __lx,
1368 __ly.cbegin(), __ly.cend()); }
1371 template<
typename _Tp,
typename _Alloc>
1375 {
return !(__lx == __ly); }
1378 template<
typename _Tp,
typename _Alloc>
1382 {
return (__ly < __lx); }
1385 template<
typename _Tp,
typename _Alloc>
1389 {
return !(__lx < __ly); }
1392 template<
typename _Tp,
typename _Alloc>
1394 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1396 {
return !(__ly < __lx); }
1399 template<
typename _Tp,
typename _Alloc>
1403 { __lx.
swap(__ly); }
1405 _GLIBCXX_END_NAMESPACE_CONTAINER
1408 #endif // _FORWARD_LIST_H