blob: adbc32cf861c9764a955408011a77dd7c54c3540 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------- forward_list ---------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FORWARD_LIST
12#define _LIBCPP_FORWARD_LIST
13
14/*
15 forward_list synopsis
16
17namespace std
18{
19
20template <class T, class Allocator = allocator<T>>
21class forward_list
22{
23public:
24 typedef T value_type;
25 typedef Allocator allocator_type;
26
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;
33
34 typedef <details> iterator;
35 typedef <details> const_iterator;
36
Howard Hinnant91a47502011-06-03 16:20:53 +000037 forward_list()
38 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000039 explicit forward_list(const allocator_type& a);
40 explicit forward_list(size_type n);
Marshall Clowf1b6d1b2013-09-09 18:19:45 +000041 explicit forward_list(size_type n, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000042 forward_list(size_type n, const value_type& v);
43 forward_list(size_type n, const value_type& v, const allocator_type& a);
44 template <class InputIterator>
45 forward_list(InputIterator first, InputIterator last);
46 template <class InputIterator>
47 forward_list(InputIterator first, InputIterator last, const allocator_type& a);
48 forward_list(const forward_list& x);
49 forward_list(const forward_list& x, const allocator_type& a);
Howard Hinnant91a47502011-06-03 16:20:53 +000050 forward_list(forward_list&& x)
51 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000052 forward_list(forward_list&& x, const allocator_type& a);
53 forward_list(initializer_list<value_type> il);
54 forward_list(initializer_list<value_type> il, const allocator_type& a);
55
56 ~forward_list();
57
58 forward_list& operator=(const forward_list& x);
Howard Hinnant91a47502011-06-03 16:20:53 +000059 forward_list& operator=(forward_list&& x)
60 noexcept(
61 allocator_type::propagate_on_container_move_assignment::value &&
62 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000063 forward_list& operator=(initializer_list<value_type> il);
64
65 template <class InputIterator>
66 void assign(InputIterator first, InputIterator last);
67 void assign(size_type n, const value_type& v);
68 void assign(initializer_list<value_type> il);
69
Howard Hinnantf9dc2832011-06-02 16:44:28 +000070 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000071
Howard Hinnantf9dc2832011-06-02 16:44:28 +000072 iterator begin() noexcept;
73 const_iterator begin() const noexcept;
74 iterator end() noexcept;
75 const_iterator end() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000076
Howard Hinnantf9dc2832011-06-02 16:44:28 +000077 const_iterator cbegin() const noexcept;
78 const_iterator cend() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000079
Howard Hinnantf9dc2832011-06-02 16:44:28 +000080 iterator before_begin() noexcept;
81 const_iterator before_begin() const noexcept;
82 const_iterator cbefore_begin() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000083
Howard Hinnantf9dc2832011-06-02 16:44:28 +000084 bool empty() const noexcept;
85 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000086
87 reference front();
88 const_reference front() const;
89
90 template <class... Args> void emplace_front(Args&&... args);
91 void push_front(const value_type& v);
92 void push_front(value_type&& v);
93
94 void pop_front();
95
96 template <class... Args>
97 iterator emplace_after(const_iterator p, Args&&... args);
98 iterator insert_after(const_iterator p, const value_type& v);
99 iterator insert_after(const_iterator p, value_type&& v);
100 iterator insert_after(const_iterator p, size_type n, const value_type& v);
101 template <class InputIterator>
102 iterator insert_after(const_iterator p,
103 InputIterator first, InputIterator last);
104 iterator insert_after(const_iterator p, initializer_list<value_type> il);
105
Howard Hinnant3db88032010-08-21 20:58:44 +0000106 iterator erase_after(const_iterator p);
107 iterator erase_after(const_iterator first, const_iterator last);
Howard Hinnant3e519522010-05-11 19:42:16 +0000108
Howard Hinnant91a47502011-06-03 16:20:53 +0000109 void swap(forward_list& x)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000110 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnant3e519522010-05-11 19:42:16 +0000111
112 void resize(size_type n);
113 void resize(size_type n, const value_type& v);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000114 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000115
Howard Hinnanteb92df72011-01-27 21:00:35 +0000116 void splice_after(const_iterator p, forward_list& x);
Howard Hinnant3e519522010-05-11 19:42:16 +0000117 void splice_after(const_iterator p, forward_list&& x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000118 void splice_after(const_iterator p, forward_list& x, const_iterator i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000119 void splice_after(const_iterator p, forward_list&& x, const_iterator i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000120 void splice_after(const_iterator p, forward_list& x,
121 const_iterator first, const_iterator last);
Howard Hinnant3e519522010-05-11 19:42:16 +0000122 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);
126 void unique();
127 template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000128 void merge(forward_list& x);
Howard Hinnant3e519522010-05-11 19:42:16 +0000129 void merge(forward_list&& x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000130 template <class Compare> void merge(forward_list& x, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16 +0000131 template <class Compare> void merge(forward_list&& x, Compare comp);
132 void sort();
133 template <class Compare> void sort(Compare comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000134 void reverse() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000135};
136
137template <class T, class Allocator>
138 bool operator==(const forward_list<T, Allocator>& x,
139 const forward_list<T, Allocator>& y);
140
141template <class T, class Allocator>
142 bool operator< (const forward_list<T, Allocator>& x,
143 const forward_list<T, Allocator>& y);
144
145template <class T, class Allocator>
146 bool operator!=(const forward_list<T, Allocator>& x,
147 const forward_list<T, Allocator>& y);
148
149template <class T, class Allocator>
150 bool operator> (const forward_list<T, Allocator>& x,
151 const forward_list<T, Allocator>& y);
152
153template <class T, class Allocator>
154 bool operator>=(const forward_list<T, Allocator>& x,
155 const forward_list<T, Allocator>& y);
156
157template <class T, class Allocator>
158 bool operator<=(const forward_list<T, Allocator>& x,
159 const forward_list<T, Allocator>& y);
160
161template <class T, class Allocator>
Howard Hinnant91a47502011-06-03 16:20:53 +0000162 void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
Howard Hinnant45900102011-06-03 17:30:28 +0000163 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000164
165} // std
166
167*/
168
169#include <__config>
170
171#include <initializer_list>
172#include <memory>
173#include <limits>
174#include <iterator>
175#include <algorithm>
176
Howard Hinnantab4f4382011-11-29 16:45:27 +0000177#include <__undef_min_max>
178
Howard Hinnant073458b2011-10-17 20:05:10 +0000179#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000180#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000181#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000182
183_LIBCPP_BEGIN_NAMESPACE_STD
184
Howard Hinnantce534202011-06-14 19:58:17 +0000185template <class _Tp, class _VoidPtr> struct __forward_list_node;
Howard Hinnant3e519522010-05-11 19:42:16 +0000186
187template <class _NodePtr>
188struct __forward_begin_node
189{
Howard Hinnant3e519522010-05-11 19:42:16 +0000190 typedef _NodePtr pointer;
191
192 pointer __next_;
193
Howard Hinnant0af133f2010-09-21 22:55:27 +0000194 _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000195};
196
197template <class _Tp, class _VoidPtr>
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000198struct _LIBCPP_HIDDEN __begin_node_of
199{
200 typedef __forward_begin_node
201 <
202 typename pointer_traits<_VoidPtr>::template
Howard Hinnant3e519522010-05-11 19:42:16 +0000203#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000204 rebind<__forward_list_node<_Tp, _VoidPtr> >
Howard Hinnant3e519522010-05-11 19:42:16 +0000205#else
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000206 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
Howard Hinnant3e519522010-05-11 19:42:16 +0000207#endif
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000208 > type;
209};
210
211template <class _Tp, class _VoidPtr>
212struct __forward_list_node
213 : public __begin_node_of<_Tp, _VoidPtr>::type
Howard Hinnant3e519522010-05-11 19:42:16 +0000214{
215 typedef _Tp value_type;
216
217 value_type __value_;
218};
219
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000220template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY forward_list;
Howard Hinnantf0544c22013-08-12 18:38:34 +0000221template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000222
223template <class _NodePtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000224class _LIBCPP_TYPE_VIS_ONLY __forward_list_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000225{
226 typedef _NodePtr __node_pointer;
227
228 __node_pointer __ptr_;
229
Howard Hinnant0af133f2010-09-21 22:55:27 +0000230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000231 explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000232
Howard Hinnantf0544c22013-08-12 18:38:34 +0000233 template<class, class> friend class _LIBCPP_TYPE_VIS_ONLY forward_list;
234 template<class> friend class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000235
236public:
237 typedef forward_iterator_tag iterator_category;
238 typedef typename pointer_traits<__node_pointer>::element_type::value_type
239 value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000240 typedef value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000241 typedef typename pointer_traits<__node_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000242 difference_type;
243 typedef typename pointer_traits<__node_pointer>::template
244#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
245 rebind<value_type>
246#else
247 rebind<value_type>::other
248#endif
249 pointer;
250
Howard Hinnant0af133f2010-09-21 22:55:27 +0000251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000252 __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000253
Howard Hinnant0af133f2010-09-21 22:55:27 +0000254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000255 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000257 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000258
Howard Hinnant0af133f2010-09-21 22:55:27 +0000259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000260 __forward_list_iterator& operator++()
261 {
262 __ptr_ = __ptr_->__next_;
263 return *this;
264 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000266 __forward_list_iterator operator++(int)
267 {
268 __forward_list_iterator __t(*this);
269 ++(*this);
270 return __t;
271 }
272
Howard Hinnant0af133f2010-09-21 22:55:27 +0000273 friend _LIBCPP_INLINE_VISIBILITY
274 bool operator==(const __forward_list_iterator& __x,
275 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000276 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000277 friend _LIBCPP_INLINE_VISIBILITY
278 bool operator!=(const __forward_list_iterator& __x,
279 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000280 {return !(__x == __y);}
281};
282
283template <class _NodeConstPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000284class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000285{
286 typedef _NodeConstPtr __node_const_pointer;
287
288 __node_const_pointer __ptr_;
289
Howard Hinnant0af133f2010-09-21 22:55:27 +0000290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000291 explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000292 : __ptr_(__p) {}
293
294 typedef typename remove_const
295 <
296 typename pointer_traits<__node_const_pointer>::element_type
297 >::type __node;
298 typedef typename pointer_traits<__node_const_pointer>::template
299#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
300 rebind<__node>
301#else
302 rebind<__node>::other
303#endif
304 __node_pointer;
305
306 template<class, class> friend class forward_list;
307
308public:
309 typedef forward_iterator_tag iterator_category;
310 typedef typename __node::value_type value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000311 typedef const value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000312 typedef typename pointer_traits<__node_const_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000313 difference_type;
314 typedef typename pointer_traits<__node_const_pointer>::template
315#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
316 rebind<const value_type>
317#else
318 rebind<const value_type>::other
319#endif
320 pointer;
321
Howard Hinnant0af133f2010-09-21 22:55:27 +0000322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000323 __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000325 __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000326 : __ptr_(__p.__ptr_) {}
327
Howard Hinnant0af133f2010-09-21 22:55:27 +0000328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000329 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000331 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000332
Howard Hinnant0af133f2010-09-21 22:55:27 +0000333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000334 __forward_list_const_iterator& operator++()
335 {
336 __ptr_ = __ptr_->__next_;
337 return *this;
338 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000340 __forward_list_const_iterator operator++(int)
341 {
342 __forward_list_const_iterator __t(*this);
343 ++(*this);
344 return __t;
345 }
346
Howard Hinnant0af133f2010-09-21 22:55:27 +0000347 friend _LIBCPP_INLINE_VISIBILITY
348 bool operator==(const __forward_list_const_iterator& __x,
349 const __forward_list_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000350 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000351 friend _LIBCPP_INLINE_VISIBILITY
352 bool operator!=(const __forward_list_const_iterator& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +0000353 const __forward_list_const_iterator& __y)
354 {return !(__x == __y);}
355};
356
357template <class _Tp, class _Alloc>
358class __forward_list_base
359{
360protected:
361 typedef _Tp value_type;
362 typedef _Alloc allocator_type;
363
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000364 typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
365 typedef __forward_list_node<value_type, void_pointer> __node;
366 typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
Marshall Clow1f508012015-04-07 05:21:38 +0000367 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000368 typedef allocator_traits<__node_allocator> __node_traits;
369 typedef typename __node_traits::pointer __node_pointer;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000370 typedef typename __node_traits::pointer __node_const_pointer;
371
Marshall Clow1f508012015-04-07 05:21:38 +0000372 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __begin_node>::type __begin_node_allocator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000373 typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000374
375 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
376
Howard Hinnant0af133f2010-09-21 22:55:27 +0000377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000378 __node_pointer __before_begin() _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000379 {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
380 pointer_to(__before_begin_.first()));}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000382 __node_const_pointer __before_begin() const _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000383 {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
384 pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
Howard Hinnant3e519522010-05-11 19:42:16 +0000385
Howard Hinnant0af133f2010-09-21 22:55:27 +0000386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000387 __node_allocator& __alloc() _NOEXCEPT
388 {return __before_begin_.second();}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000390 const __node_allocator& __alloc() const _NOEXCEPT
391 {return __before_begin_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000392
393 typedef __forward_list_iterator<__node_pointer> iterator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000394 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000395
Howard Hinnant0af133f2010-09-21 22:55:27 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000397 __forward_list_base()
Howard Hinnant91a47502011-06-03 16:20:53 +0000398 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000399 : __before_begin_(__begin_node()) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000401 __forward_list_base(const allocator_type& __a)
402 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
403
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000404#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000405public:
406 __forward_list_base(__forward_list_base&& __x)
407 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000408 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000409#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000410
411private:
412 __forward_list_base(const __forward_list_base&);
413 __forward_list_base& operator=(const __forward_list_base&);
Howard Hinnant3e519522010-05-11 19:42:16 +0000414
Howard Hinnant91a47502011-06-03 16:20:53 +0000415public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000416 ~__forward_list_base();
417
Howard Hinnant91a47502011-06-03 16:20:53 +0000418protected:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000420 void __copy_assign_alloc(const __forward_list_base& __x)
421 {__copy_assign_alloc(__x, integral_constant<bool,
422 __node_traits::propagate_on_container_copy_assignment::value>());}
423
Howard Hinnant0af133f2010-09-21 22:55:27 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000425 void __move_assign_alloc(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000426 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
427 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000428 {__move_assign_alloc(__x, integral_constant<bool,
429 __node_traits::propagate_on_container_move_assignment::value>());}
430
Howard Hinnant91a47502011-06-03 16:20:53 +0000431public:
432 void swap(__forward_list_base& __x)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000433#if _LIBCPP_STD_VER >= 14
434 _NOEXCEPT;
435#else
436 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
437 __is_nothrow_swappable<__node_allocator>::value);
438#endif
Howard Hinnant91a47502011-06-03 16:20:53 +0000439protected:
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000440 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000441
442private:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000444 void __copy_assign_alloc(const __forward_list_base&, false_type) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000446 void __copy_assign_alloc(const __forward_list_base& __x, true_type)
447 {
448 if (__alloc() != __x.__alloc())
449 clear();
450 __alloc() = __x.__alloc();
451 }
452
Howard Hinnant0af133f2010-09-21 22:55:27 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000454 void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT
455 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000457 void __move_assign_alloc(__forward_list_base& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000458 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000459 {__alloc() = _VSTD::move(__x.__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000460};
461
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000462#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000463
464template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000466__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000467 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000468 : __before_begin_(_VSTD::move(__x.__before_begin_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000469{
470 __x.__before_begin()->__next_ = nullptr;
471}
472
473template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000475__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
476 const allocator_type& __a)
477 : __before_begin_(__begin_node(), __node_allocator(__a))
478{
479 if (__alloc() == __x.__alloc())
480 {
481 __before_begin()->__next_ = __x.__before_begin()->__next_;
482 __x.__before_begin()->__next_ = nullptr;
483 }
484}
485
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000486#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000487
488template <class _Tp, class _Alloc>
489__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
490{
491 clear();
492}
493
494template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000496void
497__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000498#if _LIBCPP_STD_VER >= 14
499 _NOEXCEPT
500#else
501 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
502 __is_nothrow_swappable<__node_allocator>::value)
503#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000504{
Marshall Clowe3fbe142015-07-13 20:04:56 +0000505 __swap_allocator(__alloc(), __x.__alloc(),
506 integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
Howard Hinnantce48a112011-06-30 21:18:19 +0000507 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000508 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
509}
510
511template <class _Tp, class _Alloc>
512void
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000513__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000514{
515 __node_allocator& __a = __alloc();
516 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
517 {
518 __node_pointer __next = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +0000519 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000520 __node_traits::deallocate(__a, __p, 1);
521 __p = __next;
522 }
523 __before_begin()->__next_ = nullptr;
524}
525
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000526template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000527class _LIBCPP_TYPE_VIS_ONLY forward_list
Howard Hinnant3e519522010-05-11 19:42:16 +0000528 : private __forward_list_base<_Tp, _Alloc>
529{
530 typedef __forward_list_base<_Tp, _Alloc> base;
Howard Hinnant91a47502011-06-03 16:20:53 +0000531 typedef typename base::__node_allocator __node_allocator;
532 typedef typename base::__node __node;
533 typedef typename base::__node_traits __node_traits;
534 typedef typename base::__node_pointer __node_pointer;
535
Howard Hinnant3e519522010-05-11 19:42:16 +0000536public:
537 typedef _Tp value_type;
538 typedef _Alloc allocator_type;
539
Marshall Clow94f89ae2015-11-26 01:24:04 +0000540 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
541 "Allocator::value_type must be same type as value_type");
542
Howard Hinnant3e519522010-05-11 19:42:16 +0000543 typedef value_type& reference;
544 typedef const value_type& const_reference;
545 typedef typename allocator_traits<allocator_type>::pointer pointer;
546 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
547 typedef typename allocator_traits<allocator_type>::size_type size_type;
548 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
549
550 typedef typename base::iterator iterator;
551 typedef typename base::const_iterator const_iterator;
552
Howard Hinnant91a47502011-06-03 16:20:53 +0000553 _LIBCPP_INLINE_VISIBILITY
554 forward_list()
555 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
556 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:16 +0000557 explicit forward_list(const allocator_type& __a);
558 explicit forward_list(size_type __n);
Marshall Clowfb829762013-09-08 19:11:51 +0000559#if _LIBCPP_STD_VER > 11
560 explicit forward_list(size_type __n, const allocator_type& __a);
561#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000562 forward_list(size_type __n, const value_type& __v);
563 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
564 template <class _InputIterator>
565 forward_list(_InputIterator __f, _InputIterator __l,
566 typename enable_if<
567 __is_input_iterator<_InputIterator>::value
568 >::type* = nullptr);
569 template <class _InputIterator>
570 forward_list(_InputIterator __f, _InputIterator __l,
571 const allocator_type& __a,
572 typename enable_if<
573 __is_input_iterator<_InputIterator>::value
574 >::type* = nullptr);
575 forward_list(const forward_list& __x);
576 forward_list(const forward_list& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000577#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000579 forward_list(forward_list&& __x)
580 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000581 : base(_VSTD::move(__x)) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000582 forward_list(forward_list&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000583#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000584#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000585 forward_list(initializer_list<value_type> __il);
586 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000587#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000588
589 // ~forward_list() = default;
590
591 forward_list& operator=(const forward_list& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000592#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000593 forward_list& operator=(forward_list&& __x)
594 _NOEXCEPT_(
595 __node_traits::propagate_on_container_move_assignment::value &&
596 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000597#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000598#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000599 forward_list& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000600#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000601
602 template <class _InputIterator>
603 typename enable_if
604 <
605 __is_input_iterator<_InputIterator>::value,
606 void
607 >::type
608 assign(_InputIterator __f, _InputIterator __l);
609 void assign(size_type __n, const value_type& __v);
Howard Hinnant54976f22011-08-12 21:56:02 +0000610#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000611 void assign(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000612#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000613
Howard Hinnant0af133f2010-09-21 22:55:27 +0000614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000615 allocator_type get_allocator() const _NOEXCEPT
616 {return allocator_type(base::__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000617
Howard Hinnant0af133f2010-09-21 22:55:27 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000619 iterator begin() _NOEXCEPT
620 {return iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000622 const_iterator begin() const _NOEXCEPT
623 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000625 iterator end() _NOEXCEPT
626 {return iterator(nullptr);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000628 const_iterator end() const _NOEXCEPT
629 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000630
Howard Hinnant0af133f2010-09-21 22:55:27 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000632 const_iterator cbegin() const _NOEXCEPT
633 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000635 const_iterator cend() const _NOEXCEPT
636 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000637
Howard Hinnant0af133f2010-09-21 22:55:27 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000639 iterator before_begin() _NOEXCEPT
640 {return iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000642 const_iterator before_begin() const _NOEXCEPT
643 {return const_iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000645 const_iterator cbefore_begin() const _NOEXCEPT
646 {return const_iterator(base::__before_begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000647
Howard Hinnant0af133f2010-09-21 22:55:27 +0000648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000649 bool empty() const _NOEXCEPT
650 {return base::__before_begin()->__next_ == nullptr;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000652 size_type max_size() const _NOEXCEPT
653 {return numeric_limits<size_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000654
Howard Hinnant0af133f2010-09-21 22:55:27 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000656 reference front() {return base::__before_begin()->__next_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000658 const_reference front() const {return base::__before_begin()->__next_->__value_;}
659
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000660#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
661#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000662 template <class... _Args> void emplace_front(_Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000663#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000664 void push_front(value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000665#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000666 void push_front(const value_type& __v);
667
668 void pop_front();
669
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000670#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
671#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000672 template <class... _Args>
673 iterator emplace_after(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000674#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000675 iterator insert_after(const_iterator __p, value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000676#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000677 iterator insert_after(const_iterator __p, const value_type& __v);
678 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
679 template <class _InputIterator>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000681 typename enable_if
682 <
683 __is_input_iterator<_InputIterator>::value,
684 iterator
685 >::type
686 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
Howard Hinnant54976f22011-08-12 21:56:02 +0000687#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000688 iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
689 {return insert_after(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000690#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000691
Howard Hinnant3db88032010-08-21 20:58:44 +0000692 iterator erase_after(const_iterator __p);
693 iterator erase_after(const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000694
Howard Hinnant0af133f2010-09-21 22:55:27 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000696 void swap(forward_list& __x)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000697#if _LIBCPP_STD_VER >= 14
698 _NOEXCEPT
699#else
Howard Hinnant91a47502011-06-03 16:20:53 +0000700 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
701 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000702#endif
Howard Hinnant91a47502011-06-03 16:20:53 +0000703 {base::swap(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000704
705 void resize(size_type __n);
706 void resize(size_type __n, const value_type& __v);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000708 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000709
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000710#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnanteb92df72011-01-27 21:00:35 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000712 void splice_after(const_iterator __p, forward_list&& __x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000714 void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000716 void splice_after(const_iterator __p, forward_list&& __x,
717 const_iterator __f, const_iterator __l);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000718#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000719 void splice_after(const_iterator __p, forward_list& __x);
720 void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
721 void splice_after(const_iterator __p, forward_list& __x,
722 const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000723 void remove(const value_type& __v);
724 template <class _Predicate> void remove_if(_Predicate __pred);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000726 void unique() {unique(__equal_to<value_type>());}
727 template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000728#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteb92df72011-01-27 21:00:35 +0000730 void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
731 template <class _Compare>
732 _LIBCPP_INLINE_VISIBILITY
733 void merge(forward_list&& __x, _Compare __comp)
Howard Hinnantce48a112011-06-30 21:18:19 +0000734 {merge(__x, _VSTD::move(__comp));}
Howard Hinnanteb92df72011-01-27 21:00:35 +0000735#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000737 void merge(forward_list& __x) {merge(__x, __less<value_type>());}
738 template <class _Compare> void merge(forward_list& __x, _Compare __comp);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000740 void sort() {sort(__less<value_type>());}
741 template <class _Compare> void sort(_Compare __comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000742 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000743
744private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000745
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000746#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000747 void __move_assign(forward_list& __x, true_type)
748 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000749 void __move_assign(forward_list& __x, false_type);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000750#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000751
752 template <class _Compare>
753 static
754 __node_pointer
755 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
756
757 template <class _Compare>
758 static
759 __node_pointer
760 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
761};
762
763template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000765forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
766 : base(__a)
767{
768}
769
770template <class _Tp, class _Alloc>
771forward_list<_Tp, _Alloc>::forward_list(size_type __n)
772{
773 if (__n > 0)
774 {
775 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000776 typedef __allocator_destructor<__node_allocator> _Dp;
777 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +0000778 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
779 __p = __p->__next_)
780 {
781 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +0000782 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000783 __h->__next_ = nullptr;
784 __p->__next_ = __h.release();
785 }
786 }
787}
788
Marshall Clowfb829762013-09-08 19:11:51 +0000789#if _LIBCPP_STD_VER > 11
790template <class _Tp, class _Alloc>
791forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a)
792 : base ( __a )
793{
794 if (__n > 0)
795 {
796 __node_allocator& __a = base::__alloc();
797 typedef __allocator_destructor<__node_allocator> _Dp;
798 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
799 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
800 __p = __p->__next_)
801 {
802 __h.reset(__node_traits::allocate(__a, 1));
803 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
804 __h->__next_ = nullptr;
805 __p->__next_ = __h.release();
806 }
807 }
808}
809#endif
810
Howard Hinnant3e519522010-05-11 19:42:16 +0000811template <class _Tp, class _Alloc>
812forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
813{
814 insert_after(cbefore_begin(), __n, __v);
815}
816
817template <class _Tp, class _Alloc>
818forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
819 const allocator_type& __a)
820 : base(__a)
821{
822 insert_after(cbefore_begin(), __n, __v);
823}
824
825template <class _Tp, class _Alloc>
826template <class _InputIterator>
827forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
828 typename enable_if<
829 __is_input_iterator<_InputIterator>::value
830 >::type*)
831{
832 insert_after(cbefore_begin(), __f, __l);
833}
834
835template <class _Tp, class _Alloc>
836template <class _InputIterator>
837forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
838 const allocator_type& __a,
839 typename enable_if<
840 __is_input_iterator<_InputIterator>::value
841 >::type*)
842 : base(__a)
843{
844 insert_after(cbefore_begin(), __f, __l);
845}
846
847template <class _Tp, class _Alloc>
848forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
849 : base(allocator_type(
850 __node_traits::select_on_container_copy_construction(__x.__alloc())
851 )
852 )
853{
854 insert_after(cbefore_begin(), __x.begin(), __x.end());
855}
856
857template <class _Tp, class _Alloc>
858forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
859 const allocator_type& __a)
860 : base(__a)
861{
862 insert_after(cbefore_begin(), __x.begin(), __x.end());
863}
864
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000865#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000866
867template <class _Tp, class _Alloc>
868forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
869 const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000870 : base(_VSTD::move(__x), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000871{
872 if (base::__alloc() != __x.__alloc())
873 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000874 typedef move_iterator<iterator> _Ip;
875 insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000876 }
877}
878
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000879#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000880
Howard Hinnant54976f22011-08-12 21:56:02 +0000881#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
882
Howard Hinnant3e519522010-05-11 19:42:16 +0000883template <class _Tp, class _Alloc>
884forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
885{
886 insert_after(cbefore_begin(), __il.begin(), __il.end());
887}
888
889template <class _Tp, class _Alloc>
890forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
891 const allocator_type& __a)
892 : base(__a)
893{
894 insert_after(cbefore_begin(), __il.begin(), __il.end());
895}
896
Howard Hinnant54976f22011-08-12 21:56:02 +0000897#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
898
Howard Hinnant3e519522010-05-11 19:42:16 +0000899template <class _Tp, class _Alloc>
900forward_list<_Tp, _Alloc>&
901forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
902{
903 if (this != &__x)
904 {
905 base::__copy_assign_alloc(__x);
906 assign(__x.begin(), __x.end());
907 }
908 return *this;
909}
910
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000911#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000912
913template <class _Tp, class _Alloc>
914void
915forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000916 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000917{
918 clear();
919 base::__move_assign_alloc(__x);
920 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
921 __x.__before_begin()->__next_ = nullptr;
922}
923
924template <class _Tp, class _Alloc>
925void
926forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
927{
928 if (base::__alloc() == __x.__alloc())
929 __move_assign(__x, true_type());
930 else
931 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000932 typedef move_iterator<iterator> _Ip;
933 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000934 }
935}
936
937template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000939forward_list<_Tp, _Alloc>&
940forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000941 _NOEXCEPT_(
942 __node_traits::propagate_on_container_move_assignment::value &&
943 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000944{
945 __move_assign(__x, integral_constant<bool,
946 __node_traits::propagate_on_container_move_assignment::value>());
947 return *this;
948}
949
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000950#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000951
Howard Hinnant54976f22011-08-12 21:56:02 +0000952#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
953
Howard Hinnant3e519522010-05-11 19:42:16 +0000954template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000955inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000956forward_list<_Tp, _Alloc>&
957forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
958{
959 assign(__il.begin(), __il.end());
960 return *this;
961}
962
Howard Hinnant54976f22011-08-12 21:56:02 +0000963#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
964
Howard Hinnant3e519522010-05-11 19:42:16 +0000965template <class _Tp, class _Alloc>
966template <class _InputIterator>
967typename enable_if
968<
969 __is_input_iterator<_InputIterator>::value,
970 void
971>::type
972forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
973{
974 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000975 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000976 iterator __e = end();
Eric Fiselier910285b2014-10-27 19:28:20 +0000977 for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
Howard Hinnant3e519522010-05-11 19:42:16 +0000978 *__j = *__f;
979 if (__j == __e)
980 insert_after(__i, __f, __l);
981 else
982 erase_after(__i, __e);
983}
984
985template <class _Tp, class _Alloc>
986void
987forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
988{
989 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000990 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000991 iterator __e = end();
992 for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
993 *__j = __v;
994 if (__j == __e)
995 insert_after(__i, __n, __v);
996 else
997 erase_after(__i, __e);
998}
999
Howard Hinnant54976f22011-08-12 21:56:02 +00001000#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1001
Howard Hinnant3e519522010-05-11 19:42:16 +00001002template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001003inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001004void
1005forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
1006{
1007 assign(__il.begin(), __il.end());
1008}
1009
Howard Hinnant54976f22011-08-12 21:56:02 +00001010#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1011
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001012#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1013#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001014
1015template <class _Tp, class _Alloc>
1016template <class... _Args>
1017void
1018forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1019{
1020 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001021 typedef __allocator_destructor<__node_allocator> _Dp;
1022 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001023 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1024 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001025 __h->__next_ = base::__before_begin()->__next_;
1026 base::__before_begin()->__next_ = __h.release();
1027}
1028
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001029#endif // _LIBCPP_HAS_NO_VARIADICS
1030
Howard Hinnant3e519522010-05-11 19:42:16 +00001031template <class _Tp, class _Alloc>
1032void
1033forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
1034{
1035 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001036 typedef __allocator_destructor<__node_allocator> _Dp;
1037 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001038 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001039 __h->__next_ = base::__before_begin()->__next_;
1040 base::__before_begin()->__next_ = __h.release();
1041}
1042
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001043#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001044
1045template <class _Tp, class _Alloc>
1046void
1047forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
1048{
1049 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001050 typedef __allocator_destructor<__node_allocator> _Dp;
1051 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001052 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001053 __h->__next_ = base::__before_begin()->__next_;
1054 base::__before_begin()->__next_ = __h.release();
1055}
1056
1057template <class _Tp, class _Alloc>
1058void
1059forward_list<_Tp, _Alloc>::pop_front()
1060{
1061 __node_allocator& __a = base::__alloc();
1062 __node_pointer __p = base::__before_begin()->__next_;
1063 base::__before_begin()->__next_ = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001064 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001065 __node_traits::deallocate(__a, __p, 1);
1066}
1067
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001068#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1069#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001070
1071template <class _Tp, class _Alloc>
1072template <class... _Args>
1073typename forward_list<_Tp, _Alloc>::iterator
1074forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
1075{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001076 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001077 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001078 typedef __allocator_destructor<__node_allocator> _Dp;
1079 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001080 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1081 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001082 __h->__next_ = __r->__next_;
1083 __r->__next_ = __h.release();
1084 return iterator(__r->__next_);
1085}
1086
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001087#endif // _LIBCPP_HAS_NO_VARIADICS
1088
Howard Hinnant3e519522010-05-11 19:42:16 +00001089template <class _Tp, class _Alloc>
1090typename forward_list<_Tp, _Alloc>::iterator
1091forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
1092{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001093 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001094 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001095 typedef __allocator_destructor<__node_allocator> _Dp;
1096 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001097 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001098 __h->__next_ = __r->__next_;
1099 __r->__next_ = __h.release();
1100 return iterator(__r->__next_);
1101}
1102
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001103#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001104
1105template <class _Tp, class _Alloc>
1106typename forward_list<_Tp, _Alloc>::iterator
1107forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
1108{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001109 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001110 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001111 typedef __allocator_destructor<__node_allocator> _Dp;
1112 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001113 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001114 __h->__next_ = __r->__next_;
1115 __r->__next_ = __h.release();
1116 return iterator(__r->__next_);
1117}
1118
1119template <class _Tp, class _Alloc>
1120typename forward_list<_Tp, _Alloc>::iterator
1121forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
1122 const value_type& __v)
1123{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001124 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001125 if (__n > 0)
1126 {
1127 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001128 typedef __allocator_destructor<__node_allocator> _Dp;
1129 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001130 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001131 __node_pointer __first = __h.release();
1132 __node_pointer __last = __first;
1133#ifndef _LIBCPP_NO_EXCEPTIONS
1134 try
1135 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001136#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001137 for (--__n; __n != 0; --__n, __last = __last->__next_)
1138 {
1139 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001140 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001141 __last->__next_ = __h.release();
1142 }
1143#ifndef _LIBCPP_NO_EXCEPTIONS
1144 }
1145 catch (...)
1146 {
1147 while (__first != nullptr)
1148 {
1149 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001150 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001151 __node_traits::deallocate(__a, __first, 1);
1152 __first = __next;
1153 }
1154 throw;
1155 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001156#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001157 __last->__next_ = __r->__next_;
1158 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001159 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001160 }
1161 return iterator(__r);
1162}
1163
1164template <class _Tp, class _Alloc>
1165template <class _InputIterator>
1166typename enable_if
1167<
1168 __is_input_iterator<_InputIterator>::value,
1169 typename forward_list<_Tp, _Alloc>::iterator
1170>::type
1171forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
1172 _InputIterator __f, _InputIterator __l)
1173{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001174 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001175 if (__f != __l)
1176 {
1177 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001178 typedef __allocator_destructor<__node_allocator> _Dp;
1179 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001180 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001181 __node_pointer __first = __h.release();
1182 __node_pointer __last = __first;
1183#ifndef _LIBCPP_NO_EXCEPTIONS
1184 try
1185 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001186#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier910285b2014-10-27 19:28:20 +00001187 for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001188 {
1189 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001190 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001191 __last->__next_ = __h.release();
1192 }
1193#ifndef _LIBCPP_NO_EXCEPTIONS
1194 }
1195 catch (...)
1196 {
1197 while (__first != nullptr)
1198 {
1199 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001200 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001201 __node_traits::deallocate(__a, __first, 1);
1202 __first = __next;
1203 }
1204 throw;
1205 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001206#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001207 __last->__next_ = __r->__next_;
1208 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001209 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001210 }
1211 return iterator(__r);
1212}
1213
1214template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001215typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001216forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
1217{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001218 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001219 __node_pointer __n = __p->__next_;
1220 __p->__next_ = __n->__next_;
1221 __node_allocator& __a = base::__alloc();
Howard Hinnantce48a112011-06-30 21:18:19 +00001222 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001223 __node_traits::deallocate(__a, __n, 1);
Howard Hinnant3db88032010-08-21 20:58:44 +00001224 return iterator(__p->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001225}
1226
1227template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001228typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001229forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
1230{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001231 __node_pointer __e = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001232 if (__f != __l)
1233 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001234 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001235 __node_pointer __n = __p->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001236 if (__n != __e)
1237 {
1238 __p->__next_ = __e;
1239 __node_allocator& __a = base::__alloc();
1240 do
1241 {
1242 __p = __n->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001243 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001244 __node_traits::deallocate(__a, __n, 1);
1245 __n = __p;
1246 } while (__n != __e);
1247 }
1248 }
Howard Hinnant3db88032010-08-21 20:58:44 +00001249 return iterator(__e);
Howard Hinnant3e519522010-05-11 19:42:16 +00001250}
1251
1252template <class _Tp, class _Alloc>
1253void
1254forward_list<_Tp, _Alloc>::resize(size_type __n)
1255{
1256 size_type __sz = 0;
1257 iterator __p = before_begin();
1258 iterator __i = begin();
1259 iterator __e = end();
1260 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1261 ;
1262 if (__i != __e)
1263 erase_after(__p, __e);
1264 else
1265 {
1266 __n -= __sz;
1267 if (__n > 0)
1268 {
1269 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001270 typedef __allocator_destructor<__node_allocator> _Dp;
1271 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001272 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1273 __ptr = __ptr->__next_)
1274 {
1275 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001276 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001277 __h->__next_ = nullptr;
1278 __ptr->__next_ = __h.release();
1279 }
1280 }
1281 }
1282}
1283
1284template <class _Tp, class _Alloc>
1285void
1286forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
1287{
1288 size_type __sz = 0;
1289 iterator __p = before_begin();
1290 iterator __i = begin();
1291 iterator __e = end();
1292 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1293 ;
1294 if (__i != __e)
1295 erase_after(__p, __e);
1296 else
1297 {
1298 __n -= __sz;
1299 if (__n > 0)
1300 {
1301 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001302 typedef __allocator_destructor<__node_allocator> _Dp;
1303 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001304 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1305 __ptr = __ptr->__next_)
1306 {
1307 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001308 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001309 __h->__next_ = nullptr;
1310 __ptr->__next_ = __h.release();
1311 }
1312 }
1313 }
1314}
1315
1316template <class _Tp, class _Alloc>
1317void
1318forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001319 forward_list& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00001320{
1321 if (!__x.empty())
1322 {
1323 if (__p.__ptr_->__next_ != nullptr)
1324 {
1325 const_iterator __lm1 = __x.before_begin();
1326 while (__lm1.__ptr_->__next_ != nullptr)
1327 ++__lm1;
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001328 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001329 }
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001330 __p.__ptr_->__next_ = __x.__before_begin()->__next_;
1331 __x.__before_begin()->__next_ = nullptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001332 }
1333}
1334
1335template <class _Tp, class _Alloc>
1336void
1337forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001338 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001339 const_iterator __i)
1340{
Howard Hinnantce48a112011-06-30 21:18:19 +00001341 const_iterator __lm1 = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001342 if (__p != __i && __p != __lm1)
1343 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001344 __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
1345 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1346 __p.__ptr_->__next_ = __lm1.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001347 }
1348}
1349
1350template <class _Tp, class _Alloc>
1351void
1352forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001353 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001354 const_iterator __f, const_iterator __l)
1355{
1356 if (__f != __l && __p != __f)
1357 {
1358 const_iterator __lm1 = __f;
1359 while (__lm1.__ptr_->__next_ != __l.__ptr_)
1360 ++__lm1;
1361 if (__f != __lm1)
1362 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001363 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1364 __p.__ptr_->__next_ = __f.__ptr_->__next_;
1365 __f.__ptr_->__next_ = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001366 }
1367 }
1368}
1369
Howard Hinnanteb92df72011-01-27 21:00:35 +00001370#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1371
1372template <class _Tp, class _Alloc>
1373inline _LIBCPP_INLINE_VISIBILITY
1374void
1375forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1376 forward_list&& __x)
1377{
1378 splice_after(__p, __x);
1379}
1380
1381template <class _Tp, class _Alloc>
1382inline _LIBCPP_INLINE_VISIBILITY
1383void
1384forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1385 forward_list&& __x,
1386 const_iterator __i)
1387{
1388 splice_after(__p, __x, __i);
1389}
1390
1391template <class _Tp, class _Alloc>
1392inline _LIBCPP_INLINE_VISIBILITY
1393void
1394forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1395 forward_list&& __x,
1396 const_iterator __f, const_iterator __l)
1397{
1398 splice_after(__p, __x, __f, __l);
1399}
1400
1401#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1402
Howard Hinnant3e519522010-05-11 19:42:16 +00001403template <class _Tp, class _Alloc>
1404void
1405forward_list<_Tp, _Alloc>::remove(const value_type& __v)
1406{
Marshall Clow99d2df92014-08-08 15:58:00 +00001407 forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
Howard Hinnant3e519522010-05-11 19:42:16 +00001408 iterator __e = end();
1409 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1410 {
1411 if (__i.__ptr_->__next_->__value_ == __v)
1412 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001413 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001414 for (; __j != __e && *__j == __v; ++__j)
1415 ;
Marshall Clowc8528b52014-10-18 11:03:33 +00001416 __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
Howard Hinnant3e519522010-05-11 19:42:16 +00001417 if (__j == __e)
1418 break;
1419 __i = __j;
1420 }
1421 else
1422 ++__i;
1423 }
1424}
1425
1426template <class _Tp, class _Alloc>
1427template <class _Predicate>
1428void
1429forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
1430{
1431 iterator __e = end();
1432 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1433 {
1434 if (__pred(__i.__ptr_->__next_->__value_))
1435 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001436 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001437 for (; __j != __e && __pred(*__j); ++__j)
1438 ;
1439 erase_after(__i, __j);
1440 if (__j == __e)
1441 break;
1442 __i = __j;
1443 }
1444 else
1445 ++__i;
1446 }
1447}
1448
1449template <class _Tp, class _Alloc>
1450template <class _BinaryPredicate>
1451void
1452forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
1453{
1454 for (iterator __i = begin(), __e = end(); __i != __e;)
1455 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001456 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001457 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1458 ;
1459 if (__i.__ptr_->__next_ != __j.__ptr_)
1460 erase_after(__i, __j);
1461 __i = __j;
1462 }
1463}
1464
1465template <class _Tp, class _Alloc>
1466template <class _Compare>
1467void
Howard Hinnant3e519522010-05-11 19:42:16 +00001468forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
Howard Hinnant3e519522010-05-11 19:42:16 +00001469{
1470 if (this != &__x)
1471 {
1472 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
1473 __x.__before_begin()->__next_,
1474 __comp);
1475 __x.__before_begin()->__next_ = nullptr;
1476 }
1477}
1478
1479template <class _Tp, class _Alloc>
1480template <class _Compare>
1481typename forward_list<_Tp, _Alloc>::__node_pointer
1482forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
1483 _Compare& __comp)
1484{
1485 if (__f1 == nullptr)
1486 return __f2;
1487 if (__f2 == nullptr)
1488 return __f1;
1489 __node_pointer __r;
1490 if (__comp(__f2->__value_, __f1->__value_))
1491 {
1492 __node_pointer __t = __f2;
1493 while (__t->__next_ != nullptr &&
1494 __comp(__t->__next_->__value_, __f1->__value_))
1495 __t = __t->__next_;
1496 __r = __f2;
1497 __f2 = __t->__next_;
1498 __t->__next_ = __f1;
1499 }
1500 else
1501 __r = __f1;
1502 __node_pointer __p = __f1;
1503 __f1 = __f1->__next_;
1504 while (__f1 != nullptr && __f2 != nullptr)
1505 {
1506 if (__comp(__f2->__value_, __f1->__value_))
1507 {
1508 __node_pointer __t = __f2;
1509 while (__t->__next_ != nullptr &&
1510 __comp(__t->__next_->__value_, __f1->__value_))
1511 __t = __t->__next_;
1512 __p->__next_ = __f2;
1513 __f2 = __t->__next_;
1514 __t->__next_ = __f1;
1515 }
1516 __p = __f1;
1517 __f1 = __f1->__next_;
1518 }
1519 if (__f2 != nullptr)
1520 __p->__next_ = __f2;
1521 return __r;
1522}
1523
1524template <class _Tp, class _Alloc>
1525template <class _Compare>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001526inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001527void
1528forward_list<_Tp, _Alloc>::sort(_Compare __comp)
1529{
1530 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
Howard Hinnantce48a112011-06-30 21:18:19 +00001531 _VSTD::distance(begin(), end()), __comp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001532}
1533
1534template <class _Tp, class _Alloc>
1535template <class _Compare>
1536typename forward_list<_Tp, _Alloc>::__node_pointer
1537forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
1538 _Compare& __comp)
1539{
1540 switch (__sz)
1541 {
1542 case 0:
1543 case 1:
1544 return __f1;
1545 case 2:
1546 if (__comp(__f1->__next_->__value_, __f1->__value_))
1547 {
1548 __node_pointer __t = __f1->__next_;
1549 __t->__next_ = __f1;
1550 __f1->__next_ = nullptr;
1551 __f1 = __t;
1552 }
1553 return __f1;
1554 }
1555 difference_type __sz1 = __sz / 2;
1556 difference_type __sz2 = __sz - __sz1;
Howard Hinnantce48a112011-06-30 21:18:19 +00001557 __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001558 __node_pointer __f2 = __t->__next_;
1559 __t->__next_ = nullptr;
1560 return __merge(__sort(__f1, __sz1, __comp),
1561 __sort(__f2, __sz2, __comp), __comp);
1562}
1563
1564template <class _Tp, class _Alloc>
1565void
Howard Hinnantf9dc2832011-06-02 16:44:28 +00001566forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001567{
1568 __node_pointer __p = base::__before_begin()->__next_;
1569 if (__p != nullptr)
1570 {
1571 __node_pointer __f = __p->__next_;
1572 __p->__next_ = nullptr;
1573 while (__f != nullptr)
1574 {
1575 __node_pointer __t = __f->__next_;
1576 __f->__next_ = __p;
1577 __p = __f;
1578 __f = __t;
1579 }
1580 base::__before_begin()->__next_ = __p;
1581 }
1582}
1583
1584template <class _Tp, class _Alloc>
1585bool operator==(const forward_list<_Tp, _Alloc>& __x,
1586 const forward_list<_Tp, _Alloc>& __y)
1587{
Howard Hinnantc003db12011-11-29 18:15:50 +00001588 typedef forward_list<_Tp, _Alloc> _Cp;
1589 typedef typename _Cp::const_iterator _Ip;
1590 _Ip __ix = __x.begin();
1591 _Ip __ex = __x.end();
1592 _Ip __iy = __y.begin();
1593 _Ip __ey = __y.end();
Howard Hinnant3e519522010-05-11 19:42:16 +00001594 for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
1595 if (!(*__ix == *__iy))
1596 return false;
1597 return (__ix == __ex) == (__iy == __ey);
1598}
1599
1600template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001602bool operator!=(const forward_list<_Tp, _Alloc>& __x,
1603 const forward_list<_Tp, _Alloc>& __y)
1604{
1605 return !(__x == __y);
1606}
1607
1608template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001609inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001610bool operator< (const forward_list<_Tp, _Alloc>& __x,
1611 const forward_list<_Tp, _Alloc>& __y)
1612{
Howard Hinnantce48a112011-06-30 21:18:19 +00001613 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
Howard Hinnant3e519522010-05-11 19:42:16 +00001614 __y.begin(), __y.end());
1615}
1616
1617template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001619bool operator> (const forward_list<_Tp, _Alloc>& __x,
1620 const forward_list<_Tp, _Alloc>& __y)
1621{
1622 return __y < __x;
1623}
1624
1625template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001627bool operator>=(const forward_list<_Tp, _Alloc>& __x,
1628 const forward_list<_Tp, _Alloc>& __y)
1629{
1630 return !(__x < __y);
1631}
1632
1633template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001634inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001635bool operator<=(const forward_list<_Tp, _Alloc>& __x,
1636 const forward_list<_Tp, _Alloc>& __y)
1637{
1638 return !(__y < __x);
1639}
1640
1641template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001642inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001643void
1644swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +00001645 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001646{
1647 __x.swap(__y);
1648}
1649
1650_LIBCPP_END_NAMESPACE_STD
1651
1652#endif // _LIBCPP_FORWARD_LIST