30 #ifndef _FORWARD_LIST_H
31 #define _FORWARD_LIST_H 1
33 #pragma GCC system_header
38 namespace std _GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
57 while (__end && __end->_M_next)
58 __end = __end->_M_next;
59 return _M_transfer_after(__begin, __end);
69 __begin->_M_next = __end->_M_next;
70 __end->_M_next = _M_next;
88 __tail->_M_next = __temp->_M_next;
89 _M_next->_M_next = __keep;
99 template<
typename _Tp>
103 template<
typename... _Args>
106 _M_value(std::forward<_Args>(__args)...) { }
116 template<
typename _Tp>
122 typedef _Tp value_type;
123 typedef _Tp* pointer;
124 typedef _Tp& reference;
125 typedef ptrdiff_t difference_type;
137 {
return static_cast<_Node*
>(this->_M_node)->_M_value; }
141 {
return std::__addressof(static_cast<_Node*>
142 (this->_M_node)->_M_value); }
147 _M_node = _M_node->_M_next;
155 _M_node = _M_node->_M_next;
160 operator==(
const _Self& __x)
const
161 {
return _M_node == __x._M_node; }
164 operator!=(
const _Self& __x)
const
165 {
return _M_node != __x._M_node; }
184 template<
typename _Tp>
191 typedef _Tp value_type;
192 typedef const _Tp* pointer;
193 typedef const _Tp& reference;
194 typedef ptrdiff_t difference_type;
205 : _M_node(__iter._M_node) { }
209 {
return static_cast<_Node*
>(this->_M_node)->_M_value; }
213 {
return std::__addressof(static_cast<_Node*>
214 (this->_M_node)->_M_value); }
219 _M_node = _M_node->_M_next;
227 _M_node = _M_node->_M_next;
232 operator==(
const _Self& __x)
const
233 {
return _M_node == __x._M_node; }
236 operator!=(
const _Self& __x)
const
237 {
return _M_node != __x._M_node; }
254 template<
typename _Tp>
258 {
return __x._M_node == __y._M_node; }
263 template<
typename _Tp>
267 {
return __x._M_node != __y._M_node; }
272 template<
typename _Tp,
typename _Alloc>
276 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
278 typedef typename _Alloc::template
279 rebind<_Fwd_list_node<_Tp>>::other _Node_alloc_type;
281 struct _Fwd_list_impl
282 :
public _Node_alloc_type
287 : _Node_alloc_type(), _M_head()
290 _Fwd_list_impl(
const _Node_alloc_type& __a)
291 : _Node_alloc_type(__a), _M_head()
295 _Fwd_list_impl _M_impl;
303 _M_get_Node_allocator()
304 {
return *
static_cast<_Node_alloc_type*
>(&this->_M_impl); }
306 const _Node_alloc_type&
307 _M_get_Node_allocator()
const
308 {
return *
static_cast<const _Node_alloc_type*
>(&this->_M_impl); }
321 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
322 __lst._M_impl._M_head._M_next = 0;
326 : _M_impl(__lst._M_get_Node_allocator())
328 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
329 __lst._M_impl._M_head._M_next = 0;
333 { _M_erase_after(&_M_impl._M_head, 0); }
339 {
return _M_get_Node_allocator().allocate(1); }
341 template<
typename... _Args>
343 _M_create_node(_Args&&... __args)
345 _Node* __node = this->_M_get_node();
348 _M_get_Node_allocator().construct(__node,
349 std::forward<_Args>(__args)...);
354 this->_M_put_node(__node);
355 __throw_exception_again;
360 template<
typename... _Args>
365 _M_put_node(
_Node* __p)
366 { _M_get_Node_allocator().deallocate(__p, 1); }
407 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
414 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
418 typedef _Tp value_type;
419 typedef typename _Tp_alloc_type::pointer pointer;
420 typedef typename _Tp_alloc_type::const_pointer const_pointer;
421 typedef typename _Tp_alloc_type::reference reference;
422 typedef typename _Tp_alloc_type::const_reference const_reference;
426 typedef std::size_t size_type;
427 typedef std::ptrdiff_t difference_type;
428 typedef _Alloc allocator_type;
447 :
_Base(__list, __al)
456 :
_Base(std::move(__list), __al)
469 { _M_default_initialize(__n); }
481 const _Alloc& __al = _Alloc())
483 { _M_fill_initialize(__n, __value); }
495 template<
typename _InputIterator>
497 const _Alloc& __al = _Alloc())
501 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
502 _M_initialize_dispatch(__first, __last, _Integral());
514 :
_Base(__list._M_get_Node_allocator())
515 { _M_initialize_dispatch(__list.
begin(), __list.
end(), __false_type()); }
527 :
_Base(std::move(__list)) { }
538 const _Alloc& __al = _Alloc())
540 { _M_initialize_dispatch(__il.begin(), __il.end(), __false_type()); }
605 template<
typename _InputIterator>
607 assign(_InputIterator __first, _InputIterator __last)
648 {
return this->_M_get_Node_allocator(); }
658 {
return iterator(&this->_M_impl._M_head); }
675 {
return iterator(this->_M_impl._M_head._M_next); }
737 {
return this->_M_impl._M_head._M_next == 0; }
744 {
return this->_M_get_Node_allocator().max_size(); }
755 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
756 return __front->_M_value;
766 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
767 return __front->_M_value;
783 template<
typename... _Args>
787 std::forward<_Args>(__args)...); }
808 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
824 { this->_M_erase_after(&this->_M_impl._M_head); }
839 template<
typename... _Args>
842 {
return iterator(this->_M_insert_after(__pos,
843 std::forward<_Args>(__args)...)); }
859 {
return iterator(this->_M_insert_after(__pos, __val)); }
866 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
884 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
901 template<
typename _InputIterator>
904 _InputIterator __first, _InputIterator __last);
943 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
966 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
968 const_cast<_Node_base*>
969 (__last._M_node))); }
983 { std::swap(this->_M_impl._M_head._M_next,
984 __list._M_impl._M_head._M_next); }
1013 resize(size_type __sz,
const value_type& __val);
1025 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1043 if (!__list.empty())
1044 _M_splice_after(__pos, std::move(__list));
1063 if (__pos == __i || __pos == __j)
1084 const_iterator __before, const_iterator __last);
1098 remove(
const _Tp& __val);
1111 template<
typename _Pred>
1141 template<
typename _BinPred>
1143 unique(_BinPred __binary_pred);
1169 template<
typename _Comp>
1189 template<
typename _Comp>
1200 { this->_M_impl._M_head._M_reverse_after(); }
1203 template<
typename _Integer>
1205 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1206 { _M_fill_initialize(static_cast<size_type>(__n), __x); }
1209 template<
typename _InputIterator>
1211 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1217 _M_fill_initialize(size_type __n,
const value_type& __value);
1221 _M_splice_after(const_iterator __pos,
forward_list&& __list);
1225 _M_default_initialize(size_type __n);
1229 _M_default_insert_after(const_iterator __pos, size_type __n);
1242 template<
typename _Tp,
typename _Alloc>
1244 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1245 const forward_list<_Tp, _Alloc>& __ly);
1258 template<
typename _Tp,
typename _Alloc>
1260 operator<(const forward_list<_Tp, _Alloc>& __lx,
1263 __ly.cbegin(), __ly.cend()); }
1266 template<
typename _Tp,
typename _Alloc>
1270 {
return !(__lx == __ly); }
1273 template<
typename _Tp,
typename _Alloc>
1277 {
return (__ly < __lx); }
1280 template<
typename _Tp,
typename _Alloc>
1284 {
return !(__lx < __ly); }
1287 template<
typename _Tp,
typename _Alloc>
1289 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1291 {
return !(__ly < __lx); }
1294 template<
typename _Tp,
typename _Alloc>
1298 { __lx.
swap(__ly); }
1300 _GLIBCXX_END_NAMESPACE_CONTAINER
1303 #endif // _FORWARD_LIST_H
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
forward_list(forward_list &&__list)
The forward_list move constructor.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
A forward_list::iterator.
const_iterator begin() const
forward_list(size_type __n)
Creates a forward_list with default constructed elements.
const_iterator before_begin() const
void swap(forward_list &__list)
Swaps data with another forward_list.
void splice_after(const_iterator __pos, forward_list &&__list, const_iterator __i)
Insert element from another forward_list.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
void merge(forward_list &&__list)
Merge sorted lists.
void unique()
Remove consecutive duplicate elements.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
Forward iterators support a superset of input iterator operations.
void clear()
Erases all the elements.
One of the comparison functors.
forward_list(forward_list &&__list, const _Alloc &__al)
Move constructor with allocator argument.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
iterator emplace_after(const_iterator __pos, _Args &&...__args)
Constructs object in forward_list after the specified iterator.
forward_list(const forward_list &__list)
The forward_list copy constructor.
void sort()
Sort the elements of the list.
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
const_iterator cend() const
void emplace_front(_Args &&...__args)
Constructs object in forward_list at the front of the list.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
const_iterator end() const
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
A forward_list::const_iterator.
forward_list & operator=(forward_list &&__list)
The forward_list move assignment operator.
const_iterator cbegin() const
const_reference front() const
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 pop_front()
Removes first element.
allocator_type get_allocator() const
Get a copy of the memory allocation object.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
One of the comparison functors.
const_iterator cbefore_begin() const
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
A helper node class for forward_list. This is just a linked list with a data value in each node...
void reverse()
Reverse the elements in list.
forward_list(const _Alloc &__al=_Alloc())
Creates a forward_list with no elements.
Base class for forward_list.
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
~forward_list()
The forward_list dtor.
size_type max_size() const