30 #ifndef _FORWARD_LIST_TCC
31 #define _FORWARD_LIST_TCC 1
33 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
37 template<
typename _Tp,
typename _Alloc>
38 _Fwd_list_base<_Tp, _Alloc>::
39 _Fwd_list_base(
const _Fwd_list_base& __lst,
const _Alloc& __a)
42 this->_M_impl._M_head._M_next = 0;
43 _Fwd_list_node_base* __to = &this->_M_impl._M_head;
44 _Node* __curr =
static_cast<_Node*
>(__lst._M_impl._M_head._M_next);
48 __to->_M_next = _M_create_node(__curr->_M_value);
50 __curr =
static_cast<_Node*
>(__curr->_M_next);
54 template<
typename _Tp,
typename _Alloc>
55 template<
typename... _Args>
57 _Fwd_list_base<_Tp, _Alloc>::
58 _M_insert_after(const_iterator __pos, _Args&&... __args)
60 _Fwd_list_node_base* __to
61 =
const_cast<_Fwd_list_node_base*
>(__pos._M_node);
62 _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
63 __thing->_M_next = __to->_M_next;
64 __to->_M_next = __thing;
68 template<
typename _Tp,
typename _Alloc>
70 _Fwd_list_base<_Tp, _Alloc>::
71 _M_erase_after(_Fwd_list_node_base* __pos)
73 _Node* __curr =
static_cast<_Node*
>(__pos->_M_next);
74 __pos->_M_next = __curr->_M_next;
75 _M_get_Node_allocator().destroy(__curr);
77 return __pos->_M_next;
80 template<
typename _Tp,
typename _Alloc>
82 _Fwd_list_base<_Tp, _Alloc>::
83 _M_erase_after(_Fwd_list_node_base* __pos,
84 _Fwd_list_node_base* __last)
86 _Node* __curr =
static_cast<_Node*
>(__pos->_M_next);
87 while (__curr != __last)
89 _Node* __temp = __curr;
90 __curr =
static_cast<_Node*
>(__curr->_M_next);
91 _M_get_Node_allocator().destroy(__temp);
94 __pos->_M_next = __last;
99 template<
typename _Tp,
typename _Alloc>
100 template<
typename _InputIterator>
102 forward_list<_Tp, _Alloc>::
103 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
106 _Node_base* __to = &this->_M_impl._M_head;
107 for (; __first != __last; ++__first)
109 __to->_M_next = this->_M_create_node(*__first);
110 __to = __to->_M_next;
116 template<
typename _Tp,
typename _Alloc>
118 forward_list<_Tp, _Alloc>::
119 _M_fill_initialize(size_type __n,
const value_type& __value)
121 _Node_base* __to = &this->_M_impl._M_head;
124 __to->_M_next = this->_M_create_node(__value);
125 __to = __to->_M_next;
129 template<
typename _Tp,
typename _Alloc>
131 forward_list<_Tp, _Alloc>::
132 _M_default_initialize(size_type __n)
134 _Node_base* __to = &this->_M_impl._M_head;
137 __to->_M_next = this->_M_create_node();
138 __to = __to->_M_next;
142 template<
typename _Tp,
typename _Alloc>
143 forward_list<_Tp, _Alloc>&
144 forward_list<_Tp, _Alloc>::
154 while (__curr1 != __last1 && __first2 != __last2)
156 *__curr1 = *__first2;
161 if (__first2 == __last2)
162 erase_after(__prev1, __last1);
164 insert_after(__prev1, __first2, __last2);
169 template<
typename _Tp,
typename _Alloc>
174 const_iterator __saved_pos = __pos;
178 __pos = emplace_after(__pos);
182 erase_after(__saved_pos, ++__pos);
183 __throw_exception_again;
187 template<
typename _Tp,
typename _Alloc>
189 forward_list<_Tp, _Alloc>::
190 resize(size_type __sz)
195 while (__k._M_next() !=
end() && __len < __sz)
201 erase_after(__k,
end());
203 _M_default_insert_after(__k, __sz - __len);
206 template<
typename _Tp,
typename _Alloc>
209 resize(size_type __sz,
const value_type& __val)
214 while (__k._M_next() !=
end() && __len < __sz)
220 erase_after(__k,
end());
222 insert_after(__k, __sz - __len, __val);
225 template<
typename _Tp,
typename _Alloc>
230 _Node_base* __tmp =
const_cast<_Node_base*
>(__pos._M_node);
231 iterator __before = __list.before_begin();
232 return iterator(__tmp->_M_transfer_after(__before._M_node));
235 template<
typename _Tp,
typename _Alloc>
237 forward_list<_Tp, _Alloc>::
242 __tmp->_M_transfer_after(const_cast<_Node_base*>(__before._M_node),
243 const_cast<_Node_base*>(__last._M_node));
246 template<
typename _Tp,
typename _Alloc>
253 forward_list __tmp(__n, __val, this->_M_get_Node_allocator());
254 return _M_splice_after(__pos, std::move(__tmp));
257 return iterator(const_cast<_Node_base*>(__pos._M_node));
260 template<
typename _Tp,
typename _Alloc>
261 template<
typename _InputIterator>
265 _InputIterator __first, _InputIterator __last)
267 forward_list __tmp(__first, __last, this->_M_get_Node_allocator());
269 return _M_splice_after(__pos, std::move(__tmp));
271 return iterator(const_cast<_Node_base*>(__pos._M_node));
274 template<
typename _Tp,
typename _Alloc>
275 typename forward_list<_Tp, _Alloc>::iterator
276 forward_list<_Tp, _Alloc>::
281 forward_list __tmp(__il, this->_M_get_Node_allocator());
282 return _M_splice_after(__pos, std::move(__tmp));
285 return iterator(const_cast<_Node_base*>(__pos._M_node));
288 template<
typename _Tp,
typename _Alloc>
293 _Node* __curr =
static_cast<_Node*
>(&this->_M_impl._M_head);
296 while (
_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
298 if (__tmp->_M_value == __val)
300 if (std::__addressof(__tmp->_M_value)
301 != std::__addressof(__val))
303 this->_M_erase_after(__curr);
309 __curr =
static_cast<_Node*
>(__curr->_M_next);
313 this->_M_erase_after(__extra);
316 template<
typename _Tp,
typename _Alloc>
317 template<
typename _Pred>
322 _Node* __curr =
static_cast<_Node*
>(&this->_M_impl._M_head);
323 while (
_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
325 if (__pred(__tmp->_M_value))
326 this->_M_erase_after(__curr);
328 __curr =
static_cast<_Node*
>(__curr->_M_next);
332 template<
typename _Tp,
typename _Alloc>
333 template<
typename _BinPred>
340 if (__first == __last)
343 while (++__next != __last)
345 if (__binary_pred(*__first, *__next))
346 erase_after(__first);
353 template<
typename _Tp,
typename _Alloc>
354 template<
typename _Comp>
360 while (__node->_M_next && __list._M_impl._M_head._M_next)
362 if (__comp(static_cast<_Node*>
363 (__list._M_impl._M_head._M_next)->_M_value,
365 (__node->_M_next)->_M_value))
366 __node->_M_transfer_after(&__list._M_impl._M_head,
367 __list._M_impl._M_head._M_next);
368 __node = __node->_M_next;
370 if (__list._M_impl._M_head._M_next)
372 __node->_M_next = __list._M_impl._M_head._M_next;
373 __list._M_impl._M_head._M_next = 0;
377 template<
typename _Tp,
typename _Alloc>
384 auto __ix = __lx.
cbegin();
385 auto __iy = __ly.
cbegin();
386 while (__ix != __lx.
cend() && __iy != __ly.
cend())
393 if (__ix == __lx.
cend() && __iy == __ly.
cend())
399 template<
typename _Tp,
class _Alloc>
400 template<
typename _Comp>
402 forward_list<_Tp, _Alloc>::
406 _Node* __list =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
410 unsigned long __insize = 1;
419 unsigned long __nmerges = 0;
427 unsigned long __psize = 0;
428 for (
unsigned long __i = 0; __i < __insize; ++__i)
431 __q =
static_cast<_Node*
>(__q->_M_next);
437 unsigned long __qsize = __insize;
440 while (__psize > 0 || (__qsize > 0 && __q))
448 __q =
static_cast<_Node*
>(__q->_M_next);
451 else if (__qsize == 0 || !__q)
455 __p =
static_cast<_Node*
>(__p->_M_next);
458 else if (__comp(__p->_M_value, __q->_M_value))
462 __p =
static_cast<_Node*
>(__p->_M_next);
469 __q =
static_cast<_Node*
>(__q->_M_next);
475 __tail->_M_next = __e;
490 this->_M_impl._M_head._M_next = __list;
499 _GLIBCXX_END_NAMESPACE_CONTAINER
constexpr const _Tp * begin(initializer_list< _Tp > __ils)
Return an iterator pointing to the first element of the initilizer_list.
A forward_list::iterator.
const_iterator cend() const
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
A forward_list::const_iterator.
const_iterator cbegin() const
A helper basic node class for forward_list. This is just a linked list with nothing inside it...
constexpr const _Tp * end(initializer_list< _Tp > __ils)
Return an iterator pointing to one past the last element of the initilizer_list.
A helper node class for forward_list. This is just a linked list with a data value in each node...