29 #ifndef _FORWARD_LIST_TCC
30 #define _FORWARD_LIST_TCC 1
32 _GLIBCXX_BEGIN_NAMESPACE(std)
34 template<typename _Alloc>
36 _Fwd_list_node_base<_Alloc>::
37 _M_transfer_after(_Pointer __bbegin)
39 _Pointer __bend = __bbegin;
40 while (__bend && __bend->_M_next)
41 __bend = __bend->_M_next;
42 _M_transfer_after(__bbegin, __bend);
45 template<
typename _Alloc>
47 _Fwd_list_node_base<_Alloc>::
48 _M_transfer_after(_Pointer __bbegin, _Pointer __bend)
50 _Pointer __keep = __bbegin->_M_next;
53 __bbegin->_M_next = __bend->_M_next;
54 __bend->_M_next = _M_next;
57 __bbegin->_M_next = 0;
61 template<
typename _Alloc>
63 _Fwd_list_node_base<_Alloc>::
66 _Pointer __tail = _M_next;
69 while (_Pointer __temp = __tail->_M_next)
71 _Pointer __keep = _M_next;
73 __tail->_M_next = __temp->_M_next;
74 _M_next->_M_next = __keep;
83 template<
typename _Tp,
class _Alloc>
84 template<
typename _Comp>
86 _Fwd_list_node<_Tp, _Alloc>::
87 _M_sort_after(_Comp __comp)
90 _Pointer __list = __static_pointer_cast<_Pointer>(this->_M_next);
94 unsigned long __insize = 1;
98 _Pointer __p = __list;
103 unsigned long __nmerges = 0;
111 unsigned long __psize = 0;
112 for (
unsigned long __i = 0; __i < __insize; ++__i)
115 __q = __static_pointer_cast<_Pointer>(__q->_M_next);
121 unsigned long __qsize = __insize;
124 while (__psize > 0 || (__qsize > 0 && __q))
132 __q = __static_pointer_cast<_Pointer>(__q->_M_next);
135 else if (__qsize == 0 || !__q)
139 __p = __static_pointer_cast<_Pointer>(__p->_M_next);
142 else if (__comp(__p->_M_value, __q->_M_value))
146 __p = __static_pointer_cast<_Pointer>(__p->_M_next);
153 __q = __static_pointer_cast<_Pointer>(__q->_M_next);
159 __tail->_M_next = __e;
174 this->_M_next = __list;
183 template<
typename _Tp,
typename _Alloc>
188 this->_M_impl._M_head._M_next = 0;
189 typename _Node_base::_Pointer __to = &this->_M_impl._M_head;
190 typename _Node::_Pointer __curr
191 = __static_pointer_cast<
typename _Node::_Pointer>
192 (__lst._M_impl._M_head._M_next);
195 __to->_M_next = _M_create_node(__curr->_M_value);
196 __to = __to->_M_next;
197 __curr = __static_pointer_cast<
typename _Node::_Pointer>
202 template<
typename _Tp,
typename _Alloc>
203 template<
typename... _Args>
204 typename _Fwd_list_base<_Tp, _Alloc>::_Node_base::_Pointer
205 _Fwd_list_base<_Tp, _Alloc>::
206 _M_insert_after(const_iterator __pos, _Args&&... __args)
208 typename _Node_base::_Pointer __to
209 = __const_pointer_cast<
typename _Node_base::_Pointer>
211 typename _Node::_Pointer __thing
213 _M_create_node(std::forward<_Args>(__args)...) );
214 __thing->_M_next = __to->_M_next;
215 __to->_M_next = __thing;
220 template<
typename _Tp,
typename _Alloc>
221 typename _Fwd_list_base<_Tp, _Alloc>::_Node_base::_Pointer
222 _Fwd_list_base<_Tp, _Alloc>::
223 _M_erase_after(
typename _Node_base::_Pointer __pos)
225 typename _Node::_Pointer __curr
229 typename _Node_base::_Pointer __next = __curr->_M_next;
230 __pos->_M_next = __next;
231 _M_get_Node_allocator().destroy(__curr);
237 template<
typename _Tp,
typename _Alloc>
238 typename _Fwd_list_base<_Tp, _Alloc>::_Node_base::_Pointer
239 _Fwd_list_base<_Tp, _Alloc>::
240 _M_erase_after(
typename _Node_base::_Pointer __pos,
241 typename _Node_base::_Pointer __last)
243 typename _Node::_Pointer __curr
247 typename _Node::_Pointer __temp = __curr;
250 _M_get_Node_allocator().destroy(__temp);
252 __pos->_M_next = __curr;
253 if (__temp == __last)
260 template<
typename _Tp,
typename _Alloc>
261 template<
typename _InputIterator>
263 forward_list<_Tp, _Alloc>::
264 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
267 typename _Node_base::_Pointer __to = &this->_M_impl._M_head;
268 for (; __first != __last; ++__first)
270 __to->_M_next = this->_M_create_node(*__first);
271 __to = __to->_M_next;
277 template<
typename _Tp,
typename _Alloc>
279 forward_list<_Tp, _Alloc>::
280 _M_fill_initialize(size_type __n,
const value_type& __value)
282 typename _Node_base::_Pointer __to = &this->_M_impl._M_head;
283 for (; __n > 0; --__n)
285 __to->_M_next = this->_M_create_node(__value);
286 __to = __to->_M_next;
290 template<
typename _Tp,
typename _Alloc>
291 forward_list<_Tp, _Alloc>&
302 while (__curr1 != __last1 && __first2 != __last2)
304 *__curr1 = *__first2;
309 if (__first2 == __last2)
310 erase_after(__prev1, __last1);
312 insert_after(__prev1, __first2, __last2);
317 template<
typename _Tp,
typename _Alloc>
325 while (__k._M_next() != end() && __len < __sz)
331 erase_after(__k, end());
333 insert_after(__k, __sz - __len, __val);
336 template<
typename _Tp,
typename _Alloc>
341 if (!__list.empty() && &__list !=
this)
343 typename _Node_base::_Pointer __tmp
344 = __const_pointer_cast<
typename _Node_base::_Pointer>
347 __tmp->_M_transfer_after(__const_pointer_cast
348 <
typename _Node_base::_Pointer>
353 template<
typename _Tp,
typename _Alloc>
359 typename _Node_base::_Pointer __tmp
360 = __const_pointer_cast<
typename _Node_base::_Pointer>(__pos._M_node);
361 __tmp->_M_transfer_after(__const_pointer_cast
362 <
typename _Node_base::_Pointer>
365 <
typename _Node_base::_Pointer>
369 template<
typename _Tp,
typename _Alloc>
374 typename _Node::_Pointer __curr
375 = __static_pointer_cast<
typename _Node::_Pointer>
376 (&this->_M_impl._M_head);
377 while (
typename _Node::_Pointer __temp =
378 __static_pointer_cast<typename _Node::_Pointer>(__curr->_M_next))
380 if (__temp->_M_value == __val)
381 this->_M_erase_after(__curr);
383 __curr = __static_pointer_cast<
typename _Node::_Pointer>
388 template<
typename _Tp,
typename _Alloc>
389 template<
typename _Pred>
394 typename _Node::_Pointer __curr
395 = __static_pointer_cast<
typename _Node::_Pointer>
396 (&this->_M_impl._M_head);
397 while (
typename _Node::_Pointer __temp =
398 __static_pointer_cast<typename _Node::_Pointer>(__curr->_M_next))
400 if (__pred(__temp->_M_value))
401 this->_M_erase_after(__curr);
403 __curr = __static_pointer_cast<
typename _Node::_Pointer>
408 template<
typename _Tp,
typename _Alloc>
409 template<
typename _BinPred>
416 if (__first == __last)
419 while (++__next != __last)
421 if (__binary_pred(*__first, *__next))
422 erase_after(__first);
429 template<
typename _Tp,
typename _Alloc>
430 template<
typename _Comp>
435 typename _Node_base::_Pointer __node = &this->_M_impl._M_head;
436 while (__node->_M_next && __list._M_impl._M_head._M_next)
438 if (__comp(__static_pointer_cast<typename _Node::_Pointer>
439 (__list._M_impl._M_head._M_next)->_M_value,
440 __static_pointer_cast<typename _Node::_Pointer>
441 (__node->_M_next)->_M_value))
442 __node->_M_transfer_after(&__list._M_impl._M_head,
443 __list._M_impl._M_head._M_next);
444 __node = __node->_M_next;
446 if (__list._M_impl._M_head._M_next)
448 __node->_M_next = __list._M_impl._M_head._M_next;
449 __list._M_impl._M_head._M_next = 0;
453 template<
typename _Tp,
typename _Alloc>
460 auto __ix = __lx.
cbegin();
461 auto __iy = __ly.
cbegin();
462 while (__ix != __lx.
cend() && __iy != __ly.
cend())
469 if (__ix == __lx.
cend() && __iy == __ly.
cend())
475 _GLIBCXX_END_NAMESPACE
bool operator==(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return true if x is equal to y.
A forward_list::iterator.
void splice_after(const_iterator __pos, forward_list &&__list)
Insert contents of another forward_list.
Base class for forward_list.
_ToType __static_pointer_cast(const _FromType &__arg)
A forward_list::const_iterator.
void remove_if(_Pred __pred)
Remove all elements satisfying a predicate.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
void remove(const _Tp &__val)
Remove all elements equal to value.
const_iterator cend() const
void unique()
Remove consecutive duplicate elements.
void merge(forward_list &&__list)
Merge sorted lists.
const_iterator cbegin() const
void resize(size_type __sz)
Resizes the forward_list to the specified number of elements.
forward_list & operator=(const forward_list &__list)
The forward_list assignment operator.