35 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
37 template<
typename _Tp,
typename _Alloc>
38 _Fwd_list_base<_Tp, _Alloc>::
39 _Fwd_list_base(_Fwd_list_base&& __lst,
const _Node_alloc_type& __a)
42 if (__lst._M_get_Node_allocator() == __a)
44 this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
45 __lst._M_impl._M_head._M_next = 0;
49 this->_M_impl._M_head._M_next = 0;
50 _Fwd_list_node_base* __to = &this->_M_impl._M_head;
51 _Node* __curr =
static_cast<_Node*
>(__lst._M_impl._M_head._M_next);
56 _M_create_node(std::move_if_noexcept(*__curr->_M_valptr()));
58 __curr =
static_cast<_Node*
>(__curr->_M_next);
63 template<
typename _Tp,
typename _Alloc>
64 template<
typename... _Args>
66 _Fwd_list_base<_Tp, _Alloc>::
67 _M_insert_after(const_iterator __pos, _Args&&... __args)
69 _Fwd_list_node_base* __to
70 =
const_cast<_Fwd_list_node_base*
>(__pos._M_node);
71 _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
72 __thing->_M_next = __to->_M_next;
73 __to->_M_next = __thing;
77 template<
typename _Tp,
typename _Alloc>
79 _Fwd_list_base<_Tp, _Alloc>::
80 _M_erase_after(_Fwd_list_node_base* __pos)
82 _Node* __curr =
static_cast<_Node*
>(__pos->_M_next);
83 __pos->_M_next = __curr->_M_next;
84 _Tp_alloc_type __a(_M_get_Node_allocator());
85 allocator_traits<_Tp_alloc_type>::destroy(__a, __curr->_M_valptr());
88 return __pos->_M_next;
91 template<
typename _Tp,
typename _Alloc>
93 _Fwd_list_base<_Tp, _Alloc>::
94 _M_erase_after(_Fwd_list_node_base* __pos,
95 _Fwd_list_node_base* __last)
97 _Node* __curr =
static_cast<_Node*
>(__pos->_M_next);
98 while (__curr != __last)
100 _Node* __temp = __curr;
101 __curr =
static_cast<_Node*
>(__curr->_M_next);
102 _Tp_alloc_type __a(_M_get_Node_allocator());
103 allocator_traits<_Tp_alloc_type>::destroy(__a, __temp->_M_valptr());
107 __pos->_M_next = __last;
112 template<
typename _Tp,
typename _Alloc>
113 template<
typename _InputIterator>
115 forward_list<_Tp, _Alloc>::
116 _M_range_initialize(_InputIterator __first, _InputIterator __last)
118 _Node_base* __to = &this->_M_impl._M_head;
119 for (; __first != __last; ++__first)
121 __to->_M_next = this->_M_create_node(*__first);
122 __to = __to->_M_next;
127 template<
typename _Tp,
typename _Alloc>
129 forward_list<_Tp, _Alloc>::
130 _M_fill_initialize(size_type __n,
const value_type& __value)
132 _Node_base* __to = &this->_M_impl._M_head;
135 __to->_M_next = this->_M_create_node(__value);
136 __to = __to->_M_next;
140 template<
typename _Tp,
typename _Alloc>
142 forward_list<_Tp, _Alloc>::
143 _M_default_initialize(size_type __n)
145 _Node_base* __to = &this->_M_impl._M_head;
148 __to->_M_next = this->_M_create_node();
149 __to = __to->_M_next;
153 template<
typename _Tp,
typename _Alloc>
154 forward_list<_Tp, _Alloc>&
155 forward_list<_Tp, _Alloc>::
156 operator=(
const forward_list& __list)
160 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
162 auto& __this_alloc = this->_M_get_Node_allocator();
163 auto& __that_alloc = __list._M_get_Node_allocator();
164 if (!_Node_alloc_traits::_S_always_equal()
165 && __this_alloc != __that_alloc)
170 std::__alloc_on_copy(__this_alloc, __that_alloc);
172 assign(__list.cbegin(), __list.cend());
177 template<
typename _Tp,
typename _Alloc>
179 forward_list<_Tp, _Alloc>::
180 _M_default_insert_after(const_iterator __pos, size_type __n)
182 const_iterator __saved_pos = __pos;
186 __pos = emplace_after(__pos);
190 erase_after(__saved_pos, ++__pos);
195 template<
typename _Tp,
typename _Alloc>
197 forward_list<_Tp, _Alloc>::
198 resize(size_type __sz)
200 iterator __k = before_begin();
203 while (__k._M_next() != end() && __len < __sz)
209 erase_after(__k, end());
211 _M_default_insert_after(__k, __sz - __len);
214 template<
typename _Tp,
typename _Alloc>
216 forward_list<_Tp, _Alloc>::
217 resize(size_type __sz,
const value_type& __val)
219 iterator __k = before_begin();
222 while (__k._M_next() != end() && __len < __sz)
228 erase_after(__k, end());
230 insert_after(__k, __sz - __len, __val);
233 template<
typename _Tp,
typename _Alloc>
234 typename forward_list<_Tp, _Alloc>::iterator
235 forward_list<_Tp, _Alloc>::
236 _M_splice_after(const_iterator __pos,
237 const_iterator __before, const_iterator __last)
239 _Node_base* __tmp =
const_cast<_Node_base*
>(__pos._M_node);
240 _Node_base* __b =
const_cast<_Node_base*
>(__before._M_node);
241 _Node_base* __end = __b;
243 while (__end && __end->_M_next != __last._M_node)
244 __end = __end->_M_next;
247 return iterator(__tmp->_M_transfer_after(__b, __end));
249 return iterator(__tmp);
252 template<
typename _Tp,
typename _Alloc>
254 forward_list<_Tp, _Alloc>::
255 splice_after(const_iterator __pos, forward_list&&,
258 const_iterator __j = __i;
261 if (__pos == __i || __pos == __j)
264 _Node_base* __tmp =
const_cast<_Node_base*
>(__pos._M_node);
265 __tmp->_M_transfer_after(const_cast<_Node_base*>(__i._M_node),
266 const_cast<_Node_base*>(__j._M_node));
269 template<
typename _Tp,
typename _Alloc>
270 typename forward_list<_Tp, _Alloc>::iterator
271 forward_list<_Tp, _Alloc>::
272 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val)
276 forward_list __tmp(__n, __val, get_allocator());
277 return _M_splice_after(__pos, __tmp.before_begin(), __tmp.end());
280 return iterator(const_cast<_Node_base*>(__pos._M_node));
283 template<
typename _Tp,
typename _Alloc>
284 template<
typename _InputIterator,
typename>
285 typename forward_list<_Tp, _Alloc>::iterator
286 forward_list<_Tp, _Alloc>::
287 insert_after(const_iterator __pos,
288 _InputIterator __first, _InputIterator __last)
290 forward_list __tmp(__first, __last, get_allocator());
292 return _M_splice_after(__pos, __tmp.before_begin(), __tmp.end());
294 return iterator(const_cast<_Node_base*>(__pos._M_node));
297 template<
typename _Tp,
typename _Alloc>
299 forward_list<_Tp, _Alloc>::
300 remove(
const _Tp& __val)
302 _Node* __curr =
static_cast<_Node*
>(&this->_M_impl._M_head);
305 while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
307 if (*__tmp->_M_valptr() == __val)
309 if (__tmp->_M_valptr() != std::__addressof(__val))
311 this->_M_erase_after(__curr);
317 __curr =
static_cast<_Node*
>(__curr->_M_next);
321 this->_M_erase_after(__extra);
324 template<
typename _Tp,
typename _Alloc>
325 template<
typename _Pred>
327 forward_list<_Tp, _Alloc>::
328 remove_if(_Pred __pred)
330 _Node* __curr =
static_cast<_Node*
>(&this->_M_impl._M_head);
331 while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
333 if (__pred(*__tmp->_M_valptr()))
334 this->_M_erase_after(__curr);
336 __curr =
static_cast<_Node*
>(__curr->_M_next);
340 template<
typename _Tp,
typename _Alloc>
341 template<
typename _BinPred>
343 forward_list<_Tp, _Alloc>::
344 unique(_BinPred __binary_pred)
346 iterator __first = begin();
347 iterator __last = end();
348 if (__first == __last)
350 iterator __next = __first;
351 while (++__next != __last)
353 if (__binary_pred(*__first, *__next))
354 erase_after(__first);
361 template<
typename _Tp,
typename _Alloc>
362 template<
typename _Comp>
364 forward_list<_Tp, _Alloc>::
365 merge(forward_list&& __list, _Comp __comp)
367 _Node_base* __node = &this->_M_impl._M_head;
368 while (__node->_M_next && __list._M_impl._M_head._M_next)
370 if (__comp(*static_cast<_Node*>
371 (__list._M_impl._M_head._M_next)->_M_valptr(),
373 (__node->_M_next)->_M_valptr()))
374 __node->_M_transfer_after(&__list._M_impl._M_head,
375 __list._M_impl._M_head._M_next);
376 __node = __node->_M_next;
378 if (__list._M_impl._M_head._M_next)
380 __node->_M_next = __list._M_impl._M_head._M_next;
381 __list._M_impl._M_head._M_next = 0;
385 template<
typename _Tp,
typename _Alloc>
387 operator==(
const forward_list<_Tp, _Alloc>& __lx,
388 const forward_list<_Tp, _Alloc>& __ly)
392 auto __ix = __lx.cbegin();
393 auto __iy = __ly.cbegin();
394 while (__ix != __lx.cend() && __iy != __ly.cend())
401 if (__ix == __lx.cend() && __iy == __ly.cend())
407 template<
typename _Tp,
class _Alloc>
408 template<
typename _Comp>
410 forward_list<_Tp, _Alloc>::
414 _Node* __list =
static_cast<_Node*
>(this->_M_impl._M_head._M_next);
418 unsigned long __insize = 1;
427 unsigned long __nmerges = 0;
435 unsigned long __psize = 0;
436 for (
unsigned long __i = 0; __i < __insize; ++__i)
439 __q =
static_cast<_Node*
>(__q->_M_next);
445 unsigned long __qsize = __insize;
448 while (__psize > 0 || (__qsize > 0 && __q))
456 __q =
static_cast<_Node*
>(__q->_M_next);
459 else if (__qsize == 0 || !__q)
463 __p =
static_cast<_Node*
>(__p->_M_next);
466 else if (__comp(*__p->_M_valptr(), *__q->_M_valptr()))
470 __p =
static_cast<_Node*
>(__p->_M_next);
477 __q =
static_cast<_Node*
>(__q->_M_next);
483 __tail->_M_next = __e;
498 this->_M_impl._M_head._M_next = __list;
507 _GLIBCXX_END_NAMESPACE_CONTAINER
bool operator==(const exception_ptr &, const exception_ptr &) _GLIBCXX_USE_NOEXCEPT __attribute__((__pure__))
#define __try
Definition: exception_defines.h:35
#define __throw_exception_again
Definition: exception_defines.h:37
#define __catch(X)
Definition: exception_defines.h:36