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;
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) { }
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>
277 typedef __alloc_rebind<_Alloc, _Tp> _Tp_alloc_type;
278 typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _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()
294 _Fwd_list_impl(_Node_alloc_type&& __a)
295 : _Node_alloc_type(std::move(__a)), _M_head()
299 _Fwd_list_impl _M_impl;
307 _M_get_Node_allocator() noexcept
308 {
return *
static_cast<_Node_alloc_type*
>(&this->_M_impl); }
310 const _Node_alloc_type&
311 _M_get_Node_allocator()
const noexcept
312 {
return *
static_cast<const _Node_alloc_type*
>(&this->_M_impl); }
323 : _M_impl(std::move(__lst._M_get_Node_allocator()))
325 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
326 __lst._M_impl._M_head._M_next = 0;
330 { _M_erase_after(&_M_impl._M_head, 0); }
337 auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
341 template<
typename... _Args>
343 _M_create_node(_Args&&... __args)
345 _Node* __node = this->_M_get_node();
348 _Tp_alloc_type __a(_M_get_Node_allocator());
350 ::new ((
void*)__node) _Node;
351 _Alloc_traits::construct(__a, __node->_M_valptr(),
352 std::forward<_Args>(__args)...);
356 this->_M_put_node(__node);
357 __throw_exception_again;
362 template<
typename... _Args>
364 _M_insert_after(const_iterator __pos, _Args&&... __args);
367 _M_put_node(_Node* __p)
369 typedef typename _Node_alloc_traits::pointer _Ptr;
371 _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
408 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
415 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
416 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
422 typedef _Tp value_type;
423 typedef typename _Alloc_traits::pointer pointer;
424 typedef typename _Alloc_traits::const_pointer const_pointer;
425 typedef value_type& reference;
426 typedef const value_type& const_reference;
430 typedef std::size_t size_type;
431 typedef std::ptrdiff_t difference_type;
432 typedef _Alloc allocator_type;
442 : _Base(_Node_alloc_type(__al))
451 : _Base(_Node_alloc_type(__al))
452 { _M_range_initialize(__list.
begin(), __list.
end()); }
460 noexcept(_Node_alloc_traits::_S_always_equal())
461 : _Base(
std::move(__list), _Node_alloc_type(__al))
474 : _Base(_Node_alloc_type(__al))
475 { _M_default_initialize(__n); }
487 const _Alloc& __al = _Alloc())
488 : _Base(_Node_alloc_type(__al))
489 { _M_fill_initialize(__n, __value); }
501 template<
typename _InputIterator,
502 typename = std::_RequireInputIter<_InputIterator>>
504 const _Alloc& __al = _Alloc())
505 : _Base(_Node_alloc_type(__al))
506 { _M_range_initialize(__first, __last); }
514 : _Base(_Node_alloc_traits::_S_select_on_copy(
515 __list._M_get_Node_allocator()))
516 { _M_range_initialize(__list.
begin(), __list.
end()); }
528 : _Base(
std::move(__list)) { }
539 const _Alloc& __al = _Alloc())
540 : _Base(_Node_alloc_type(__al))
541 { _M_range_initialize(__il.begin(), __il.end()); }
571 noexcept(_Node_alloc_traits::_S_nothrow_move())
573 constexpr
bool __move_storage =
574 _Node_alloc_traits::_S_propagate_on_move_assign()
575 || _Node_alloc_traits::_S_always_equal();
576 _M_move_assign(std::move(__list),
608 template<
typename _InputIterator,
609 typename = std::_RequireInputIter<_InputIterator>>
611 assign(_InputIterator __first, _InputIterator __last)
613 typedef is_assignable<_Tp, decltype(*__first)> __assignable;
614 _M_assign(__first, __last, __assignable());
629 { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
641 { assign(__il.begin(), __il.end()); }
646 {
return allocator_type(this->_M_get_Node_allocator()); }
656 {
return iterator(&this->_M_impl._M_head); }
665 {
return const_iterator(&this->_M_impl._M_head); }
673 {
return iterator(this->_M_impl._M_head._M_next); }
682 {
return const_iterator(this->_M_impl._M_head._M_next); }
691 {
return iterator(0); }
700 {
return const_iterator(0); }
709 {
return const_iterator(this->_M_impl._M_head._M_next); }
718 {
return const_iterator(&this->_M_impl._M_head); }
727 {
return const_iterator(0); }
735 {
return this->_M_impl._M_head._M_next == 0; }
742 {
return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
753 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
754 return *__front->_M_valptr();
764 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
765 return *__front->_M_valptr();
781 template<
typename... _Args>
784 { this->_M_insert_after(cbefore_begin(),
785 std::forward<_Args>(__args)...); }
799 { this->_M_insert_after(cbefore_begin(), __val); }
805 push_front(_Tp&& __val)
806 { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
822 { this->_M_erase_after(&this->_M_impl._M_head); }
837 template<
typename... _Args>
840 {
return iterator(this->_M_insert_after(__pos,
841 std::forward<_Args>(__args)...)); }
857 {
return iterator(this->_M_insert_after(__pos, __val)); }
863 insert_after(const_iterator __pos, _Tp&& __val)
864 {
return iterator(this->_M_insert_after(__pos, std::move(__val))); }
882 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val);
899 template<
typename _InputIterator,
900 typename = std::_RequireInputIter<_InputIterator>>
902 insert_after(const_iterator __pos,
903 _InputIterator __first, _InputIterator __last);
922 {
return insert_after(__pos, __il.begin(), __il.end()); }
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 noexcept(_Node_alloc_traits::_S_nothrow_swap())
985 std::swap(this->_M_impl._M_head._M_next,
986 __list._M_impl._M_head._M_next);
987 _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
988 __list._M_get_Node_allocator());
1003 resize(size_type __sz);
1018 resize(size_type __sz,
const value_type& __val);
1030 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1048 if (!__list.
empty())
1053 splice_after(const_iterator __pos,
forward_list& __list)
1054 { splice_after(__pos, std::move(__list)); }
1067 splice_after(const_iterator __pos,
forward_list&& __list,
1068 const_iterator __i);
1071 splice_after(const_iterator __pos,
forward_list& __list,
1073 { splice_after(__pos, std::move(__list), __i); }
1091 const_iterator __before, const_iterator __last)
1092 { _M_splice_after(__pos, __before, __last); }
1096 const_iterator __before, const_iterator __last)
1097 { _M_splice_after(__pos, __before, __last); }
1112 remove(
const _Tp& __val);
1125 template<
typename _Pred>
1127 remove_if(_Pred __pred);
1155 template<
typename _BinPred>
1157 unique(_BinPred __binary_pred);
1174 { merge(std::move(__list)); }
1187 template<
typename _Comp>
1191 template<
typename _Comp>
1194 { merge(std::move(__list), __comp); }
1212 template<
typename _Comp>
1223 { this->_M_impl._M_head._M_reverse_after(); }
1227 template<
typename _InputIterator>
1229 _M_range_initialize(_InputIterator __first, _InputIterator __last);
1234 _M_fill_initialize(size_type __n,
const value_type& __value);
1238 _M_splice_after(const_iterator __pos, const_iterator __before,
1239 const_iterator __last);
1243 _M_default_initialize(size_type __n);
1247 _M_default_insert_after(const_iterator __pos, size_type __n);
1254 std::swap(this->_M_impl._M_head._M_next,
1255 __list._M_impl._M_head._M_next);
1256 std::__alloc_on_move(this->_M_get_Node_allocator(),
1257 __list._M_get_Node_allocator());
1264 if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
1269 this->assign(std::__make_move_if_noexcept_iterator(__list.
begin()),
1270 std::__make_move_if_noexcept_iterator(__list.
end()));
1275 template<
typename _InputIterator>
1277 _M_assign(_InputIterator __first, _InputIterator __last,
true_type)
1279 auto __prev = before_begin();
1280 auto __curr =
begin();
1282 while (__curr != __end && __first != __last)
1289 if (__first != __last)
1290 insert_after(__prev, __first, __last);
1291 else if (__curr != __end)
1292 erase_after(__prev, __end);
1297 template<
typename _InputIterator>
1299 _M_assign(_InputIterator __first, _InputIterator __last,
false_type)
1302 insert_after(cbefore_begin(), __first, __last);
1307 _M_assign_n(size_type __n,
const _Tp& __val,
true_type)
1309 auto __prev = before_begin();
1310 auto __curr =
begin();
1312 while (__curr != __end && __n > 0)
1320 insert_after(__prev, __n, __val);
1321 else if (__curr != __end)
1322 erase_after(__prev, __end);
1327 _M_assign_n(size_type __n,
const _Tp& __val,
false_type)
1330 insert_after(cbefore_begin(), __n, __val);
1344 template<
typename _Tp,
typename _Alloc>
1361 template<
typename _Tp,
typename _Alloc>
1363 operator<(const forward_list<_Tp, _Alloc>& __lx,
1369 template<
typename _Tp,
typename _Alloc>
1373 {
return !(__lx == __ly); }
1376 template<
typename _Tp,
typename _Alloc>
1380 {
return (__ly < __lx); }
1383 template<
typename _Tp,
typename _Alloc>
1387 {
return !(__lx < __ly); }
1390 template<
typename _Tp,
typename _Alloc>
1392 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1394 {
return !(__ly < __lx); }
1397 template<
typename _Tp,
typename _Alloc>
1401 { __lx.
swap(__ly); }
1403 _GLIBCXX_END_NAMESPACE_CONTAINER
1406 #endif // _FORWARD_LIST_H void sort()
Sort the elements of the list.
const_iterator begin() const noexcept
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
const_reference front() const
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
forward_list(size_type __n, const _Alloc &__al=_Alloc())
Creates a forward_list with default constructed elements.
_Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
void clear() noexcept
Erases all the elements.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
iterator before_begin() noexcept
forward_list & operator=(forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
The forward_list move assignment operator.
void reverse() noexcept
Reverse the elements in list.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
A forward_list::const_iterator.
const_iterator cend() const noexcept
forward_list(forward_list &&__list, const _Alloc &__al) noexcept(_Node_alloc_traits::_S_always_equal())
Move constructor with allocator argument.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
iterator emplace_after(const_iterator __pos, _Args &&...__args)
Constructs object in forward_list after the specified iterator.
const_iterator cbefore_begin() const noexcept
forward_list(const forward_list &__list)
The forward_list copy constructor.
const_iterator cbegin() const noexcept
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void pop_front()
Removes first element.
One of the comparison functors.
bool empty() const noexcept
One of the comparison functors.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
void merge(forward_list &&__list)
Merge sorted lists.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last)
Insert range from another forward_list.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
iterator begin() noexcept
Uniform interface to all pointer-like types.
~forward_list() noexcept
The forward_list dtor.
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
void emplace_front(_Args &&...__args)
Constructs object in forward_list at the front of the list.
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 swap(forward_list &__list) noexcept(_Node_alloc_traits::_S_nothrow_swap())
Swaps data with another forward_list.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
forward_list(const _Alloc &__al=_Alloc())
Creates a forward_list with no elements.
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
Base class for forward_list.
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
forward_list(forward_list &&__list) noexcept
The forward_list move constructor.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
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
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator end() const noexcept
void unique()
Remove consecutive duplicate elements.
Forward iterators support a superset of input iterator operations.
ISO C++ entities toplevel namespace is std.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
Uniform interface to C++98 and C++0x allocators.
size_type max_size() const noexcept
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
A forward_list::iterator.