2 //===----------------------- forward_list ---------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_FORWARD_LIST
12 #define _LIBCPP_FORWARD_LIST
20 template <class T, class Allocator = allocator<T>>
25 typedef Allocator allocator_type;
27 typedef value_type& reference;
28 typedef const value_type& const_reference;
29 typedef typename allocator_traits<allocator_type>::pointer pointer;
30 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
31 typedef typename allocator_traits<allocator_type>::size_type size_type;
32 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
34 typedef <details> iterator;
35 typedef <details> const_iterator;
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
39 explicit forward_list(const allocator_type& a);
40 explicit forward_list(size_type n);
41 forward_list(size_type n, const value_type& v);
42 forward_list(size_type n, const value_type& v, const allocator_type& a);
43 template <class InputIterator>
44 forward_list(InputIterator first, InputIterator last);
45 template <class InputIterator>
46 forward_list(InputIterator first, InputIterator last, const allocator_type& a);
47 forward_list(const forward_list& x);
48 forward_list(const forward_list& x, const allocator_type& a);
49 forward_list(forward_list&& x)
50 noexcept(is_nothrow_move_constructible<allocator_type>::value);
51 forward_list(forward_list&& x, const allocator_type& a);
52 forward_list(initializer_list<value_type> il);
53 forward_list(initializer_list<value_type> il, const allocator_type& a);
57 forward_list& operator=(const forward_list& x);
58 forward_list& operator=(forward_list&& x)
60 allocator_type::propagate_on_container_move_assignment::value &&
61 is_nothrow_move_assignable<allocator_type>::value);
62 forward_list& operator=(initializer_list<value_type> il);
64 template <class InputIterator>
65 void assign(InputIterator first, InputIterator last);
66 void assign(size_type n, const value_type& v);
67 void assign(initializer_list<value_type> il);
69 allocator_type get_allocator() const noexcept;
71 iterator begin() noexcept;
72 const_iterator begin() const noexcept;
73 iterator end() noexcept;
74 const_iterator end() const noexcept;
76 const_iterator cbegin() const noexcept;
77 const_iterator cend() const noexcept;
79 iterator before_begin() noexcept;
80 const_iterator before_begin() const noexcept;
81 const_iterator cbefore_begin() const noexcept;
83 bool empty() const noexcept;
84 size_type max_size() const noexcept;
87 const_reference front() const;
89 template <class... Args> void emplace_front(Args&&... args);
90 void push_front(const value_type& v);
91 void push_front(value_type&& v);
95 template <class... Args>
96 iterator emplace_after(const_iterator p, Args&&... args);
97 iterator insert_after(const_iterator p, const value_type& v);
98 iterator insert_after(const_iterator p, value_type&& v);
99 iterator insert_after(const_iterator p, size_type n, const value_type& v);
100 template <class InputIterator>
101 iterator insert_after(const_iterator p,
102 InputIterator first, InputIterator last);
103 iterator insert_after(const_iterator p, initializer_list<value_type> il);
105 iterator erase_after(const_iterator p);
106 iterator erase_after(const_iterator first, const_iterator last);
108 void swap(forward_list& x)
109 noexcept(!allocator_type::propagate_on_container_swap::value ||
110 __is_nothrow_swappable<allocator_type>::value);
112 void resize(size_type n);
113 void resize(size_type n, const value_type& v);
114 void clear() noexcept;
116 void splice_after(const_iterator p, forward_list& x);
117 void splice_after(const_iterator p, forward_list&& x);
118 void splice_after(const_iterator p, forward_list& x, const_iterator i);
119 void splice_after(const_iterator p, forward_list&& x, const_iterator i);
120 void splice_after(const_iterator p, forward_list& x,
121 const_iterator first, const_iterator last);
122 void splice_after(const_iterator p, forward_list&& x,
123 const_iterator first, const_iterator last);
124 void remove(const value_type& v);
125 template <class Predicate> void remove_if(Predicate pred);
127 template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
128 void merge(forward_list& x);
129 void merge(forward_list&& x);
130 template <class Compare> void merge(forward_list& x, Compare comp);
131 template <class Compare> void merge(forward_list&& x, Compare comp);
133 template <class Compare> void sort(Compare comp);
134 void reverse() noexcept;
137 template <class T, class Allocator>
138 bool operator==(const forward_list<T, Allocator>& x,
139 const forward_list<T, Allocator>& y);
141 template <class T, class Allocator>
142 bool operator< (const forward_list<T, Allocator>& x,
143 const forward_list<T, Allocator>& y);
145 template <class T, class Allocator>
146 bool operator!=(const forward_list<T, Allocator>& x,
147 const forward_list<T, Allocator>& y);
149 template <class T, class Allocator>
150 bool operator> (const forward_list<T, Allocator>& x,
151 const forward_list<T, Allocator>& y);
153 template <class T, class Allocator>
154 bool operator>=(const forward_list<T, Allocator>& x,
155 const forward_list<T, Allocator>& y);
157 template <class T, class Allocator>
158 bool operator<=(const forward_list<T, Allocator>& x,
159 const forward_list<T, Allocator>& y);
161 template <class T, class Allocator>
162 void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
163 noexcept(noexcept(x.swap(y)));
171 #include <initializer_list>
177 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
178 #pragma GCC system_header
181 _LIBCPP_BEGIN_NAMESPACE_STD
183 template <class _Tp, class _VoidPtr> struct __forward_list_node;
185 template <class _NodePtr>
186 struct __forward_begin_node
188 typedef __forward_begin_node __self;
189 typedef _NodePtr pointer;
193 _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
196 template <class _Tp, class _VoidPtr>
197 struct __forward_list_node
198 : public __forward_begin_node
200 typename pointer_traits<_VoidPtr>::template
201 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
202 rebind<__forward_list_node<_Tp, _VoidPtr> >
204 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
208 typedef _Tp value_type;
213 template<class _Tp, class _Alloc> class forward_list;
214 template<class _NodeConstPtr> class __forward_list_const_iterator;
216 template <class _NodePtr>
217 class _LIBCPP_VISIBLE __forward_list_iterator
219 typedef _NodePtr __node_pointer;
221 __node_pointer __ptr_;
223 _LIBCPP_INLINE_VISIBILITY
224 explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
226 template<class, class> friend class forward_list;
227 template<class> friend class __forward_list_const_iterator;
230 typedef forward_iterator_tag iterator_category;
231 typedef typename pointer_traits<__node_pointer>::element_type::value_type
233 typedef value_type& reference;
234 typedef typename pointer_traits<__node_pointer>::difference_type
236 typedef typename pointer_traits<__node_pointer>::template
237 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
240 rebind<value_type>::other
244 _LIBCPP_INLINE_VISIBILITY
245 __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
247 _LIBCPP_INLINE_VISIBILITY
248 reference operator*() const {return __ptr_->__value_;}
249 _LIBCPP_INLINE_VISIBILITY
250 pointer operator->() const {return &__ptr_->__value_;}
252 _LIBCPP_INLINE_VISIBILITY
253 __forward_list_iterator& operator++()
255 __ptr_ = __ptr_->__next_;
258 _LIBCPP_INLINE_VISIBILITY
259 __forward_list_iterator operator++(int)
261 __forward_list_iterator __t(*this);
266 friend _LIBCPP_INLINE_VISIBILITY
267 bool operator==(const __forward_list_iterator& __x,
268 const __forward_list_iterator& __y)
269 {return __x.__ptr_ == __y.__ptr_;}
270 friend _LIBCPP_INLINE_VISIBILITY
271 bool operator!=(const __forward_list_iterator& __x,
272 const __forward_list_iterator& __y)
273 {return !(__x == __y);}
276 template <class _NodeConstPtr>
277 class _LIBCPP_VISIBLE __forward_list_const_iterator
279 typedef _NodeConstPtr __node_const_pointer;
281 __node_const_pointer __ptr_;
283 _LIBCPP_INLINE_VISIBILITY
284 explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT
287 typedef typename remove_const
289 typename pointer_traits<__node_const_pointer>::element_type
291 typedef typename pointer_traits<__node_const_pointer>::template
292 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
295 rebind<__node>::other
299 template<class, class> friend class forward_list;
302 typedef forward_iterator_tag iterator_category;
303 typedef typename __node::value_type value_type;
304 typedef const value_type& reference;
305 typedef typename pointer_traits<__node_const_pointer>::difference_type
307 typedef typename pointer_traits<__node_const_pointer>::template
308 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
309 rebind<const value_type>
311 rebind<const value_type>::other
315 _LIBCPP_INLINE_VISIBILITY
316 __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
317 _LIBCPP_INLINE_VISIBILITY
318 __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
319 : __ptr_(__p.__ptr_) {}
321 _LIBCPP_INLINE_VISIBILITY
322 reference operator*() const {return __ptr_->__value_;}
323 _LIBCPP_INLINE_VISIBILITY
324 pointer operator->() const {return &__ptr_->__value_;}
326 _LIBCPP_INLINE_VISIBILITY
327 __forward_list_const_iterator& operator++()
329 __ptr_ = __ptr_->__next_;
332 _LIBCPP_INLINE_VISIBILITY
333 __forward_list_const_iterator operator++(int)
335 __forward_list_const_iterator __t(*this);
340 friend _LIBCPP_INLINE_VISIBILITY
341 bool operator==(const __forward_list_const_iterator& __x,
342 const __forward_list_const_iterator& __y)
343 {return __x.__ptr_ == __y.__ptr_;}
344 friend _LIBCPP_INLINE_VISIBILITY
345 bool operator!=(const __forward_list_const_iterator& __x,
346 const __forward_list_const_iterator& __y)
347 {return !(__x == __y);}
350 template <class _Tp, class _Alloc>
351 class __forward_list_base
354 typedef _Tp value_type;
355 typedef _Alloc allocator_type;
357 typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
358 typedef __forward_list_node<value_type, void_pointer> __node;
359 typedef typename __node::__self __begin_node;
360 typedef typename allocator_traits<allocator_type>::template
361 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
364 rebind_alloc<__node>::other
367 typedef allocator_traits<__node_allocator> __node_traits;
368 typedef typename __node_traits::pointer __node_pointer;
369 typedef typename __node_traits::const_pointer __node_const_pointer;
371 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
373 _LIBCPP_INLINE_VISIBILITY
374 __node_pointer __before_begin() _NOEXCEPT
375 {return pointer_traits<__node_pointer>::pointer_to(
376 static_cast<__node&>(__before_begin_.first()));}
377 _LIBCPP_INLINE_VISIBILITY
378 __node_const_pointer __before_begin() const _NOEXCEPT
379 {return pointer_traits<__node_const_pointer>::pointer_to(
380 static_cast<const __node&>(__before_begin_.first()));}
382 _LIBCPP_INLINE_VISIBILITY
383 __node_allocator& __alloc() _NOEXCEPT
384 {return __before_begin_.second();}
385 _LIBCPP_INLINE_VISIBILITY
386 const __node_allocator& __alloc() const _NOEXCEPT
387 {return __before_begin_.second();}
389 typedef __forward_list_iterator<__node_pointer> iterator;
390 typedef __forward_list_const_iterator<__node_const_pointer> const_iterator;
392 _LIBCPP_INLINE_VISIBILITY
393 __forward_list_base()
394 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
395 : __before_begin_(__begin_node()) {}
396 _LIBCPP_INLINE_VISIBILITY
397 __forward_list_base(const allocator_type& __a)
398 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
400 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
402 __forward_list_base(__forward_list_base&& __x)
403 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
404 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
405 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
408 __forward_list_base(const __forward_list_base&);
409 __forward_list_base& operator=(const __forward_list_base&);
412 ~__forward_list_base();
415 _LIBCPP_INLINE_VISIBILITY
416 void __copy_assign_alloc(const __forward_list_base& __x)
417 {__copy_assign_alloc(__x, integral_constant<bool,
418 __node_traits::propagate_on_container_copy_assignment::value>());}
420 _LIBCPP_INLINE_VISIBILITY
421 void __move_assign_alloc(__forward_list_base& __x)
422 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
423 is_nothrow_move_assignable<__node_allocator>::value)
424 {__move_assign_alloc(__x, integral_constant<bool,
425 __node_traits::propagate_on_container_move_assignment::value>());}
428 void swap(__forward_list_base& __x)
429 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
430 __is_nothrow_swappable<__node_allocator>::value);
432 void clear() _NOEXCEPT;
435 _LIBCPP_INLINE_VISIBILITY
436 void __copy_assign_alloc(const __forward_list_base&, false_type) {}
437 _LIBCPP_INLINE_VISIBILITY
438 void __copy_assign_alloc(const __forward_list_base& __x, true_type)
440 if (__alloc() != __x.__alloc())
442 __alloc() = __x.__alloc();
445 _LIBCPP_INLINE_VISIBILITY
446 void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT
448 _LIBCPP_INLINE_VISIBILITY
449 void __move_assign_alloc(__forward_list_base& __x, true_type)
450 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
451 {__alloc() = _VSTD::move(__x.__alloc());}
453 _LIBCPP_INLINE_VISIBILITY
454 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
455 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
456 __is_nothrow_swappable<__node_allocator>::value)
457 {__swap_alloc(__x, __y, integral_constant<bool,
458 __node_traits::propagate_on_container_swap::value>());}
459 _LIBCPP_INLINE_VISIBILITY
460 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
464 _LIBCPP_INLINE_VISIBILITY
465 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
467 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
474 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
476 template <class _Tp, class _Alloc>
477 inline _LIBCPP_INLINE_VISIBILITY
478 __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
479 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
480 : __before_begin_(_VSTD::move(__x.__before_begin_))
482 __x.__before_begin()->__next_ = nullptr;
485 template <class _Tp, class _Alloc>
486 inline _LIBCPP_INLINE_VISIBILITY
487 __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
488 const allocator_type& __a)
489 : __before_begin_(__begin_node(), __node_allocator(__a))
491 if (__alloc() == __x.__alloc())
493 __before_begin()->__next_ = __x.__before_begin()->__next_;
494 __x.__before_begin()->__next_ = nullptr;
498 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
500 template <class _Tp, class _Alloc>
501 __forward_list_base<_Tp, _Alloc>::~__forward_list_base()
506 template <class _Tp, class _Alloc>
507 inline _LIBCPP_INLINE_VISIBILITY
509 __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
510 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
511 __is_nothrow_swappable<__node_allocator>::value)
513 __swap_alloc(__alloc(), __x.__alloc());
515 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
518 template <class _Tp, class _Alloc>
520 __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
522 __node_allocator& __a = __alloc();
523 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
525 __node_pointer __next = __p->__next_;
526 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
527 __node_traits::deallocate(__a, __p, 1);
530 __before_begin()->__next_ = nullptr;
533 template <class _Tp, class _Alloc = allocator<_Tp> >
534 class _LIBCPP_VISIBLE forward_list
535 : private __forward_list_base<_Tp, _Alloc>
537 typedef __forward_list_base<_Tp, _Alloc> base;
538 typedef typename base::__node_allocator __node_allocator;
539 typedef typename base::__node __node;
540 typedef typename base::__node_traits __node_traits;
541 typedef typename base::__node_pointer __node_pointer;
544 typedef _Tp value_type;
545 typedef _Alloc allocator_type;
547 typedef value_type& reference;
548 typedef const value_type& const_reference;
549 typedef typename allocator_traits<allocator_type>::pointer pointer;
550 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
551 typedef typename allocator_traits<allocator_type>::size_type size_type;
552 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
554 typedef typename base::iterator iterator;
555 typedef typename base::const_iterator const_iterator;
557 _LIBCPP_INLINE_VISIBILITY
559 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
561 explicit forward_list(const allocator_type& __a);
562 explicit forward_list(size_type __n);
563 forward_list(size_type __n, const value_type& __v);
564 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
565 template <class _InputIterator>
566 forward_list(_InputIterator __f, _InputIterator __l,
568 __is_input_iterator<_InputIterator>::value
570 template <class _InputIterator>
571 forward_list(_InputIterator __f, _InputIterator __l,
572 const allocator_type& __a,
574 __is_input_iterator<_InputIterator>::value
576 forward_list(const forward_list& __x);
577 forward_list(const forward_list& __x, const allocator_type& __a);
578 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
579 _LIBCPP_INLINE_VISIBILITY
580 forward_list(forward_list&& __x)
581 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
582 : base(_VSTD::move(__x)) {}
583 forward_list(forward_list&& __x, const allocator_type& __a);
584 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
585 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
586 forward_list(initializer_list<value_type> __il);
587 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
588 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
590 // ~forward_list() = default;
592 forward_list& operator=(const forward_list& __x);
593 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
594 forward_list& operator=(forward_list&& __x)
596 __node_traits::propagate_on_container_move_assignment::value &&
597 is_nothrow_move_assignable<allocator_type>::value);
599 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
600 forward_list& operator=(initializer_list<value_type> __il);
601 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
603 template <class _InputIterator>
606 __is_input_iterator<_InputIterator>::value,
609 assign(_InputIterator __f, _InputIterator __l);
610 void assign(size_type __n, const value_type& __v);
611 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
612 void assign(initializer_list<value_type> __il);
613 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
615 _LIBCPP_INLINE_VISIBILITY
616 allocator_type get_allocator() const _NOEXCEPT
617 {return allocator_type(base::__alloc());}
619 _LIBCPP_INLINE_VISIBILITY
620 iterator begin() _NOEXCEPT
621 {return iterator(base::__before_begin()->__next_);}
622 _LIBCPP_INLINE_VISIBILITY
623 const_iterator begin() const _NOEXCEPT
624 {return const_iterator(base::__before_begin()->__next_);}
625 _LIBCPP_INLINE_VISIBILITY
626 iterator end() _NOEXCEPT
627 {return iterator(nullptr);}
628 _LIBCPP_INLINE_VISIBILITY
629 const_iterator end() const _NOEXCEPT
630 {return const_iterator(nullptr);}
632 _LIBCPP_INLINE_VISIBILITY
633 const_iterator cbegin() const _NOEXCEPT
634 {return const_iterator(base::__before_begin()->__next_);}
635 _LIBCPP_INLINE_VISIBILITY
636 const_iterator cend() const _NOEXCEPT
637 {return const_iterator(nullptr);}
639 _LIBCPP_INLINE_VISIBILITY
640 iterator before_begin() _NOEXCEPT
641 {return iterator(base::__before_begin());}
642 _LIBCPP_INLINE_VISIBILITY
643 const_iterator before_begin() const _NOEXCEPT
644 {return const_iterator(base::__before_begin());}
645 _LIBCPP_INLINE_VISIBILITY
646 const_iterator cbefore_begin() const _NOEXCEPT
647 {return const_iterator(base::__before_begin());}
649 _LIBCPP_INLINE_VISIBILITY
650 bool empty() const _NOEXCEPT
651 {return base::__before_begin()->__next_ == nullptr;}
652 _LIBCPP_INLINE_VISIBILITY
653 size_type max_size() const _NOEXCEPT
654 {return numeric_limits<size_type>::max();}
656 _LIBCPP_INLINE_VISIBILITY
657 reference front() {return base::__before_begin()->__next_->__value_;}
658 _LIBCPP_INLINE_VISIBILITY
659 const_reference front() const {return base::__before_begin()->__next_->__value_;}
661 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
662 #ifndef _LIBCPP_HAS_NO_VARIADICS
663 template <class... _Args> void emplace_front(_Args&&... __args);
665 void push_front(value_type&& __v);
666 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
667 void push_front(const value_type& __v);
671 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
672 #ifndef _LIBCPP_HAS_NO_VARIADICS
673 template <class... _Args>
674 iterator emplace_after(const_iterator __p, _Args&&... __args);
675 #endif // _LIBCPP_HAS_NO_VARIADICS
676 iterator insert_after(const_iterator __p, value_type&& __v);
677 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
678 iterator insert_after(const_iterator __p, const value_type& __v);
679 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
680 template <class _InputIterator>
681 _LIBCPP_INLINE_VISIBILITY
684 __is_input_iterator<_InputIterator>::value,
687 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
688 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
689 iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
690 {return insert_after(__p, __il.begin(), __il.end());}
691 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
693 iterator erase_after(const_iterator __p);
694 iterator erase_after(const_iterator __f, const_iterator __l);
696 _LIBCPP_INLINE_VISIBILITY
697 void swap(forward_list& __x)
698 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
699 __is_nothrow_swappable<__node_allocator>::value)
702 void resize(size_type __n);
703 void resize(size_type __n, const value_type& __v);
704 _LIBCPP_INLINE_VISIBILITY
705 void clear() _NOEXCEPT {base::clear();}
707 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
708 _LIBCPP_INLINE_VISIBILITY
709 void splice_after(const_iterator __p, forward_list&& __x);
710 _LIBCPP_INLINE_VISIBILITY
711 void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
712 _LIBCPP_INLINE_VISIBILITY
713 void splice_after(const_iterator __p, forward_list&& __x,
714 const_iterator __f, const_iterator __l);
715 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
716 void splice_after(const_iterator __p, forward_list& __x);
717 void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
718 void splice_after(const_iterator __p, forward_list& __x,
719 const_iterator __f, const_iterator __l);
720 void remove(const value_type& __v);
721 template <class _Predicate> void remove_if(_Predicate __pred);
722 _LIBCPP_INLINE_VISIBILITY
723 void unique() {unique(__equal_to<value_type>());}
724 template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
725 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
726 _LIBCPP_INLINE_VISIBILITY
727 void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
728 template <class _Compare>
729 _LIBCPP_INLINE_VISIBILITY
730 void merge(forward_list&& __x, _Compare __comp)
731 {merge(__x, _VSTD::move(__comp));}
732 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
733 _LIBCPP_INLINE_VISIBILITY
734 void merge(forward_list& __x) {merge(__x, __less<value_type>());}
735 template <class _Compare> void merge(forward_list& __x, _Compare __comp);
736 _LIBCPP_INLINE_VISIBILITY
737 void sort() {sort(__less<value_type>());}
738 template <class _Compare> void sort(_Compare __comp);
739 void reverse() _NOEXCEPT;
743 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
744 void __move_assign(forward_list& __x, true_type)
745 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
746 void __move_assign(forward_list& __x, false_type);
747 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
749 template <class _Compare>
752 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
754 template <class _Compare>
757 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
760 template <class _Tp, class _Alloc>
761 inline _LIBCPP_INLINE_VISIBILITY
762 forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
767 template <class _Tp, class _Alloc>
768 forward_list<_Tp, _Alloc>::forward_list(size_type __n)
772 __node_allocator& __a = base::__alloc();
773 typedef __allocator_destructor<__node_allocator> _D;
774 unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
775 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
778 __h.reset(__node_traits::allocate(__a, 1));
779 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
780 __h->__next_ = nullptr;
781 __p->__next_ = __h.release();
786 template <class _Tp, class _Alloc>
787 forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
789 insert_after(cbefore_begin(), __n, __v);
792 template <class _Tp, class _Alloc>
793 forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
794 const allocator_type& __a)
797 insert_after(cbefore_begin(), __n, __v);
800 template <class _Tp, class _Alloc>
801 template <class _InputIterator>
802 forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
804 __is_input_iterator<_InputIterator>::value
807 insert_after(cbefore_begin(), __f, __l);
810 template <class _Tp, class _Alloc>
811 template <class _InputIterator>
812 forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
813 const allocator_type& __a,
815 __is_input_iterator<_InputIterator>::value
819 insert_after(cbefore_begin(), __f, __l);
822 template <class _Tp, class _Alloc>
823 forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
824 : base(allocator_type(
825 __node_traits::select_on_container_copy_construction(__x.__alloc())
829 insert_after(cbefore_begin(), __x.begin(), __x.end());
832 template <class _Tp, class _Alloc>
833 forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
834 const allocator_type& __a)
837 insert_after(cbefore_begin(), __x.begin(), __x.end());
840 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
842 template <class _Tp, class _Alloc>
843 forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
844 const allocator_type& __a)
845 : base(_VSTD::move(__x), __a)
847 if (base::__alloc() != __x.__alloc())
849 typedef move_iterator<iterator> _I;
850 insert_after(cbefore_begin(), _I(__x.begin()), _I(__x.end()));
854 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
856 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
858 template <class _Tp, class _Alloc>
859 forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
861 insert_after(cbefore_begin(), __il.begin(), __il.end());
864 template <class _Tp, class _Alloc>
865 forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
866 const allocator_type& __a)
869 insert_after(cbefore_begin(), __il.begin(), __il.end());
872 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
874 template <class _Tp, class _Alloc>
875 forward_list<_Tp, _Alloc>&
876 forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
880 base::__copy_assign_alloc(__x);
881 assign(__x.begin(), __x.end());
886 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
888 template <class _Tp, class _Alloc>
890 forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
891 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
894 base::__move_assign_alloc(__x);
895 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
896 __x.__before_begin()->__next_ = nullptr;
899 template <class _Tp, class _Alloc>
901 forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
903 if (base::__alloc() == __x.__alloc())
904 __move_assign(__x, true_type());
907 typedef move_iterator<iterator> _I;
908 assign(_I(__x.begin()), _I(__x.end()));
912 template <class _Tp, class _Alloc>
913 inline _LIBCPP_INLINE_VISIBILITY
914 forward_list<_Tp, _Alloc>&
915 forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
917 __node_traits::propagate_on_container_move_assignment::value &&
918 is_nothrow_move_assignable<allocator_type>::value)
920 __move_assign(__x, integral_constant<bool,
921 __node_traits::propagate_on_container_move_assignment::value>());
925 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
927 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
929 template <class _Tp, class _Alloc>
930 inline _LIBCPP_INLINE_VISIBILITY
931 forward_list<_Tp, _Alloc>&
932 forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
934 assign(__il.begin(), __il.end());
938 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
940 template <class _Tp, class _Alloc>
941 template <class _InputIterator>
944 __is_input_iterator<_InputIterator>::value,
947 forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
949 iterator __i = before_begin();
950 iterator __j = _VSTD::next(__i);
951 iterator __e = end();
952 for (; __j != __e && __f != __l; ++__i, ++__j, ++__f)
955 insert_after(__i, __f, __l);
957 erase_after(__i, __e);
960 template <class _Tp, class _Alloc>
962 forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
964 iterator __i = before_begin();
965 iterator __j = _VSTD::next(__i);
966 iterator __e = end();
967 for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
970 insert_after(__i, __n, __v);
972 erase_after(__i, __e);
975 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
977 template <class _Tp, class _Alloc>
978 inline _LIBCPP_INLINE_VISIBILITY
980 forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
982 assign(__il.begin(), __il.end());
985 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
987 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
988 #ifndef _LIBCPP_HAS_NO_VARIADICS
990 template <class _Tp, class _Alloc>
991 template <class... _Args>
993 forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
995 __node_allocator& __a = base::__alloc();
996 typedef __allocator_destructor<__node_allocator> _D;
997 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
998 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
999 _VSTD::forward<_Args>(__args)...);
1000 __h->__next_ = base::__before_begin()->__next_;
1001 base::__before_begin()->__next_ = __h.release();
1004 #endif // _LIBCPP_HAS_NO_VARIADICS
1006 template <class _Tp, class _Alloc>
1008 forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
1010 __node_allocator& __a = base::__alloc();
1011 typedef __allocator_destructor<__node_allocator> _D;
1012 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1013 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
1014 __h->__next_ = base::__before_begin()->__next_;
1015 base::__before_begin()->__next_ = __h.release();
1018 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1020 template <class _Tp, class _Alloc>
1022 forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
1024 __node_allocator& __a = base::__alloc();
1025 typedef __allocator_destructor<__node_allocator> _D;
1026 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1027 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
1028 __h->__next_ = base::__before_begin()->__next_;
1029 base::__before_begin()->__next_ = __h.release();
1032 template <class _Tp, class _Alloc>
1034 forward_list<_Tp, _Alloc>::pop_front()
1036 __node_allocator& __a = base::__alloc();
1037 __node_pointer __p = base::__before_begin()->__next_;
1038 base::__before_begin()->__next_ = __p->__next_;
1039 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
1040 __node_traits::deallocate(__a, __p, 1);
1043 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1044 #ifndef _LIBCPP_HAS_NO_VARIADICS
1046 template <class _Tp, class _Alloc>
1047 template <class... _Args>
1048 typename forward_list<_Tp, _Alloc>::iterator
1049 forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
1051 __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
1052 __node_allocator& __a = base::__alloc();
1053 typedef __allocator_destructor<__node_allocator> _D;
1054 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1055 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1056 _VSTD::forward<_Args>(__args)...);
1057 __h->__next_ = __r->__next_;
1058 __r->__next_ = __h.release();
1059 return iterator(__r->__next_);
1062 #endif // _LIBCPP_HAS_NO_VARIADICS
1064 template <class _Tp, class _Alloc>
1065 typename forward_list<_Tp, _Alloc>::iterator
1066 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
1068 __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
1069 __node_allocator& __a = base::__alloc();
1070 typedef __allocator_destructor<__node_allocator> _D;
1071 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1072 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
1073 __h->__next_ = __r->__next_;
1074 __r->__next_ = __h.release();
1075 return iterator(__r->__next_);
1078 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1080 template <class _Tp, class _Alloc>
1081 typename forward_list<_Tp, _Alloc>::iterator
1082 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
1084 __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
1085 __node_allocator& __a = base::__alloc();
1086 typedef __allocator_destructor<__node_allocator> _D;
1087 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1088 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
1089 __h->__next_ = __r->__next_;
1090 __r->__next_ = __h.release();
1091 return iterator(__r->__next_);
1094 template <class _Tp, class _Alloc>
1095 typename forward_list<_Tp, _Alloc>::iterator
1096 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
1097 const value_type& __v)
1099 __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
1102 __node_allocator& __a = base::__alloc();
1103 typedef __allocator_destructor<__node_allocator> _D;
1104 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1105 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
1106 __node_pointer __first = __h.release();
1107 __node_pointer __last = __first;
1108 #ifndef _LIBCPP_NO_EXCEPTIONS
1111 #endif // _LIBCPP_NO_EXCEPTIONS
1112 for (--__n; __n != 0; --__n, __last = __last->__next_)
1114 __h.reset(__node_traits::allocate(__a, 1));
1115 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
1116 __last->__next_ = __h.release();
1118 #ifndef _LIBCPP_NO_EXCEPTIONS
1122 while (__first != nullptr)
1124 __node_pointer __next = __first->__next_;
1125 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
1126 __node_traits::deallocate(__a, __first, 1);
1131 #endif // _LIBCPP_NO_EXCEPTIONS
1132 __last->__next_ = __r->__next_;
1133 __r->__next_ = __first;
1136 return iterator(__r);
1139 template <class _Tp, class _Alloc>
1140 template <class _InputIterator>
1143 __is_input_iterator<_InputIterator>::value,
1144 typename forward_list<_Tp, _Alloc>::iterator
1146 forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
1147 _InputIterator __f, _InputIterator __l)
1149 __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
1152 __node_allocator& __a = base::__alloc();
1153 typedef __allocator_destructor<__node_allocator> _D;
1154 unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1));
1155 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
1156 __node_pointer __first = __h.release();
1157 __node_pointer __last = __first;
1158 #ifndef _LIBCPP_NO_EXCEPTIONS
1161 #endif // _LIBCPP_NO_EXCEPTIONS
1162 for (++__f; __f != __l; ++__f, __last = __last->__next_)
1164 __h.reset(__node_traits::allocate(__a, 1));
1165 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
1166 __last->__next_ = __h.release();
1168 #ifndef _LIBCPP_NO_EXCEPTIONS
1172 while (__first != nullptr)
1174 __node_pointer __next = __first->__next_;
1175 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
1176 __node_traits::deallocate(__a, __first, 1);
1181 #endif // _LIBCPP_NO_EXCEPTIONS
1182 __last->__next_ = __r->__next_;
1183 __r->__next_ = __first;
1186 return iterator(__r);
1189 template <class _Tp, class _Alloc>
1190 typename forward_list<_Tp, _Alloc>::iterator
1191 forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
1193 __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
1194 __node_pointer __n = __p->__next_;
1195 __p->__next_ = __n->__next_;
1196 __node_allocator& __a = base::__alloc();
1197 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
1198 __node_traits::deallocate(__a, __n, 1);
1199 return iterator(__p->__next_);
1202 template <class _Tp, class _Alloc>
1203 typename forward_list<_Tp, _Alloc>::iterator
1204 forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
1206 __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
1209 __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
1210 __node_pointer __n = __p->__next_;
1214 __node_allocator& __a = base::__alloc();
1218 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
1219 __node_traits::deallocate(__a, __n, 1);
1221 } while (__n != __e);
1224 return iterator(__e);
1227 template <class _Tp, class _Alloc>
1229 forward_list<_Tp, _Alloc>::resize(size_type __n)
1232 iterator __p = before_begin();
1233 iterator __i = begin();
1234 iterator __e = end();
1235 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1238 erase_after(__p, __e);
1244 __node_allocator& __a = base::__alloc();
1245 typedef __allocator_destructor<__node_allocator> _D;
1246 unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
1247 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1248 __ptr = __ptr->__next_)
1250 __h.reset(__node_traits::allocate(__a, 1));
1251 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
1252 __h->__next_ = nullptr;
1253 __ptr->__next_ = __h.release();
1259 template <class _Tp, class _Alloc>
1261 forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
1264 iterator __p = before_begin();
1265 iterator __i = begin();
1266 iterator __e = end();
1267 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1270 erase_after(__p, __e);
1276 __node_allocator& __a = base::__alloc();
1277 typedef __allocator_destructor<__node_allocator> _D;
1278 unique_ptr<__node, _D> __h(nullptr, _D(__a, 1));
1279 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1280 __ptr = __ptr->__next_)
1282 __h.reset(__node_traits::allocate(__a, 1));
1283 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
1284 __h->__next_ = nullptr;
1285 __ptr->__next_ = __h.release();
1291 template <class _Tp, class _Alloc>
1293 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1298 if (__p.__ptr_->__next_ != nullptr)
1300 const_iterator __lm1 = __x.before_begin();
1301 while (__lm1.__ptr_->__next_ != nullptr)
1303 const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
1304 const_cast<__node_pointer>(__p.__ptr_)->__next_;
1306 const_cast<__node_pointer>(__p.__ptr_)->__next_ =
1307 const_cast<__node_pointer>(__x.__before_begin())->__next_;
1308 const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr;
1312 template <class _Tp, class _Alloc>
1314 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1318 const_iterator __lm1 = _VSTD::next(__i);
1319 if (__p != __i && __p != __lm1)
1321 const_cast<__node_pointer>(__i.__ptr_)->__next_ =
1322 const_cast<__node_pointer>(__lm1.__ptr_)->__next_;
1323 const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
1324 const_cast<__node_pointer>(__p.__ptr_)->__next_;
1325 const_cast<__node_pointer>(__p.__ptr_)->__next_ =
1326 const_cast<__node_pointer>(__lm1.__ptr_);
1330 template <class _Tp, class _Alloc>
1332 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1334 const_iterator __f, const_iterator __l)
1336 if (__f != __l && __p != __f)
1338 const_iterator __lm1 = __f;
1339 while (__lm1.__ptr_->__next_ != __l.__ptr_)
1343 const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
1344 const_cast<__node_pointer>(__p.__ptr_)->__next_;
1345 const_cast<__node_pointer>(__p.__ptr_)->__next_ =
1346 const_cast<__node_pointer>(__f.__ptr_)->__next_;
1347 const_cast<__node_pointer>(__f.__ptr_)->__next_ =
1348 const_cast<__node_pointer>(__l.__ptr_);
1353 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1355 template <class _Tp, class _Alloc>
1356 inline _LIBCPP_INLINE_VISIBILITY
1358 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1361 splice_after(__p, __x);
1364 template <class _Tp, class _Alloc>
1365 inline _LIBCPP_INLINE_VISIBILITY
1367 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1371 splice_after(__p, __x, __i);
1374 template <class _Tp, class _Alloc>
1375 inline _LIBCPP_INLINE_VISIBILITY
1377 forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1379 const_iterator __f, const_iterator __l)
1381 splice_after(__p, __x, __f, __l);
1384 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1386 template <class _Tp, class _Alloc>
1388 forward_list<_Tp, _Alloc>::remove(const value_type& __v)
1390 iterator __e = end();
1391 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1393 if (__i.__ptr_->__next_->__value_ == __v)
1395 iterator __j = _VSTD::next(__i, 2);
1396 for (; __j != __e && *__j == __v; ++__j)
1398 erase_after(__i, __j);
1408 template <class _Tp, class _Alloc>
1409 template <class _Predicate>
1411 forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
1413 iterator __e = end();
1414 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1416 if (__pred(__i.__ptr_->__next_->__value_))
1418 iterator __j = _VSTD::next(__i, 2);
1419 for (; __j != __e && __pred(*__j); ++__j)
1421 erase_after(__i, __j);
1431 template <class _Tp, class _Alloc>
1432 template <class _BinaryPredicate>
1434 forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
1436 for (iterator __i = begin(), __e = end(); __i != __e;)
1438 iterator __j = _VSTD::next(__i);
1439 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1441 if (__i.__ptr_->__next_ != __j.__ptr_)
1442 erase_after(__i, __j);
1447 template <class _Tp, class _Alloc>
1448 template <class _Compare>
1450 forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
1454 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
1455 __x.__before_begin()->__next_,
1457 __x.__before_begin()->__next_ = nullptr;
1461 template <class _Tp, class _Alloc>
1462 template <class _Compare>
1463 typename forward_list<_Tp, _Alloc>::__node_pointer
1464 forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
1467 if (__f1 == nullptr)
1469 if (__f2 == nullptr)
1472 if (__comp(__f2->__value_, __f1->__value_))
1474 __node_pointer __t = __f2;
1475 while (__t->__next_ != nullptr &&
1476 __comp(__t->__next_->__value_, __f1->__value_))
1479 __f2 = __t->__next_;
1480 __t->__next_ = __f1;
1484 __node_pointer __p = __f1;
1485 __f1 = __f1->__next_;
1486 while (__f1 != nullptr && __f2 != nullptr)
1488 if (__comp(__f2->__value_, __f1->__value_))
1490 __node_pointer __t = __f2;
1491 while (__t->__next_ != nullptr &&
1492 __comp(__t->__next_->__value_, __f1->__value_))
1494 __p->__next_ = __f2;
1495 __f2 = __t->__next_;
1496 __t->__next_ = __f1;
1499 __f1 = __f1->__next_;
1501 if (__f2 != nullptr)
1502 __p->__next_ = __f2;
1506 template <class _Tp, class _Alloc>
1507 template <class _Compare>
1508 inline _LIBCPP_INLINE_VISIBILITY
1510 forward_list<_Tp, _Alloc>::sort(_Compare __comp)
1512 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
1513 _VSTD::distance(begin(), end()), __comp);
1516 template <class _Tp, class _Alloc>
1517 template <class _Compare>
1518 typename forward_list<_Tp, _Alloc>::__node_pointer
1519 forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
1528 if (__comp(__f1->__next_->__value_, __f1->__value_))
1530 __node_pointer __t = __f1->__next_;
1531 __t->__next_ = __f1;
1532 __f1->__next_ = nullptr;
1537 difference_type __sz1 = __sz / 2;
1538 difference_type __sz2 = __sz - __sz1;
1539 __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
1540 __node_pointer __f2 = __t->__next_;
1541 __t->__next_ = nullptr;
1542 return __merge(__sort(__f1, __sz1, __comp),
1543 __sort(__f2, __sz2, __comp), __comp);
1546 template <class _Tp, class _Alloc>
1548 forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
1550 __node_pointer __p = base::__before_begin()->__next_;
1553 __node_pointer __f = __p->__next_;
1554 __p->__next_ = nullptr;
1555 while (__f != nullptr)
1557 __node_pointer __t = __f->__next_;
1562 base::__before_begin()->__next_ = __p;
1566 template <class _Tp, class _Alloc>
1567 bool operator==(const forward_list<_Tp, _Alloc>& __x,
1568 const forward_list<_Tp, _Alloc>& __y)
1570 typedef forward_list<_Tp, _Alloc> _C;
1571 typedef typename _C::const_iterator _I;
1572 _I __ix = __x.begin();
1573 _I __ex = __x.end();
1574 _I __iy = __y.begin();
1575 _I __ey = __y.end();
1576 for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
1577 if (!(*__ix == *__iy))
1579 return (__ix == __ex) == (__iy == __ey);
1582 template <class _Tp, class _Alloc>
1583 inline _LIBCPP_INLINE_VISIBILITY
1584 bool operator!=(const forward_list<_Tp, _Alloc>& __x,
1585 const forward_list<_Tp, _Alloc>& __y)
1587 return !(__x == __y);
1590 template <class _Tp, class _Alloc>
1591 inline _LIBCPP_INLINE_VISIBILITY
1592 bool operator< (const forward_list<_Tp, _Alloc>& __x,
1593 const forward_list<_Tp, _Alloc>& __y)
1595 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
1596 __y.begin(), __y.end());
1599 template <class _Tp, class _Alloc>
1600 inline _LIBCPP_INLINE_VISIBILITY
1601 bool operator> (const forward_list<_Tp, _Alloc>& __x,
1602 const forward_list<_Tp, _Alloc>& __y)
1607 template <class _Tp, class _Alloc>
1608 inline _LIBCPP_INLINE_VISIBILITY
1609 bool operator>=(const forward_list<_Tp, _Alloc>& __x,
1610 const forward_list<_Tp, _Alloc>& __y)
1612 return !(__x < __y);
1615 template <class _Tp, class _Alloc>
1616 inline _LIBCPP_INLINE_VISIBILITY
1617 bool operator<=(const forward_list<_Tp, _Alloc>& __x,
1618 const forward_list<_Tp, _Alloc>& __y)
1620 return !(__y < __x);
1623 template <class _Tp, class _Alloc>
1624 inline _LIBCPP_INLINE_VISIBILITY
1626 swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
1627 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1632 _LIBCPP_END_NAMESPACE_STD
1634 #endif // _LIBCPP_FORWARD_LIST