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)
303 : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
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; }
329 : _M_impl(std::move(__a)) { }
334 : _M_impl(std::move(__lst._M_impl), std::move(__a))
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 #ifdef __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()); }
479 : _Base(
std::move(__list),
std::move(__al))
484 std::__make_move_if_noexcept_iterator(__list.begin()),
485 std::__make_move_if_noexcept_iterator(__list.end()));
491 : _Base(std::move(__list), _Node_alloc_type(__al),
true_type{})
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 859 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
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)); }
917 {
return iterator(this->_M_insert_after(__pos, std::move(__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()); }
996 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1019 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1021 const_cast<_Node_base*>
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);
1244 {
merge(std::move(__list)); }
1257 template<
typename _Comp>
1261 template<
typename _Comp>
1264 {
merge(std::move(__list), __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())
1335 _M_move_assign(std::move(__list),
true_type());
1339 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1340 std::__make_move_if_noexcept_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>
1443 operator<(const forward_list<_Tp, _Alloc>& __lx,
1446 __ly.cbegin(), __ly.cend()); }
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>
1472 operator<=(const forward_list<_Tp, _Alloc>& __lx,
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 forward_list()=default
Creates a forward_list with no elements.
friend bool operator!=(const _Self &__x, const _Self &__y) noexcept
Forward list iterator inequality comparison.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
const_iterator cbefore_begin() const noexcept
static _GLIBCXX_NODISCARD pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
ISO C++ entities toplevel namespace is std.
const_iterator begin() const noexcept
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
Forward iterators support a superset of input iterator operations.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
forward_list(const forward_list &__list)
The forward_list copy constructor.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
forward_list(forward_list &&__list, const _Alloc &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
void pop_front()
Removes first element.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
void reverse() noexcept
Reverse the elements in list.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
void emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
void splice_after(const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
const_iterator cend() const noexcept
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
is_nothrow_default_constructible
friend bool operator!=(const _Self &__x, const _Self &__y) noexcept
Forward list const_iterator inequality comparison.
_GLIBCXX_NODISCARD bool empty() const noexcept
const_reference front() const
iterator before_begin() noexcept
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
__remove_return_type remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
~forward_list() noexcept
The forward_list dtor.
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
Uniform interface to all allocator types.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Base class for forward_list.
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.
Uniform interface to all pointer-like types.
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list const_iterator equality comparison.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
iterator begin() noexcept
void clear() noexcept
Erases all the elements.
void merge(forward_list &&__list)
Merge sorted lists.
Uniform interface to C++98 and C++11 allocators.
const_iterator before_begin() const noexcept
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
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.
__remove_return_type unique()
Remove consecutive duplicate elements.
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...
const_iterator cbegin() const noexcept
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
One of the comparison functors.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
size_type max_size() const noexcept
One of the comparison functors.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
const_iterator end() const noexcept
friend bool operator==(const _Self &__x, const _Self &__y) noexcept
Forward list iterator equality comparison.
A forward_list::iterator.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
void sort()
Sort the elements of the list.