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_VERSION
47 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
58 : _M_next(__x._M_next)
59 { __x._M_next =
nullptr; }
67 _M_next = __x._M_next;
68 __x._M_next =
nullptr;
81 __begin->_M_next = __end->_M_next;
82 __end->_M_next = _M_next;
85 __begin->_M_next =
nullptr;
91 _M_reverse_after() noexcept
100 __tail->_M_next = __temp->_M_next;
101 _M_next->_M_next = __keep;
112 template<
typename _Tp>
118 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
122 {
return _M_storage._M_ptr(); }
125 _M_valptr()
const noexcept
126 {
return _M_storage._M_ptr(); }
134 template<
typename _Tp>
140 typedef _Tp value_type;
141 typedef _Tp* pointer;
142 typedef _Tp& reference;
143 typedef ptrdiff_t difference_type;
154 operator*()
const noexcept
155 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
158 operator->()
const noexcept
159 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
162 operator++() noexcept
164 _M_node = _M_node->_M_next;
169 operator++(
int) noexcept
172 _M_node = _M_node->_M_next;
181 {
return __x._M_node == __y._M_node; }
189 {
return __x._M_node != __y._M_node; }
192 _M_next() const noexcept
200 _Fwd_list_node_base* _M_node;
208 template<
typename _Tp>
215 typedef _Tp value_type;
216 typedef const _Tp* pointer;
217 typedef const _Tp& reference;
218 typedef ptrdiff_t difference_type;
229 : _M_node(__iter._M_node) { }
232 operator*()
const noexcept
233 {
return *
static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
236 operator->()
const noexcept
237 {
return static_cast<_Node*
>(this->_M_node)->_M_valptr(); }
240 operator++() noexcept
242 _M_node = _M_node->_M_next;
247 operator++(
int) noexcept
250 _M_node = _M_node->_M_next;
259 {
return __x._M_node == __y._M_node; }
266 {
return __x._M_node != __y._M_node; }
269 _M_next() const noexcept
277 const _Fwd_list_node_base* _M_node;
283 template<
typename _Tp,
typename _Alloc>
287 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
290 struct _Fwd_list_impl
291 :
public _Node_alloc_type
297 : _Node_alloc_type(), _M_head()
300 _Fwd_list_impl(_Fwd_list_impl&&) =
default;
302 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
306 _Fwd_list_impl(_Node_alloc_type&& __a)
307 : _Node_alloc_type(
std::move(__a)), _M_head()
311 _Fwd_list_impl _M_impl;
319 _M_get_Node_allocator() noexcept
320 {
return this->_M_impl; }
322 const _Node_alloc_type&
323 _M_get_Node_allocator()
const noexcept
324 {
return this->_M_impl; }
343 { _M_erase_after(&_M_impl._M_head,
nullptr); }
350 return std::__to_address(__ptr);
353 template<
typename... _Args>
355 _M_create_node(_Args&&... __args)
357 _Node* __node = this->_M_get_node();
360 ::new ((
void*)__node)
_Node;
361 _Node_alloc_traits::construct(_M_get_Node_allocator(),
363 std::forward<_Args>(__args)...);
367 this->_M_put_node(__node);
368 __throw_exception_again;
373 template<
typename... _Args>
378 _M_put_node(
_Node* __p)
380 typedef typename _Node_alloc_traits::pointer _Ptr;
419 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
422 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
423 "std::forward_list must have a non-const, non-volatile value_type");
424 #if __cplusplus > 201703L || defined __STRICT_ANSI__
426 "std::forward_list must have the same value_type as its allocator");
433 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
439 typedef _Tp value_type;
442 typedef value_type& reference;
443 typedef const value_type& const_reference;
447 typedef std::size_t size_type;
448 typedef std::ptrdiff_t difference_type;
449 typedef _Alloc allocator_type;
464 :
_Base(_Node_alloc_type(__al))
473 :
_Base(_Node_alloc_type(__al))
474 { _M_range_initialize(__list.
begin(), __list.
end()); }
484 std::__make_move_if_noexcept_iterator(__list.begin()),
485 std::__make_move_if_noexcept_iterator(__list.end()));
501 noexcept(_Node_alloc_traits::_S_always_equal())
516 :
_Base(_Node_alloc_type(__al))
517 { _M_default_initialize(__n); }
529 const _Alloc& __al = _Alloc())
530 :
_Base(_Node_alloc_type(__al))
531 { _M_fill_initialize(__n, __value); }
543 template<
typename _InputIterator,
544 typename = std::_RequireInputIter<_InputIterator>>
546 const _Alloc& __al = _Alloc())
547 :
_Base(_Node_alloc_type(__al))
548 { _M_range_initialize(__first, __last); }
557 __list._M_get_Node_allocator()))
558 { _M_range_initialize(__list.
begin(), __list.
end()); }
580 const _Alloc& __al = _Alloc())
581 :
_Base(_Node_alloc_type(__al))
582 { _M_range_initialize(__il.begin(), __il.end()); }
616 noexcept(_Node_alloc_traits::_S_nothrow_move())
618 constexpr
bool __move_storage =
619 _Node_alloc_traits::_S_propagate_on_move_assign()
620 || _Node_alloc_traits::_S_always_equal();
652 template<
typename _InputIterator,
653 typename = std::_RequireInputIter<_InputIterator>>
655 assign(_InputIterator __first, _InputIterator __last)
658 _M_assign(__first, __last, __assignable());
685 {
assign(__il.begin(), __il.end()); }
690 {
return allocator_type(this->_M_get_Node_allocator()); }
700 {
return iterator(&this->_M_impl._M_head); }
717 {
return iterator(this->_M_impl._M_head._M_next); }
777 _GLIBCXX_NODISCARD
bool
779 {
return this->_M_impl._M_head._M_next ==
nullptr; }
797 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
798 return *__front->_M_valptr();
808 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
809 return *__front->_M_valptr();
825 template<
typename... _Args>
826 #if __cplusplus > 201402L
834 std::forward<_Args>(__args)...);
835 #if __cplusplus > 201402L
875 { this->_M_erase_after(&this->_M_impl._M_head); }
890 template<
typename... _Args>
893 {
return iterator(this->_M_insert_after(__pos,
894 std::forward<_Args>(__args)...)); }
910 {
return iterator(this->_M_insert_after(__pos, __val)); }
935 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
952 template<
typename _InputIterator,
953 typename = std::_RequireInputIter<_InputIterator>>
956 _InputIterator __first, _InputIterator __last);
975 {
return insert_after(__pos, __il.begin(), __il.end()); }
1022 (__last._M_node))); }
1039 std::swap(this->_M_impl._M_head._M_next,
1040 __list._M_impl._M_head._M_next);
1041 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1042 __list._M_get_Node_allocator());
1072 resize(size_type __sz,
const value_type& __val);
1084 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1102 if (!__list.empty())
1103 _M_splice_after(__pos, __list.before_begin(), __list.end());
1122 const_iterator __i) noexcept;
1126 const_iterator __i) noexcept
1146 { _M_splice_after(__pos, __before, __last); }
1151 { _M_splice_after(__pos, __before, __last); }
1155 #if __cplusplus > 201703L
1156 # define __cpp_lib_list_remove_return_type 201806L
1157 using __remove_return_type = size_type;
1158 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG \
1159 __attribute__((__abi_tag__("__cxx20")))
1161 using __remove_return_type = void;
1162 # define _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1177 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1178 __remove_return_type
1179 remove(
const _Tp& __val);
1192 template<
typename _Pred>
1193 __remove_return_type
1206 _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1207 __remove_return_type
1211 #undef _GLIBCXX_FWDLIST_REMOVE_RETURN_TYPE_TAG
1225 template<
typename _BinPred>
1226 __remove_return_type
1227 unique(_BinPred __binary_pred);
1257 template<
typename _Comp>
1261 template<
typename _Comp>
1282 template<
typename _Comp>
1293 { this->_M_impl._M_head._M_reverse_after(); }
1297 template<
typename _InputIterator>
1299 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1304 _M_fill_initialize(size_type __n,
const value_type& __value);
1308 _M_splice_after(const_iterator __pos, const_iterator __before,
1309 const_iterator __last);
1313 _M_default_initialize(size_type __n);
1317 _M_default_insert_after(const_iterator __pos, size_type __n);
1324 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1325 __list._M_impl._M_head._M_next =
nullptr;
1326 std::__alloc_on_move(this->_M_get_Node_allocator(),
1327 __list._M_get_Node_allocator());
1334 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1339 this->
assign(std::make_move_iterator(__list.begin()),
1340 std::make_move_iterator(__list.end()));
1345 template<
typename _InputIterator>
1347 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1350 auto __curr =
begin();
1352 while (__curr != __end && __first != __last)
1359 if (__first != __last)
1361 else if (__curr != __end)
1367 template<
typename _InputIterator>
1369 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1377 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1380 auto __curr =
begin();
1382 while (__curr != __end && __n > 0)
1391 else if (__curr != __end)
1397 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1404 #if __cpp_deduction_guides >= 201606
1405 template<
typename _InputIterator,
typename _ValT
1406 =
typename iterator_traits<_InputIterator>::value_type,
1407 typename _Allocator = allocator<_ValT>,
1408 typename = _RequireInputIter<_InputIterator>,
1409 typename = _RequireAllocator<_Allocator>>
1410 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1411 -> forward_list<_ValT, _Allocator>;
1424 template<
typename _Tp,
typename _Alloc>
1426 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1427 const forward_list<_Tp, _Alloc>& __ly);
1441 template<
typename _Tp,
typename _Alloc>
1449 template<
typename _Tp,
typename _Alloc>
1453 {
return !(__lx == __ly); }
1456 template<
typename _Tp,
typename _Alloc>
1460 {
return (__ly < __lx); }
1463 template<
typename _Tp,
typename _Alloc>
1467 {
return !(__lx < __ly); }
1470 template<
typename _Tp,
typename _Alloc>
1474 {
return !(__ly < __lx); }
1477 template<
typename _Tp,
typename _Alloc>
1481 noexcept(noexcept(__lx.swap(__ly)))
1482 { __lx.swap(__ly); }
1484 _GLIBCXX_END_NAMESPACE_CONTAINER
1485 _GLIBCXX_END_NAMESPACE_VERSION
1488 #endif // _FORWARD_LIST_H