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;
177 operator==(
const _Self& __x)
const noexcept
178 {
return _M_node == __x._M_node; }
181 operator!=(
const _Self& __x)
const noexcept
182 {
return _M_node != __x._M_node; }
185 _M_next()
const noexcept
201 template<
typename _Tp>
208 typedef _Tp value_type;
209 typedef const _Tp* pointer;
210 typedef const _Tp& reference;
211 typedef ptrdiff_t difference_type;
222 : _M_node(__iter._M_node) { }
225 operator*()
const noexcept
226 {
return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
229 operator->()
const noexcept
230 {
return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
233 operator++() noexcept
235 _M_node = _M_node->_M_next;
240 operator++(
int) noexcept
243 _M_node = _M_node->_M_next;
248 operator==(
const _Self& __x)
const noexcept
249 {
return _M_node == __x._M_node; }
252 operator!=(
const _Self& __x)
const noexcept
253 {
return _M_node != __x._M_node; }
256 _M_next()
const noexcept
270 template<
typename _Tp>
274 {
return __x._M_node == __y._M_node; }
279 template<
typename _Tp>
283 {
return __x._M_node != __y._M_node; }
288 template<
typename _Tp,
typename _Alloc>
292 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
295 struct _Fwd_list_impl
296 :
public _Node_alloc_type
302 : _Node_alloc_type(), _M_head()
305 _Fwd_list_impl(_Fwd_list_impl&&) =
default;
307 _Fwd_list_impl(_Fwd_list_impl&& __fl, _Node_alloc_type&& __a)
308 : _Node_alloc_type(std::move(__a)), _M_head(std::move(__fl._M_head))
311 _Fwd_list_impl(_Node_alloc_type&& __a)
312 : _Node_alloc_type(std::move(__a)), _M_head()
316 _Fwd_list_impl _M_impl;
324 _M_get_Node_allocator() noexcept
325 {
return this->_M_impl; }
327 const _Node_alloc_type&
328 _M_get_Node_allocator()
const noexcept
329 {
return this->_M_impl; }
334 : _M_impl(std::move(__a)) { }
339 : _M_impl(std::move(__lst._M_impl), std::move(__a))
348 { _M_erase_after(&_M_impl._M_head,
nullptr); }
355 return std::__to_address(__ptr);
358 template<
typename... _Args>
360 _M_create_node(_Args&&... __args)
362 _Node* __node = this->_M_get_node();
365 ::new ((
void*)__node)
_Node;
366 _Node_alloc_traits::construct(_M_get_Node_allocator(),
368 std::forward<_Args>(__args)...);
372 this->_M_put_node(__node);
373 __throw_exception_again;
378 template<
typename... _Args>
383 _M_put_node(
_Node* __p)
385 typedef typename _Node_alloc_traits::pointer _Ptr;
424 template<
typename _Tp,
typename _Alloc = allocator<_Tp>>
427 static_assert(
is_same<
typename remove_cv<_Tp>::type, _Tp>::value,
428 "std::forward_list must have a non-const, non-volatile value_type");
429 #ifdef __STRICT_ANSI__ 431 "std::forward_list must have the same value_type as its allocator");
438 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
444 typedef _Tp value_type;
447 typedef value_type& reference;
448 typedef const value_type& const_reference;
452 typedef std::size_t size_type;
453 typedef std::ptrdiff_t difference_type;
454 typedef _Alloc allocator_type;
469 :
_Base(_Node_alloc_type(__al))
478 :
_Base(_Node_alloc_type(__al))
479 { _M_range_initialize(__list.
begin(), __list.
end()); }
484 : _Base(
std::move(__list),
std::move(__al))
489 std::__make_move_if_noexcept_iterator(__list.begin()),
490 std::__make_move_if_noexcept_iterator(__list.end()));
496 : _Base(std::move(__list), _Node_alloc_type(__al),
true_type{})
506 noexcept(_Node_alloc_traits::_S_always_equal())
521 :
_Base(_Node_alloc_type(__al))
522 { _M_default_initialize(__n); }
534 const _Alloc& __al = _Alloc())
535 :
_Base(_Node_alloc_type(__al))
536 { _M_fill_initialize(__n, __value); }
548 template<
typename _InputIterator,
549 typename = std::_RequireInputIter<_InputIterator>>
551 const _Alloc& __al = _Alloc())
552 :
_Base(_Node_alloc_type(__al))
553 { _M_range_initialize(__first, __last); }
562 __list._M_get_Node_allocator()))
563 { _M_range_initialize(__list.
begin(), __list.
end()); }
585 const _Alloc& __al = _Alloc())
586 :
_Base(_Node_alloc_type(__al))
587 { _M_range_initialize(__il.begin(), __il.end()); }
621 noexcept(_Node_alloc_traits::_S_nothrow_move())
623 constexpr
bool __move_storage =
624 _Node_alloc_traits::_S_propagate_on_move_assign()
625 || _Node_alloc_traits::_S_always_equal();
657 template<
typename _InputIterator,
658 typename = std::_RequireInputIter<_InputIterator>>
660 assign(_InputIterator __first, _InputIterator __last)
663 _M_assign(__first, __last, __assignable());
690 {
assign(__il.begin(), __il.end()); }
695 {
return allocator_type(this->_M_get_Node_allocator()); }
705 {
return iterator(&this->_M_impl._M_head); }
722 {
return iterator(this->_M_impl._M_head._M_next); }
784 {
return this->_M_impl._M_head._M_next ==
nullptr; }
802 _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
803 return *__front->_M_valptr();
813 _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
814 return *__front->_M_valptr();
830 template<
typename... _Args>
831 #if __cplusplus > 201402L 839 std::forward<_Args>(__args)...);
840 #if __cplusplus > 201402L 864 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
880 { this->_M_erase_after(&this->_M_impl._M_head); }
895 template<
typename... _Args>
898 {
return iterator(this->_M_insert_after(__pos,
899 std::forward<_Args>(__args)...)); }
915 {
return iterator(this->_M_insert_after(__pos, __val)); }
922 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
940 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
957 template<
typename _InputIterator,
958 typename = std::_RequireInputIter<_InputIterator>>
961 _InputIterator __first, _InputIterator __last);
980 {
return insert_after(__pos, __il.begin(), __il.end()); }
1001 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1002 (__pos._M_node))); }
1024 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
1026 const_cast<_Node_base*>
1027 (__last._M_node))); }
1044 std::swap(this->_M_impl._M_head._M_next,
1045 __list._M_impl._M_head._M_next);
1046 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
1047 __list._M_get_Node_allocator());
1077 resize(size_type __sz,
const value_type& __val);
1089 { this->_M_erase_after(&this->_M_impl._M_head,
nullptr); }
1107 if (!__list.empty())
1108 _M_splice_after(__pos, __list.before_begin(), __list.end());
1127 const_iterator __i) noexcept;
1131 const_iterator __i) noexcept
1151 { _M_splice_after(__pos, __before, __last); }
1156 { _M_splice_after(__pos, __before, __last); }
1171 remove(
const _Tp& __val);
1184 template<
typename _Pred>
1214 template<
typename _BinPred>
1216 unique(_BinPred __binary_pred);
1233 {
merge(std::move(__list)); }
1246 template<
typename _Comp>
1250 template<
typename _Comp>
1253 {
merge(std::move(__list), __comp); }
1271 template<
typename _Comp>
1282 { this->_M_impl._M_head._M_reverse_after(); }
1286 template<
typename _InputIterator>
1288 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1293 _M_fill_initialize(size_type __n,
const value_type& __value);
1297 _M_splice_after(const_iterator __pos, const_iterator __before,
1298 const_iterator __last);
1302 _M_default_initialize(size_type __n);
1306 _M_default_insert_after(const_iterator __pos, size_type __n);
1313 this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
1314 __list._M_impl._M_head._M_next =
nullptr;
1315 std::__alloc_on_move(this->_M_get_Node_allocator(),
1316 __list._M_get_Node_allocator());
1323 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1324 _M_move_assign(std::move(__list),
true_type());
1328 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1329 std::__make_move_if_noexcept_iterator(__list.end()));
1334 template<
typename _InputIterator>
1336 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1339 auto __curr =
begin();
1341 while (__curr != __end && __first != __last)
1348 if (__first != __last)
1350 else if (__curr != __end)
1356 template<
typename _InputIterator>
1358 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1366 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1369 auto __curr =
begin();
1371 while (__curr != __end && __n > 0)
1380 else if (__curr != __end)
1386 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1393 #if __cpp_deduction_guides >= 201606 1394 template<
typename _InputIterator,
typename _ValT
1395 =
typename iterator_traits<_InputIterator>::value_type,
1396 typename _Allocator = allocator<_ValT>,
1397 typename = _RequireInputIter<_InputIterator>,
1398 typename = _RequireAllocator<_Allocator>>
1399 forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
1400 -> forward_list<_ValT, _Allocator>;
1413 template<
typename _Tp,
typename _Alloc>
1415 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1416 const forward_list<_Tp, _Alloc>& __ly);
1430 template<
typename _Tp,
typename _Alloc>
1438 template<
typename _Tp,
typename _Alloc>
1442 {
return !(__lx == __ly); }
1445 template<
typename _Tp,
typename _Alloc>
1449 {
return (__ly < __lx); }
1452 template<
typename _Tp,
typename _Alloc>
1456 {
return !(__lx < __ly); }
1459 template<
typename _Tp,
typename _Alloc>
1463 {
return !(__ly < __lx); }
1466 template<
typename _Tp,
typename _Alloc>
1470 noexcept(noexcept(__lx.swap(__ly)))
1471 { __lx.swap(__ly); }
1473 _GLIBCXX_END_NAMESPACE_CONTAINER
1474 _GLIBCXX_END_NAMESPACE_VERSION
1477 #endif // _FORWARD_LIST_H A forward_list::const_iterator.
A helper basic node class for forward_list. This is just a linked list with nothing inside it....
One of the comparison functors.
const_iterator cend() const noexcept
forward_list(const forward_list &__list)
The forward_list copy constructor.
One of the comparison functors.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
void sort()
Sort the elements of the list.
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
forward_list()=default
Creates a forward_list with no elements.
const_reference front() const
A forward_list::iterator.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
Uniform interface to all allocator types.
forward_list(const _Alloc &__al) noexcept
Creates a forward_list with no elements.
const_iterator cbegin() const noexcept
Forward iterators support a superset of input iterator operations.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
void merge(forward_list &&__list)
Merge sorted lists.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
iterator emplace_after(const_iterator __pos, _Args &&... __args)
Constructs object in forward_list after the specified iterator.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
void pop_front()
Removes first element.
const_iterator end() const noexcept
ISO C++ entities toplevel namespace is std.
forward_list(forward_list &&__list, const _Alloc &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
~forward_list() noexcept
The forward_list dtor.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
void splice_after(const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
Insert range from another forward_list.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
void swap(forward_list &__list) noexcept
Swaps data with another forward_list.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
Base class for forward_list.
Uniform interface to all pointer-like types.
void remove(const _Tp &__val)
Remove all elements equal to value.
Uniform interface to C++98 and C++11 allocators.
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.
size_type max_size() const noexcept
void emplace_front(_Args &&... __args)
Constructs object in forward_list at the front of the list.
typename _Ptr< __c_pointer, const value_type >::type const_pointer
The allocator's const pointer type.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
bool empty() const noexcept
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
is_nothrow_default_constructible
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
const_iterator cbefore_begin() const noexcept
iterator before_begin() noexcept
iterator begin() noexcept
void splice_after(const_iterator __pos, forward_list &&__list) noexcept
Insert contents of another forward_list.
const_iterator before_begin() const noexcept
void reverse() noexcept
Reverse the elements in list.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
const_iterator begin() const noexcept
void clear() noexcept
Erases all the elements.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void unique()
Remove consecutive duplicate elements.