blob: 72d31dc7e074d31882a0b68940936b61db4be188 [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
Howard Hinnantf0544c22013-08-12 18:38:34 +0000221template<class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS_ONLY forward_list;
222template<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;
Howard Hinnant3e519522010-05-11 19:42:16 +0000368 typedef typename allocator_traits<allocator_type>::template
369#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
370 rebind_alloc<__node>
371#else
372 rebind_alloc<__node>::other
373#endif
374 __node_allocator;
375 typedef allocator_traits<__node_allocator> __node_traits;
376 typedef typename __node_traits::pointer __node_pointer;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000377 typedef typename __node_traits::pointer __node_const_pointer;
378
379 typedef typename allocator_traits<allocator_type>::template
380#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
381 rebind_alloc<__begin_node>
382#else
383 rebind_alloc<__begin_node>::other
384#endif
385 __begin_node_allocator;
386 typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000387
388 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
389
Howard Hinnant0af133f2010-09-21 22:55:27 +0000390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000391 __node_pointer __before_begin() _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000392 {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
393 pointer_to(__before_begin_.first()));}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000395 __node_const_pointer __before_begin() const _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000396 {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
397 pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
Howard Hinnant3e519522010-05-11 19:42:16 +0000398
Howard Hinnant0af133f2010-09-21 22:55:27 +0000399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000400 __node_allocator& __alloc() _NOEXCEPT
401 {return __before_begin_.second();}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000403 const __node_allocator& __alloc() const _NOEXCEPT
404 {return __before_begin_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000405
406 typedef __forward_list_iterator<__node_pointer> iterator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000407 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000408
Howard Hinnant0af133f2010-09-21 22:55:27 +0000409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000410 __forward_list_base()
Howard Hinnant91a47502011-06-03 16:20:53 +0000411 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000412 : __before_begin_(__begin_node()) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000414 __forward_list_base(const allocator_type& __a)
415 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
416
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000417#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000418public:
419 __forward_list_base(__forward_list_base&& __x)
420 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000421 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000422#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000423
424private:
425 __forward_list_base(const __forward_list_base&);
426 __forward_list_base& operator=(const __forward_list_base&);
Howard Hinnant3e519522010-05-11 19:42:16 +0000427
Howard Hinnant91a47502011-06-03 16:20:53 +0000428public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000429 ~__forward_list_base();
430
Howard Hinnant91a47502011-06-03 16:20:53 +0000431protected:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000433 void __copy_assign_alloc(const __forward_list_base& __x)
434 {__copy_assign_alloc(__x, integral_constant<bool,
435 __node_traits::propagate_on_container_copy_assignment::value>());}
436
Howard Hinnant0af133f2010-09-21 22:55:27 +0000437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000438 void __move_assign_alloc(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000439 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
440 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000441 {__move_assign_alloc(__x, integral_constant<bool,
442 __node_traits::propagate_on_container_move_assignment::value>());}
443
Howard Hinnant91a47502011-06-03 16:20:53 +0000444public:
445 void swap(__forward_list_base& __x)
446 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
447 __is_nothrow_swappable<__node_allocator>::value);
448protected:
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000449 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000450
451private:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000453 void __copy_assign_alloc(const __forward_list_base&, false_type) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000455 void __copy_assign_alloc(const __forward_list_base& __x, true_type)
456 {
457 if (__alloc() != __x.__alloc())
458 clear();
459 __alloc() = __x.__alloc();
460 }
461
Howard Hinnant0af133f2010-09-21 22:55:27 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000463 void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT
464 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000466 void __move_assign_alloc(__forward_list_base& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000467 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000468 {__alloc() = _VSTD::move(__x.__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000469
Howard Hinnant0af133f2010-09-21 22:55:27 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000471 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +0000472 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
473 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000474 {__swap_alloc(__x, __y, integral_constant<bool,
475 __node_traits::propagate_on_container_swap::value>());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000477 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
478 false_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000479 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000480 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000482 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
483 true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000484 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000485 {
Howard Hinnantce48a112011-06-30 21:18:19 +0000486 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000487 swap(__x, __y);
488 }
489};
490
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000491#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000492
493template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000494inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000495__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000496 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000497 : __before_begin_(_VSTD::move(__x.__before_begin_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000498{
499 __x.__before_begin()->__next_ = nullptr;
500}
501
502template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000503inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000504__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
505 const allocator_type& __a)
506 : __before_begin_(__begin_node(), __node_allocator(__a))
507{
508 if (__alloc() == __x.__alloc())
509 {
510 __before_begin()->__next_ = __x.__before_begin()->__next_;
511 __x.__before_begin()->__next_ = nullptr;
512 }
513}
514
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000515#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000516
517template <class _Tp, class _Alloc>
518__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
519{
520 clear();
521}
522
523template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000524inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000525void
526__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000527 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
528 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000529{
530 __swap_alloc(__alloc(), __x.__alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +0000531 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000532 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
533}
534
535template <class _Tp, class _Alloc>
536void
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000537__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000538{
539 __node_allocator& __a = __alloc();
540 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
541 {
542 __node_pointer __next = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +0000543 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000544 __node_traits::deallocate(__a, __p, 1);
545 __p = __next;
546 }
547 __before_begin()->__next_ = nullptr;
548}
549
550template <class _Tp, class _Alloc = allocator<_Tp> >
Howard Hinnantf0544c22013-08-12 18:38:34 +0000551class _LIBCPP_TYPE_VIS_ONLY forward_list
Howard Hinnant3e519522010-05-11 19:42:16 +0000552 : private __forward_list_base<_Tp, _Alloc>
553{
554 typedef __forward_list_base<_Tp, _Alloc> base;
Howard Hinnant91a47502011-06-03 16:20:53 +0000555 typedef typename base::__node_allocator __node_allocator;
556 typedef typename base::__node __node;
557 typedef typename base::__node_traits __node_traits;
558 typedef typename base::__node_pointer __node_pointer;
559
Howard Hinnant3e519522010-05-11 19:42:16 +0000560public:
561 typedef _Tp value_type;
562 typedef _Alloc allocator_type;
563
564 typedef value_type& reference;
565 typedef const value_type& const_reference;
566 typedef typename allocator_traits<allocator_type>::pointer pointer;
567 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
568 typedef typename allocator_traits<allocator_type>::size_type size_type;
569 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
570
571 typedef typename base::iterator iterator;
572 typedef typename base::const_iterator const_iterator;
573
Howard Hinnant91a47502011-06-03 16:20:53 +0000574 _LIBCPP_INLINE_VISIBILITY
575 forward_list()
576 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
577 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 explicit forward_list(const allocator_type& __a);
579 explicit forward_list(size_type __n);
Marshall Clowfb829762013-09-08 19:11:51 +0000580#if _LIBCPP_STD_VER > 11
581 explicit forward_list(size_type __n, const allocator_type& __a);
582#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000583 forward_list(size_type __n, const value_type& __v);
584 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
585 template <class _InputIterator>
586 forward_list(_InputIterator __f, _InputIterator __l,
587 typename enable_if<
588 __is_input_iterator<_InputIterator>::value
589 >::type* = nullptr);
590 template <class _InputIterator>
591 forward_list(_InputIterator __f, _InputIterator __l,
592 const allocator_type& __a,
593 typename enable_if<
594 __is_input_iterator<_InputIterator>::value
595 >::type* = nullptr);
596 forward_list(const forward_list& __x);
597 forward_list(const forward_list& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000598#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000600 forward_list(forward_list&& __x)
601 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000602 : base(_VSTD::move(__x)) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 forward_list(forward_list&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000604#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000605#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000606 forward_list(initializer_list<value_type> __il);
607 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000608#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000609
610 // ~forward_list() = default;
611
612 forward_list& operator=(const forward_list& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000613#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000614 forward_list& operator=(forward_list&& __x)
615 _NOEXCEPT_(
616 __node_traits::propagate_on_container_move_assignment::value &&
617 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000618#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000619#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000620 forward_list& operator=(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
623 template <class _InputIterator>
624 typename enable_if
625 <
626 __is_input_iterator<_InputIterator>::value,
627 void
628 >::type
629 assign(_InputIterator __f, _InputIterator __l);
630 void assign(size_type __n, const value_type& __v);
Howard Hinnant54976f22011-08-12 21:56:02 +0000631#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000632 void assign(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000633#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000634
Howard Hinnant0af133f2010-09-21 22:55:27 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000636 allocator_type get_allocator() const _NOEXCEPT
637 {return allocator_type(base::__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000638
Howard Hinnant0af133f2010-09-21 22:55:27 +0000639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000640 iterator begin() _NOEXCEPT
641 {return iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000643 const_iterator begin() const _NOEXCEPT
644 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000646 iterator end() _NOEXCEPT
647 {return iterator(nullptr);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000649 const_iterator end() const _NOEXCEPT
650 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000651
Howard Hinnant0af133f2010-09-21 22:55:27 +0000652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000653 const_iterator cbegin() const _NOEXCEPT
654 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000656 const_iterator cend() const _NOEXCEPT
657 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000658
Howard Hinnant0af133f2010-09-21 22:55:27 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000660 iterator before_begin() _NOEXCEPT
661 {return iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000663 const_iterator before_begin() const _NOEXCEPT
664 {return const_iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000666 const_iterator cbefore_begin() const _NOEXCEPT
667 {return const_iterator(base::__before_begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000668
Howard Hinnant0af133f2010-09-21 22:55:27 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000670 bool empty() const _NOEXCEPT
671 {return base::__before_begin()->__next_ == nullptr;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000673 size_type max_size() const _NOEXCEPT
674 {return numeric_limits<size_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000675
Howard Hinnant0af133f2010-09-21 22:55:27 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000677 reference front() {return base::__before_begin()->__next_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000679 const_reference front() const {return base::__before_begin()->__next_->__value_;}
680
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000681#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
682#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000683 template <class... _Args> void emplace_front(_Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000684#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000685 void push_front(value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000686#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000687 void push_front(const value_type& __v);
688
689 void pop_front();
690
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000691#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
692#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000693 template <class... _Args>
694 iterator emplace_after(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000695#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000696 iterator insert_after(const_iterator __p, value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000697#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000698 iterator insert_after(const_iterator __p, const value_type& __v);
699 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
700 template <class _InputIterator>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000702 typename enable_if
703 <
704 __is_input_iterator<_InputIterator>::value,
705 iterator
706 >::type
707 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
Howard Hinnant54976f22011-08-12 21:56:02 +0000708#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000709 iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
710 {return insert_after(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000711#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000712
Howard Hinnant3db88032010-08-21 20:58:44 +0000713 iterator erase_after(const_iterator __p);
714 iterator erase_after(const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000715
Howard Hinnant0af133f2010-09-21 22:55:27 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000717 void swap(forward_list& __x)
718 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
719 __is_nothrow_swappable<__node_allocator>::value)
720 {base::swap(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000721
722 void resize(size_type __n);
723 void resize(size_type __n, const value_type& __v);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000725 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000726
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000727#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnanteb92df72011-01-27 21:00:35 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000729 void splice_after(const_iterator __p, forward_list&& __x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000731 void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000733 void splice_after(const_iterator __p, forward_list&& __x,
734 const_iterator __f, const_iterator __l);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000735#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000736 void splice_after(const_iterator __p, forward_list& __x);
737 void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
738 void splice_after(const_iterator __p, forward_list& __x,
739 const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000740 void remove(const value_type& __v);
741 template <class _Predicate> void remove_if(_Predicate __pred);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000743 void unique() {unique(__equal_to<value_type>());}
744 template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000745#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteb92df72011-01-27 21:00:35 +0000747 void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
748 template <class _Compare>
749 _LIBCPP_INLINE_VISIBILITY
750 void merge(forward_list&& __x, _Compare __comp)
Howard Hinnantce48a112011-06-30 21:18:19 +0000751 {merge(__x, _VSTD::move(__comp));}
Howard Hinnanteb92df72011-01-27 21:00:35 +0000752#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000754 void merge(forward_list& __x) {merge(__x, __less<value_type>());}
755 template <class _Compare> void merge(forward_list& __x, _Compare __comp);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000757 void sort() {sort(__less<value_type>());}
758 template <class _Compare> void sort(_Compare __comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000759 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000760
761private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000762
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000763#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000764 void __move_assign(forward_list& __x, true_type)
765 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000766 void __move_assign(forward_list& __x, false_type);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000767#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000768
769 template <class _Compare>
770 static
771 __node_pointer
772 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
773
774 template <class _Compare>
775 static
776 __node_pointer
777 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
778};
779
780template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000782forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
783 : base(__a)
784{
785}
786
787template <class _Tp, class _Alloc>
788forward_list<_Tp, _Alloc>::forward_list(size_type __n)
789{
790 if (__n > 0)
791 {
792 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000793 typedef __allocator_destructor<__node_allocator> _Dp;
794 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +0000795 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
796 __p = __p->__next_)
797 {
798 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +0000799 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000800 __h->__next_ = nullptr;
801 __p->__next_ = __h.release();
802 }
803 }
804}
805
Marshall Clowfb829762013-09-08 19:11:51 +0000806#if _LIBCPP_STD_VER > 11
807template <class _Tp, class _Alloc>
808forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a)
809 : base ( __a )
810{
811 if (__n > 0)
812 {
813 __node_allocator& __a = base::__alloc();
814 typedef __allocator_destructor<__node_allocator> _Dp;
815 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
816 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
817 __p = __p->__next_)
818 {
819 __h.reset(__node_traits::allocate(__a, 1));
820 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
821 __h->__next_ = nullptr;
822 __p->__next_ = __h.release();
823 }
824 }
825}
826#endif
827
Howard Hinnant3e519522010-05-11 19:42:16 +0000828template <class _Tp, class _Alloc>
829forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
830{
831 insert_after(cbefore_begin(), __n, __v);
832}
833
834template <class _Tp, class _Alloc>
835forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
836 const allocator_type& __a)
837 : base(__a)
838{
839 insert_after(cbefore_begin(), __n, __v);
840}
841
842template <class _Tp, class _Alloc>
843template <class _InputIterator>
844forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
845 typename enable_if<
846 __is_input_iterator<_InputIterator>::value
847 >::type*)
848{
849 insert_after(cbefore_begin(), __f, __l);
850}
851
852template <class _Tp, class _Alloc>
853template <class _InputIterator>
854forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
855 const allocator_type& __a,
856 typename enable_if<
857 __is_input_iterator<_InputIterator>::value
858 >::type*)
859 : base(__a)
860{
861 insert_after(cbefore_begin(), __f, __l);
862}
863
864template <class _Tp, class _Alloc>
865forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
866 : base(allocator_type(
867 __node_traits::select_on_container_copy_construction(__x.__alloc())
868 )
869 )
870{
871 insert_after(cbefore_begin(), __x.begin(), __x.end());
872}
873
874template <class _Tp, class _Alloc>
875forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
876 const allocator_type& __a)
877 : base(__a)
878{
879 insert_after(cbefore_begin(), __x.begin(), __x.end());
880}
881
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000882#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000883
884template <class _Tp, class _Alloc>
885forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
886 const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000887 : base(_VSTD::move(__x), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000888{
889 if (base::__alloc() != __x.__alloc())
890 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000891 typedef move_iterator<iterator> _Ip;
892 insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000893 }
894}
895
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000896#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000897
Howard Hinnant54976f22011-08-12 21:56:02 +0000898#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
899
Howard Hinnant3e519522010-05-11 19:42:16 +0000900template <class _Tp, class _Alloc>
901forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
902{
903 insert_after(cbefore_begin(), __il.begin(), __il.end());
904}
905
906template <class _Tp, class _Alloc>
907forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
908 const allocator_type& __a)
909 : base(__a)
910{
911 insert_after(cbefore_begin(), __il.begin(), __il.end());
912}
913
Howard Hinnant54976f22011-08-12 21:56:02 +0000914#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
915
Howard Hinnant3e519522010-05-11 19:42:16 +0000916template <class _Tp, class _Alloc>
917forward_list<_Tp, _Alloc>&
918forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
919{
920 if (this != &__x)
921 {
922 base::__copy_assign_alloc(__x);
923 assign(__x.begin(), __x.end());
924 }
925 return *this;
926}
927
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000928#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000929
930template <class _Tp, class _Alloc>
931void
932forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000933 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000934{
935 clear();
936 base::__move_assign_alloc(__x);
937 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
938 __x.__before_begin()->__next_ = nullptr;
939}
940
941template <class _Tp, class _Alloc>
942void
943forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
944{
945 if (base::__alloc() == __x.__alloc())
946 __move_assign(__x, true_type());
947 else
948 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000949 typedef move_iterator<iterator> _Ip;
950 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000951 }
952}
953
954template <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=(forward_list&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000958 _NOEXCEPT_(
959 __node_traits::propagate_on_container_move_assignment::value &&
960 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000961{
962 __move_assign(__x, integral_constant<bool,
963 __node_traits::propagate_on_container_move_assignment::value>());
964 return *this;
965}
966
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000967#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000968
Howard Hinnant54976f22011-08-12 21:56:02 +0000969#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
970
Howard Hinnant3e519522010-05-11 19:42:16 +0000971template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000973forward_list<_Tp, _Alloc>&
974forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
975{
976 assign(__il.begin(), __il.end());
977 return *this;
978}
979
Howard Hinnant54976f22011-08-12 21:56:02 +0000980#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
981
Howard Hinnant3e519522010-05-11 19:42:16 +0000982template <class _Tp, class _Alloc>
983template <class _InputIterator>
984typename enable_if
985<
986 __is_input_iterator<_InputIterator>::value,
987 void
988>::type
989forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
990{
991 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000992 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000993 iterator __e = end();
994 for (; __j != __e && __f != __l; ++__i, ++__j, ++__f)
995 *__j = *__f;
996 if (__j == __e)
997 insert_after(__i, __f, __l);
998 else
999 erase_after(__i, __e);
1000}
1001
1002template <class _Tp, class _Alloc>
1003void
1004forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
1005{
1006 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +00001007 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001008 iterator __e = end();
1009 for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
1010 *__j = __v;
1011 if (__j == __e)
1012 insert_after(__i, __n, __v);
1013 else
1014 erase_after(__i, __e);
1015}
1016
Howard Hinnant54976f22011-08-12 21:56:02 +00001017#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1018
Howard Hinnant3e519522010-05-11 19:42:16 +00001019template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001020inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001021void
1022forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
1023{
1024 assign(__il.begin(), __il.end());
1025}
1026
Howard Hinnant54976f22011-08-12 21:56:02 +00001027#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1028
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001029#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1030#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001031
1032template <class _Tp, class _Alloc>
1033template <class... _Args>
1034void
1035forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1036{
1037 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001038 typedef __allocator_destructor<__node_allocator> _Dp;
1039 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001040 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1041 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001042 __h->__next_ = base::__before_begin()->__next_;
1043 base::__before_begin()->__next_ = __h.release();
1044}
1045
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001046#endif // _LIBCPP_HAS_NO_VARIADICS
1047
Howard Hinnant3e519522010-05-11 19:42:16 +00001048template <class _Tp, class _Alloc>
1049void
1050forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
1051{
1052 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001053 typedef __allocator_destructor<__node_allocator> _Dp;
1054 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001055 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001056 __h->__next_ = base::__before_begin()->__next_;
1057 base::__before_begin()->__next_ = __h.release();
1058}
1059
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001060#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001061
1062template <class _Tp, class _Alloc>
1063void
1064forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
1065{
1066 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001067 typedef __allocator_destructor<__node_allocator> _Dp;
1068 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001069 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001070 __h->__next_ = base::__before_begin()->__next_;
1071 base::__before_begin()->__next_ = __h.release();
1072}
1073
1074template <class _Tp, class _Alloc>
1075void
1076forward_list<_Tp, _Alloc>::pop_front()
1077{
1078 __node_allocator& __a = base::__alloc();
1079 __node_pointer __p = base::__before_begin()->__next_;
1080 base::__before_begin()->__next_ = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001081 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001082 __node_traits::deallocate(__a, __p, 1);
1083}
1084
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001085#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1086#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001087
1088template <class _Tp, class _Alloc>
1089template <class... _Args>
1090typename forward_list<_Tp, _Alloc>::iterator
1091forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
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_),
1098 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001099 __h->__next_ = __r->__next_;
1100 __r->__next_ = __h.release();
1101 return iterator(__r->__next_);
1102}
1103
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001104#endif // _LIBCPP_HAS_NO_VARIADICS
1105
Howard Hinnant3e519522010-05-11 19:42:16 +00001106template <class _Tp, class _Alloc>
1107typename forward_list<_Tp, _Alloc>::iterator
1108forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
1109{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001110 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001111 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001112 typedef __allocator_destructor<__node_allocator> _Dp;
1113 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001114 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001115 __h->__next_ = __r->__next_;
1116 __r->__next_ = __h.release();
1117 return iterator(__r->__next_);
1118}
1119
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001120#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001121
1122template <class _Tp, class _Alloc>
1123typename forward_list<_Tp, _Alloc>::iterator
1124forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
1125{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001126 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001127 __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 __h->__next_ = __r->__next_;
1132 __r->__next_ = __h.release();
1133 return iterator(__r->__next_);
1134}
1135
1136template <class _Tp, class _Alloc>
1137typename forward_list<_Tp, _Alloc>::iterator
1138forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
1139 const value_type& __v)
1140{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001141 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001142 if (__n > 0)
1143 {
1144 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001145 typedef __allocator_destructor<__node_allocator> _Dp;
1146 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001147 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001148 __node_pointer __first = __h.release();
1149 __node_pointer __last = __first;
1150#ifndef _LIBCPP_NO_EXCEPTIONS
1151 try
1152 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001153#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001154 for (--__n; __n != 0; --__n, __last = __last->__next_)
1155 {
1156 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001157 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001158 __last->__next_ = __h.release();
1159 }
1160#ifndef _LIBCPP_NO_EXCEPTIONS
1161 }
1162 catch (...)
1163 {
1164 while (__first != nullptr)
1165 {
1166 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001167 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001168 __node_traits::deallocate(__a, __first, 1);
1169 __first = __next;
1170 }
1171 throw;
1172 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001173#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001174 __last->__next_ = __r->__next_;
1175 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001176 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001177 }
1178 return iterator(__r);
1179}
1180
1181template <class _Tp, class _Alloc>
1182template <class _InputIterator>
1183typename enable_if
1184<
1185 __is_input_iterator<_InputIterator>::value,
1186 typename forward_list<_Tp, _Alloc>::iterator
1187>::type
1188forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
1189 _InputIterator __f, _InputIterator __l)
1190{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001191 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001192 if (__f != __l)
1193 {
1194 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001195 typedef __allocator_destructor<__node_allocator> _Dp;
1196 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001197 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001198 __node_pointer __first = __h.release();
1199 __node_pointer __last = __first;
1200#ifndef _LIBCPP_NO_EXCEPTIONS
1201 try
1202 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001203#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001204 for (++__f; __f != __l; ++__f, __last = __last->__next_)
1205 {
1206 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001207 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001208 __last->__next_ = __h.release();
1209 }
1210#ifndef _LIBCPP_NO_EXCEPTIONS
1211 }
1212 catch (...)
1213 {
1214 while (__first != nullptr)
1215 {
1216 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001217 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001218 __node_traits::deallocate(__a, __first, 1);
1219 __first = __next;
1220 }
1221 throw;
1222 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001223#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001224 __last->__next_ = __r->__next_;
1225 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001226 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001227 }
1228 return iterator(__r);
1229}
1230
1231template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001232typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001233forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
1234{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001235 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001236 __node_pointer __n = __p->__next_;
1237 __p->__next_ = __n->__next_;
1238 __node_allocator& __a = base::__alloc();
Howard Hinnantce48a112011-06-30 21:18:19 +00001239 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001240 __node_traits::deallocate(__a, __n, 1);
Howard Hinnant3db88032010-08-21 20:58:44 +00001241 return iterator(__p->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001242}
1243
1244template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001245typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001246forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
1247{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001248 __node_pointer __e = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001249 if (__f != __l)
1250 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001251 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001252 __node_pointer __n = __p->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001253 if (__n != __e)
1254 {
1255 __p->__next_ = __e;
1256 __node_allocator& __a = base::__alloc();
1257 do
1258 {
1259 __p = __n->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001260 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001261 __node_traits::deallocate(__a, __n, 1);
1262 __n = __p;
1263 } while (__n != __e);
1264 }
1265 }
Howard Hinnant3db88032010-08-21 20:58:44 +00001266 return iterator(__e);
Howard Hinnant3e519522010-05-11 19:42:16 +00001267}
1268
1269template <class _Tp, class _Alloc>
1270void
1271forward_list<_Tp, _Alloc>::resize(size_type __n)
1272{
1273 size_type __sz = 0;
1274 iterator __p = before_begin();
1275 iterator __i = begin();
1276 iterator __e = end();
1277 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1278 ;
1279 if (__i != __e)
1280 erase_after(__p, __e);
1281 else
1282 {
1283 __n -= __sz;
1284 if (__n > 0)
1285 {
1286 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001287 typedef __allocator_destructor<__node_allocator> _Dp;
1288 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001289 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1290 __ptr = __ptr->__next_)
1291 {
1292 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001293 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001294 __h->__next_ = nullptr;
1295 __ptr->__next_ = __h.release();
1296 }
1297 }
1298 }
1299}
1300
1301template <class _Tp, class _Alloc>
1302void
1303forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
1304{
1305 size_type __sz = 0;
1306 iterator __p = before_begin();
1307 iterator __i = begin();
1308 iterator __e = end();
1309 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1310 ;
1311 if (__i != __e)
1312 erase_after(__p, __e);
1313 else
1314 {
1315 __n -= __sz;
1316 if (__n > 0)
1317 {
1318 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001319 typedef __allocator_destructor<__node_allocator> _Dp;
1320 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001321 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1322 __ptr = __ptr->__next_)
1323 {
1324 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001325 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001326 __h->__next_ = nullptr;
1327 __ptr->__next_ = __h.release();
1328 }
1329 }
1330 }
1331}
1332
1333template <class _Tp, class _Alloc>
1334void
1335forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001336 forward_list& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00001337{
1338 if (!__x.empty())
1339 {
1340 if (__p.__ptr_->__next_ != nullptr)
1341 {
1342 const_iterator __lm1 = __x.before_begin();
1343 while (__lm1.__ptr_->__next_ != nullptr)
1344 ++__lm1;
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001345 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001346 }
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001347 __p.__ptr_->__next_ = __x.__before_begin()->__next_;
1348 __x.__before_begin()->__next_ = nullptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001349 }
1350}
1351
1352template <class _Tp, class _Alloc>
1353void
1354forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001355 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001356 const_iterator __i)
1357{
Howard Hinnantce48a112011-06-30 21:18:19 +00001358 const_iterator __lm1 = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001359 if (__p != __i && __p != __lm1)
1360 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001361 __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
1362 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1363 __p.__ptr_->__next_ = __lm1.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001364 }
1365}
1366
1367template <class _Tp, class _Alloc>
1368void
1369forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001370 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001371 const_iterator __f, const_iterator __l)
1372{
1373 if (__f != __l && __p != __f)
1374 {
1375 const_iterator __lm1 = __f;
1376 while (__lm1.__ptr_->__next_ != __l.__ptr_)
1377 ++__lm1;
1378 if (__f != __lm1)
1379 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001380 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1381 __p.__ptr_->__next_ = __f.__ptr_->__next_;
1382 __f.__ptr_->__next_ = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001383 }
1384 }
1385}
1386
Howard Hinnanteb92df72011-01-27 21:00:35 +00001387#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1388
1389template <class _Tp, class _Alloc>
1390inline _LIBCPP_INLINE_VISIBILITY
1391void
1392forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1393 forward_list&& __x)
1394{
1395 splice_after(__p, __x);
1396}
1397
1398template <class _Tp, class _Alloc>
1399inline _LIBCPP_INLINE_VISIBILITY
1400void
1401forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1402 forward_list&& __x,
1403 const_iterator __i)
1404{
1405 splice_after(__p, __x, __i);
1406}
1407
1408template <class _Tp, class _Alloc>
1409inline _LIBCPP_INLINE_VISIBILITY
1410void
1411forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1412 forward_list&& __x,
1413 const_iterator __f, const_iterator __l)
1414{
1415 splice_after(__p, __x, __f, __l);
1416}
1417
1418#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1419
Howard Hinnant3e519522010-05-11 19:42:16 +00001420template <class _Tp, class _Alloc>
1421void
1422forward_list<_Tp, _Alloc>::remove(const value_type& __v)
1423{
1424 iterator __e = end();
1425 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1426 {
1427 if (__i.__ptr_->__next_->__value_ == __v)
1428 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001429 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001430 for (; __j != __e && *__j == __v; ++__j)
1431 ;
1432 erase_after(__i, __j);
1433 if (__j == __e)
1434 break;
1435 __i = __j;
1436 }
1437 else
1438 ++__i;
1439 }
1440}
1441
1442template <class _Tp, class _Alloc>
1443template <class _Predicate>
1444void
1445forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
1446{
1447 iterator __e = end();
1448 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1449 {
1450 if (__pred(__i.__ptr_->__next_->__value_))
1451 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001452 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001453 for (; __j != __e && __pred(*__j); ++__j)
1454 ;
1455 erase_after(__i, __j);
1456 if (__j == __e)
1457 break;
1458 __i = __j;
1459 }
1460 else
1461 ++__i;
1462 }
1463}
1464
1465template <class _Tp, class _Alloc>
1466template <class _BinaryPredicate>
1467void
1468forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
1469{
1470 for (iterator __i = begin(), __e = end(); __i != __e;)
1471 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001472 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001473 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1474 ;
1475 if (__i.__ptr_->__next_ != __j.__ptr_)
1476 erase_after(__i, __j);
1477 __i = __j;
1478 }
1479}
1480
1481template <class _Tp, class _Alloc>
1482template <class _Compare>
1483void
Howard Hinnant3e519522010-05-11 19:42:16 +00001484forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
Howard Hinnant3e519522010-05-11 19:42:16 +00001485{
1486 if (this != &__x)
1487 {
1488 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
1489 __x.__before_begin()->__next_,
1490 __comp);
1491 __x.__before_begin()->__next_ = nullptr;
1492 }
1493}
1494
1495template <class _Tp, class _Alloc>
1496template <class _Compare>
1497typename forward_list<_Tp, _Alloc>::__node_pointer
1498forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
1499 _Compare& __comp)
1500{
1501 if (__f1 == nullptr)
1502 return __f2;
1503 if (__f2 == nullptr)
1504 return __f1;
1505 __node_pointer __r;
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 __r = __f2;
1513 __f2 = __t->__next_;
1514 __t->__next_ = __f1;
1515 }
1516 else
1517 __r = __f1;
1518 __node_pointer __p = __f1;
1519 __f1 = __f1->__next_;
1520 while (__f1 != nullptr && __f2 != nullptr)
1521 {
1522 if (__comp(__f2->__value_, __f1->__value_))
1523 {
1524 __node_pointer __t = __f2;
1525 while (__t->__next_ != nullptr &&
1526 __comp(__t->__next_->__value_, __f1->__value_))
1527 __t = __t->__next_;
1528 __p->__next_ = __f2;
1529 __f2 = __t->__next_;
1530 __t->__next_ = __f1;
1531 }
1532 __p = __f1;
1533 __f1 = __f1->__next_;
1534 }
1535 if (__f2 != nullptr)
1536 __p->__next_ = __f2;
1537 return __r;
1538}
1539
1540template <class _Tp, class _Alloc>
1541template <class _Compare>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001542inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001543void
1544forward_list<_Tp, _Alloc>::sort(_Compare __comp)
1545{
1546 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
Howard Hinnantce48a112011-06-30 21:18:19 +00001547 _VSTD::distance(begin(), end()), __comp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001548}
1549
1550template <class _Tp, class _Alloc>
1551template <class _Compare>
1552typename forward_list<_Tp, _Alloc>::__node_pointer
1553forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
1554 _Compare& __comp)
1555{
1556 switch (__sz)
1557 {
1558 case 0:
1559 case 1:
1560 return __f1;
1561 case 2:
1562 if (__comp(__f1->__next_->__value_, __f1->__value_))
1563 {
1564 __node_pointer __t = __f1->__next_;
1565 __t->__next_ = __f1;
1566 __f1->__next_ = nullptr;
1567 __f1 = __t;
1568 }
1569 return __f1;
1570 }
1571 difference_type __sz1 = __sz / 2;
1572 difference_type __sz2 = __sz - __sz1;
Howard Hinnantce48a112011-06-30 21:18:19 +00001573 __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001574 __node_pointer __f2 = __t->__next_;
1575 __t->__next_ = nullptr;
1576 return __merge(__sort(__f1, __sz1, __comp),
1577 __sort(__f2, __sz2, __comp), __comp);
1578}
1579
1580template <class _Tp, class _Alloc>
1581void
Howard Hinnantf9dc2832011-06-02 16:44:28 +00001582forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001583{
1584 __node_pointer __p = base::__before_begin()->__next_;
1585 if (__p != nullptr)
1586 {
1587 __node_pointer __f = __p->__next_;
1588 __p->__next_ = nullptr;
1589 while (__f != nullptr)
1590 {
1591 __node_pointer __t = __f->__next_;
1592 __f->__next_ = __p;
1593 __p = __f;
1594 __f = __t;
1595 }
1596 base::__before_begin()->__next_ = __p;
1597 }
1598}
1599
1600template <class _Tp, class _Alloc>
1601bool operator==(const forward_list<_Tp, _Alloc>& __x,
1602 const forward_list<_Tp, _Alloc>& __y)
1603{
Howard Hinnantc003db12011-11-29 18:15:50 +00001604 typedef forward_list<_Tp, _Alloc> _Cp;
1605 typedef typename _Cp::const_iterator _Ip;
1606 _Ip __ix = __x.begin();
1607 _Ip __ex = __x.end();
1608 _Ip __iy = __y.begin();
1609 _Ip __ey = __y.end();
Howard Hinnant3e519522010-05-11 19:42:16 +00001610 for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
1611 if (!(*__ix == *__iy))
1612 return false;
1613 return (__ix == __ex) == (__iy == __ey);
1614}
1615
1616template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001617inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001618bool operator!=(const forward_list<_Tp, _Alloc>& __x,
1619 const forward_list<_Tp, _Alloc>& __y)
1620{
1621 return !(__x == __y);
1622}
1623
1624template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001626bool operator< (const forward_list<_Tp, _Alloc>& __x,
1627 const forward_list<_Tp, _Alloc>& __y)
1628{
Howard Hinnantce48a112011-06-30 21:18:19 +00001629 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
Howard Hinnant3e519522010-05-11 19:42:16 +00001630 __y.begin(), __y.end());
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 +00001643bool operator>=(const forward_list<_Tp, _Alloc>& __x,
1644 const forward_list<_Tp, _Alloc>& __y)
1645{
1646 return !(__x < __y);
1647}
1648
1649template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001651bool operator<=(const forward_list<_Tp, _Alloc>& __x,
1652 const forward_list<_Tp, _Alloc>& __y)
1653{
1654 return !(__y < __x);
1655}
1656
1657template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001659void
1660swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +00001661 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001662{
1663 __x.swap(__y);
1664}
1665
1666_LIBCPP_END_NAMESPACE_STD
1667
1668#endif // _LIBCPP_FORWARD_LIST