blob: 2fbcdbe30e51c7e73ff48c967189ed801ef7c7c1 [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 Clowfb829762013-09-08 19:11:51 +000041 explicit forward_list(size_type n, const Allocator& 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{
191 typedef __forward_begin_node __self;
192 typedef _NodePtr pointer;
193
194 pointer __next_;
195
Howard Hinnant0af133f2010-09-21 22:55:27 +0000196 _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000197};
198
199template <class _Tp, class _VoidPtr>
200struct __forward_list_node
201 : public __forward_begin_node
202 <
203 typename pointer_traits<_VoidPtr>::template
204#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
205 rebind<__forward_list_node<_Tp, _VoidPtr> >
206#else
207 rebind<__forward_list_node<_Tp, _VoidPtr> >::other
208#endif
209 >
210{
211 typedef _Tp value_type;
212
213 value_type __value_;
214};
215
Howard Hinnantf0544c22013-08-12 18:38:34 +0000216template<class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS_ONLY forward_list;
217template<class _NodeConstPtr> class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000218
219template <class _NodePtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000220class _LIBCPP_TYPE_VIS_ONLY __forward_list_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000221{
222 typedef _NodePtr __node_pointer;
223
224 __node_pointer __ptr_;
225
Howard Hinnant0af133f2010-09-21 22:55:27 +0000226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000227 explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000228
Howard Hinnantf0544c22013-08-12 18:38:34 +0000229 template<class, class> friend class _LIBCPP_TYPE_VIS_ONLY forward_list;
230 template<class> friend class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000231
232public:
233 typedef forward_iterator_tag iterator_category;
234 typedef typename pointer_traits<__node_pointer>::element_type::value_type
235 value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000236 typedef value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000237 typedef typename pointer_traits<__node_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000238 difference_type;
239 typedef typename pointer_traits<__node_pointer>::template
240#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
241 rebind<value_type>
242#else
243 rebind<value_type>::other
244#endif
245 pointer;
246
Howard Hinnant0af133f2010-09-21 22:55:27 +0000247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000248 __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000249
Howard Hinnant0af133f2010-09-21 22:55:27 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000251 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000253 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
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 __forward_list_iterator& operator++()
257 {
258 __ptr_ = __ptr_->__next_;
259 return *this;
260 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000262 __forward_list_iterator operator++(int)
263 {
264 __forward_list_iterator __t(*this);
265 ++(*this);
266 return __t;
267 }
268
Howard Hinnant0af133f2010-09-21 22:55:27 +0000269 friend _LIBCPP_INLINE_VISIBILITY
270 bool operator==(const __forward_list_iterator& __x,
271 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000272 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000273 friend _LIBCPP_INLINE_VISIBILITY
274 bool operator!=(const __forward_list_iterator& __x,
275 const __forward_list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000276 {return !(__x == __y);}
277};
278
279template <class _NodeConstPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000280class _LIBCPP_TYPE_VIS_ONLY __forward_list_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000281{
282 typedef _NodeConstPtr __node_const_pointer;
283
284 __node_const_pointer __ptr_;
285
Howard Hinnant0af133f2010-09-21 22:55:27 +0000286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000287 explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000288 : __ptr_(__p) {}
289
290 typedef typename remove_const
291 <
292 typename pointer_traits<__node_const_pointer>::element_type
293 >::type __node;
294 typedef typename pointer_traits<__node_const_pointer>::template
295#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
296 rebind<__node>
297#else
298 rebind<__node>::other
299#endif
300 __node_pointer;
301
302 template<class, class> friend class forward_list;
303
304public:
305 typedef forward_iterator_tag iterator_category;
306 typedef typename __node::value_type value_type;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000307 typedef const value_type& reference;
Howard Hinnantb3371f62010-08-22 00:02:43 +0000308 typedef typename pointer_traits<__node_const_pointer>::difference_type
Howard Hinnant3e519522010-05-11 19:42:16 +0000309 difference_type;
310 typedef typename pointer_traits<__node_const_pointer>::template
311#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
312 rebind<const value_type>
313#else
314 rebind<const value_type>::other
315#endif
316 pointer;
317
Howard Hinnant0af133f2010-09-21 22:55:27 +0000318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000319 __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000321 __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000322 : __ptr_(__p.__ptr_) {}
323
Howard Hinnant0af133f2010-09-21 22:55:27 +0000324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000325 reference operator*() const {return __ptr_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000327 pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000328
Howard Hinnant0af133f2010-09-21 22:55:27 +0000329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000330 __forward_list_const_iterator& operator++()
331 {
332 __ptr_ = __ptr_->__next_;
333 return *this;
334 }
Howard Hinnant0af133f2010-09-21 22:55:27 +0000335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000336 __forward_list_const_iterator operator++(int)
337 {
338 __forward_list_const_iterator __t(*this);
339 ++(*this);
340 return __t;
341 }
342
Howard Hinnant0af133f2010-09-21 22:55:27 +0000343 friend _LIBCPP_INLINE_VISIBILITY
344 bool operator==(const __forward_list_const_iterator& __x,
345 const __forward_list_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000346 {return __x.__ptr_ == __y.__ptr_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000347 friend _LIBCPP_INLINE_VISIBILITY
348 bool operator!=(const __forward_list_const_iterator& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +0000349 const __forward_list_const_iterator& __y)
350 {return !(__x == __y);}
351};
352
353template <class _Tp, class _Alloc>
354class __forward_list_base
355{
356protected:
357 typedef _Tp value_type;
358 typedef _Alloc allocator_type;
359
360 typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
361 typedef __forward_list_node<value_type, void_pointer> __node;
362 typedef typename __node::__self __begin_node;
363 typedef typename allocator_traits<allocator_type>::template
364#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
365 rebind_alloc<__node>
366#else
367 rebind_alloc<__node>::other
368#endif
369 __node_allocator;
370 typedef allocator_traits<__node_allocator> __node_traits;
371 typedef typename __node_traits::pointer __node_pointer;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000372 typedef typename __node_traits::pointer __node_const_pointer;
373
374 typedef typename allocator_traits<allocator_type>::template
375#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
376 rebind_alloc<__begin_node>
377#else
378 rebind_alloc<__begin_node>::other
379#endif
380 __begin_node_allocator;
381 typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000382
383 __compressed_pair<__begin_node, __node_allocator> __before_begin_;
384
Howard Hinnant0af133f2010-09-21 22:55:27 +0000385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000386 __node_pointer __before_begin() _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000387 {return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
388 pointer_to(__before_begin_.first()));}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000390 __node_const_pointer __before_begin() const _NOEXCEPT
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000391 {return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
392 pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
Howard Hinnant3e519522010-05-11 19:42:16 +0000393
Howard Hinnant0af133f2010-09-21 22:55:27 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000395 __node_allocator& __alloc() _NOEXCEPT
396 {return __before_begin_.second();}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000398 const __node_allocator& __alloc() const _NOEXCEPT
399 {return __before_begin_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000400
401 typedef __forward_list_iterator<__node_pointer> iterator;
Howard Hinnant8a27ba82013-06-24 17:17:28 +0000402 typedef __forward_list_const_iterator<__node_pointer> const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000403
Howard Hinnant0af133f2010-09-21 22:55:27 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000405 __forward_list_base()
Howard Hinnant91a47502011-06-03 16:20:53 +0000406 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000407 : __before_begin_(__begin_node()) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000409 __forward_list_base(const allocator_type& __a)
410 : __before_begin_(__begin_node(), __node_allocator(__a)) {}
411
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000412#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000413public:
414 __forward_list_base(__forward_list_base&& __x)
415 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000416 __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000417#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000418
419private:
420 __forward_list_base(const __forward_list_base&);
421 __forward_list_base& operator=(const __forward_list_base&);
Howard Hinnant3e519522010-05-11 19:42:16 +0000422
Howard Hinnant91a47502011-06-03 16:20:53 +0000423public:
Howard Hinnant3e519522010-05-11 19:42:16 +0000424 ~__forward_list_base();
425
Howard Hinnant91a47502011-06-03 16:20:53 +0000426protected:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000428 void __copy_assign_alloc(const __forward_list_base& __x)
429 {__copy_assign_alloc(__x, integral_constant<bool,
430 __node_traits::propagate_on_container_copy_assignment::value>());}
431
Howard Hinnant0af133f2010-09-21 22:55:27 +0000432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000433 void __move_assign_alloc(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000434 _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
435 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000436 {__move_assign_alloc(__x, integral_constant<bool,
437 __node_traits::propagate_on_container_move_assignment::value>());}
438
Howard Hinnant91a47502011-06-03 16:20:53 +0000439public:
440 void swap(__forward_list_base& __x)
441 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
442 __is_nothrow_swappable<__node_allocator>::value);
443protected:
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000444 void clear() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000445
446private:
Howard Hinnant0af133f2010-09-21 22:55:27 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000448 void __copy_assign_alloc(const __forward_list_base&, false_type) {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000450 void __copy_assign_alloc(const __forward_list_base& __x, true_type)
451 {
452 if (__alloc() != __x.__alloc())
453 clear();
454 __alloc() = __x.__alloc();
455 }
456
Howard Hinnant0af133f2010-09-21 22:55:27 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000458 void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT
459 {}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000461 void __move_assign_alloc(__forward_list_base& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000462 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000463 {__alloc() = _VSTD::move(__x.__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000464
Howard Hinnant0af133f2010-09-21 22:55:27 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000466 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +0000467 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
468 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000469 {__swap_alloc(__x, __y, integral_constant<bool,
470 __node_traits::propagate_on_container_swap::value>());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000472 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y,
473 false_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000474 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000475 {}
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 true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000479 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000480 {
Howard Hinnantce48a112011-06-30 21:18:19 +0000481 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000482 swap(__x, __y);
483 }
484};
485
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000486#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000487
488template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000490__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000491 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000492 : __before_begin_(_VSTD::move(__x.__before_begin_))
Howard Hinnant3e519522010-05-11 19:42:16 +0000493{
494 __x.__before_begin()->__next_ = nullptr;
495}
496
497template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000499__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
500 const allocator_type& __a)
501 : __before_begin_(__begin_node(), __node_allocator(__a))
502{
503 if (__alloc() == __x.__alloc())
504 {
505 __before_begin()->__next_ = __x.__before_begin()->__next_;
506 __x.__before_begin()->__next_ = nullptr;
507 }
508}
509
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000510#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000511
512template <class _Tp, class _Alloc>
513__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
514{
515 clear();
516}
517
518template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000519inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000520void
521__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000522 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
523 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000524{
525 __swap_alloc(__alloc(), __x.__alloc());
Howard Hinnantce48a112011-06-30 21:18:19 +0000526 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:16 +0000527 swap(__before_begin()->__next_, __x.__before_begin()->__next_);
528}
529
530template <class _Tp, class _Alloc>
531void
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000532__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000533{
534 __node_allocator& __a = __alloc();
535 for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
536 {
537 __node_pointer __next = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +0000538 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000539 __node_traits::deallocate(__a, __p, 1);
540 __p = __next;
541 }
542 __before_begin()->__next_ = nullptr;
543}
544
545template <class _Tp, class _Alloc = allocator<_Tp> >
Howard Hinnantf0544c22013-08-12 18:38:34 +0000546class _LIBCPP_TYPE_VIS_ONLY forward_list
Howard Hinnant3e519522010-05-11 19:42:16 +0000547 : private __forward_list_base<_Tp, _Alloc>
548{
549 typedef __forward_list_base<_Tp, _Alloc> base;
Howard Hinnant91a47502011-06-03 16:20:53 +0000550 typedef typename base::__node_allocator __node_allocator;
551 typedef typename base::__node __node;
552 typedef typename base::__node_traits __node_traits;
553 typedef typename base::__node_pointer __node_pointer;
554
Howard Hinnant3e519522010-05-11 19:42:16 +0000555public:
556 typedef _Tp value_type;
557 typedef _Alloc allocator_type;
558
559 typedef value_type& reference;
560 typedef const value_type& const_reference;
561 typedef typename allocator_traits<allocator_type>::pointer pointer;
562 typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
563 typedef typename allocator_traits<allocator_type>::size_type size_type;
564 typedef typename allocator_traits<allocator_type>::difference_type difference_type;
565
566 typedef typename base::iterator iterator;
567 typedef typename base::const_iterator const_iterator;
568
Howard Hinnant91a47502011-06-03 16:20:53 +0000569 _LIBCPP_INLINE_VISIBILITY
570 forward_list()
571 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
572 {} // = default;
Howard Hinnant3e519522010-05-11 19:42:16 +0000573 explicit forward_list(const allocator_type& __a);
574 explicit forward_list(size_type __n);
Marshall Clowfb829762013-09-08 19:11:51 +0000575#if _LIBCPP_STD_VER > 11
576 explicit forward_list(size_type __n, const allocator_type& __a);
577#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000578 forward_list(size_type __n, const value_type& __v);
579 forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
580 template <class _InputIterator>
581 forward_list(_InputIterator __f, _InputIterator __l,
582 typename enable_if<
583 __is_input_iterator<_InputIterator>::value
584 >::type* = nullptr);
585 template <class _InputIterator>
586 forward_list(_InputIterator __f, _InputIterator __l,
587 const allocator_type& __a,
588 typename enable_if<
589 __is_input_iterator<_InputIterator>::value
590 >::type* = nullptr);
591 forward_list(const forward_list& __x);
592 forward_list(const forward_list& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000593#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000595 forward_list(forward_list&& __x)
596 _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +0000597 : base(_VSTD::move(__x)) {}
Howard Hinnant3e519522010-05-11 19:42:16 +0000598 forward_list(forward_list&& __x, const allocator_type& __a);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000599#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000600#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000601 forward_list(initializer_list<value_type> __il);
602 forward_list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000603#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000604
605 // ~forward_list() = default;
606
607 forward_list& operator=(const forward_list& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000608#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000609 forward_list& operator=(forward_list&& __x)
610 _NOEXCEPT_(
611 __node_traits::propagate_on_container_move_assignment::value &&
612 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000613#endif
Howard Hinnant54976f22011-08-12 21:56:02 +0000614#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000615 forward_list& operator=(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000616#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000617
618 template <class _InputIterator>
619 typename enable_if
620 <
621 __is_input_iterator<_InputIterator>::value,
622 void
623 >::type
624 assign(_InputIterator __f, _InputIterator __l);
625 void assign(size_type __n, const value_type& __v);
Howard Hinnant54976f22011-08-12 21:56:02 +0000626#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000627 void assign(initializer_list<value_type> __il);
Howard Hinnant54976f22011-08-12 21:56:02 +0000628#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000629
Howard Hinnant0af133f2010-09-21 22:55:27 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000631 allocator_type get_allocator() const _NOEXCEPT
632 {return allocator_type(base::__alloc());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000633
Howard Hinnant0af133f2010-09-21 22:55:27 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000635 iterator begin() _NOEXCEPT
636 {return iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000638 const_iterator begin() const _NOEXCEPT
639 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000641 iterator end() _NOEXCEPT
642 {return iterator(nullptr);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000644 const_iterator end() 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 const_iterator cbegin() const _NOEXCEPT
649 {return const_iterator(base::__before_begin()->__next_);}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000651 const_iterator cend() const _NOEXCEPT
652 {return const_iterator(nullptr);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000653
Howard Hinnant0af133f2010-09-21 22:55:27 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000655 iterator before_begin() _NOEXCEPT
656 {return iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000658 const_iterator before_begin() const _NOEXCEPT
659 {return const_iterator(base::__before_begin());}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000661 const_iterator cbefore_begin() const _NOEXCEPT
662 {return const_iterator(base::__before_begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000663
Howard Hinnant0af133f2010-09-21 22:55:27 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000665 bool empty() const _NOEXCEPT
666 {return base::__before_begin()->__next_ == nullptr;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000668 size_type max_size() const _NOEXCEPT
669 {return numeric_limits<size_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000670
Howard Hinnant0af133f2010-09-21 22:55:27 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000672 reference front() {return base::__before_begin()->__next_->__value_;}
Howard Hinnant0af133f2010-09-21 22:55:27 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000674 const_reference front() const {return base::__before_begin()->__next_->__value_;}
675
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000676#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
677#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000678 template <class... _Args> void emplace_front(_Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000679#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000680 void push_front(value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000681#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000682 void push_front(const value_type& __v);
683
684 void pop_front();
685
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000686#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
687#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000688 template <class... _Args>
689 iterator emplace_after(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000690#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000691 iterator insert_after(const_iterator __p, value_type&& __v);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000692#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000693 iterator insert_after(const_iterator __p, const value_type& __v);
694 iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
695 template <class _InputIterator>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000697 typename enable_if
698 <
699 __is_input_iterator<_InputIterator>::value,
700 iterator
701 >::type
702 insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
Howard Hinnant54976f22011-08-12 21:56:02 +0000703#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000704 iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
705 {return insert_after(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000706#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000707
Howard Hinnant3db88032010-08-21 20:58:44 +0000708 iterator erase_after(const_iterator __p);
709 iterator erase_after(const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000710
Howard Hinnant0af133f2010-09-21 22:55:27 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant91a47502011-06-03 16:20:53 +0000712 void swap(forward_list& __x)
713 _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
714 __is_nothrow_swappable<__node_allocator>::value)
715 {base::swap(__x);}
Howard Hinnant3e519522010-05-11 19:42:16 +0000716
717 void resize(size_type __n);
718 void resize(size_type __n, const value_type& __v);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000720 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000721
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000722#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnanteb92df72011-01-27 21:00:35 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000724 void splice_after(const_iterator __p, forward_list&& __x);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000726 void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000728 void splice_after(const_iterator __p, forward_list&& __x,
729 const_iterator __f, const_iterator __l);
Howard Hinnanteb92df72011-01-27 21:00:35 +0000730#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000731 void splice_after(const_iterator __p, forward_list& __x);
732 void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
733 void splice_after(const_iterator __p, forward_list& __x,
734 const_iterator __f, const_iterator __l);
Howard Hinnant3e519522010-05-11 19:42:16 +0000735 void remove(const value_type& __v);
736 template <class _Predicate> void remove_if(_Predicate __pred);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000738 void unique() {unique(__equal_to<value_type>());}
739 template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000740#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanteb92df72011-01-27 21:00:35 +0000742 void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
743 template <class _Compare>
744 _LIBCPP_INLINE_VISIBILITY
745 void merge(forward_list&& __x, _Compare __comp)
Howard Hinnantce48a112011-06-30 21:18:19 +0000746 {merge(__x, _VSTD::move(__comp));}
Howard Hinnanteb92df72011-01-27 21:00:35 +0000747#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant0af133f2010-09-21 22:55:27 +0000748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000749 void merge(forward_list& __x) {merge(__x, __less<value_type>());}
750 template <class _Compare> void merge(forward_list& __x, _Compare __comp);
Howard Hinnant0af133f2010-09-21 22:55:27 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000752 void sort() {sort(__less<value_type>());}
753 template <class _Compare> void sort(_Compare __comp);
Howard Hinnantf9dc2832011-06-02 16:44:28 +0000754 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000755
756private:
Howard Hinnant3e519522010-05-11 19:42:16 +0000757
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000758#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant91a47502011-06-03 16:20:53 +0000759 void __move_assign(forward_list& __x, true_type)
760 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000761 void __move_assign(forward_list& __x, false_type);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000762#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000763
764 template <class _Compare>
765 static
766 __node_pointer
767 __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
768
769 template <class _Compare>
770 static
771 __node_pointer
772 __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
773};
774
775template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000777forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
778 : base(__a)
779{
780}
781
782template <class _Tp, class _Alloc>
783forward_list<_Tp, _Alloc>::forward_list(size_type __n)
784{
785 if (__n > 0)
786 {
787 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +0000788 typedef __allocator_destructor<__node_allocator> _Dp;
789 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +0000790 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
791 __p = __p->__next_)
792 {
793 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +0000794 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +0000795 __h->__next_ = nullptr;
796 __p->__next_ = __h.release();
797 }
798 }
799}
800
Marshall Clowfb829762013-09-08 19:11:51 +0000801#if _LIBCPP_STD_VER > 11
802template <class _Tp, class _Alloc>
803forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a)
804 : base ( __a )
805{
806 if (__n > 0)
807 {
808 __node_allocator& __a = base::__alloc();
809 typedef __allocator_destructor<__node_allocator> _Dp;
810 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
811 for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
812 __p = __p->__next_)
813 {
814 __h.reset(__node_traits::allocate(__a, 1));
815 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
816 __h->__next_ = nullptr;
817 __p->__next_ = __h.release();
818 }
819 }
820}
821#endif
822
Howard Hinnant3e519522010-05-11 19:42:16 +0000823template <class _Tp, class _Alloc>
824forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
825{
826 insert_after(cbefore_begin(), __n, __v);
827}
828
829template <class _Tp, class _Alloc>
830forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
831 const allocator_type& __a)
832 : base(__a)
833{
834 insert_after(cbefore_begin(), __n, __v);
835}
836
837template <class _Tp, class _Alloc>
838template <class _InputIterator>
839forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
840 typename enable_if<
841 __is_input_iterator<_InputIterator>::value
842 >::type*)
843{
844 insert_after(cbefore_begin(), __f, __l);
845}
846
847template <class _Tp, class _Alloc>
848template <class _InputIterator>
849forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
850 const allocator_type& __a,
851 typename enable_if<
852 __is_input_iterator<_InputIterator>::value
853 >::type*)
854 : base(__a)
855{
856 insert_after(cbefore_begin(), __f, __l);
857}
858
859template <class _Tp, class _Alloc>
860forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
861 : base(allocator_type(
862 __node_traits::select_on_container_copy_construction(__x.__alloc())
863 )
864 )
865{
866 insert_after(cbefore_begin(), __x.begin(), __x.end());
867}
868
869template <class _Tp, class _Alloc>
870forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
871 const allocator_type& __a)
872 : base(__a)
873{
874 insert_after(cbefore_begin(), __x.begin(), __x.end());
875}
876
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000877#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000878
879template <class _Tp, class _Alloc>
880forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
881 const allocator_type& __a)
Howard Hinnantce48a112011-06-30 21:18:19 +0000882 : base(_VSTD::move(__x), __a)
Howard Hinnant3e519522010-05-11 19:42:16 +0000883{
884 if (base::__alloc() != __x.__alloc())
885 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000886 typedef move_iterator<iterator> _Ip;
887 insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000888 }
889}
890
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000891#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000892
Howard Hinnant54976f22011-08-12 21:56:02 +0000893#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
894
Howard Hinnant3e519522010-05-11 19:42:16 +0000895template <class _Tp, class _Alloc>
896forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
897{
898 insert_after(cbefore_begin(), __il.begin(), __il.end());
899}
900
901template <class _Tp, class _Alloc>
902forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
903 const allocator_type& __a)
904 : base(__a)
905{
906 insert_after(cbefore_begin(), __il.begin(), __il.end());
907}
908
Howard Hinnant54976f22011-08-12 21:56:02 +0000909#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
910
Howard Hinnant3e519522010-05-11 19:42:16 +0000911template <class _Tp, class _Alloc>
912forward_list<_Tp, _Alloc>&
913forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
914{
915 if (this != &__x)
916 {
917 base::__copy_assign_alloc(__x);
918 assign(__x.begin(), __x.end());
919 }
920 return *this;
921}
922
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000923#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000924
925template <class _Tp, class _Alloc>
926void
927forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
Howard Hinnant91a47502011-06-03 16:20:53 +0000928 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000929{
930 clear();
931 base::__move_assign_alloc(__x);
932 base::__before_begin()->__next_ = __x.__before_begin()->__next_;
933 __x.__before_begin()->__next_ = nullptr;
934}
935
936template <class _Tp, class _Alloc>
937void
938forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
939{
940 if (base::__alloc() == __x.__alloc())
941 __move_assign(__x, true_type());
942 else
943 {
Howard Hinnantc003db12011-11-29 18:15:50 +0000944 typedef move_iterator<iterator> _Ip;
945 assign(_Ip(__x.begin()), _Ip(__x.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +0000946 }
947}
948
949template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000951forward_list<_Tp, _Alloc>&
952forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
Howard Hinnant91a47502011-06-03 16:20:53 +0000953 _NOEXCEPT_(
954 __node_traits::propagate_on_container_move_assignment::value &&
955 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000956{
957 __move_assign(__x, integral_constant<bool,
958 __node_traits::propagate_on_container_move_assignment::value>());
959 return *this;
960}
961
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000962#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000963
Howard Hinnant54976f22011-08-12 21:56:02 +0000964#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
965
Howard Hinnant3e519522010-05-11 19:42:16 +0000966template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +0000967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000968forward_list<_Tp, _Alloc>&
969forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
970{
971 assign(__il.begin(), __il.end());
972 return *this;
973}
974
Howard Hinnant54976f22011-08-12 21:56:02 +0000975#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
976
Howard Hinnant3e519522010-05-11 19:42:16 +0000977template <class _Tp, class _Alloc>
978template <class _InputIterator>
979typename enable_if
980<
981 __is_input_iterator<_InputIterator>::value,
982 void
983>::type
984forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
985{
986 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +0000987 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +0000988 iterator __e = end();
989 for (; __j != __e && __f != __l; ++__i, ++__j, ++__f)
990 *__j = *__f;
991 if (__j == __e)
992 insert_after(__i, __f, __l);
993 else
994 erase_after(__i, __e);
995}
996
997template <class _Tp, class _Alloc>
998void
999forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
1000{
1001 iterator __i = before_begin();
Howard Hinnantce48a112011-06-30 21:18:19 +00001002 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001003 iterator __e = end();
1004 for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
1005 *__j = __v;
1006 if (__j == __e)
1007 insert_after(__i, __n, __v);
1008 else
1009 erase_after(__i, __e);
1010}
1011
Howard Hinnant54976f22011-08-12 21:56:02 +00001012#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1013
Howard Hinnant3e519522010-05-11 19:42:16 +00001014template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001015inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001016void
1017forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
1018{
1019 assign(__il.begin(), __il.end());
1020}
1021
Howard Hinnant54976f22011-08-12 21:56:02 +00001022#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1023
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001024#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1025#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001026
1027template <class _Tp, class _Alloc>
1028template <class... _Args>
1029void
1030forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1031{
1032 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001033 typedef __allocator_destructor<__node_allocator> _Dp;
1034 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001035 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1036 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001037 __h->__next_ = base::__before_begin()->__next_;
1038 base::__before_begin()->__next_ = __h.release();
1039}
1040
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001041#endif // _LIBCPP_HAS_NO_VARIADICS
1042
Howard Hinnant3e519522010-05-11 19:42:16 +00001043template <class _Tp, class _Alloc>
1044void
1045forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
1046{
1047 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001048 typedef __allocator_destructor<__node_allocator> _Dp;
1049 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001050 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001051 __h->__next_ = base::__before_begin()->__next_;
1052 base::__before_begin()->__next_ = __h.release();
1053}
1054
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001055#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001056
1057template <class _Tp, class _Alloc>
1058void
1059forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
1060{
1061 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001062 typedef __allocator_destructor<__node_allocator> _Dp;
1063 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001064 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001065 __h->__next_ = base::__before_begin()->__next_;
1066 base::__before_begin()->__next_ = __h.release();
1067}
1068
1069template <class _Tp, class _Alloc>
1070void
1071forward_list<_Tp, _Alloc>::pop_front()
1072{
1073 __node_allocator& __a = base::__alloc();
1074 __node_pointer __p = base::__before_begin()->__next_;
1075 base::__before_begin()->__next_ = __p->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001076 __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001077 __node_traits::deallocate(__a, __p, 1);
1078}
1079
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001080#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1081#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +00001082
1083template <class _Tp, class _Alloc>
1084template <class... _Args>
1085typename forward_list<_Tp, _Alloc>::iterator
1086forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
1087{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001088 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001089 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001090 typedef __allocator_destructor<__node_allocator> _Dp;
1091 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001092 __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
1093 _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:16 +00001094 __h->__next_ = __r->__next_;
1095 __r->__next_ = __h.release();
1096 return iterator(__r->__next_);
1097}
1098
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001099#endif // _LIBCPP_HAS_NO_VARIADICS
1100
Howard Hinnant3e519522010-05-11 19:42:16 +00001101template <class _Tp, class _Alloc>
1102typename forward_list<_Tp, _Alloc>::iterator
1103forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
1104{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001105 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001106 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001107 typedef __allocator_destructor<__node_allocator> _Dp;
1108 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001109 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
Howard Hinnant3e519522010-05-11 19:42:16 +00001110 __h->__next_ = __r->__next_;
1111 __r->__next_ = __h.release();
1112 return iterator(__r->__next_);
1113}
1114
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001115#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001116
1117template <class _Tp, class _Alloc>
1118typename forward_list<_Tp, _Alloc>::iterator
1119forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
1120{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001121 __node_pointer const __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001122 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001123 typedef __allocator_destructor<__node_allocator> _Dp;
1124 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001125 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001126 __h->__next_ = __r->__next_;
1127 __r->__next_ = __h.release();
1128 return iterator(__r->__next_);
1129}
1130
1131template <class _Tp, class _Alloc>
1132typename forward_list<_Tp, _Alloc>::iterator
1133forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
1134 const value_type& __v)
1135{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001136 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001137 if (__n > 0)
1138 {
1139 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001140 typedef __allocator_destructor<__node_allocator> _Dp;
1141 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001142 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001143 __node_pointer __first = __h.release();
1144 __node_pointer __last = __first;
1145#ifndef _LIBCPP_NO_EXCEPTIONS
1146 try
1147 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001148#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001149 for (--__n; __n != 0; --__n, __last = __last->__next_)
1150 {
1151 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001152 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001153 __last->__next_ = __h.release();
1154 }
1155#ifndef _LIBCPP_NO_EXCEPTIONS
1156 }
1157 catch (...)
1158 {
1159 while (__first != nullptr)
1160 {
1161 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001162 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001163 __node_traits::deallocate(__a, __first, 1);
1164 __first = __next;
1165 }
1166 throw;
1167 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001168#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001169 __last->__next_ = __r->__next_;
1170 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001171 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001172 }
1173 return iterator(__r);
1174}
1175
1176template <class _Tp, class _Alloc>
1177template <class _InputIterator>
1178typename enable_if
1179<
1180 __is_input_iterator<_InputIterator>::value,
1181 typename forward_list<_Tp, _Alloc>::iterator
1182>::type
1183forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
1184 _InputIterator __f, _InputIterator __l)
1185{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001186 __node_pointer __r = __p.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001187 if (__f != __l)
1188 {
1189 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001190 typedef __allocator_destructor<__node_allocator> _Dp;
1191 unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001192 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001193 __node_pointer __first = __h.release();
1194 __node_pointer __last = __first;
1195#ifndef _LIBCPP_NO_EXCEPTIONS
1196 try
1197 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001198#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001199 for (++__f; __f != __l; ++__f, __last = __last->__next_)
1200 {
1201 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001202 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001203 __last->__next_ = __h.release();
1204 }
1205#ifndef _LIBCPP_NO_EXCEPTIONS
1206 }
1207 catch (...)
1208 {
1209 while (__first != nullptr)
1210 {
1211 __node_pointer __next = __first->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001212 __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001213 __node_traits::deallocate(__a, __first, 1);
1214 __first = __next;
1215 }
1216 throw;
1217 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001218#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001219 __last->__next_ = __r->__next_;
1220 __r->__next_ = __first;
Howard Hinnante57dc142010-08-19 17:40:04 +00001221 __r = __last;
Howard Hinnant3e519522010-05-11 19:42:16 +00001222 }
1223 return iterator(__r);
1224}
1225
1226template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001227typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001228forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
1229{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001230 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001231 __node_pointer __n = __p->__next_;
1232 __p->__next_ = __n->__next_;
1233 __node_allocator& __a = base::__alloc();
Howard Hinnantce48a112011-06-30 21:18:19 +00001234 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001235 __node_traits::deallocate(__a, __n, 1);
Howard Hinnant3db88032010-08-21 20:58:44 +00001236 return iterator(__p->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001237}
1238
1239template <class _Tp, class _Alloc>
Howard Hinnant3db88032010-08-21 20:58:44 +00001240typename forward_list<_Tp, _Alloc>::iterator
Howard Hinnant3e519522010-05-11 19:42:16 +00001241forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
1242{
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001243 __node_pointer __e = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001244 if (__f != __l)
1245 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001246 __node_pointer __p = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001247 __node_pointer __n = __p->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001248 if (__n != __e)
1249 {
1250 __p->__next_ = __e;
1251 __node_allocator& __a = base::__alloc();
1252 do
1253 {
1254 __p = __n->__next_;
Howard Hinnantce48a112011-06-30 21:18:19 +00001255 __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001256 __node_traits::deallocate(__a, __n, 1);
1257 __n = __p;
1258 } while (__n != __e);
1259 }
1260 }
Howard Hinnant3db88032010-08-21 20:58:44 +00001261 return iterator(__e);
Howard Hinnant3e519522010-05-11 19:42:16 +00001262}
1263
1264template <class _Tp, class _Alloc>
1265void
1266forward_list<_Tp, _Alloc>::resize(size_type __n)
1267{
1268 size_type __sz = 0;
1269 iterator __p = before_begin();
1270 iterator __i = begin();
1271 iterator __e = end();
1272 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1273 ;
1274 if (__i != __e)
1275 erase_after(__p, __e);
1276 else
1277 {
1278 __n -= __sz;
1279 if (__n > 0)
1280 {
1281 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001282 typedef __allocator_destructor<__node_allocator> _Dp;
1283 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001284 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1285 __ptr = __ptr->__next_)
1286 {
1287 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001288 __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001289 __h->__next_ = nullptr;
1290 __ptr->__next_ = __h.release();
1291 }
1292 }
1293 }
1294}
1295
1296template <class _Tp, class _Alloc>
1297void
1298forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
1299{
1300 size_type __sz = 0;
1301 iterator __p = before_begin();
1302 iterator __i = begin();
1303 iterator __e = end();
1304 for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
1305 ;
1306 if (__i != __e)
1307 erase_after(__p, __e);
1308 else
1309 {
1310 __n -= __sz;
1311 if (__n > 0)
1312 {
1313 __node_allocator& __a = base::__alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001314 typedef __allocator_destructor<__node_allocator> _Dp;
1315 unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001316 for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n,
1317 __ptr = __ptr->__next_)
1318 {
1319 __h.reset(__node_traits::allocate(__a, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001320 __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
Howard Hinnant3e519522010-05-11 19:42:16 +00001321 __h->__next_ = nullptr;
1322 __ptr->__next_ = __h.release();
1323 }
1324 }
1325 }
1326}
1327
1328template <class _Tp, class _Alloc>
1329void
1330forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001331 forward_list& __x)
Howard Hinnant3e519522010-05-11 19:42:16 +00001332{
1333 if (!__x.empty())
1334 {
1335 if (__p.__ptr_->__next_ != nullptr)
1336 {
1337 const_iterator __lm1 = __x.before_begin();
1338 while (__lm1.__ptr_->__next_ != nullptr)
1339 ++__lm1;
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001340 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001341 }
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001342 __p.__ptr_->__next_ = __x.__before_begin()->__next_;
1343 __x.__before_begin()->__next_ = nullptr;
Howard Hinnant3e519522010-05-11 19:42:16 +00001344 }
1345}
1346
1347template <class _Tp, class _Alloc>
1348void
1349forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001350 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001351 const_iterator __i)
1352{
Howard Hinnantce48a112011-06-30 21:18:19 +00001353 const_iterator __lm1 = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001354 if (__p != __i && __p != __lm1)
1355 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001356 __i.__ptr_->__next_ = __lm1.__ptr_->__next_;
1357 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1358 __p.__ptr_->__next_ = __lm1.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001359 }
1360}
1361
1362template <class _Tp, class _Alloc>
1363void
1364forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
Howard Hinnant3e519522010-05-11 19:42:16 +00001365 forward_list& __x,
Howard Hinnant3e519522010-05-11 19:42:16 +00001366 const_iterator __f, const_iterator __l)
1367{
1368 if (__f != __l && __p != __f)
1369 {
1370 const_iterator __lm1 = __f;
1371 while (__lm1.__ptr_->__next_ != __l.__ptr_)
1372 ++__lm1;
1373 if (__f != __lm1)
1374 {
Howard Hinnant8a27ba82013-06-24 17:17:28 +00001375 __lm1.__ptr_->__next_ = __p.__ptr_->__next_;
1376 __p.__ptr_->__next_ = __f.__ptr_->__next_;
1377 __f.__ptr_->__next_ = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001378 }
1379 }
1380}
1381
Howard Hinnanteb92df72011-01-27 21:00:35 +00001382#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1383
1384template <class _Tp, class _Alloc>
1385inline _LIBCPP_INLINE_VISIBILITY
1386void
1387forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1388 forward_list&& __x)
1389{
1390 splice_after(__p, __x);
1391}
1392
1393template <class _Tp, class _Alloc>
1394inline _LIBCPP_INLINE_VISIBILITY
1395void
1396forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1397 forward_list&& __x,
1398 const_iterator __i)
1399{
1400 splice_after(__p, __x, __i);
1401}
1402
1403template <class _Tp, class _Alloc>
1404inline _LIBCPP_INLINE_VISIBILITY
1405void
1406forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1407 forward_list&& __x,
1408 const_iterator __f, const_iterator __l)
1409{
1410 splice_after(__p, __x, __f, __l);
1411}
1412
1413#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1414
Howard Hinnant3e519522010-05-11 19:42:16 +00001415template <class _Tp, class _Alloc>
1416void
1417forward_list<_Tp, _Alloc>::remove(const value_type& __v)
1418{
1419 iterator __e = end();
1420 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1421 {
1422 if (__i.__ptr_->__next_->__value_ == __v)
1423 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001424 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001425 for (; __j != __e && *__j == __v; ++__j)
1426 ;
1427 erase_after(__i, __j);
1428 if (__j == __e)
1429 break;
1430 __i = __j;
1431 }
1432 else
1433 ++__i;
1434 }
1435}
1436
1437template <class _Tp, class _Alloc>
1438template <class _Predicate>
1439void
1440forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
1441{
1442 iterator __e = end();
1443 for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;)
1444 {
1445 if (__pred(__i.__ptr_->__next_->__value_))
1446 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001447 iterator __j = _VSTD::next(__i, 2);
Howard Hinnant3e519522010-05-11 19:42:16 +00001448 for (; __j != __e && __pred(*__j); ++__j)
1449 ;
1450 erase_after(__i, __j);
1451 if (__j == __e)
1452 break;
1453 __i = __j;
1454 }
1455 else
1456 ++__i;
1457 }
1458}
1459
1460template <class _Tp, class _Alloc>
1461template <class _BinaryPredicate>
1462void
1463forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
1464{
1465 for (iterator __i = begin(), __e = end(); __i != __e;)
1466 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001467 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00001468 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1469 ;
1470 if (__i.__ptr_->__next_ != __j.__ptr_)
1471 erase_after(__i, __j);
1472 __i = __j;
1473 }
1474}
1475
1476template <class _Tp, class _Alloc>
1477template <class _Compare>
1478void
Howard Hinnant3e519522010-05-11 19:42:16 +00001479forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
Howard Hinnant3e519522010-05-11 19:42:16 +00001480{
1481 if (this != &__x)
1482 {
1483 base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
1484 __x.__before_begin()->__next_,
1485 __comp);
1486 __x.__before_begin()->__next_ = nullptr;
1487 }
1488}
1489
1490template <class _Tp, class _Alloc>
1491template <class _Compare>
1492typename forward_list<_Tp, _Alloc>::__node_pointer
1493forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
1494 _Compare& __comp)
1495{
1496 if (__f1 == nullptr)
1497 return __f2;
1498 if (__f2 == nullptr)
1499 return __f1;
1500 __node_pointer __r;
1501 if (__comp(__f2->__value_, __f1->__value_))
1502 {
1503 __node_pointer __t = __f2;
1504 while (__t->__next_ != nullptr &&
1505 __comp(__t->__next_->__value_, __f1->__value_))
1506 __t = __t->__next_;
1507 __r = __f2;
1508 __f2 = __t->__next_;
1509 __t->__next_ = __f1;
1510 }
1511 else
1512 __r = __f1;
1513 __node_pointer __p = __f1;
1514 __f1 = __f1->__next_;
1515 while (__f1 != nullptr && __f2 != nullptr)
1516 {
1517 if (__comp(__f2->__value_, __f1->__value_))
1518 {
1519 __node_pointer __t = __f2;
1520 while (__t->__next_ != nullptr &&
1521 __comp(__t->__next_->__value_, __f1->__value_))
1522 __t = __t->__next_;
1523 __p->__next_ = __f2;
1524 __f2 = __t->__next_;
1525 __t->__next_ = __f1;
1526 }
1527 __p = __f1;
1528 __f1 = __f1->__next_;
1529 }
1530 if (__f2 != nullptr)
1531 __p->__next_ = __f2;
1532 return __r;
1533}
1534
1535template <class _Tp, class _Alloc>
1536template <class _Compare>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001537inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001538void
1539forward_list<_Tp, _Alloc>::sort(_Compare __comp)
1540{
1541 base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
Howard Hinnantce48a112011-06-30 21:18:19 +00001542 _VSTD::distance(begin(), end()), __comp);
Howard Hinnant3e519522010-05-11 19:42:16 +00001543}
1544
1545template <class _Tp, class _Alloc>
1546template <class _Compare>
1547typename forward_list<_Tp, _Alloc>::__node_pointer
1548forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
1549 _Compare& __comp)
1550{
1551 switch (__sz)
1552 {
1553 case 0:
1554 case 1:
1555 return __f1;
1556 case 2:
1557 if (__comp(__f1->__next_->__value_, __f1->__value_))
1558 {
1559 __node_pointer __t = __f1->__next_;
1560 __t->__next_ = __f1;
1561 __f1->__next_ = nullptr;
1562 __f1 = __t;
1563 }
1564 return __f1;
1565 }
1566 difference_type __sz1 = __sz / 2;
1567 difference_type __sz2 = __sz - __sz1;
Howard Hinnantce48a112011-06-30 21:18:19 +00001568 __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001569 __node_pointer __f2 = __t->__next_;
1570 __t->__next_ = nullptr;
1571 return __merge(__sort(__f1, __sz1, __comp),
1572 __sort(__f2, __sz2, __comp), __comp);
1573}
1574
1575template <class _Tp, class _Alloc>
1576void
Howard Hinnantf9dc2832011-06-02 16:44:28 +00001577forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001578{
1579 __node_pointer __p = base::__before_begin()->__next_;
1580 if (__p != nullptr)
1581 {
1582 __node_pointer __f = __p->__next_;
1583 __p->__next_ = nullptr;
1584 while (__f != nullptr)
1585 {
1586 __node_pointer __t = __f->__next_;
1587 __f->__next_ = __p;
1588 __p = __f;
1589 __f = __t;
1590 }
1591 base::__before_begin()->__next_ = __p;
1592 }
1593}
1594
1595template <class _Tp, class _Alloc>
1596bool operator==(const forward_list<_Tp, _Alloc>& __x,
1597 const forward_list<_Tp, _Alloc>& __y)
1598{
Howard Hinnantc003db12011-11-29 18:15:50 +00001599 typedef forward_list<_Tp, _Alloc> _Cp;
1600 typedef typename _Cp::const_iterator _Ip;
1601 _Ip __ix = __x.begin();
1602 _Ip __ex = __x.end();
1603 _Ip __iy = __y.begin();
1604 _Ip __ey = __y.end();
Howard Hinnant3e519522010-05-11 19:42:16 +00001605 for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
1606 if (!(*__ix == *__iy))
1607 return false;
1608 return (__ix == __ex) == (__iy == __ey);
1609}
1610
1611template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001613bool operator!=(const forward_list<_Tp, _Alloc>& __x,
1614 const forward_list<_Tp, _Alloc>& __y)
1615{
1616 return !(__x == __y);
1617}
1618
1619template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001621bool operator< (const forward_list<_Tp, _Alloc>& __x,
1622 const forward_list<_Tp, _Alloc>& __y)
1623{
Howard Hinnantce48a112011-06-30 21:18:19 +00001624 return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
Howard Hinnant3e519522010-05-11 19:42:16 +00001625 __y.begin(), __y.end());
1626}
1627
1628template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001630bool operator> (const forward_list<_Tp, _Alloc>& __x,
1631 const forward_list<_Tp, _Alloc>& __y)
1632{
1633 return __y < __x;
1634}
1635
1636template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001637inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001638bool operator>=(const forward_list<_Tp, _Alloc>& __x,
1639 const forward_list<_Tp, _Alloc>& __y)
1640{
1641 return !(__x < __y);
1642}
1643
1644template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001646bool operator<=(const forward_list<_Tp, _Alloc>& __x,
1647 const forward_list<_Tp, _Alloc>& __y)
1648{
1649 return !(__y < __x);
1650}
1651
1652template <class _Tp, class _Alloc>
Howard Hinnant0af133f2010-09-21 22:55:27 +00001653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001654void
1655swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
Howard Hinnant91a47502011-06-03 16:20:53 +00001656 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00001657{
1658 __x.swap(__y);
1659}
1660
1661_LIBCPP_END_NAMESPACE_STD
1662
1663#endif // _LIBCPP_FORWARD_LIST