30 #ifndef _FORWARD_LIST_TCC 31 #define _FORWARD_LIST_TCC 1 33 namespace std _GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
38 template<
typename _Tp,
typename _Alloc>
39 _Fwd_list_base<_Tp, _Alloc>::
40 _Fwd_list_base(_Fwd_list_base&& __lst, _Node_alloc_type&& __a)
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)
53 _Fwd_list_node_base* __to
54 = const_cast<_Fwd_list_node_base*>(__pos._M_node);
55 _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
56 __thing->_M_next = __to->_M_next;
57 __to->_M_next = __thing;
61 template<
typename _Tp,
typename _Alloc>
63 _Fwd_list_base<_Tp, _Alloc>::
64 _M_erase_after(_Fwd_list_node_base* __pos)
66 _Node* __curr = static_cast<_Node*>(__pos->_M_next);
67 __pos->_M_next = __curr->_M_next;
68 _Node_alloc_traits::destroy(_M_get_Node_allocator(),
72 return __pos->_M_next;
75 template<
typename _Tp,
typename _Alloc>
77 _Fwd_list_base<_Tp, _Alloc>::
78 _M_erase_after(_Fwd_list_node_base* __pos,
79 _Fwd_list_node_base* __last)
81 _Node* __curr = static_cast<_Node*>(__pos->_M_next);
82 while (__curr != __last)
84 _Node* __temp = __curr;
85 __curr = static_cast<_Node*>(__curr->_M_next);
86 _Node_alloc_traits::destroy(_M_get_Node_allocator(),
91 __pos->_M_next = __last;
96 template<
typename _Tp,
typename _Alloc>
97 template<
typename _InputIterator>
99 forward_list<_Tp, _Alloc>::
100 _M_range_initialize(_InputIterator __first, _InputIterator __last)
102 _Node_base* __to = &this->_M_impl._M_head;
103 for (; __first != __last; ++__first)
105 __to->_M_next = this->_M_create_node(*__first);
106 __to = __to->_M_next;
111 template<
typename _Tp,
typename _Alloc>
113 forward_list<_Tp, _Alloc>::
114 _M_fill_initialize(size_type __n,
const value_type& __value)
116 _Node_base* __to = &this->_M_impl._M_head;
119 __to->_M_next = this->_M_create_node(__value);
120 __to = __to->_M_next;
124 template<
typename _Tp,
typename _Alloc>
126 forward_list<_Tp, _Alloc>::
127 _M_default_initialize(size_type __n)
129 _Node_base* __to = &this->_M_impl._M_head;
132 __to->_M_next = this->_M_create_node();
133 __to = __to->_M_next;
137 template<
typename _Tp,
typename _Alloc>
138 forward_list<_Tp, _Alloc>&
139 forward_list<_Tp, _Alloc>::
144 if (_Node_alloc_traits::_S_propagate_on_copy_assign())
146 auto& __this_alloc = this->_M_get_Node_allocator();
147 auto& __that_alloc = __list._M_get_Node_allocator();
148 if (!_Node_alloc_traits::_S_always_equal()
149 && __this_alloc != __that_alloc)
154 std::__alloc_on_copy(__this_alloc, __that_alloc);
161 template<
typename _Tp,
typename _Alloc>
166 const_iterator __saved_pos = __pos;
170 __pos = emplace_after(__pos);
174 erase_after(__saved_pos, ++__pos);
175 __throw_exception_again;
179 template<
typename _Tp,
typename _Alloc>
181 forward_list<_Tp, _Alloc>::
182 resize(size_type __sz)
187 while (__k._M_next() !=
end() && __len < __sz)
193 erase_after(__k,
end());
195 _M_default_insert_after(__k, __sz - __len);
198 template<
typename _Tp,
typename _Alloc>
201 resize(size_type __sz,
const value_type& __val)
206 while (__k._M_next() !=
end() && __len < __sz)
212 erase_after(__k,
end());
214 insert_after(__k, __sz - __len, __val);
217 template<
typename _Tp,
typename _Alloc>
221 const_iterator __before, const_iterator __last)
223 _Node_base* __tmp = const_cast<_Node_base*>(__pos._M_node);
224 _Node_base* __b = const_cast<_Node_base*>(__before._M_node);
225 _Node_base* __end = __b;
227 while (__end && __end->_M_next != __last._M_node)
228 __end = __end->_M_next;
231 return iterator(__tmp->_M_transfer_after(__b, __end));
236 template<
typename _Tp,
typename _Alloc>
238 forward_list<_Tp, _Alloc>::
245 if (__pos == __i || __pos == __j)
248 _Node_base* __tmp = const_cast<_Node_base*>(__pos._M_node);
249 __tmp->_M_transfer_after(const_cast<_Node_base*>(__i._M_node),
250 const_cast<_Node_base*>(__j._M_node));
253 template<
typename _Tp,
typename _Alloc>
264 return iterator(const_cast<_Node_base*>(__pos._M_node));
267 template<
typename _Tp,
typename _Alloc>
268 template<
typename _InputIterator,
typename>
272 _InputIterator __first, _InputIterator __last)
278 return iterator(const_cast<_Node_base*>(__pos._M_node));
281 template<
typename _Tp,
typename _Alloc>
289 while (
_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
291 if (*__tmp->_M_valptr() == __val)
295 this->_M_erase_after(__curr);
301 __curr = __curr->_M_next;
305 this->_M_erase_after(__extra);
308 template<
typename _Tp,
typename _Alloc>
309 template<
typename _Pred>
315 while (
_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
317 if (__pred(*__tmp->_M_valptr()))
318 this->_M_erase_after(__curr);
320 __curr = __curr->_M_next;
324 template<
typename _Tp,
typename _Alloc>
325 template<
typename _BinPred>
332 if (__first == __last)
335 while (++__next != __last)
337 if (__binary_pred(*__first, *__next))
338 erase_after(__first);
345 template<
typename _Tp,
typename _Alloc>
346 template<
typename _Comp>
352 while (__node->_M_next && __list._M_impl._M_head._M_next)
354 if (__comp(*static_cast<_Node*>
355 (__list._M_impl._M_head._M_next)->_M_valptr(),
357 (__node->_M_next)->_M_valptr()))
358 __node->_M_transfer_after(&__list._M_impl._M_head,
359 __list._M_impl._M_head._M_next);
360 __node = __node->_M_next;
363 if (__list._M_impl._M_head._M_next)
364 *__node = std::move(__list._M_impl._M_head);
367 template<
typename _Tp,
typename _Alloc>
374 auto __ix = __lx.
cbegin();
375 auto __iy = __ly.
cbegin();
376 while (__ix != __lx.
cend() && __iy != __ly.
cend())
378 if (!(*__ix == *__iy))
383 if (__ix == __lx.
cend() && __iy == __ly.
cend())
389 template<
typename _Tp,
class _Alloc>
390 template<
typename _Comp>
392 forward_list<_Tp, _Alloc>::
396 _Node* __list = static_cast<_Node*>(this->_M_impl._M_head._M_next);
400 unsigned long __insize = 1;
406 _Node* __tail =
nullptr;
409 unsigned long __nmerges = 0;
417 unsigned long __psize = 0;
418 for (
unsigned long __i = 0; __i < __insize; ++__i)
421 __q = static_cast<_Node*>(__q->_M_next);
427 unsigned long __qsize = __insize;
430 while (__psize > 0 || (__qsize > 0 && __q))
438 __q = static_cast<_Node*>(__q->_M_next);
441 else if (__qsize == 0 || !__q)
445 __p = static_cast<_Node*>(__p->_M_next);
448 else if (!__comp(*__q->_M_valptr(), *__p->_M_valptr()))
452 __p = static_cast<_Node*>(__p->_M_next);
459 __q = static_cast<_Node*>(__q->_M_next);
465 __tail->_M_next = __e;
474 __tail->_M_next =
nullptr;
480 this->_M_impl._M_head._M_next = __list;
489 _GLIBCXX_END_NAMESPACE_CONTAINER
490 _GLIBCXX_END_NAMESPACE_VERSION
A forward_list::const_iterator.
A helper basic node class for forward_list. This is just a linked list with nothing inside it....
const_iterator cend() const noexcept
A forward_list::iterator.
const_iterator cbegin() const noexcept
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
bool empty() const noexcept
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
A helper node class for forward_list. This is just a linked list with uninitialized storage for a dat...
iterator before_begin() noexcept
A standard container with linear time access to elements, and fixed time insertion/deletion at any po...