30#ifndef _FORWARD_LIST_TCC
31#define _FORWARD_LIST_TCC 1
33namespace std _GLIBCXX_VISIBILITY(default)
35_GLIBCXX_BEGIN_NAMESPACE_VERSION
36_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
38 template<
typename _Tp,
typename _Alloc>
41 : _M_impl(std::
move(__a))
43 if (__lst._M_get_Node_allocator() == _M_get_Node_allocator())
44 this->_M_impl._M_head =
std::move(__lst._M_impl._M_head);
47 template<
typename _Tp,
typename _Alloc>
48 template<
typename... _Args>
50 _Fwd_list_base<_Tp, _Alloc>::
51 _M_insert_after(const_iterator __pos, _Args&&... __args)
54 auto __to = __pos._M_const_cast()._M_node;
56 __thing->_M_next = __to->_M_next;
57 __to->_M_next = __thing->_M_base_ptr();
61 template<
typename _Tp,
typename _Alloc>
63 _Fwd_list_base<_Tp, _Alloc>::
64 _M_erase_after(_Base_ptr __pos)
67 auto& __curr =
static_cast<_Node&
>(*__pos->_M_next);
68 __pos->_M_next = __curr._M_next;
69 _M_destroy_node(__curr._M_node_ptr());
70 return __pos->_M_next;
73 template<
typename _Tp,
typename _Alloc>
75 _Fwd_list_base<_Tp, _Alloc>::
76 _M_erase_after(_Base_ptr __pos, _Base_ptr __last)
79 _Base_ptr __curr = __pos->_M_next;
80 while (__curr != __last)
82 auto& __node =
static_cast<_Node&
>(*__curr);
83 __curr = __curr->_M_next;
84 _M_destroy_node(__node._M_node_ptr());
86 __pos->_M_next = __last;
91 template<
typename _Tp,
typename _Alloc>
92 template<
typename _InputIterator>
94 forward_list<_Tp, _Alloc>::
95 _M_range_initialize(_InputIterator __first, _InputIterator __last)
97 auto __to = this->_M_impl._M_head._M_base_ptr();
98 for (; __first != __last; ++__first)
100 __to->_M_next = this->_M_create_node(*__first)->_M_base_ptr();
101 __to = __to->_M_next;
106 template<
typename _Tp,
typename _Alloc>
108 forward_list<_Tp, _Alloc>::
109 _M_fill_initialize(size_type __n,
const value_type& __value)
111 auto __to = this->_M_impl._M_head._M_base_ptr();
114 __to->_M_next = this->_M_create_node(__value)->_M_base_ptr();
115 __to = __to->_M_next;
119 template<
typename _Tp,
typename _Alloc>
121 forward_list<_Tp, _Alloc>::
122 _M_default_initialize(size_type __n)
124 auto __to = this->_M_impl._M_head._M_base_ptr();
127 __to->_M_next = this->_M_create_node()->_M_base_ptr();
128 __to = __to->_M_next;
132 template<
typename _Tp,
typename _Alloc>
133 forward_list<_Tp, _Alloc>&
139 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
141 auto& __this_alloc = this->_M_get_Node_allocator();
142 auto& __that_alloc = __list._M_get_Node_allocator();
143 if (!_Node_alloc_traits::_S_always_equal()
144 && __this_alloc != __that_alloc)
149 std::__alloc_on_copy(__this_alloc, __that_alloc);
151 assign(__list.cbegin(), __list.cend());
156 template<
typename _Tp,
typename _Alloc>
161 const_iterator __saved_pos = __pos;
165 __pos = emplace_after(__pos);
169 erase_after(__saved_pos, ++__pos);
170 __throw_exception_again;
174 template<
typename _Tp,
typename _Alloc>
182 while (__k._M_next() !=
end() && __len < __sz)
190 _M_default_insert_after(__k, __sz - __len);
193 template<
typename _Tp,
typename _Alloc>
196 resize(size_type __sz,
const value_type& __val)
201 while (__k._M_next() !=
end() && __len < __sz)
212 template<
typename _Tp,
typename _Alloc>
213 typename forward_list<_Tp, _Alloc>::iterator
216 const_iterator __before, const_iterator __last)
218 auto __tmp = __pos._M_const_cast()._M_node;
219 auto __b = __before._M_const_cast()._M_node;
222 while (__end && __end->_M_next != __last._M_node)
223 __end = __end->_M_next;
226 return iterator(__tmp->_M_transfer_after(__b, __end));
231 template<
typename _Tp,
typename _Alloc>
235 const_iterator __i)
noexcept
237 const_iterator __j = __i;
240 if (__pos == __i || __pos == __j)
243 auto __tmp = __pos._M_const_cast()._M_node;
244 __tmp->_M_transfer_after(__i._M_const_cast()._M_node,
245 __j._M_const_cast()._M_node);
248 template<
typename _Tp,
typename _Alloc>
249 typename forward_list<_Tp, _Alloc>::iterator
251 insert_after(const_iterator __pos, size_type __n,
const _Tp& __val)
259 return __pos._M_const_cast();
262 template<
typename _Tp,
typename _Alloc>
263 template<
typename _InputIterator,
typename>
264 typename forward_list<_Tp, _Alloc>::iterator
267 _InputIterator __first, _InputIterator __last)
273 return __pos._M_const_cast();
276#if __cplusplus > 201703L
277# define _GLIBCXX20_ONLY(__expr) __expr
279# define _GLIBCXX20_ONLY(__expr)
282 template<
typename _Tp,
typename _Alloc>
285 remove(
const _Tp& __val) -> __remove_return_type
287 size_type __removed __attribute__((__unused__)) = 0;
291 while (
auto __tmp = __prev_it._M_node->_M_next)
292 if (*
static_cast<_Node&
>(*__tmp)._M_valptr() == __val)
296 _GLIBCXX20_ONLY( __removed++ );
301 return _GLIBCXX20_ONLY( __removed );
304 template<
typename _Tp,
typename _Alloc>
305 template<
typename _Pred>
308 remove_if(_Pred __pred) -> __remove_return_type
310 size_type __removed __attribute__((__unused__)) = 0;
313 auto __prev_it = cbefore_begin();
314 while (
auto __tmp = __prev_it._M_node->_M_next)
315 if (__pred(*
static_cast<_Node&
>(*__tmp)._M_valptr()))
317 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
319 _GLIBCXX20_ONLY( __removed++ );
324 return _GLIBCXX20_ONLY( __removed );
327 template<
typename _Tp,
typename _Alloc>
328 template<
typename _BinPred>
330 forward_list<_Tp, _Alloc>::
331 unique(_BinPred __binary_pred) -> __remove_return_type
333 iterator __first =
begin();
334 iterator __last =
end();
335 if (__first == __last)
336 return _GLIBCXX20_ONLY(0);
338 forward_list __to_destroy(get_allocator());
339 size_type __removed __attribute__((__unused__)) = 0;
340 iterator __next = __first;
341 while (++__next != __last)
343 if (__binary_pred(*__first, *__next))
345 __to_destroy.splice_after(__to_destroy.cbefore_begin(),
347 _GLIBCXX20_ONLY( __removed++ );
354 return _GLIBCXX20_ONLY( __removed );
357#undef _GLIBCXX20_ONLY
359 template<
typename _Tp,
typename _Alloc>
360 template<
typename _Comp>
370 using _Base_ptr =
typename _Node::_Base_ptr;
372 _Base_ptr __node = this->_M_impl._M_head._M_base_ptr();
373 _Base_ptr __other = __list._M_impl._M_head._M_base_ptr();
374 while (__node->_M_next && __other->_M_next)
376 auto& __l =
static_cast<_Node&
>(*__other->_M_next);
377 auto& __r =
static_cast<_Node&
>(*__node->_M_next);
378 if (__comp(*__l._M_valptr(), *__r._M_valptr()))
379 __node->_M_transfer_after(__other, __other->_M_next);
380 __node = __node->_M_next;
383 if (__list._M_impl._M_head._M_next)
384 *__node =
std::move(__list._M_impl._M_head);
387 template<
typename _Tp,
typename _Alloc>
394 auto __ix = __lx.
cbegin();
395 auto __iy = __ly.
cbegin();
396 while (__ix != __lx.
cend() && __iy != __ly.
cend())
398 if (!(*__ix == *__iy))
403 if (__ix == __lx.
cend() && __iy == __ly.
cend())
409 template<
typename _Tp,
class _Alloc>
410 template<
typename _Comp>
418 using _Base_ptr =
typename _Node::_Base_ptr;
421 _Base_ptr __list = this->_M_impl._M_head._M_next;
423 unsigned long __insize = 1;
427 _Base_ptr __p = __list;
429 _Base_ptr __tail =
nullptr;
432 unsigned long __nmerges = 0;
440 unsigned long __psize = 0;
441 for (
unsigned long __i = 0; __i < __insize; ++__i)
450 unsigned long __qsize = __insize;
453 while (__psize > 0 || (__qsize > 0 && __q))
464 else if (__qsize == 0 || !__q)
471 else if (!__comp(*
static_cast<_Node&
>(*__q)._M_valptr(),
472 *
static_cast<_Node&
>(*__p)._M_valptr()))
489 __tail->_M_next = __e;
498 __tail->_M_next =
nullptr;
504 this->_M_impl._M_head._M_next = __list;
513_GLIBCXX_END_NAMESPACE_CONTAINER
514_GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
ISO C++ entities toplevel namespace is std.
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...
forward_list()=default
Creates a forward_list with no elements.
iterator erase_after(const_iterator __pos)
Removes the element pointed to by the iterator following pos.
iterator before_begin() noexcept
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 &&__list) noexcept
Insert contents of another forward_list.
const_iterator cbefore_begin() const noexcept
void clear() noexcept
Erases all the elements.
const_iterator cend() const noexcept
void assign(_InputIterator __first, _InputIterator __last)
Assigns a range to a forward_list.
bool empty() const noexcept
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
const_iterator cbegin() const noexcept
Base class for forward_list.