blob: fbb850c3b23050ef170144939d31c539adcd9336 [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)
110 noexcept(!allocator_type::propagate_on_container_swap::value ||
111 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000112
113 void resize(size_type n);
114 void resize(size_type n, const value_type& v);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000115 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000116
Howard Hinnanteb92df72011-01-27 21:00:35 +0000117 void splice_after(const_iterator p, forward_list& x);
Howard Hinnant3e519522010-05-11 19:42:16 +0000118 void splice_after(const_iterator p, forward_list&& x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000119 void splice_after(const_iterator p, forward_list& x, const_iterator i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000120 void splice_after(const_iterator p, forward_list&& x, const_iterator i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000121 void splice_after(const_iterator p, forward_list& x,
122 const_iterator first, const_iterator last);
Howard Hinnant3e519522010-05-11 19:42:16 +0000123 void splice_after(const_iterator p, forward_list&& x,
124 const_iterator first, const_iterator last);
125 void remove(const value_type& v);
126 template <class Predicate> void remove_if(Predicate pred);
127 void unique();
128 template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000129 void merge(forward_list& x);
Howard Hinnant3e519522010-05-11 19:42:16 +0000130 void merge(forward_list&& x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000131 template <class Compare> void merge(forward_list& x, Compare comp);
Howard Hinnant3e519522010-05-11 19:42:16 +0000132 template <class Compare> void merge(forward_list&& x, Compare comp);
133 void sort();
134 template <class Compare> void sort(Compare comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000135 void reverse() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000136};
137
138template <class T, class Allocator>
139 bool operator==(const forward_list<T, Allocator>& x,
140 const forward_list<T, Allocator>& y);
141
142template <class T, class Allocator>
143 bool operator< (const forward_list<T, Allocator>& x,
144 const forward_list<T, Allocator>& y);
145
146template <class T, class Allocator>
147 bool operator!=(const forward_list<T, Allocator>& x,
148 const forward_list<T, Allocator>& y);
149
150template <class T, class Allocator>
151 bool operator> (const forward_list<T, Allocator>& x,
152 const forward_list<T, Allocator>& y);
153
154template <class T, class Allocator>
155 bool operator>=(const forward_list<T, Allocator>& x,
156 const forward_list<T, Allocator>& y);
157
158template <class T, class Allocator>
159 bool operator<=(const forward_list<T, Allocator>& x,
160 const forward_list<T, Allocator>& y);
161
162template <class T, class Allocator>
Howard Hinnant91a47502011-06-03 16:20:53 +0000163 void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
Howard Hinnant45900102011-06-03 17:30:28 +0000164 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000165
166} // std
167
168*/
169
170#include <__config>
171
172#include <initializer_list>
173#include <memory>
174#include <limits>
175#include <iterator>
176#include <algorithm>
177
Howard Hinnantab4f4382011-11-29 16:45:27 +0000178#include <__undef_min_max>
179
Howard Hinnant073458b2011-10-17 20:05:10 +0000180#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000181#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000182#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000183
184_LIBCPP_BEGIN_NAMESPACE_STD
185
Howard Hinnantce534202011-06-14 19:58:17 +0000186template <class _Tp, class _VoidPtr> struct __forward_list_node;
Howard Hinnant3e519522010-05-11 19:42:16 +0000187
188template <class _NodePtr>
189struct __forward_begin_node
190{
Howard Hinnant3e519522010-05-11 19:42:16 +0000191 typedef _NodePtr pointer;
192
193 pointer __next_;
194
Howard Hinnant0af133f2010-09-21 22:55:27 +0000195 _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000196};
197
198template <class _Tp, class _VoidPtr>
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000199struct _LIBCPP_HIDDEN __begin_node_of
200{
201 typedef __forward_begin_node
202 <
203 typename pointer_traits<_VoidPtr>::template
Howard Hinnant3e519522010-05-11 19:42:16 +0000204#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000205 rebind<__forward_list_node<_Tp, _VoidPtr> >
Howard Hinnant3e519522010-05-11 19:42:16 +0000206#else
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000207 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
Howard Hinnant3e519522010-05-11 19:42:16 +0000208#endif
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000209 > type;
210};
211
212template <class _Tp, class _VoidPtr>
213struct __forward_list_node
214 : public __begin_node_of<_Tp, _VoidPtr>::type
Howard Hinnant3e519522010-05-11 19:42:16 +0000215{
216 typedef _Tp value_type;
217
218 value_type __value_;
219};
220
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000221template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY forward_list;
Howard Hinnantf0544c22013-08-12 18:38:34 +0000222template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000223
224template <class _NodePtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000225class _LIBCPP_TYPE_VIS_ONLY __forward_list_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000226{
227 typedef _NodePtr __node_pointer;
228
229 __node_pointer __ptr_;
230
Howard Hinnant0af133f2010-09-21 22:55:27 +0000231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000232 explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000233
Howard Hinnantf0544c22013-08-12 18:38:34 +0000234 template<class, class> friend class _LIBCPP_TYPE_VIS_ONLY forward_list;
235 template<class> friend class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000236
237public:
238 typedef forward_iterator_tag iterator_category;
239 typedef typename pointer_traits<__node_pointer>::element_type::value_type
240 value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000241 typedef value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000242 typedef typename pointer_traits<__node_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000243 difference_type;
244 typedef typename pointer_traits<__node_pointer>::template
245#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
246 rebind<value_type>
247#else
248 rebind<value_type>::other
249#endif
250 pointer;
251
Howard Hinnant0af133f2010-09-21 22:55:27 +0000252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000253 __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000254
Howard Hinnant0af133f2010-09-21 22:55:27 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000256 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000258 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000259
Howard Hinnant0af133f2010-09-21 22:55:27 +0000260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000261 __forward_list_iterator& operator++()
262 {
263 __ptr_ = __ptr_->__next_;
264 return *this;
265 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000267 __forward_list_iterator operator++(int)
268 {
269 __forward_list_iterator __t(*this);
270 ++(*this);
271 return __t;
272 }
273
Howard Hinnant0af133f2010-09-21 22:55:27 +0000274 friend _LIBCPP_INLINE_VISIBILITY
275 bool operator==(const __forward_list_iterator& __x,
276 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000277 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000278 friend _LIBCPP_INLINE_VISIBILITY
279 bool operator!=(const __forward_list_iterator& __x,
280 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000281 {return !(__x == __y);}
282};
283
284template <class _NodeConstPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000285class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000286{
287 typedef _NodeConstPtr __node_const_pointer;
288
289 __node_const_pointer __ptr_;
290
Howard Hinnant0af133f2010-09-21 22:55:27 +0000291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000292 explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000293 : __ptr_(__p) {}
294
295 typedef typename remove_const
296 <
297 typename pointer_traits<__node_const_pointer>::element_type
298 >::type __node;
299 typedef typename pointer_traits<__node_const_pointer>::template
300#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
301 rebind<__node>
302#else
303 rebind<__node>::other
304#endif
305 __node_pointer;
306
307 template<class, class> friend class forward_list;
308
309public:
310 typedef forward_iterator_tag iterator_category;
311 typedef typename __node::value_type value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000312 typedef const value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000313 typedef typename pointer_traits<__node_const_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000314 difference_type;
315 typedef typename pointer_traits<__node_const_pointer>::template
316#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
317 rebind<const value_type>
318#else
319 rebind<const value_type>::other
320#endif
321 pointer;
322
Howard Hinnant0af133f2010-09-21 22:55:27 +0000323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000324 __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000326 __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000327 : __ptr_(__p.__ptr_) {}
328
Howard Hinnant0af133f2010-09-21 22:55:27 +0000329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000330 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000332 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000333
Howard Hinnant0af133f2010-09-21 22:55:27 +0000334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000335 __forward_list_const_iterator& operator++()
336 {
337 __ptr_ = __ptr_->__next_;
338 return *this;
339 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000341 __forward_list_const_iterator operator++(int)
342 {
343 __forward_list_const_iterator __t(*this);
344 ++(*this);
345 return __t;
346 }
347
Howard Hinnant0af133f2010-09-21 22:55:27 +0000348 friend _LIBCPP_INLINE_VISIBILITY
349 bool operator==(const __forward_list_const_iterator& __x,
350 const __forward_list_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000351 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000352 friend _LIBCPP_INLINE_VISIBILITY
353 bool operator!=(const __forward_list_const_iterator& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +0000354 const __forward_list_const_iterator& __y)
355 {return !(__x == __y);}
356};
357
358template <class _Tp, class _Alloc>
359class __forward_list_base
360{
361protected:
362 typedef _Tp value_type;
363 typedef _Alloc allocator_type;
364
Peter Collingbourne09df4a62014-02-05 01:44:17 +0000365 typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
366 typedef __forward_list_node<value_type, void_pointer> __node;
367 typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
Marshall Clow1f508012015-04-07 05:21:38 +0000368 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000369 typedef allocator_traits<__node_allocator> __node_traits;
370 typedef typename __node_traits::pointer __node_pointer;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000371 typedef typename __node_traits::pointer __node_const_pointer;
372
Marshall Clow1f508012015-04-07 05:21:38 +0000373 typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __begin_node>::type __begin_node_allocator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000374 typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000375
376 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
377
Howard Hinnant0af133f2010-09-21 22:55:27 +0000378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000379 __node_pointer __before_begin() _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000380 {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
381 pointer_to(__before_begin_.first()));}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000383 __node_const_pointer __before_begin() const _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000384 {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
385 pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
Howard Hinnant3e519522010-05-11 19:42:16 +0000386
Howard Hinnant0af133f2010-09-21 22:55:27 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000388 __node_allocator& __alloc() _NOEXCEPT
389 {return __before_begin_.second();}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000391 const __node_allocator& __alloc() const _NOEXCEPT
392 {return __before_begin_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000393
394 typedef __forward_list_iterator<__node_pointer> iterator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000395 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000396
Howard Hinnant0af133f2010-09-21 22:55:27 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000398 __forward_list_base()
Howard Hinnant91a47502011-06-03 16:20:53 +0000399 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000400 : __before_begin_(__begin_node()) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000402 __forward_list_base(const allocator_type& __a)
403 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
404
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000405#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000406public:
407 __forward_list_base(__forward_list_base&& __x)
408 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000409 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000410#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000411
412private:
413 __forward_list_base(const __forward_list_base&);
414 __forward_list_base& operator=(const __forward_list_base&);
Howard Hinnant3e519522010-05-11 19:42:16 +0000415
Howard Hinnant91a47502011-06-03 16:20:53 +0000416public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000417 ~__forward_list_base();
418
Howard Hinnant91a47502011-06-03 16:20:53 +0000419protected:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000421 void __copy_assign_alloc(const __forward_list_base& __x)
422 {__copy_assign_alloc(__x, integral_constant<bool,
423 __node_traits::propagate_on_container_copy_assignment::value>());}
424
Howard Hinnant0af133f2010-09-21 22:55:27 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000426 void __move_assign_alloc(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000427 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
428 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000429 {__move_assign_alloc(__x, integral_constant<bool,
430 __node_traits::propagate_on_container_move_assignment::value>());}
431
Howard Hinnant91a47502011-06-03 16:20:53 +0000432public:
433 void swap(__forward_list_base& __x)
434 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
435 __is_nothrow_swappable<__node_allocator>::value);
436protected:
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000437 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000438
439private:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000441 void __copy_assign_alloc(const __forward_list_base&, false_type) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000443 void __copy_assign_alloc(const __forward_list_base& __x, true_type)
444 {
445 if (__alloc() != __x.__alloc())
446 clear();
447 __alloc() = __x.__alloc();
448 }
449
Howard Hinnant0af133f2010-09-21 22:55:27 +0000450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000451 void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT
452 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000454 void __move_assign_alloc(__forward_list_base& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000455 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000456 {__alloc() = _VSTD::move(__x.__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000457
Howard Hinnant0af133f2010-09-21 22:55:27 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000459 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +0000460 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
461 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000462 {__swap_alloc(__x, __y, integral_constant<bool,
463 __node_traits::propagate_on_container_swap::value>());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000465 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
466 false_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000467 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000468 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000470 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
471 true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000472 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000473 {
Howard Hinnantce48a112011-06-30 21:18:19 +0000474 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000475 swap(__x, __y);
476 }
477};
478
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000479#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000480
481template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000483__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000484 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000485 : __before_begin_(_VSTD::move(__x.__before_begin_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000486{
487 __x.__before_begin()->__next_ = nullptr;
488}
489
490template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000492__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
493 const allocator_type& __a)
494 : __before_begin_(__begin_node(), __node_allocator(__a))
495{
496 if (__alloc() == __x.__alloc())
497 {
498 __before_begin()->__next_ = __x.__before_begin()->__next_;
499 __x.__before_begin()->__next_ = nullptr;
500 }
501}
502
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000503#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000504
505template <class _Tp, class _Alloc>
506__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
507{
508 clear();
509}
510
511template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000513void
514__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000515 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
516 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000517{
518 __swap_alloc(__alloc(), __x.__alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +0000519 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000520 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
521}
522
523template <class _Tp, class _Alloc>
524void
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000525__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000526{
527 __node_allocator& __a = __alloc();
528 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
529 {
530 __node_pointer __next = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +0000531 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000532 __node_traits::deallocate(__a, __p, 1);
533 __p = __next;
534 }
535 __before_begin()->__next_ = nullptr;
536}
537
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000538template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000539class _LIBCPP_TYPE_VIS_ONLY forward_list
Howard Hinnant3e519522010-05-11 19:42:16 +0000540 : private __forward_list_base<_Tp, _Alloc>
541{
542 typedef __forward_list_base<_Tp, _Alloc> base;
Howard Hinnant91a47502011-06-03 16:20:53 +0000543 typedef typename base::__node_allocator __node_allocator;
544 typedef typename base::__node __node;
545 typedef typename base::__node_traits __node_traits;
546 typedef typename base::__node_pointer __node_pointer;
547
Howard Hinnant3e519522010-05-11 19:42:16 +0000548public:
549 typedef _Tp value_type;
550 typedef _Alloc allocator_type;
551
552 typedef value_type& reference;
553 typedef const value_type& const_reference;
554 typedef typename allocator_traits<allocator_type>::pointer pointer;
555 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
556 typedef typename allocator_traits<allocator_type>::size_type size_type;
557 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
558
559 typedef typename base::iterator iterator;
560 typedef typename base::const_iterator const_iterator;
561
Howard Hinnant91a47502011-06-03 16:20:53 +0000562 _LIBCPP_INLINE_VISIBILITY
563 forward_list()
564 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
565 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:16 +0000566 explicit forward_list(const allocator_type& __a);
567 explicit forward_list(size_type __n);
Marshall Clowfb829762013-09-08 19:11:51 +0000568#if _LIBCPP_STD_VER > 11
569 explicit forward_list(size_type __n, const allocator_type& __a);
570#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000571 forward_list(size_type __n, const value_type& __v);
572 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
573 template <class _InputIterator>
574 forward_list(_InputIterator __f, _InputIterator __l,
575 typename enable_if<
576 __is_input_iterator<_InputIterator>::value
577 >::type* = nullptr);
578 template <class _InputIterator>
579 forward_list(_InputIterator __f, _InputIterator __l,
580 const allocator_type& __a,
581 typename enable_if<
582 __is_input_iterator<_InputIterator>::value
583 >::type* = nullptr);
584 forward_list(const forward_list& __x);
585 forward_list(const forward_list& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000586#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000588 forward_list(forward_list&& __x)
589 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000590 : base(_VSTD::move(__x)) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000591 forward_list(forward_list&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000592#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000593#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000594 forward_list(initializer_list<value_type> __il);
595 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000596#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000597
598 // ~forward_list() = default;
599
600 forward_list& operator=(const forward_list& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000601#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000602 forward_list& operator=(forward_list&& __x)
603 _NOEXCEPT_(
604 __node_traits::propagate_on_container_move_assignment::value &&
605 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000606#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000607#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000608 forward_list& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000609#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000610
611 template <class _InputIterator>
612 typename enable_if
613 <
614 __is_input_iterator<_InputIterator>::value,
615 void
616 >::type
617 assign(_InputIterator __f, _InputIterator __l);
618 void assign(size_type __n, const value_type& __v);
Howard Hinnant54976f22011-08-12 21:56:02 +0000619#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000620 void assign(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000621#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000622
Howard Hinnant0af133f2010-09-21 22:55:27 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000624 allocator_type get_allocator() const _NOEXCEPT
625 {return allocator_type(base::__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000626
Howard Hinnant0af133f2010-09-21 22:55:27 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000628 iterator begin() _NOEXCEPT
629 {return iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000631 const_iterator begin() const _NOEXCEPT
632 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000634 iterator end() _NOEXCEPT
635 {return iterator(nullptr);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000637 const_iterator end() const _NOEXCEPT
638 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000639
Howard Hinnant0af133f2010-09-21 22:55:27 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000641 const_iterator cbegin() const _NOEXCEPT
642 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000644 const_iterator cend() const _NOEXCEPT
645 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000646
Howard Hinnant0af133f2010-09-21 22:55:27 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000648 iterator before_begin() _NOEXCEPT
649 {return iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000651 const_iterator before_begin() const _NOEXCEPT
652 {return const_iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000654 const_iterator cbefore_begin() const _NOEXCEPT
655 {return const_iterator(base::__before_begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000656
Howard Hinnant0af133f2010-09-21 22:55:27 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000658 bool empty() const _NOEXCEPT
659 {return base::__before_begin()->__next_ == nullptr;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000661 size_type max_size() const _NOEXCEPT
662 {return numeric_limits<size_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000663
Howard Hinnant0af133f2010-09-21 22:55:27 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000665 reference front() {return base::__before_begin()->__next_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000667 const_reference front() const {return base::__before_begin()->__next_->__value_;}
668
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000669#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
670#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000671 template <class... _Args> void emplace_front(_Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000672#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000673 void push_front(value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000674#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000675 void push_front(const value_type& __v);
676
677 void pop_front();
678
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000679#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
680#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000681 template <class... _Args>
682 iterator emplace_after(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000683#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000684 iterator insert_after(const_iterator __p, value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000685#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000686 iterator insert_after(const_iterator __p, const value_type& __v);
687 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
688 template <class _InputIterator>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000690 typename enable_if
691 <
692 __is_input_iterator<_InputIterator>::value,
693 iterator
694 >::type
695 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
Howard Hinnant54976f22011-08-12 21:56:02 +0000696#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000697 iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
698 {return insert_after(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000699#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000700
Howard Hinnant3db88032010-08-21 20:58:44 +0000701 iterator erase_after(const_iterator __p);
702 iterator erase_after(const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000703
Howard Hinnant0af133f2010-09-21 22:55:27 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000705 void swap(forward_list& __x)
706 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
707 __is_nothrow_swappable<__node_allocator>::value)
708 {base::swap(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000709
710 void resize(size_type __n);
711 void resize(size_type __n, const value_type& __v);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000713 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000714
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000715#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnanteb92df72011-01-27 21:00:35 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000717 void splice_after(const_iterator __p, forward_list&& __x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000719 void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000720 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000721 void splice_after(const_iterator __p, forward_list&& __x,
722 const_iterator __f, const_iterator __l);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000723#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000724 void splice_after(const_iterator __p, forward_list& __x);
725 void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
726 void splice_after(const_iterator __p, forward_list& __x,
727 const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000728 void remove(const value_type& __v);
729 template <class _Predicate> void remove_if(_Predicate __pred);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000731 void unique() {unique(__equal_to<value_type>());}
732 template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000733#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteb92df72011-01-27 21:00:35 +0000735 void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
736 template <class _Compare>
737 _LIBCPP_INLINE_VISIBILITY
738 void merge(forward_list&& __x, _Compare __comp)
Howard Hinnantce48a112011-06-30 21:18:19 +0000739 {merge(__x, _VSTD::move(__comp));}
Howard Hinnanteb92df72011-01-27 21:00:35 +0000740#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000742 void merge(forward_list& __x) {merge(__x, __less<value_type>());}
743 template <class _Compare> void merge(forward_list& __x, _Compare __comp);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000745 void sort() {sort(__less<value_type>());}
746 template <class _Compare> void sort(_Compare __comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000747 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000748
749private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000750
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000751#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000752 void __move_assign(forward_list& __x, true_type)
753 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000754 void __move_assign(forward_list& __x, false_type);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000755#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000756
757 template <class _Compare>
758 static
759 __node_pointer
760 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
761
762 template <class _Compare>
763 static
764 __node_pointer
765 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
766};
767
768template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000769inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000770forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
771 : base(__a)
772{
773}
774
775template <class _Tp, class _Alloc>
776forward_list<_Tp, _Alloc>::forward_list(size_type __n)
777{
778 if (__n > 0)
779 {
780 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000781 typedef __allocator_destructor<__node_allocator> _Dp;
782 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +0000783 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
784 __p = __p->__next_)
785 {
786 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +0000787 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000788 __h->__next_ = nullptr;
789 __p->__next_ = __h.release();
790 }
791 }
792}
793
Marshall Clowfb829762013-09-08 19:11:51 +0000794#if _LIBCPP_STD_VER > 11
795template <class _Tp, class _Alloc>
796forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a)
797 : base ( __a )
798{
799 if (__n > 0)
800 {
801 __node_allocator& __a = base::__alloc();
802 typedef __allocator_destructor<__node_allocator> _Dp;
803 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
804 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
805 __p = __p->__next_)
806 {
807 __h.reset(__node_traits::allocate(__a, 1));
808 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
809 __h->__next_ = nullptr;
810 __p->__next_ = __h.release();
811 }
812 }
813}
814#endif
815
Howard Hinnant3e519522010-05-11 19:42:16 +0000816template <class _Tp, class _Alloc>
817forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
818{
819 insert_after(cbefore_begin(), __n, __v);
820}
821
822template <class _Tp, class _Alloc>
823forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
824 const allocator_type& __a)
825 : base(__a)
826{
827 insert_after(cbefore_begin(), __n, __v);
828}
829
830template <class _Tp, class _Alloc>
831template <class _InputIterator>
832forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
833 typename enable_if<
834 __is_input_iterator<_InputIterator>::value
835 >::type*)
836{
837 insert_after(cbefore_begin(), __f, __l);
838}
839
840template <class _Tp, class _Alloc>
841template <class _InputIterator>
842forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
843 const allocator_type& __a,
844 typename enable_if<
845 __is_input_iterator<_InputIterator>::value
846 >::type*)
847 : base(__a)
848{
849 insert_after(cbefore_begin(), __f, __l);
850}
851
852template <class _Tp, class _Alloc>
853forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
854 : base(allocator_type(
855 __node_traits::select_on_container_copy_construction(__x.__alloc())
856 )
857 )
858{
859 insert_after(cbefore_begin(), __x.begin(), __x.end());
860}
861
862template <class _Tp, class _Alloc>
863forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
864 const allocator_type& __a)
865 : base(__a)
866{
867 insert_after(cbefore_begin(), __x.begin(), __x.end());
868}
869
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000870#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000871
872template <class _Tp, class _Alloc>
873forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
874 const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000875 : base(_VSTD::move(__x), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000876{
877 if (base::__alloc() != __x.__alloc())
878 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000879 typedef move_iterator<iterator> _Ip;
880 insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000881 }
882}
883
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000884#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000885
Howard Hinnant54976f22011-08-12 21:56:02 +0000886#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
887
Howard Hinnant3e519522010-05-11 19:42:16 +0000888template <class _Tp, class _Alloc>
889forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
890{
891 insert_after(cbefore_begin(), __il.begin(), __il.end());
892}
893
894template <class _Tp, class _Alloc>
895forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
896 const allocator_type& __a)
897 : base(__a)
898{
899 insert_after(cbefore_begin(), __il.begin(), __il.end());
900}
901
Howard Hinnant54976f22011-08-12 21:56:02 +0000902#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
903
Howard Hinnant3e519522010-05-11 19:42:16 +0000904template <class _Tp, class _Alloc>
905forward_list<_Tp, _Alloc>&
906forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
907{
908 if (this != &__x)
909 {
910 base::__copy_assign_alloc(__x);
911 assign(__x.begin(), __x.end());
912 }
913 return *this;
914}
915
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000916#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000917
918template <class _Tp, class _Alloc>
919void
920forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000921 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000922{
923 clear();
924 base::__move_assign_alloc(__x);
925 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
926 __x.__before_begin()->__next_ = nullptr;
927}
928
929template <class _Tp, class _Alloc>
930void
931forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
932{
933 if (base::__alloc() == __x.__alloc())
934 __move_assign(__x, true_type());
935 else
936 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000937 typedef move_iterator<iterator> _Ip;
938 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000939 }
940}
941
942template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000944forward_list<_Tp, _Alloc>&
945forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000946 _NOEXCEPT_(
947 __node_traits::propagate_on_container_move_assignment::value &&
948 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000949{
950 __move_assign(__x, integral_constant<bool,
951 __node_traits::propagate_on_container_move_assignment::value>());
952 return *this;
953}
954
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000955#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000956
Howard Hinnant54976f22011-08-12 21:56:02 +0000957#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
958
Howard Hinnant3e519522010-05-11 19:42:16 +0000959template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000960inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000961forward_list<_Tp, _Alloc>&
962forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
963{
964 assign(__il.begin(), __il.end());
965 return *this;
966}
967
Howard Hinnant54976f22011-08-12 21:56:02 +0000968#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
969
Howard Hinnant3e519522010-05-11 19:42:16 +0000970template <class _Tp, class _Alloc>
971template <class _InputIterator>
972typename enable_if
973<
974 __is_input_iterator<_InputIterator>::value,
975 void
976>::type
977forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
978{
979 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000980 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000981 iterator __e = end();
Eric Fiselier910285b2014-10-27 19:28:20 +0000982 for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
Howard Hinnant3e519522010-05-11 19:42:16 +0000983 *__j = *__f;
984 if (__j == __e)
985 insert_after(__i, __f, __l);
986 else
987 erase_after(__i, __e);
988}
989
990template <class _Tp, class _Alloc>
991void
992forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
993{
994 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000995 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000996 iterator __e = end();
997 for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
998 *__j = __v;
999 if (__j == __e)
1000 insert_after(__i, __n, __v);
1001 else
1002 erase_after(__i, __e);
1003}
1004
Howard Hinnant54976f22011-08-12 21:56:02 +00001005#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1006
Howard Hinnant3e519522010-05-11 19:42:16 +00001007template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001008inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001009void
1010forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
1011{
1012 assign(__il.begin(), __il.end());
1013}
1014
Howard Hinnant54976f22011-08-12 21:56:02 +00001015#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1016
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001017#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1018#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001019
1020template <class _Tp, class _Alloc>
1021template <class... _Args>
1022void
1023forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1024{
1025 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001026 typedef __allocator_destructor<__node_allocator> _Dp;
1027 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001028 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1029 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001030 __h->__next_ = base::__before_begin()->__next_;
1031 base::__before_begin()->__next_ = __h.release();
1032}
1033
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001034#endif // _LIBCPP_HAS_NO_VARIADICS
1035
Howard Hinnant3e519522010-05-11 19:42:16 +00001036template <class _Tp, class _Alloc>
1037void
1038forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
1039{
1040 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001041 typedef __allocator_destructor<__node_allocator> _Dp;
1042 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001043 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001044 __h->__next_ = base::__before_begin()->__next_;
1045 base::__before_begin()->__next_ = __h.release();
1046}
1047
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001048#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001049
1050template <class _Tp, class _Alloc>
1051void
1052forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
1053{
1054 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001055 typedef __allocator_destructor<__node_allocator> _Dp;
1056 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001057 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001058 __h->__next_ = base::__before_begin()->__next_;
1059 base::__before_begin()->__next_ = __h.release();
1060}
1061
1062template <class _Tp, class _Alloc>
1063void
1064forward_list<_Tp, _Alloc>::pop_front()
1065{
1066 __node_allocator& __a = base::__alloc();
1067 __node_pointer __p = base::__before_begin()->__next_;
1068 base::__before_begin()->__next_ = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001069 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001070 __node_traits::deallocate(__a, __p, 1);
1071}
1072
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001073#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1074#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001075
1076template <class _Tp, class _Alloc>
1077template <class... _Args>
1078typename forward_list<_Tp, _Alloc>::iterator
1079forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
1080{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001081 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001082 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001083 typedef __allocator_destructor<__node_allocator> _Dp;
1084 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001085 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1086 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001087 __h->__next_ = __r->__next_;
1088 __r->__next_ = __h.release();
1089 return iterator(__r->__next_);
1090}
1091
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001092#endif // _LIBCPP_HAS_NO_VARIADICS
1093
Howard Hinnant3e519522010-05-11 19:42:16 +00001094template <class _Tp, class _Alloc>
1095typename forward_list<_Tp, _Alloc>::iterator
1096forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
1097{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001098 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001099 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001100 typedef __allocator_destructor<__node_allocator> _Dp;
1101 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001102 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001103 __h->__next_ = __r->__next_;
1104 __r->__next_ = __h.release();
1105 return iterator(__r->__next_);
1106}
1107
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001108#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001109
1110template <class _Tp, class _Alloc>
1111typename forward_list<_Tp, _Alloc>::iterator
1112forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
1113{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001114 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001115 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001116 typedef __allocator_destructor<__node_allocator> _Dp;
1117 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001118 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001119 __h->__next_ = __r->__next_;
1120 __r->__next_ = __h.release();
1121 return iterator(__r->__next_);
1122}
1123
1124template <class _Tp, class _Alloc>
1125typename forward_list<_Tp, _Alloc>::iterator
1126forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
1127 const value_type& __v)
1128{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001129 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001130 if (__n > 0)
1131 {
1132 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001133 typedef __allocator_destructor<__node_allocator> _Dp;
1134 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001135 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001136 __node_pointer __first = __h.release();
1137 __node_pointer __last = __first;
1138#ifndef _LIBCPP_NO_EXCEPTIONS
1139 try
1140 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001141#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001142 for (--__n; __n != 0; --__n, __last = __last->__next_)
1143 {
1144 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001145 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001146 __last->__next_ = __h.release();
1147 }
1148#ifndef _LIBCPP_NO_EXCEPTIONS
1149 }
1150 catch (...)
1151 {
1152 while (__first != nullptr)
1153 {
1154 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001155 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001156 __node_traits::deallocate(__a, __first, 1);
1157 __first = __next;
1158 }
1159 throw;
1160 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001161#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001162 __last->__next_ = __r->__next_;
1163 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001164 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001165 }
1166 return iterator(__r);
1167}
1168
1169template <class _Tp, class _Alloc>
1170template <class _InputIterator>
1171typename enable_if
1172<
1173 __is_input_iterator<_InputIterator>::value,
1174 typename forward_list<_Tp, _Alloc>::iterator
1175>::type
1176forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
1177 _InputIterator __f, _InputIterator __l)
1178{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001179 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001180 if (__f != __l)
1181 {
1182 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001183 typedef __allocator_destructor<__node_allocator> _Dp;
1184 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001185 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001186 __node_pointer __first = __h.release();
1187 __node_pointer __last = __first;
1188#ifndef _LIBCPP_NO_EXCEPTIONS
1189 try
1190 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001191#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier910285b2014-10-27 19:28:20 +00001192 for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001193 {
1194 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001195 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001196 __last->__next_ = __h.release();
1197 }
1198#ifndef _LIBCPP_NO_EXCEPTIONS
1199 }
1200 catch (...)
1201 {
1202 while (__first != nullptr)
1203 {
1204 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001205 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001206 __node_traits::deallocate(__a, __first, 1);
1207 __first = __next;
1208 }
1209 throw;
1210 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001211#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001212 __last->__next_ = __r->__next_;
1213 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001214 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001215 }
1216 return iterator(__r);
1217}
1218
1219template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001220typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001221forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
1222{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001223 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001224 __node_pointer __n = __p->__next_;
1225 __p->__next_ = __n->__next_;
1226 __node_allocator& __a = base::__alloc();
Howard Hinnantce48a112011-06-30 21:18:19 +00001227 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001228 __node_traits::deallocate(__a, __n, 1);
Howard Hinnant3db88032010-08-21 20:58:44 +00001229 return iterator(__p->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001230}
1231
1232template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001233typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001234forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
1235{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001236 __node_pointer __e = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001237 if (__f != __l)
1238 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001239 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001240 __node_pointer __n = __p->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001241 if (__n != __e)
1242 {
1243 __p->__next_ = __e;
1244 __node_allocator& __a = base::__alloc();
1245 do
1246 {
1247 __p = __n->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001248 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001249 __node_traits::deallocate(__a, __n, 1);
1250 __n = __p;
1251 } while (__n != __e);
1252 }
1253 }
Howard Hinnant3db88032010-08-21 20:58:44 +00001254 return iterator(__e);
Howard Hinnant3e519522010-05-11 19:42:16 +00001255}
1256
1257template <class _Tp, class _Alloc>
1258void
1259forward_list<_Tp, _Alloc>::resize(size_type __n)
1260{
1261 size_type __sz = 0;
1262 iterator __p = before_begin();
1263 iterator __i = begin();
1264 iterator __e = end();
1265 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1266 ;
1267 if (__i != __e)
1268 erase_after(__p, __e);
1269 else
1270 {
1271 __n -= __sz;
1272 if (__n > 0)
1273 {
1274 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001275 typedef __allocator_destructor<__node_allocator> _Dp;
1276 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001277 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1278 __ptr = __ptr->__next_)
1279 {
1280 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001281 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001282 __h->__next_ = nullptr;
1283 __ptr->__next_ = __h.release();
1284 }
1285 }
1286 }
1287}
1288
1289template <class _Tp, class _Alloc>
1290void
1291forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
1292{
1293 size_type __sz = 0;
1294 iterator __p = before_begin();
1295 iterator __i = begin();
1296 iterator __e = end();
1297 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1298 ;
1299 if (__i != __e)
1300 erase_after(__p, __e);
1301 else
1302 {
1303 __n -= __sz;
1304 if (__n > 0)
1305 {
1306 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001307 typedef __allocator_destructor<__node_allocator> _Dp;
1308 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001309 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1310 __ptr = __ptr->__next_)
1311 {
1312 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001313 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001314 __h->__next_ = nullptr;
1315 __ptr->__next_ = __h.release();
1316 }
1317 }
1318 }
1319}
1320
1321template <class _Tp, class _Alloc>
1322void
1323forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001324 forward_list& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00001325{
1326 if (!__x.empty())
1327 {
1328 if (__p.__ptr_->__next_ != nullptr)
1329 {
1330 const_iterator __lm1 = __x.before_begin();
1331 while (__lm1.__ptr_->__next_ != nullptr)
1332 ++__lm1;
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001333 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001334 }
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001335 __p.__ptr_->__next_ = __x.__before_begin()->__next_;
1336 __x.__before_begin()->__next_ = nullptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001337 }
1338}
1339
1340template <class _Tp, class _Alloc>
1341void
1342forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001343 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001344 const_iterator __i)
1345{
Howard Hinnantce48a112011-06-30 21:18:19 +00001346 const_iterator __lm1 = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001347 if (__p != __i && __p != __lm1)
1348 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001349 __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
1350 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1351 __p.__ptr_->__next_ = __lm1.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001352 }
1353}
1354
1355template <class _Tp, class _Alloc>
1356void
1357forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001358 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001359 const_iterator __f, const_iterator __l)
1360{
1361 if (__f != __l && __p != __f)
1362 {
1363 const_iterator __lm1 = __f;
1364 while (__lm1.__ptr_->__next_ != __l.__ptr_)
1365 ++__lm1;
1366 if (__f != __lm1)
1367 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001368 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1369 __p.__ptr_->__next_ = __f.__ptr_->__next_;
1370 __f.__ptr_->__next_ = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001371 }
1372 }
1373}
1374
Howard Hinnanteb92df72011-01-27 21:00:35 +00001375#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1376
1377template <class _Tp, class _Alloc>
1378inline _LIBCPP_INLINE_VISIBILITY
1379void
1380forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1381 forward_list&& __x)
1382{
1383 splice_after(__p, __x);
1384}
1385
1386template <class _Tp, class _Alloc>
1387inline _LIBCPP_INLINE_VISIBILITY
1388void
1389forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1390 forward_list&& __x,
1391 const_iterator __i)
1392{
1393 splice_after(__p, __x, __i);
1394}
1395
1396template <class _Tp, class _Alloc>
1397inline _LIBCPP_INLINE_VISIBILITY
1398void
1399forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1400 forward_list&& __x,
1401 const_iterator __f, const_iterator __l)
1402{
1403 splice_after(__p, __x, __f, __l);
1404}
1405
1406#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1407
Howard Hinnant3e519522010-05-11 19:42:16 +00001408template <class _Tp, class _Alloc>
1409void
1410forward_list<_Tp, _Alloc>::remove(const value_type& __v)
1411{
Marshall Clow99d2df92014-08-08 15:58:00 +00001412 forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
Howard Hinnant3e519522010-05-11 19:42:16 +00001413 iterator __e = end();
1414 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1415 {
1416 if (__i.__ptr_->__next_->__value_ == __v)
1417 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001418 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001419 for (; __j != __e && *__j == __v; ++__j)
1420 ;
Marshall Clowc8528b52014-10-18 11:03:33 +00001421 __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
Howard Hinnant3e519522010-05-11 19:42:16 +00001422 if (__j == __e)
1423 break;
1424 __i = __j;
1425 }
1426 else
1427 ++__i;
1428 }
1429}
1430
1431template <class _Tp, class _Alloc>
1432template <class _Predicate>
1433void
1434forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
1435{
1436 iterator __e = end();
1437 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1438 {
1439 if (__pred(__i.__ptr_->__next_->__value_))
1440 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001441 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001442 for (; __j != __e && __pred(*__j); ++__j)
1443 ;
1444 erase_after(__i, __j);
1445 if (__j == __e)
1446 break;
1447 __i = __j;
1448 }
1449 else
1450 ++__i;
1451 }
1452}
1453
1454template <class _Tp, class _Alloc>
1455template <class _BinaryPredicate>
1456void
1457forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
1458{
1459 for (iterator __i = begin(), __e = end(); __i != __e;)
1460 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001461 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001462 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1463 ;
1464 if (__i.__ptr_->__next_ != __j.__ptr_)
1465 erase_after(__i, __j);
1466 __i = __j;
1467 }
1468}
1469
1470template <class _Tp, class _Alloc>
1471template <class _Compare>
1472void
Howard Hinnant3e519522010-05-11 19:42:16 +00001473forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
Howard Hinnant3e519522010-05-11 19:42:16 +00001474{
1475 if (this != &__x)
1476 {
1477 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
1478 __x.__before_begin()->__next_,
1479 __comp);
1480 __x.__before_begin()->__next_ = nullptr;
1481 }
1482}
1483
1484template <class _Tp, class _Alloc>
1485template <class _Compare>
1486typename forward_list<_Tp, _Alloc>::__node_pointer
1487forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
1488 _Compare& __comp)
1489{
1490 if (__f1 == nullptr)
1491 return __f2;
1492 if (__f2 == nullptr)
1493 return __f1;
1494 __node_pointer __r;
1495 if (__comp(__f2->__value_, __f1->__value_))
1496 {
1497 __node_pointer __t = __f2;
1498 while (__t->__next_ != nullptr &&
1499 __comp(__t->__next_->__value_, __f1->__value_))
1500 __t = __t->__next_;
1501 __r = __f2;
1502 __f2 = __t->__next_;
1503 __t->__next_ = __f1;
1504 }
1505 else
1506 __r = __f1;
1507 __node_pointer __p = __f1;
1508 __f1 = __f1->__next_;
1509 while (__f1 != nullptr && __f2 != nullptr)
1510 {
1511 if (__comp(__f2->__value_, __f1->__value_))
1512 {
1513 __node_pointer __t = __f2;
1514 while (__t->__next_ != nullptr &&
1515 __comp(__t->__next_->__value_, __f1->__value_))
1516 __t = __t->__next_;
1517 __p->__next_ = __f2;
1518 __f2 = __t->__next_;
1519 __t->__next_ = __f1;
1520 }
1521 __p = __f1;
1522 __f1 = __f1->__next_;
1523 }
1524 if (__f2 != nullptr)
1525 __p->__next_ = __f2;
1526 return __r;
1527}
1528
1529template <class _Tp, class _Alloc>
1530template <class _Compare>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001532void
1533forward_list<_Tp, _Alloc>::sort(_Compare __comp)
1534{
1535 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
Howard Hinnantce48a112011-06-30 21:18:19 +00001536 _VSTD::distance(begin(), end()), __comp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001537}
1538
1539template <class _Tp, class _Alloc>
1540template <class _Compare>
1541typename forward_list<_Tp, _Alloc>::__node_pointer
1542forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
1543 _Compare& __comp)
1544{
1545 switch (__sz)
1546 {
1547 case 0:
1548 case 1:
1549 return __f1;
1550 case 2:
1551 if (__comp(__f1->__next_->__value_, __f1->__value_))
1552 {
1553 __node_pointer __t = __f1->__next_;
1554 __t->__next_ = __f1;
1555 __f1->__next_ = nullptr;
1556 __f1 = __t;
1557 }
1558 return __f1;
1559 }
1560 difference_type __sz1 = __sz / 2;
1561 difference_type __sz2 = __sz - __sz1;
Howard Hinnantce48a112011-06-30 21:18:19 +00001562 __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001563 __node_pointer __f2 = __t->__next_;
1564 __t->__next_ = nullptr;
1565 return __merge(__sort(__f1, __sz1, __comp),
1566 __sort(__f2, __sz2, __comp), __comp);
1567}
1568
1569template <class _Tp, class _Alloc>
1570void
Howard Hinnantf9dc2832011-06-02 16:44:28 +00001571forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001572{
1573 __node_pointer __p = base::__before_begin()->__next_;
1574 if (__p != nullptr)
1575 {
1576 __node_pointer __f = __p->__next_;
1577 __p->__next_ = nullptr;
1578 while (__f != nullptr)
1579 {
1580 __node_pointer __t = __f->__next_;
1581 __f->__next_ = __p;
1582 __p = __f;
1583 __f = __t;
1584 }
1585 base::__before_begin()->__next_ = __p;
1586 }
1587}
1588
1589template <class _Tp, class _Alloc>
1590bool operator==(const forward_list<_Tp, _Alloc>& __x,
1591 const forward_list<_Tp, _Alloc>& __y)
1592{
Howard Hinnantc003db12011-11-29 18:15:50 +00001593 typedef forward_list<_Tp, _Alloc> _Cp;
1594 typedef typename _Cp::const_iterator _Ip;
1595 _Ip __ix = __x.begin();
1596 _Ip __ex = __x.end();
1597 _Ip __iy = __y.begin();
1598 _Ip __ey = __y.end();
Howard Hinnant3e519522010-05-11 19:42:16 +00001599 for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
1600 if (!(*__ix == *__iy))
1601 return false;
1602 return (__ix == __ex) == (__iy == __ey);
1603}
1604
1605template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001607bool operator!=(const forward_list<_Tp, _Alloc>& __x,
1608 const forward_list<_Tp, _Alloc>& __y)
1609{
1610 return !(__x == __y);
1611}
1612
1613template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001615bool operator< (const forward_list<_Tp, _Alloc>& __x,
1616 const forward_list<_Tp, _Alloc>& __y)
1617{
Howard Hinnantce48a112011-06-30 21:18:19 +00001618 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
Howard Hinnant3e519522010-05-11 19:42:16 +00001619 __y.begin(), __y.end());
1620}
1621
1622template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001624bool operator> (const forward_list<_Tp, _Alloc>& __x,
1625 const forward_list<_Tp, _Alloc>& __y)
1626{
1627 return __y < __x;
1628}
1629
1630template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001632bool operator>=(const forward_list<_Tp, _Alloc>& __x,
1633 const forward_list<_Tp, _Alloc>& __y)
1634{
1635 return !(__x < __y);
1636}
1637
1638template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001639inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001640bool operator<=(const forward_list<_Tp, _Alloc>& __x,
1641 const forward_list<_Tp, _Alloc>& __y)
1642{
1643 return !(__y < __x);
1644}
1645
1646template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001648void
1649swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +00001650 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001651{
1652 __x.swap(__y);
1653}
1654
1655_LIBCPP_END_NAMESPACE_STD
1656
1657#endif // _LIBCPP_FORWARD_LIST