30 #ifndef _FORWARD_LIST_H
31 #define _FORWARD_LIST_H 1
33 #pragma GCC system_header
36 #ifdef __GXX_EXPERIMENTAL_CXX0X__
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
62 __begin->_M_next = __end->_M_next;
63 __end->_M_next = _M_next;
72 _M_reverse_after() noexcept
81 __tail->_M_next = __temp->_M_next;
82 _M_next->_M_next = __keep;
92 template<
typename _Tp>
96 template<
typename... _Args>
99 _M_value(std::forward<_Args>(__args)...) { }
109 template<
typename _Tp>
115 typedef _Tp value_type;
116 typedef _Tp* pointer;
117 typedef _Tp& reference;
118 typedef ptrdiff_t difference_type;
130 {
return static_cast<_Node*
>(this->_M_node)->_M_value; }
135 (this->_M_node)->_M_value); }
140 _M_node = _M_node->_M_next;
148 _M_node = _M_node->_M_next;
153 operator==(
const _Self& __x)
const
154 {
return _M_node == __x._M_node; }
157 operator!=(
const _Self& __x)
const
158 {
return _M_node != __x._M_node; }
177 template<
typename _Tp>
184 typedef _Tp value_type;
185 typedef const _Tp* pointer;
186 typedef const _Tp& reference;
187 typedef ptrdiff_t difference_type;
198 : _M_node(__iter._M_node) { }
202 {
return static_cast<_Node*
>(this->_M_node)->_M_value; }
207 (this->_M_node)->_M_value); }
212 _M_node = _M_node->_M_next;
220 _M_node = _M_node->_M_next;
225 operator==(
const _Self& __x)
const
226 {
return _M_node == __x._M_node; }
229 operator!=(
const _Self& __x)
const
230 {
return _M_node != __x._M_node; }
247 template<
typename _Tp>
251 {
return __x._M_node == __y._M_node; }
256 template<
typename _Tp>
260 {
return __x._M_node != __y._M_node; }
265 template<
typename _Tp,
typename _Alloc>
269 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
271 typedef typename _Alloc::template
272 rebind<_Fwd_list_node<_Tp>>::other _Node_alloc_type;
274 struct _Fwd_list_impl
275 :
public _Node_alloc_type
280 : _Node_alloc_type(), _M_head()
283 _Fwd_list_impl(
const _Node_alloc_type& __a)
284 : _Node_alloc_type(__a), _M_head()
287 _Fwd_list_impl(_Node_alloc_type&& __a)
288 : _Node_alloc_type(std::move(__a)), _M_head()
292 _Fwd_list_impl _M_impl;
300 _M_get_Node_allocator() noexcept
301 {
return *
static_cast<_Node_alloc_type*
>(&this->_M_impl); }
303 const _Node_alloc_type&
304 _M_get_Node_allocator()
const noexcept
305 {
return *
static_cast<const _Node_alloc_type*
>(&this->_M_impl); }
318 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
319 __lst._M_impl._M_head._M_next = 0;
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); }
336 {
return _M_get_Node_allocator().allocate(1); }
338 template<
typename... _Args>
340 _M_create_node(_Args&&... __args)
342 _Node* __node = this->_M_get_node();
345 _M_get_Node_allocator().construct(__node,
346 std::forward<_Args>(__args)...);
351 this->_M_put_node(__node);
352 __throw_exception_again;
357 template<
typename... _Args>
362 _M_put_node(
_Node* __p)
363 { _M_get_Node_allocator().deallocate(__p, 1); }
404 template<
typename _Tp,
typename _Alloc = allocator<_Tp> >
411 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
412 typedef typename _Base::_Node_alloc_type _Node_alloc_type;
416 typedef _Tp value_type;
417 typedef typename _Tp_alloc_type::pointer pointer;
418 typedef typename _Tp_alloc_type::const_pointer const_pointer;
419 typedef typename _Tp_alloc_type::reference reference;
420 typedef typename _Tp_alloc_type::const_reference const_reference;
424 typedef std::size_t size_type;
425 typedef std::ptrdiff_t difference_type;
426 typedef _Alloc allocator_type;
436 :
_Base(_Node_alloc_type(__al))
445 :
_Base(__list, _Node_alloc_type(__al))
454 :
_Base(std::move(__list), _Node_alloc_type(__al))
467 { _M_default_initialize(__n); }
479 const _Alloc& __al = _Alloc())
480 :
_Base(_Node_alloc_type(__al))
481 { _M_fill_initialize(__n, __value); }
493 template<
typename _InputIterator>
495 const _Alloc& __al = _Alloc())
496 :
_Base(_Node_alloc_type(__al))
499 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
500 _M_initialize_dispatch(__first, __last, _Integral());
512 :
_Base(__list._M_get_Node_allocator())
513 { _M_initialize_dispatch(__list.
begin(), __list.
end(), __false_type()); }
525 :
_Base(std::move(__list)) { }
536 const _Alloc& __al = _Alloc())
537 :
_Base(_Node_alloc_type(__al))
538 { _M_initialize_dispatch(__il.begin(), __il.end(), __false_type()); }
603 template<
typename _InputIterator>
605 assign(_InputIterator __first, _InputIterator __last)
646 {
return allocator_type(this->_M_get_Node_allocator()); }
656 {
return iterator(&this->_M_impl._M_head); }
673 {
return iterator(this->_M_impl._M_head._M_next); }
735 {
return this->_M_impl._M_head._M_next == 0; }
742 {
return this->_M_get_Node_allocator().max_size(); }
753 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
754 return __front->_M_value;
764 _Node* __front =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
765 return __front->_M_value;
781 template<
typename... _Args>
785 std::forward<_Args>(__args)...); }
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)); }
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>
902 _InputIterator __first, _InputIterator __last);
921 {
return insert_after(__pos, __il.begin(), __il.end()); }
942 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
965 {
return iterator(this->_M_erase_after(const_cast<_Node_base*>
967 const_cast<_Node_base*>
968 (__last._M_node))); }
982 { std::swap(this->_M_impl._M_head._M_next,
983 __list._M_impl._M_head._M_next); }
1012 resize(size_type __sz,
const value_type& __val);
1024 { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1042 if (!__list.empty())
1043 _M_splice_after(__pos, __list.before_begin(), __list.end());
1062 const_iterator __i);
1085 { _M_splice_after(__pos, __before, __last); }
1089 const_iterator __before, const_iterator __last)
1090 { _M_splice_after(__pos, __before, __last); }
1104 remove(
const _Tp& __val);
1117 template<
typename _Pred>
1147 template<
typename _BinPred>
1149 unique(_BinPred __binary_pred);
1166 {
merge(std::move(__list)); }
1179 template<
typename _Comp>
1183 template<
typename _Comp>
1186 {
merge(std::move(__list), __comp); }
1204 template<
typename _Comp>
1215 { this->_M_impl._M_head._M_reverse_after(); }
1218 template<
typename _Integer>
1220 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1221 { _M_fill_initialize(static_cast<size_type>(__n), __x); }
1224 template<
typename _InputIterator>
1226 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1232 _M_fill_initialize(size_type __n,
const value_type& __value);
1236 _M_splice_after(const_iterator __pos, const_iterator __before,
1237 const_iterator __last);
1241 _M_default_initialize(size_type __n);
1245 _M_default_insert_after(const_iterator __pos, size_type __n);
1258 template<
typename _Tp,
typename _Alloc>
1260 operator==(
const forward_list<_Tp, _Alloc>& __lx,
1261 const forward_list<_Tp, _Alloc>& __ly);
1275 template<
typename _Tp,
typename _Alloc>
1277 operator<(const forward_list<_Tp, _Alloc>& __lx,
1280 __ly.cbegin(), __ly.cend()); }
1283 template<
typename _Tp,
typename _Alloc>
1287 {
return !(__lx == __ly); }
1290 template<
typename _Tp,
typename _Alloc>
1294 {
return (__ly < __lx); }
1297 template<
typename _Tp,
typename _Alloc>
1301 {
return !(__lx < __ly); }
1304 template<
typename _Tp,
typename _Alloc>
1306 operator<=(const forward_list<_Tp, _Alloc>& __lx,
1308 {
return !(__ly < __lx); }
1311 template<
typename _Tp,
typename _Alloc>
1315 { __lx.
swap(__ly); }
1317 _GLIBCXX_END_NAMESPACE_CONTAINER
1320 #endif // _FORWARD_LIST_H
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
void sort()
Sort the elements of the list.
forward_list(const _Alloc &__al=_Alloc())
Creates a forward_list with no elements.
iterator insert_after(const_iterator __pos, const _Tp &__val)
Inserts given value into forward_list after specified iterator.
void splice_after(const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last)
Insert range from another forward_list.
iterator begin() noexcept
const_reference front() const
const_iterator begin() const noexcept
bool lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
Performs dictionary comparison on ranges.
void push_front(const _Tp &__val)
Add data to the front of the forward_list.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
forward_list(size_type __n)
Creates a forward_list with default constructed elements.
forward_list & operator=(forward_list &&__list)
The forward_list move assignment operator.
void assign(size_type __n, const _Tp &__val)
Assigns a given value to a forward_list.
const_iterator cbefore_begin() const noexcept
One of the comparison functors.
A helper node class for forward_list. This is just a linked list with a data value in each node...
iterator before_begin() noexcept
void reverse() noexcept
Reverse the elements in list.
void swap(forward_list &__list)
Swaps data with another forward_list.
void pop_front()
Removes first element.
void emplace_front(_Args &&...__args)
Constructs object in forward_list at the front of the list.
Base class for forward_list.
One of the comparison functors.
iterator emplace_after(const_iterator __pos, _Args &&...__args)
Constructs object in forward_list after the specified iterator.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
forward_list(const forward_list &__list, const _Alloc &__al)
Copy constructor with allocator argument.
void merge(forward_list &&__list)
Merge sorted lists.
const_iterator end() const noexcept
~forward_list() noexcept
The forward_list dtor.
forward_list(std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
Builds a forward_list from an initializer_list.
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
forward_list(forward_list &&__list, const _Alloc &__al)
Move constructor with allocator argument.
forward_list(const forward_list &__list)
The forward_list copy constructor.
size_type max_size() const noexcept
A forward_list::iterator.
void clear() noexcept
Erases all the elements.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
forward_list(_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
Builds a forward_list from a range.
void assign(std::initializer_list< _Tp > __il)
Assigns an initializer_list to a forward_list.
const_iterator before_begin() const noexcept
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
forward_list & operator=(std::initializer_list< _Tp > __il)
The forward_list initializer list assignment operator.
void unique()
Remove consecutive duplicate elements.
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
const_iterator cbegin() const noexcept
Forward iterators support a superset of input iterator operations.
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...
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.
forward_list(size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
Creates a forward_list with copies of an exemplar element.
const_iterator cend() const noexcept
iterator erase_after(const_iterator __pos, const_iterator __last)
Remove a range of elements.
_Tp * __addressof(_Tp &__r) _GLIBCXX_NOEXCEPT
Same as C++11 std::addressof.
forward_list(forward_list &&__list) noexcept
The forward_list move constructor.
bool empty() const noexcept
A forward_list::const_iterator.
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.