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;
139 operator*()
const noexcept
140 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
143 operator->()
const noexcept
144 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
147 operator++() noexcept
149 _M_node = _M_node->_M_next;
154 operator++(
int) noexcept
157 _M_node = _M_node->_M_next;
162 operator==(
const _Self& __x)
const noexcept
163 {
return _M_node == __x._M_node; }
166 operator!=(
const _Self& __x)
const noexcept
167 {
return _M_node != __x._M_node; }
170 _M_next()
const noexcept
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) { }
210 operator*()
const noexcept
211 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
214 operator->()
const noexcept
215 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
218 operator++() noexcept
220 _M_node = _M_node->_M_next;
225 operator++(
int) noexcept
228 _M_node = _M_node->_M_next;
233 operator==(
const _Self& __x)
const noexcept
234 {
return _M_node == __x._M_node; }
237 operator!=(
const _Self& __x)
const noexcept
238 {
return _M_node != __x._M_node; }
241 _M_next()
const noexcept
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>
277 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
280 struct _Fwd_list_impl
281 :
public _Node_alloc_type
286 : _Node_alloc_type(), _M_head()
289 _Fwd_list_impl(
const _Node_alloc_type& __a)
290 : _Node_alloc_type(__a), _M_head()
293 _Fwd_list_impl(_Node_alloc_type&& __a)
294 : _Node_alloc_type(std::move(__a)), _M_head()
298 _Fwd_list_impl _M_impl;
306 _M_get_Node_allocator() noexcept
307 {
return this->_M_impl; }
309 const _Node_alloc_type&
310 _M_get_Node_allocator()
const noexcept
311 {
return this->_M_impl; }
317 : _M_impl(std::move(__a)) { }
322 : _M_impl(std::move(__lst._M_get_Node_allocator()))
324 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
325 __lst._M_impl._M_head._M_next = 0;
329 { _M_erase_after(&_M_impl._M_head, 0); }
340 template<
typename... _Args>
342 _M_create_node(_Args&&... __args)
344 _Node* __node = this->_M_get_node();
347 ::new ((
void*)__node)
_Node;
348 _Node_alloc_traits::construct(_M_get_Node_allocator(),
350 std::forward<_Args>(__args)...);
354 this->_M_put_node(__node);
355 __throw_exception_again;
360 template<
typename... _Args>
365 _M_put_node(
_Node* __p)
367 typedef typename _Node_alloc_traits::pointer _Ptr;
406 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
413 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
419 typedef _Tp value_type;
422 typedef value_type& reference;
423 typedef const value_type& const_reference;
427 typedef std::size_t size_type;
428 typedef std::ptrdiff_t difference_type;
429 typedef _Alloc allocator_type;
437 noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
447 :
_Base(_Node_alloc_type(__al))
457 :
_Base(_Node_alloc_type(__al))
458 { _M_range_initialize(__list.
begin(), __list.
end()); }
466 noexcept(_Node_alloc_traits::_S_always_equal())
467 :
_Base(
std::move(__list), _Node_alloc_type(__al))
472 std::__make_move_if_noexcept_iterator(__list.begin()),
473 std::__make_move_if_noexcept_iterator(__list.end()));
486 :
_Base(_Node_alloc_type(__al))
487 { _M_default_initialize(__n); }
499 const _Alloc& __al = _Alloc())
500 :
_Base(_Node_alloc_type(__al))
501 { _M_fill_initialize(__n, __value); }
513 template<
typename _InputIterator,
514 typename = std::_RequireInputIter<_InputIterator>>
516 const _Alloc& __al = _Alloc())
517 :
_Base(_Node_alloc_type(__al))
518 { _M_range_initialize(__first, __last); }
527 __list._M_get_Node_allocator()))
528 { _M_range_initialize(__list.
begin(), __list.
end()); }
540 :
_Base(std::move(__list)) { }
551 const _Alloc& __al = _Alloc())
552 :
_Base(_Node_alloc_type(__al))
553 { _M_range_initialize(__il.begin(), __il.end()); }
587 noexcept(_Node_alloc_traits::_S_nothrow_move())
589 constexpr
bool __move_storage =
590 _Node_alloc_traits::_S_propagate_on_move_assign()
591 || _Node_alloc_traits::_S_always_equal();
623 template<
typename _InputIterator,
624 typename = std::_RequireInputIter<_InputIterator>>
626 assign(_InputIterator __first, _InputIterator __last)
628 typedef is_assignable<_Tp, decltype(*__first)> __assignable;
629 _M_assign(__first, __last, __assignable());
644 { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
656 {
assign(__il.begin(), __il.end()); }
661 {
return allocator_type(this->_M_get_Node_allocator()); }
671 {
return iterator(&this->_M_impl._M_head); }
688 {
return iterator(this->_M_impl._M_head._M_next); }
750 {
return this->_M_impl._M_head._M_next == 0; }
768 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
769 return *__front->_M_valptr();
779 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
780 return *__front->_M_valptr();
796 template<
typename... _Args>
797 #if __cplusplus > 201402L
805 std::forward<_Args>(__args)...);
806 #if __cplusplus > 201402L
830 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
846 { this->_M_erase_after(&this->_M_impl._M_head); }
861 template<
typename... _Args>
864 {
return iterator(this->_M_insert_after(__pos,
865 std::forward<_Args>(__args)...)); }
881 {
return iterator(this->_M_insert_after(__pos, __val)); }
888 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
906 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
923 template<
typename _InputIterator,
924 typename = std::_RequireInputIter<_InputIterator>>
927 _InputIterator __first, _InputIterator __last);
946 {
return insert_after(__pos, __il.begin(), __il.end()); }
993 (__last._M_node))); }
1010 std::swap(this->_M_impl._M_head._M_next,
1011 __list._M_impl._M_head._M_next);
1012 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1013 __list._M_get_Node_allocator());
1043 resize(size_type __sz,
const value_type& __val);
1055 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1073 if (!__list.empty())
1074 _M_splice_after(__pos, __list.before_begin(), __list.end());
1093 const_iterator __i) noexcept;
1097 const_iterator __i) noexcept
1117 { _M_splice_after(__pos, __before, __last); }
1122 { _M_splice_after(__pos, __before, __last); }
1137 remove(
const _Tp& __val);
1150 template<
typename _Pred>
1180 template<
typename _BinPred>
1182 unique(_BinPred __binary_pred);
1199 {
merge(std::move(__list)); }
1212 template<
typename _Comp>
1216 template<
typename _Comp>
1219 {
merge(std::move(__list), __comp); }
1237 template<
typename _Comp>
1248 { this->_M_impl._M_head._M_reverse_after(); }
1252 template<
typename _InputIterator>
1254 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1259 _M_fill_initialize(size_type __n,
const value_type& __value);
1263 _M_splice_after(const_iterator __pos, const_iterator __before,
1264 const_iterator __last);
1268 _M_default_initialize(size_type __n);
1272 _M_default_insert_after(const_iterator __pos, size_type __n);
1279 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1280 __list._M_impl._M_head._M_next =
nullptr;
1281 std::__alloc_on_move(this->_M_get_Node_allocator(),
1282 __list._M_get_Node_allocator());
1289 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1294 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1295 std::__make_move_if_noexcept_iterator(__list.end()));
1300 template<
typename _InputIterator>
1302 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1305 auto __curr =
begin();
1307 while (__curr != __end && __first != __last)
1314 if (__first != __last)
1316 else if (__curr != __end)
1322 template<
typename _InputIterator>
1324 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1332 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1335 auto __curr =
begin();
1337 while (__curr != __end && __n > 0)
1346 else if (__curr != __end)
1352 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1369 template<
typename _Tp,
typename _Alloc>
1371 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1372 const forward_list<_Tp, _Alloc>& __ly);
1386 template<
typename _Tp,
typename _Alloc>
1394 template<
typename _Tp,
typename _Alloc>
1398 {
return !(__lx == __ly); }
1401 template<
typename _Tp,
typename _Alloc>
1405 {
return (__ly < __lx); }
1408 template<
typename _Tp,
typename _Alloc>
1412 {
return !(__lx < __ly); }
1415 template<
typename _Tp,
typename _Alloc>
1419 {
return !(__ly < __lx); }
1422 template<
typename _Tp,
typename _Alloc>
1426 noexcept(noexcept(__lx.swap(__ly)))
1427 { __lx.swap(__ly); }
1429 _GLIBCXX_END_NAMESPACE_CONTAINER
1432 #endif // _FORWARD_LIST_H