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>
278 typedef typename _Alloc_traits::template rebind<_Tp>::other
281 typedef typename _Alloc_traits::template
282 rebind<_Fwd_list_node<_Tp>>::other _Node_alloc_type;
286 struct _Fwd_list_impl
287 :
public _Node_alloc_type
292 : _Node_alloc_type(), _M_head()
295 _Fwd_list_impl(
const _Node_alloc_type& __a)
296 : _Node_alloc_type(__a), _M_head()
299 _Fwd_list_impl(_Node_alloc_type&& __a)
300 : _Node_alloc_type(std::move(__a)), _M_head()
304 _Fwd_list_impl _M_impl;
312 _M_get_Node_allocator() noexcept
313 {
return *
static_cast<_Node_alloc_type*
>(&this->_M_impl); }
315 const _Node_alloc_type&
316 _M_get_Node_allocator()
const noexcept
317 {
return *
static_cast<const _Node_alloc_type*
>(&this->_M_impl); }
328 : _M_impl(std::move(__lst._M_get_Node_allocator()))
330 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
331 __lst._M_impl._M_head._M_next = 0;
335 { _M_erase_after(&_M_impl._M_head, 0); }
346 template<
typename... _Args>
348 _M_create_node(_Args&&... __args)
350 _Node* __node = this->_M_get_node();
353 _Tp_alloc_type __a(_M_get_Node_allocator());
355 ::new ((
void*)__node)
_Node;
356 _Alloc_traits::construct(__a, __node->_M_valptr(),
357 std::forward<_Args>(__args)...);
361 this->_M_put_node(__node);
362 __throw_exception_again;
367 template<
typename... _Args>
372 _M_put_node(
_Node* __p)
374 typedef typename _Node_alloc_traits::pointer _Ptr;
413 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
420 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
421 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
427 typedef _Tp value_type;
428 typedef typename _Alloc_traits::pointer pointer;
429 typedef typename _Alloc_traits::const_pointer const_pointer;
430 typedef value_type& reference;
431 typedef const value_type& const_reference;
435 typedef std::size_t size_type;
436 typedef std::ptrdiff_t difference_type;
437 typedef _Alloc allocator_type;
447 :
_Base(_Node_alloc_type(__al))
456 :
_Base(_Node_alloc_type(__al))
457 { _M_range_initialize(__list.
begin(), __list.end()); }
465 noexcept(_Node_alloc_traits::_S_always_equal())
466 :
_Base(std::move(__list), _Node_alloc_type(__al))
477 forward_list(size_type __n,
const _Alloc& __al = _Alloc())
478 : _Base(_Node_alloc_type(__al))
479 { _M_default_initialize(__n); }
491 const _Alloc& __al = _Alloc())
492 :
_Base(_Node_alloc_type(__al))
493 { _M_fill_initialize(__n, __value); }
505 template<
typename _InputIterator,
506 typename = std::_RequireInputIter<_InputIterator>>
508 const _Alloc& __al = _Alloc())
509 :
_Base(_Node_alloc_type(__al))
510 { _M_range_initialize(__first, __last); }
519 __list._M_get_Node_allocator()))
520 { _M_range_initialize(__list.
begin(), __list.end()); }
532 :
_Base(std::move(__list)) { }
543 const _Alloc& __al = _Alloc())
544 :
_Base(_Node_alloc_type(__al))
545 { _M_range_initialize(__il.begin(), __il.end()); }
577 constexpr
bool __move_storage =
578 _Node_alloc_traits::_S_propagate_on_move_assign()
579 || _Node_alloc_traits::_S_always_equal();
580 _M_move_assign(std::move(__list),
612 template<
typename _InputIterator,
613 typename = std::_RequireInputIter<_InputIterator>>
615 assign(_InputIterator __first, _InputIterator __last)
617 typedef is_assignable<_Tp, decltype(*__first)> __assignable;
618 _M_assign(__first, __last, __assignable());
633 { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
645 {
assign(__il.begin(), __il.end()); }
650 {
return allocator_type(this->_M_get_Node_allocator()); }
660 {
return iterator(&this->_M_impl._M_head); }
677 {
return iterator(this->_M_impl._M_head._M_next); }
739 {
return this->_M_impl._M_head._M_next == 0; }
757 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
758 return *__front->_M_valptr();
768 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
769 return *__front->_M_valptr();
785 template<
typename... _Args>
789 std::forward<_Args>(__args)...); }
810 { this->_M_insert_after(
cbefore_begin(), std::move(__val)); }
826 { this->_M_erase_after(&this->_M_impl._M_head); }
841 template<
typename... _Args>
844 {
return iterator(this->_M_insert_after(__pos,
845 std::forward<_Args>(__args)...)); }
861 {
return iterator(this->_M_insert_after(__pos, __val)); }
868 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
886 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
903 template<
typename _InputIterator,
904 typename = std::_RequireInputIter<_InputIterator>>
907 _InputIterator __first, _InputIterator __last);
926 {
return insert_after(__pos, __il.begin(), __il.end()); }
947 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
970 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
972 const_cast<_Node_base*>
973 (__last._M_node))); }
987 noexcept(_Node_alloc_traits::_S_nothrow_swap())
990 __list._M_impl._M_head._M_next);
991 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
992 __list._M_get_Node_allocator());
1022 resize(size_type __sz,
const value_type& __val);
1034 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1052 if (!__list.empty())
1053 _M_splice_after(__pos, __list.before_begin(), __list.end());
1072 const_iterator __i);
1095 { _M_splice_after(__pos, __before, __last); }
1099 const_iterator __before, const_iterator __last)
1100 { _M_splice_after(__pos, __before, __last); }
1114 remove(
const _Tp& __val);
1127 template<
typename _Pred>
1157 template<
typename _BinPred>
1159 unique(_BinPred __binary_pred);
1176 {
merge(std::move(__list)); }
1189 template<
typename _Comp>
1193 template<
typename _Comp>
1196 {
merge(std::move(__list), __comp); }
1214 template<
typename _Comp>
1225 { this->_M_impl._M_head._M_reverse_after(); }
1229 template<
typename _InputIterator>
1231 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1236 _M_fill_initialize(size_type __n,
const value_type& __value);
1240 _M_splice_after(const_iterator __pos, const_iterator __before,
1241 const_iterator __last);
1245 _M_default_initialize(size_type __n);
1249 _M_default_insert_after(const_iterator __pos, size_type __n);
1256 std::swap(this->_M_impl._M_head._M_next,
1257 __list._M_impl._M_head._M_next);
1258 std::__alloc_on_move(this->_M_get_Node_allocator(),
1259 __list._M_get_Node_allocator());
1266 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1271 this->
assign(std::__make_move_if_noexcept_iterator(__list.begin()),
1272 std::__make_move_if_noexcept_iterator(__list.end()));
1277 template<
typename _InputIterator>
1279 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1282 auto __curr =
begin();
1284 while (__curr != __end && __first != __last)
1291 if (__first != __last)
1293 else if (__curr != __end)
1299 template<
typename _InputIterator>
1301 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1309 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1312 auto __curr =
begin();
1314 while (__curr != __end && __n > 0)
1323 else if (__curr != __end)
1329 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1346 template<
typename _Tp,
typename _Alloc>
1348 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1349 const forward_list<_Tp, _Alloc>& __ly);
1363 template<
typename _Tp,
typename _Alloc>
1365 operator<(const forward_list<_Tp, _Alloc>& __lx,
1368 __ly.cbegin(), __ly.cend()); }
1371 template<
typename _Tp,
typename _Alloc>
1375 {
return !(__lx == __ly); }
1378 template<
typename _Tp,
typename _Alloc>
1382 {
return (__ly < __lx); }
1385 template<
typename _Tp,
typename _Alloc>
1389 {
return !(__lx < __ly); }
1392 template<
typename _Tp,
typename _Alloc>
1394 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1396 {
return !(__ly < __lx); }
1399 template<
typename _Tp,
typename _Alloc>
1403 { __lx.swap(__ly); }
1405 _GLIBCXX_END_NAMESPACE_CONTAINER
1408 #endif // _FORWARD_LIST_H
void merge(forward_list &&__list)
Merge sorted lists.
const_reference front() const
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
Uniform interface to all pointer-like types.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
Base class for forward_list.
iterator before_begin() noexcept
Forward iterators support a superset of input iterator operations.
Uniform interface to C++98 and C++0x allocators.
size_type max_size() const noexcept
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
iterator begin() noexcept
void sort()
Sort the elements of the list.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
const_iterator cbegin() const noexcept
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
forward_list & operator=(forward_list &&__list)
The forward_list move assignment operator.
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
forward_list(forward_list &&__list) noexcept
The forward_list move constructor.
static void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
One of the comparison functors.
iterator emplace_after(const_iterator __pos, _Args &&...__args)
Constructs object in forward_list after the specified iterator.
~forward_list() noexcept
The forward_list dtor.
A forward_list::iterator.
static size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
void emplace_front(_Args &&...__args)
Constructs object in forward_list at the front of the list.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
const_iterator cbefore_begin() const noexcept
forward_list(const forward_list &__list)
The forward_list copy constructor.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
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...
void reverse() noexcept
Reverse the elements in list.
static pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
void unique()
Remove consecutive duplicate elements.
A forward_list::const_iterator.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator cend() const noexcept
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
const_iterator begin() const noexcept
bool empty() const noexcept
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
One of the comparison functors.
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 push_front(const _Tp &__val)
Add data to the front of the forward_list.
void pop_front()
Removes first element.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last)
Insert range from another forward_list.
const_iterator before_begin() const noexcept
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
const_iterator end() const noexcept