Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------- forward_list ---------------------------------===// |
| 3 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_FORWARD_LIST |
| 12 | #define _LIBCPP_FORWARD_LIST |
| 13 | |
| 14 | /* |
| 15 | forward_list synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class T, class Allocator = allocator<T>> |
| 21 | class forward_list |
| 22 | { |
| 23 | public: |
| 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 Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 37 | forward_list() |
| 38 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | explicit forward_list(const allocator_type& a); |
| 40 | explicit forward_list(size_type n); |
| 41 | forward_list(size_type n, const value_type& v); |
| 42 | forward_list(size_type n, const value_type& v, const allocator_type& a); |
| 43 | template <class InputIterator> |
| 44 | forward_list(InputIterator first, InputIterator last); |
| 45 | template <class InputIterator> |
| 46 | forward_list(InputIterator first, InputIterator last, const allocator_type& a); |
| 47 | forward_list(const forward_list& x); |
| 48 | forward_list(const forward_list& x, const allocator_type& a); |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 49 | forward_list(forward_list&& x) |
| 50 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | forward_list(forward_list&& x, const allocator_type& a); |
| 52 | forward_list(initializer_list<value_type> il); |
| 53 | forward_list(initializer_list<value_type> il, const allocator_type& a); |
| 54 | |
| 55 | ~forward_list(); |
| 56 | |
| 57 | forward_list& operator=(const forward_list& x); |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 58 | forward_list& operator=(forward_list&& x) |
| 59 | noexcept( |
| 60 | allocator_type::propagate_on_container_move_assignment::value && |
| 61 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | forward_list& operator=(initializer_list<value_type> il); |
| 63 | |
| 64 | template <class InputIterator> |
| 65 | void assign(InputIterator first, InputIterator last); |
| 66 | void assign(size_type n, const value_type& v); |
| 67 | void assign(initializer_list<value_type> il); |
| 68 | |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 69 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 71 | iterator begin() noexcept; |
| 72 | const_iterator begin() const noexcept; |
| 73 | iterator end() noexcept; |
| 74 | const_iterator end() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 76 | const_iterator cbegin() const noexcept; |
| 77 | const_iterator cend() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 78 | |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 79 | iterator before_begin() noexcept; |
| 80 | const_iterator before_begin() const noexcept; |
| 81 | const_iterator cbefore_begin() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 83 | bool empty() const noexcept; |
| 84 | size_type max_size() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | |
| 86 | reference front(); |
| 87 | const_reference front() const; |
| 88 | |
| 89 | template <class... Args> void emplace_front(Args&&... args); |
| 90 | void push_front(const value_type& v); |
| 91 | void push_front(value_type&& v); |
| 92 | |
| 93 | void pop_front(); |
| 94 | |
| 95 | template <class... Args> |
| 96 | iterator emplace_after(const_iterator p, Args&&... args); |
| 97 | iterator insert_after(const_iterator p, const value_type& v); |
| 98 | iterator insert_after(const_iterator p, value_type&& v); |
| 99 | iterator insert_after(const_iterator p, size_type n, const value_type& v); |
| 100 | template <class InputIterator> |
| 101 | iterator insert_after(const_iterator p, |
| 102 | InputIterator first, InputIterator last); |
| 103 | iterator insert_after(const_iterator p, initializer_list<value_type> il); |
| 104 | |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 105 | iterator erase_after(const_iterator p); |
| 106 | iterator erase_after(const_iterator first, const_iterator last); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 107 | |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 108 | void swap(forward_list& x) |
| 109 | noexcept(!allocator_type::propagate_on_container_swap::value || |
| 110 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | |
| 112 | void resize(size_type n); |
| 113 | void resize(size_type n, const value_type& v); |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 114 | void clear() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 116 | void splice_after(const_iterator p, forward_list& x); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 117 | void splice_after(const_iterator p, forward_list&& x); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 118 | void splice_after(const_iterator p, forward_list& x, const_iterator i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 119 | void splice_after(const_iterator p, forward_list&& x, const_iterator i); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 120 | void splice_after(const_iterator p, forward_list& x, |
| 121 | const_iterator first, const_iterator last); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 122 | void splice_after(const_iterator p, forward_list&& x, |
| 123 | const_iterator first, const_iterator last); |
| 124 | void remove(const value_type& v); |
| 125 | template <class Predicate> void remove_if(Predicate pred); |
| 126 | void unique(); |
| 127 | template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 128 | void merge(forward_list& x); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 129 | void merge(forward_list&& x); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 130 | template <class Compare> void merge(forward_list& x, Compare comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | template <class Compare> void merge(forward_list&& x, Compare comp); |
| 132 | void sort(); |
| 133 | template <class Compare> void sort(Compare comp); |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 134 | void reverse() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | template <class T, class Allocator> |
| 138 | bool operator==(const forward_list<T, Allocator>& x, |
| 139 | const forward_list<T, Allocator>& y); |
| 140 | |
| 141 | template <class T, class Allocator> |
| 142 | bool operator< (const forward_list<T, Allocator>& x, |
| 143 | const forward_list<T, Allocator>& y); |
| 144 | |
| 145 | template <class T, class Allocator> |
| 146 | bool operator!=(const forward_list<T, Allocator>& x, |
| 147 | const forward_list<T, Allocator>& y); |
| 148 | |
| 149 | template <class T, class Allocator> |
| 150 | bool operator> (const forward_list<T, Allocator>& x, |
| 151 | const forward_list<T, Allocator>& y); |
| 152 | |
| 153 | template <class T, class Allocator> |
| 154 | bool operator>=(const forward_list<T, Allocator>& x, |
| 155 | const forward_list<T, Allocator>& y); |
| 156 | |
| 157 | template <class T, class Allocator> |
| 158 | bool operator<=(const forward_list<T, Allocator>& x, |
| 159 | const forward_list<T, Allocator>& y); |
| 160 | |
| 161 | template <class T, class Allocator> |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 162 | void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 163 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 164 | |
| 165 | } // std |
| 166 | |
| 167 | */ |
| 168 | |
| 169 | #include <__config> |
| 170 | |
| 171 | #include <initializer_list> |
| 172 | #include <memory> |
| 173 | #include <limits> |
| 174 | #include <iterator> |
| 175 | #include <algorithm> |
| 176 | |
| 177 | #pragma GCC system_header |
| 178 | |
| 179 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 180 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 181 | template <class _Tp, class _VoidPtr> struct __forward_list_node; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | |
| 183 | template <class _NodePtr> |
| 184 | struct __forward_begin_node |
| 185 | { |
| 186 | typedef __forward_begin_node __self; |
| 187 | typedef _NodePtr pointer; |
| 188 | |
| 189 | pointer __next_; |
| 190 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 191 | _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | template <class _Tp, class _VoidPtr> |
| 195 | struct __forward_list_node |
| 196 | : public __forward_begin_node |
| 197 | < |
| 198 | typename pointer_traits<_VoidPtr>::template |
| 199 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 200 | rebind<__forward_list_node<_Tp, _VoidPtr> > |
| 201 | #else |
| 202 | rebind<__forward_list_node<_Tp, _VoidPtr> >::other |
| 203 | #endif |
| 204 | > |
| 205 | { |
| 206 | typedef _Tp value_type; |
| 207 | |
| 208 | value_type __value_; |
| 209 | }; |
| 210 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 211 | template<class _Tp, class _Alloc> class forward_list; |
| 212 | template<class _NodeConstPtr> class __forward_list_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 213 | |
| 214 | template <class _NodePtr> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 215 | class _LIBCPP_VISIBLE __forward_list_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | { |
| 217 | typedef _NodePtr __node_pointer; |
| 218 | |
| 219 | __node_pointer __ptr_; |
| 220 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 221 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 222 | explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 223 | |
| 224 | template<class, class> friend class forward_list; |
| 225 | template<class> friend class __forward_list_const_iterator; |
| 226 | |
| 227 | public: |
| 228 | typedef forward_iterator_tag iterator_category; |
| 229 | typedef typename pointer_traits<__node_pointer>::element_type::value_type |
| 230 | value_type; |
| 231 | typedef value_type& reference; |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 232 | typedef typename pointer_traits<__node_pointer>::difference_type |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | difference_type; |
| 234 | typedef typename pointer_traits<__node_pointer>::template |
| 235 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 236 | rebind<value_type> |
| 237 | #else |
| 238 | rebind<value_type>::other |
| 239 | #endif |
| 240 | pointer; |
| 241 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 243 | __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 244 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | reference operator*() const {return __ptr_->__value_;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 248 | pointer operator->() const {return &__ptr_->__value_;} |
| 249 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | __forward_list_iterator& operator++() |
| 252 | { |
| 253 | __ptr_ = __ptr_->__next_; |
| 254 | return *this; |
| 255 | } |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 256 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 257 | __forward_list_iterator operator++(int) |
| 258 | { |
| 259 | __forward_list_iterator __t(*this); |
| 260 | ++(*this); |
| 261 | return __t; |
| 262 | } |
| 263 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 264 | friend _LIBCPP_INLINE_VISIBILITY |
| 265 | bool operator==(const __forward_list_iterator& __x, |
| 266 | const __forward_list_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | {return __x.__ptr_ == __y.__ptr_;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 268 | friend _LIBCPP_INLINE_VISIBILITY |
| 269 | bool operator!=(const __forward_list_iterator& __x, |
| 270 | const __forward_list_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 271 | {return !(__x == __y);} |
| 272 | }; |
| 273 | |
| 274 | template <class _NodeConstPtr> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 275 | class _LIBCPP_VISIBLE __forward_list_const_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | { |
| 277 | typedef _NodeConstPtr __node_const_pointer; |
| 278 | |
| 279 | __node_const_pointer __ptr_; |
| 280 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 281 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 282 | explicit __forward_list_const_iterator(__node_const_pointer __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 283 | : __ptr_(__p) {} |
| 284 | |
| 285 | typedef typename remove_const |
| 286 | < |
| 287 | typename pointer_traits<__node_const_pointer>::element_type |
| 288 | >::type __node; |
| 289 | typedef typename pointer_traits<__node_const_pointer>::template |
| 290 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 291 | rebind<__node> |
| 292 | #else |
| 293 | rebind<__node>::other |
| 294 | #endif |
| 295 | __node_pointer; |
| 296 | |
| 297 | template<class, class> friend class forward_list; |
| 298 | |
| 299 | public: |
| 300 | typedef forward_iterator_tag iterator_category; |
| 301 | typedef typename __node::value_type value_type; |
| 302 | typedef const value_type& reference; |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 303 | typedef typename pointer_traits<__node_const_pointer>::difference_type |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | difference_type; |
| 305 | typedef typename pointer_traits<__node_const_pointer>::template |
| 306 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 307 | rebind<const value_type> |
| 308 | #else |
| 309 | rebind<const value_type>::other |
| 310 | #endif |
| 311 | pointer; |
| 312 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 313 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 314 | __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 316 | __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 317 | : __ptr_(__p.__ptr_) {} |
| 318 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | reference operator*() const {return __ptr_->__value_;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 322 | pointer operator->() const {return &__ptr_->__value_;} |
| 323 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 | __forward_list_const_iterator& operator++() |
| 326 | { |
| 327 | __ptr_ = __ptr_->__next_; |
| 328 | return *this; |
| 329 | } |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 331 | __forward_list_const_iterator operator++(int) |
| 332 | { |
| 333 | __forward_list_const_iterator __t(*this); |
| 334 | ++(*this); |
| 335 | return __t; |
| 336 | } |
| 337 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 338 | friend _LIBCPP_INLINE_VISIBILITY |
| 339 | bool operator==(const __forward_list_const_iterator& __x, |
| 340 | const __forward_list_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 341 | {return __x.__ptr_ == __y.__ptr_;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 342 | friend _LIBCPP_INLINE_VISIBILITY |
| 343 | bool operator!=(const __forward_list_const_iterator& __x, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | const __forward_list_const_iterator& __y) |
| 345 | {return !(__x == __y);} |
| 346 | }; |
| 347 | |
| 348 | template <class _Tp, class _Alloc> |
| 349 | class __forward_list_base |
| 350 | { |
| 351 | protected: |
| 352 | typedef _Tp value_type; |
| 353 | typedef _Alloc allocator_type; |
| 354 | |
| 355 | typedef typename allocator_traits<allocator_type>::void_pointer void_pointer; |
| 356 | typedef __forward_list_node<value_type, void_pointer> __node; |
| 357 | typedef typename __node::__self __begin_node; |
| 358 | typedef typename allocator_traits<allocator_type>::template |
| 359 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 360 | rebind_alloc<__node> |
| 361 | #else |
| 362 | rebind_alloc<__node>::other |
| 363 | #endif |
| 364 | __node_allocator; |
| 365 | typedef allocator_traits<__node_allocator> __node_traits; |
| 366 | typedef typename __node_traits::pointer __node_pointer; |
| 367 | typedef typename __node_traits::const_pointer __node_const_pointer; |
| 368 | |
| 369 | __compressed_pair<__begin_node, __node_allocator> __before_begin_; |
| 370 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 371 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 372 | __node_pointer __before_begin() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | {return pointer_traits<__node_pointer>::pointer_to( |
| 374 | static_cast<__node&>(__before_begin_.first()));} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 376 | __node_const_pointer __before_begin() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | {return pointer_traits<__node_const_pointer>::pointer_to( |
| 378 | static_cast<const __node&>(__before_begin_.first()));} |
| 379 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 380 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 381 | __node_allocator& __alloc() _NOEXCEPT |
| 382 | {return __before_begin_.second();} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 383 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 384 | const __node_allocator& __alloc() const _NOEXCEPT |
| 385 | {return __before_begin_.second();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | |
| 387 | typedef __forward_list_iterator<__node_pointer> iterator; |
| 388 | typedef __forward_list_const_iterator<__node_const_pointer> const_iterator; |
| 389 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 390 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | __forward_list_base() |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 392 | _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | : __before_begin_(__begin_node()) {} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | __forward_list_base(const allocator_type& __a) |
| 396 | : __before_begin_(__begin_node(), __node_allocator(__a)) {} |
| 397 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 398 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 399 | public: |
| 400 | __forward_list_base(__forward_list_base&& __x) |
| 401 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | __forward_list_base(__forward_list_base&& __x, const allocator_type& __a); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 403 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | private: |
| 406 | __forward_list_base(const __forward_list_base&); |
| 407 | __forward_list_base& operator=(const __forward_list_base&); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 408 | |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 409 | public: |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | ~__forward_list_base(); |
| 411 | |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 412 | protected: |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 413 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | void __copy_assign_alloc(const __forward_list_base& __x) |
| 415 | {__copy_assign_alloc(__x, integral_constant<bool, |
| 416 | __node_traits::propagate_on_container_copy_assignment::value>());} |
| 417 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | void __move_assign_alloc(__forward_list_base& __x) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 420 | _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || |
| 421 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 422 | {__move_assign_alloc(__x, integral_constant<bool, |
| 423 | __node_traits::propagate_on_container_move_assignment::value>());} |
| 424 | |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 425 | public: |
| 426 | void swap(__forward_list_base& __x) |
| 427 | _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || |
| 428 | __is_nothrow_swappable<__node_allocator>::value); |
| 429 | protected: |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 430 | void clear() _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | |
| 432 | private: |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 433 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | void __copy_assign_alloc(const __forward_list_base&, false_type) {} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 435 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 436 | void __copy_assign_alloc(const __forward_list_base& __x, true_type) |
| 437 | { |
| 438 | if (__alloc() != __x.__alloc()) |
| 439 | clear(); |
| 440 | __alloc() = __x.__alloc(); |
| 441 | } |
| 442 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 444 | void __move_assign_alloc(__forward_list_base& __x, false_type) _NOEXCEPT |
| 445 | {} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 447 | void __move_assign_alloc(__forward_list_base& __x, true_type) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 448 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 449 | {__alloc() = _VSTD::move(__x.__alloc());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 450 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 452 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 453 | _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || |
| 454 | __is_nothrow_swappable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | {__swap_alloc(__x, __y, integral_constant<bool, |
| 456 | __node_traits::propagate_on_container_swap::value>());} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, |
| 459 | false_type) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 460 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 461 | {} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, |
| 464 | true_type) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 465 | _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 466 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 467 | using _VSTD::swap; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | swap(__x, __y); |
| 469 | } |
| 470 | }; |
| 471 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 472 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 473 | |
| 474 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 475 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 477 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 478 | : __before_begin_(_VSTD::move(__x.__before_begin_)) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 479 | { |
| 480 | __x.__before_begin()->__next_ = nullptr; |
| 481 | } |
| 482 | |
| 483 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 484 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | __forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x, |
| 486 | const allocator_type& __a) |
| 487 | : __before_begin_(__begin_node(), __node_allocator(__a)) |
| 488 | { |
| 489 | if (__alloc() == __x.__alloc()) |
| 490 | { |
| 491 | __before_begin()->__next_ = __x.__before_begin()->__next_; |
| 492 | __x.__before_begin()->__next_ = nullptr; |
| 493 | } |
| 494 | } |
| 495 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 496 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 497 | |
| 498 | template <class _Tp, class _Alloc> |
| 499 | __forward_list_base<_Tp, _Alloc>::~__forward_list_base() |
| 500 | { |
| 501 | clear(); |
| 502 | } |
| 503 | |
| 504 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 505 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 506 | void |
| 507 | __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 508 | _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || |
| 509 | __is_nothrow_swappable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | { |
| 511 | __swap_alloc(__alloc(), __x.__alloc()); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 512 | using _VSTD::swap; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | swap(__before_begin()->__next_, __x.__before_begin()->__next_); |
| 514 | } |
| 515 | |
| 516 | template <class _Tp, class _Alloc> |
| 517 | void |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 518 | __forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 519 | { |
| 520 | __node_allocator& __a = __alloc(); |
| 521 | for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;) |
| 522 | { |
| 523 | __node_pointer __next = __p->__next_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 524 | __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 525 | __node_traits::deallocate(__a, __p, 1); |
| 526 | __p = __next; |
| 527 | } |
| 528 | __before_begin()->__next_ = nullptr; |
| 529 | } |
| 530 | |
| 531 | template <class _Tp, class _Alloc = allocator<_Tp> > |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 532 | class _LIBCPP_VISIBLE forward_list |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | : private __forward_list_base<_Tp, _Alloc> |
| 534 | { |
| 535 | typedef __forward_list_base<_Tp, _Alloc> base; |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 536 | typedef typename base::__node_allocator __node_allocator; |
| 537 | typedef typename base::__node __node; |
| 538 | typedef typename base::__node_traits __node_traits; |
| 539 | typedef typename base::__node_pointer __node_pointer; |
| 540 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | public: |
| 542 | typedef _Tp value_type; |
| 543 | typedef _Alloc allocator_type; |
| 544 | |
| 545 | typedef value_type& reference; |
| 546 | typedef const value_type& const_reference; |
| 547 | typedef typename allocator_traits<allocator_type>::pointer pointer; |
| 548 | typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; |
| 549 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 550 | typedef typename allocator_traits<allocator_type>::difference_type difference_type; |
| 551 | |
| 552 | typedef typename base::iterator iterator; |
| 553 | typedef typename base::const_iterator const_iterator; |
| 554 | |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY |
| 556 | forward_list() |
| 557 | _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) |
| 558 | {} // = default; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 559 | explicit forward_list(const allocator_type& __a); |
| 560 | explicit forward_list(size_type __n); |
| 561 | forward_list(size_type __n, const value_type& __v); |
| 562 | forward_list(size_type __n, const value_type& __v, const allocator_type& __a); |
| 563 | template <class _InputIterator> |
| 564 | forward_list(_InputIterator __f, _InputIterator __l, |
| 565 | typename enable_if< |
| 566 | __is_input_iterator<_InputIterator>::value |
| 567 | >::type* = nullptr); |
| 568 | template <class _InputIterator> |
| 569 | forward_list(_InputIterator __f, _InputIterator __l, |
| 570 | const allocator_type& __a, |
| 571 | typename enable_if< |
| 572 | __is_input_iterator<_InputIterator>::value |
| 573 | >::type* = nullptr); |
| 574 | forward_list(const forward_list& __x); |
| 575 | forward_list(const forward_list& __x, const allocator_type& __a); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 576 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 577 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 578 | forward_list(forward_list&& __x) |
| 579 | _NOEXCEPT_(is_nothrow_move_constructible<base>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 580 | : base(_VSTD::move(__x)) {} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | forward_list(forward_list&& __x, const allocator_type& __a); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 582 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 583 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | forward_list(initializer_list<value_type> __il); |
| 585 | forward_list(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 586 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | |
| 588 | // ~forward_list() = default; |
| 589 | |
| 590 | forward_list& operator=(const forward_list& __x); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 591 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 592 | forward_list& operator=(forward_list&& __x) |
| 593 | _NOEXCEPT_( |
| 594 | __node_traits::propagate_on_container_move_assignment::value && |
| 595 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 596 | #endif |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 597 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | forward_list& operator=(initializer_list<value_type> __il); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 599 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | |
| 601 | template <class _InputIterator> |
| 602 | typename enable_if |
| 603 | < |
| 604 | __is_input_iterator<_InputIterator>::value, |
| 605 | void |
| 606 | >::type |
| 607 | assign(_InputIterator __f, _InputIterator __l); |
| 608 | void assign(size_type __n, const value_type& __v); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 609 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 610 | void assign(initializer_list<value_type> __il); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 611 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 612 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 613 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 614 | allocator_type get_allocator() const _NOEXCEPT |
| 615 | {return allocator_type(base::__alloc());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 618 | iterator begin() _NOEXCEPT |
| 619 | {return iterator(base::__before_begin()->__next_);} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 620 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 621 | const_iterator begin() const _NOEXCEPT |
| 622 | {return const_iterator(base::__before_begin()->__next_);} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 623 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 624 | iterator end() _NOEXCEPT |
| 625 | {return iterator(nullptr);} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 626 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 627 | const_iterator end() const _NOEXCEPT |
| 628 | {return const_iterator(nullptr);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 630 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 631 | const_iterator cbegin() const _NOEXCEPT |
| 632 | {return const_iterator(base::__before_begin()->__next_);} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 633 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 634 | const_iterator cend() const _NOEXCEPT |
| 635 | {return const_iterator(nullptr);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 637 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 638 | iterator before_begin() _NOEXCEPT |
| 639 | {return iterator(base::__before_begin());} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 641 | const_iterator before_begin() const _NOEXCEPT |
| 642 | {return const_iterator(base::__before_begin());} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 643 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 644 | const_iterator cbefore_begin() const _NOEXCEPT |
| 645 | {return const_iterator(base::__before_begin());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 647 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 648 | bool empty() const _NOEXCEPT |
| 649 | {return base::__before_begin()->__next_ == nullptr;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 650 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 651 | size_type max_size() const _NOEXCEPT |
| 652 | {return numeric_limits<size_type>::max();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 654 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | reference front() {return base::__before_begin()->__next_->__value_;} |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | const_reference front() const {return base::__before_begin()->__next_->__value_;} |
| 658 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 659 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 660 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | template <class... _Args> void emplace_front(_Args&&... __args); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 662 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 663 | void push_front(value_type&& __v); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 664 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | void push_front(const value_type& __v); |
| 666 | |
| 667 | void pop_front(); |
| 668 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 669 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 670 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | template <class... _Args> |
| 672 | iterator emplace_after(const_iterator __p, _Args&&... __args); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 673 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 674 | iterator insert_after(const_iterator __p, value_type&& __v); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 675 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | iterator insert_after(const_iterator __p, const value_type& __v); |
| 677 | iterator insert_after(const_iterator __p, size_type __n, const value_type& __v); |
| 678 | template <class _InputIterator> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 679 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | typename enable_if |
| 681 | < |
| 682 | __is_input_iterator<_InputIterator>::value, |
| 683 | iterator |
| 684 | >::type |
| 685 | insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 686 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | iterator insert_after(const_iterator __p, initializer_list<value_type> __il) |
| 688 | {return insert_after(__p, __il.begin(), __il.end());} |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 689 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 691 | iterator erase_after(const_iterator __p); |
| 692 | iterator erase_after(const_iterator __f, const_iterator __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 693 | |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 694 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 695 | void swap(forward_list& __x) |
| 696 | _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value || |
| 697 | __is_nothrow_swappable<__node_allocator>::value) |
| 698 | {base::swap(__x);} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 699 | |
| 700 | void resize(size_type __n); |
| 701 | void resize(size_type __n, const value_type& __v); |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 702 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 703 | void clear() _NOEXCEPT {base::clear();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 704 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 705 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 707 | void splice_after(const_iterator __p, forward_list&& __x); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 708 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 710 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | void splice_after(const_iterator __p, forward_list&& __x, |
| 712 | const_iterator __f, const_iterator __l); |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 713 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 714 | void splice_after(const_iterator __p, forward_list& __x); |
| 715 | void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); |
| 716 | void splice_after(const_iterator __p, forward_list& __x, |
| 717 | const_iterator __f, const_iterator __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | void remove(const value_type& __v); |
| 719 | template <class _Predicate> void remove_if(_Predicate __pred); |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 720 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 721 | void unique() {unique(__equal_to<value_type>());} |
| 722 | template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 723 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 725 | void merge(forward_list&& __x) {merge(__x, __less<value_type>());} |
| 726 | template <class _Compare> |
| 727 | _LIBCPP_INLINE_VISIBILITY |
| 728 | void merge(forward_list&& __x, _Compare __comp) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 729 | {merge(__x, _VSTD::move(__comp));} |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 730 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | void merge(forward_list& __x) {merge(__x, __less<value_type>());} |
| 733 | template <class _Compare> void merge(forward_list& __x, _Compare __comp); |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 734 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 735 | void sort() {sort(__less<value_type>());} |
| 736 | template <class _Compare> void sort(_Compare __comp); |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 737 | void reverse() _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | |
| 739 | private: |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 740 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 741 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 742 | void __move_assign(forward_list& __x, true_type) |
| 743 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | void __move_assign(forward_list& __x, false_type); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 745 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | |
| 747 | template <class _Compare> |
| 748 | static |
| 749 | __node_pointer |
| 750 | __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp); |
| 751 | |
| 752 | template <class _Compare> |
| 753 | static |
| 754 | __node_pointer |
| 755 | __sort(__node_pointer __f, difference_type __sz, _Compare& __comp); |
| 756 | }; |
| 757 | |
| 758 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 759 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 760 | forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a) |
| 761 | : base(__a) |
| 762 | { |
| 763 | } |
| 764 | |
| 765 | template <class _Tp, class _Alloc> |
| 766 | forward_list<_Tp, _Alloc>::forward_list(size_type __n) |
| 767 | { |
| 768 | if (__n > 0) |
| 769 | { |
| 770 | __node_allocator& __a = base::__alloc(); |
| 771 | typedef __allocator_destructor<__node_allocator> _D; |
| 772 | unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); |
| 773 | for (__node_pointer __p = base::__before_begin(); __n > 0; --__n, |
| 774 | __p = __p->__next_) |
| 775 | { |
| 776 | __h.reset(__node_traits::allocate(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 777 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | __h->__next_ = nullptr; |
| 779 | __p->__next_ = __h.release(); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | template <class _Tp, class _Alloc> |
| 785 | forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v) |
| 786 | { |
| 787 | insert_after(cbefore_begin(), __n, __v); |
| 788 | } |
| 789 | |
| 790 | template <class _Tp, class _Alloc> |
| 791 | forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v, |
| 792 | const allocator_type& __a) |
| 793 | : base(__a) |
| 794 | { |
| 795 | insert_after(cbefore_begin(), __n, __v); |
| 796 | } |
| 797 | |
| 798 | template <class _Tp, class _Alloc> |
| 799 | template <class _InputIterator> |
| 800 | forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, |
| 801 | typename enable_if< |
| 802 | __is_input_iterator<_InputIterator>::value |
| 803 | >::type*) |
| 804 | { |
| 805 | insert_after(cbefore_begin(), __f, __l); |
| 806 | } |
| 807 | |
| 808 | template <class _Tp, class _Alloc> |
| 809 | template <class _InputIterator> |
| 810 | forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l, |
| 811 | const allocator_type& __a, |
| 812 | typename enable_if< |
| 813 | __is_input_iterator<_InputIterator>::value |
| 814 | >::type*) |
| 815 | : base(__a) |
| 816 | { |
| 817 | insert_after(cbefore_begin(), __f, __l); |
| 818 | } |
| 819 | |
| 820 | template <class _Tp, class _Alloc> |
| 821 | forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x) |
| 822 | : base(allocator_type( |
| 823 | __node_traits::select_on_container_copy_construction(__x.__alloc()) |
| 824 | ) |
| 825 | ) |
| 826 | { |
| 827 | insert_after(cbefore_begin(), __x.begin(), __x.end()); |
| 828 | } |
| 829 | |
| 830 | template <class _Tp, class _Alloc> |
| 831 | forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x, |
| 832 | const allocator_type& __a) |
| 833 | : base(__a) |
| 834 | { |
| 835 | insert_after(cbefore_begin(), __x.begin(), __x.end()); |
| 836 | } |
| 837 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 838 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | |
| 840 | template <class _Tp, class _Alloc> |
| 841 | forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x, |
| 842 | const allocator_type& __a) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 843 | : base(_VSTD::move(__x), __a) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | { |
| 845 | if (base::__alloc() != __x.__alloc()) |
| 846 | { |
| 847 | typedef move_iterator<iterator> _I; |
| 848 | insert_after(cbefore_begin(), _I(__x.begin()), _I(__x.end())); |
| 849 | } |
| 850 | } |
| 851 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 852 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 853 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 854 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 855 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | template <class _Tp, class _Alloc> |
| 857 | forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il) |
| 858 | { |
| 859 | insert_after(cbefore_begin(), __il.begin(), __il.end()); |
| 860 | } |
| 861 | |
| 862 | template <class _Tp, class _Alloc> |
| 863 | forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il, |
| 864 | const allocator_type& __a) |
| 865 | : base(__a) |
| 866 | { |
| 867 | insert_after(cbefore_begin(), __il.begin(), __il.end()); |
| 868 | } |
| 869 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 870 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 871 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 872 | template <class _Tp, class _Alloc> |
| 873 | forward_list<_Tp, _Alloc>& |
| 874 | forward_list<_Tp, _Alloc>::operator=(const forward_list& __x) |
| 875 | { |
| 876 | if (this != &__x) |
| 877 | { |
| 878 | base::__copy_assign_alloc(__x); |
| 879 | assign(__x.begin(), __x.end()); |
| 880 | } |
| 881 | return *this; |
| 882 | } |
| 883 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 884 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 885 | |
| 886 | template <class _Tp, class _Alloc> |
| 887 | void |
| 888 | forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 889 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | { |
| 891 | clear(); |
| 892 | base::__move_assign_alloc(__x); |
| 893 | base::__before_begin()->__next_ = __x.__before_begin()->__next_; |
| 894 | __x.__before_begin()->__next_ = nullptr; |
| 895 | } |
| 896 | |
| 897 | template <class _Tp, class _Alloc> |
| 898 | void |
| 899 | forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type) |
| 900 | { |
| 901 | if (base::__alloc() == __x.__alloc()) |
| 902 | __move_assign(__x, true_type()); |
| 903 | else |
| 904 | { |
| 905 | typedef move_iterator<iterator> _I; |
| 906 | assign(_I(__x.begin()), _I(__x.end())); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 911 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 912 | forward_list<_Tp, _Alloc>& |
| 913 | forward_list<_Tp, _Alloc>::operator=(forward_list&& __x) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 914 | _NOEXCEPT_( |
| 915 | __node_traits::propagate_on_container_move_assignment::value && |
| 916 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | { |
| 918 | __move_assign(__x, integral_constant<bool, |
| 919 | __node_traits::propagate_on_container_move_assignment::value>()); |
| 920 | return *this; |
| 921 | } |
| 922 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 923 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 925 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 926 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 928 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | forward_list<_Tp, _Alloc>& |
| 930 | forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il) |
| 931 | { |
| 932 | assign(__il.begin(), __il.end()); |
| 933 | return *this; |
| 934 | } |
| 935 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 936 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 937 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 938 | template <class _Tp, class _Alloc> |
| 939 | template <class _InputIterator> |
| 940 | typename enable_if |
| 941 | < |
| 942 | __is_input_iterator<_InputIterator>::value, |
| 943 | void |
| 944 | >::type |
| 945 | forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l) |
| 946 | { |
| 947 | iterator __i = before_begin(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 948 | iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 949 | iterator __e = end(); |
| 950 | for (; __j != __e && __f != __l; ++__i, ++__j, ++__f) |
| 951 | *__j = *__f; |
| 952 | if (__j == __e) |
| 953 | insert_after(__i, __f, __l); |
| 954 | else |
| 955 | erase_after(__i, __e); |
| 956 | } |
| 957 | |
| 958 | template <class _Tp, class _Alloc> |
| 959 | void |
| 960 | forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v) |
| 961 | { |
| 962 | iterator __i = before_begin(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 963 | iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | iterator __e = end(); |
| 965 | for (; __j != __e && __n > 0; --__n, ++__i, ++__j) |
| 966 | *__j = __v; |
| 967 | if (__j == __e) |
| 968 | insert_after(__i, __n, __v); |
| 969 | else |
| 970 | erase_after(__i, __e); |
| 971 | } |
| 972 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 973 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 974 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 975 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 976 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | void |
| 978 | forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il) |
| 979 | { |
| 980 | assign(__il.begin(), __il.end()); |
| 981 | } |
| 982 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 983 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 984 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 985 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 986 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | |
| 988 | template <class _Tp, class _Alloc> |
| 989 | template <class... _Args> |
| 990 | void |
| 991 | forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args) |
| 992 | { |
| 993 | __node_allocator& __a = base::__alloc(); |
| 994 | typedef __allocator_destructor<__node_allocator> _D; |
| 995 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 996 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), |
| 997 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | __h->__next_ = base::__before_begin()->__next_; |
| 999 | base::__before_begin()->__next_ = __h.release(); |
| 1000 | } |
| 1001 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1002 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1003 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | template <class _Tp, class _Alloc> |
| 1005 | void |
| 1006 | forward_list<_Tp, _Alloc>::push_front(value_type&& __v) |
| 1007 | { |
| 1008 | __node_allocator& __a = base::__alloc(); |
| 1009 | typedef __allocator_destructor<__node_allocator> _D; |
| 1010 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1011 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | __h->__next_ = base::__before_begin()->__next_; |
| 1013 | base::__before_begin()->__next_ = __h.release(); |
| 1014 | } |
| 1015 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1016 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1017 | |
| 1018 | template <class _Tp, class _Alloc> |
| 1019 | void |
| 1020 | forward_list<_Tp, _Alloc>::push_front(const value_type& __v) |
| 1021 | { |
| 1022 | __node_allocator& __a = base::__alloc(); |
| 1023 | typedef __allocator_destructor<__node_allocator> _D; |
| 1024 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1025 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1026 | __h->__next_ = base::__before_begin()->__next_; |
| 1027 | base::__before_begin()->__next_ = __h.release(); |
| 1028 | } |
| 1029 | |
| 1030 | template <class _Tp, class _Alloc> |
| 1031 | void |
| 1032 | forward_list<_Tp, _Alloc>::pop_front() |
| 1033 | { |
| 1034 | __node_allocator& __a = base::__alloc(); |
| 1035 | __node_pointer __p = base::__before_begin()->__next_; |
| 1036 | base::__before_begin()->__next_ = __p->__next_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1037 | __node_traits::destroy(__a, _VSTD::addressof(__p->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1038 | __node_traits::deallocate(__a, __p, 1); |
| 1039 | } |
| 1040 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1041 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1042 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | |
| 1044 | template <class _Tp, class _Alloc> |
| 1045 | template <class... _Args> |
| 1046 | typename forward_list<_Tp, _Alloc>::iterator |
| 1047 | forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args) |
| 1048 | { |
| 1049 | __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); |
| 1050 | __node_allocator& __a = base::__alloc(); |
| 1051 | typedef __allocator_destructor<__node_allocator> _D; |
| 1052 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1053 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), |
| 1054 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | __h->__next_ = __r->__next_; |
| 1056 | __r->__next_ = __h.release(); |
| 1057 | return iterator(__r->__next_); |
| 1058 | } |
| 1059 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1060 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1061 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | template <class _Tp, class _Alloc> |
| 1063 | typename forward_list<_Tp, _Alloc>::iterator |
| 1064 | forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v) |
| 1065 | { |
| 1066 | __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); |
| 1067 | __node_allocator& __a = base::__alloc(); |
| 1068 | typedef __allocator_destructor<__node_allocator> _D; |
| 1069 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1070 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | __h->__next_ = __r->__next_; |
| 1072 | __r->__next_ = __h.release(); |
| 1073 | return iterator(__r->__next_); |
| 1074 | } |
| 1075 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1076 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1077 | |
| 1078 | template <class _Tp, class _Alloc> |
| 1079 | typename forward_list<_Tp, _Alloc>::iterator |
| 1080 | forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v) |
| 1081 | { |
| 1082 | __node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_); |
| 1083 | __node_allocator& __a = base::__alloc(); |
| 1084 | typedef __allocator_destructor<__node_allocator> _D; |
| 1085 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1086 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1087 | __h->__next_ = __r->__next_; |
| 1088 | __r->__next_ = __h.release(); |
| 1089 | return iterator(__r->__next_); |
| 1090 | } |
| 1091 | |
| 1092 | template <class _Tp, class _Alloc> |
| 1093 | typename forward_list<_Tp, _Alloc>::iterator |
| 1094 | forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n, |
| 1095 | const value_type& __v) |
| 1096 | { |
Howard Hinnant | e57dc14 | 2010-08-19 17:40:04 +0000 | [diff] [blame] | 1097 | __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1098 | if (__n > 0) |
| 1099 | { |
| 1100 | __node_allocator& __a = base::__alloc(); |
| 1101 | typedef __allocator_destructor<__node_allocator> _D; |
| 1102 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1103 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1104 | __node_pointer __first = __h.release(); |
| 1105 | __node_pointer __last = __first; |
| 1106 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1107 | try |
| 1108 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1109 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1110 | for (--__n; __n != 0; --__n, __last = __last->__next_) |
| 1111 | { |
| 1112 | __h.reset(__node_traits::allocate(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1113 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1114 | __last->__next_ = __h.release(); |
| 1115 | } |
| 1116 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1117 | } |
| 1118 | catch (...) |
| 1119 | { |
| 1120 | while (__first != nullptr) |
| 1121 | { |
| 1122 | __node_pointer __next = __first->__next_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1123 | __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1124 | __node_traits::deallocate(__a, __first, 1); |
| 1125 | __first = __next; |
| 1126 | } |
| 1127 | throw; |
| 1128 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1129 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | __last->__next_ = __r->__next_; |
| 1131 | __r->__next_ = __first; |
Howard Hinnant | e57dc14 | 2010-08-19 17:40:04 +0000 | [diff] [blame] | 1132 | __r = __last; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1133 | } |
| 1134 | return iterator(__r); |
| 1135 | } |
| 1136 | |
| 1137 | template <class _Tp, class _Alloc> |
| 1138 | template <class _InputIterator> |
| 1139 | typename enable_if |
| 1140 | < |
| 1141 | __is_input_iterator<_InputIterator>::value, |
| 1142 | typename forward_list<_Tp, _Alloc>::iterator |
| 1143 | >::type |
| 1144 | forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, |
| 1145 | _InputIterator __f, _InputIterator __l) |
| 1146 | { |
Howard Hinnant | e57dc14 | 2010-08-19 17:40:04 +0000 | [diff] [blame] | 1147 | __node_pointer __r = const_cast<__node_pointer>(__p.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1148 | if (__f != __l) |
| 1149 | { |
| 1150 | __node_allocator& __a = base::__alloc(); |
| 1151 | typedef __allocator_destructor<__node_allocator> _D; |
| 1152 | unique_ptr<__node, _D> __h(__node_traits::allocate(__a, 1), _D(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1153 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | __node_pointer __first = __h.release(); |
| 1155 | __node_pointer __last = __first; |
| 1156 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1157 | try |
| 1158 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1159 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | for (++__f; __f != __l; ++__f, __last = __last->__next_) |
| 1161 | { |
| 1162 | __h.reset(__node_traits::allocate(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1163 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1164 | __last->__next_ = __h.release(); |
| 1165 | } |
| 1166 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1167 | } |
| 1168 | catch (...) |
| 1169 | { |
| 1170 | while (__first != nullptr) |
| 1171 | { |
| 1172 | __node_pointer __next = __first->__next_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1173 | __node_traits::destroy(__a, _VSTD::addressof(__first->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1174 | __node_traits::deallocate(__a, __first, 1); |
| 1175 | __first = __next; |
| 1176 | } |
| 1177 | throw; |
| 1178 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1179 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | __last->__next_ = __r->__next_; |
| 1181 | __r->__next_ = __first; |
Howard Hinnant | e57dc14 | 2010-08-19 17:40:04 +0000 | [diff] [blame] | 1182 | __r = __last; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | } |
| 1184 | return iterator(__r); |
| 1185 | } |
| 1186 | |
| 1187 | template <class _Tp, class _Alloc> |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 1188 | typename forward_list<_Tp, _Alloc>::iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1189 | forward_list<_Tp, _Alloc>::erase_after(const_iterator __f) |
| 1190 | { |
| 1191 | __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); |
| 1192 | __node_pointer __n = __p->__next_; |
| 1193 | __p->__next_ = __n->__next_; |
| 1194 | __node_allocator& __a = base::__alloc(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1195 | __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | __node_traits::deallocate(__a, __n, 1); |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 1197 | return iterator(__p->__next_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | template <class _Tp, class _Alloc> |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 1201 | typename forward_list<_Tp, _Alloc>::iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1202 | forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l) |
| 1203 | { |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 1204 | __node_pointer __e = const_cast<__node_pointer>(__l.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1205 | if (__f != __l) |
| 1206 | { |
| 1207 | __node_pointer __p = const_cast<__node_pointer>(__f.__ptr_); |
| 1208 | __node_pointer __n = __p->__next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | if (__n != __e) |
| 1210 | { |
| 1211 | __p->__next_ = __e; |
| 1212 | __node_allocator& __a = base::__alloc(); |
| 1213 | do |
| 1214 | { |
| 1215 | __p = __n->__next_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1216 | __node_traits::destroy(__a, _VSTD::addressof(__n->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | __node_traits::deallocate(__a, __n, 1); |
| 1218 | __n = __p; |
| 1219 | } while (__n != __e); |
| 1220 | } |
| 1221 | } |
Howard Hinnant | 3db8803 | 2010-08-21 20:58:44 +0000 | [diff] [blame] | 1222 | return iterator(__e); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | template <class _Tp, class _Alloc> |
| 1226 | void |
| 1227 | forward_list<_Tp, _Alloc>::resize(size_type __n) |
| 1228 | { |
| 1229 | size_type __sz = 0; |
| 1230 | iterator __p = before_begin(); |
| 1231 | iterator __i = begin(); |
| 1232 | iterator __e = end(); |
| 1233 | for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) |
| 1234 | ; |
| 1235 | if (__i != __e) |
| 1236 | erase_after(__p, __e); |
| 1237 | else |
| 1238 | { |
| 1239 | __n -= __sz; |
| 1240 | if (__n > 0) |
| 1241 | { |
| 1242 | __node_allocator& __a = base::__alloc(); |
| 1243 | typedef __allocator_destructor<__node_allocator> _D; |
| 1244 | unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); |
| 1245 | for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n, |
| 1246 | __ptr = __ptr->__next_) |
| 1247 | { |
| 1248 | __h.reset(__node_traits::allocate(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1249 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1250 | __h->__next_ = nullptr; |
| 1251 | __ptr->__next_ = __h.release(); |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | template <class _Tp, class _Alloc> |
| 1258 | void |
| 1259 | forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v) |
| 1260 | { |
| 1261 | size_type __sz = 0; |
| 1262 | iterator __p = before_begin(); |
| 1263 | iterator __i = begin(); |
| 1264 | iterator __e = end(); |
| 1265 | for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz) |
| 1266 | ; |
| 1267 | if (__i != __e) |
| 1268 | erase_after(__p, __e); |
| 1269 | else |
| 1270 | { |
| 1271 | __n -= __sz; |
| 1272 | if (__n > 0) |
| 1273 | { |
| 1274 | __node_allocator& __a = base::__alloc(); |
| 1275 | typedef __allocator_destructor<__node_allocator> _D; |
| 1276 | unique_ptr<__node, _D> __h(nullptr, _D(__a, 1)); |
| 1277 | for (__node_pointer __ptr = __p.__ptr_; __n > 0; --__n, |
| 1278 | __ptr = __ptr->__next_) |
| 1279 | { |
| 1280 | __h.reset(__node_traits::allocate(__a, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1281 | __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | __h->__next_ = nullptr; |
| 1283 | __ptr->__next_ = __h.release(); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | template <class _Tp, class _Alloc> |
| 1290 | void |
| 1291 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1292 | forward_list& __x) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | { |
| 1294 | if (!__x.empty()) |
| 1295 | { |
| 1296 | if (__p.__ptr_->__next_ != nullptr) |
| 1297 | { |
| 1298 | const_iterator __lm1 = __x.before_begin(); |
| 1299 | while (__lm1.__ptr_->__next_ != nullptr) |
| 1300 | ++__lm1; |
| 1301 | const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = |
| 1302 | const_cast<__node_pointer>(__p.__ptr_)->__next_; |
| 1303 | } |
| 1304 | const_cast<__node_pointer>(__p.__ptr_)->__next_ = |
| 1305 | const_cast<__node_pointer>(__x.__before_begin())->__next_; |
| 1306 | const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | template <class _Tp, class _Alloc> |
| 1311 | void |
| 1312 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | forward_list& __x, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1314 | const_iterator __i) |
| 1315 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1316 | const_iterator __lm1 = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1317 | if (__p != __i && __p != __lm1) |
| 1318 | { |
| 1319 | const_cast<__node_pointer>(__i.__ptr_)->__next_ = |
| 1320 | const_cast<__node_pointer>(__lm1.__ptr_)->__next_; |
| 1321 | const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = |
| 1322 | const_cast<__node_pointer>(__p.__ptr_)->__next_; |
| 1323 | const_cast<__node_pointer>(__p.__ptr_)->__next_ = |
| 1324 | const_cast<__node_pointer>(__lm1.__ptr_); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | template <class _Tp, class _Alloc> |
| 1329 | void |
| 1330 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1331 | forward_list& __x, |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1332 | const_iterator __f, const_iterator __l) |
| 1333 | { |
| 1334 | if (__f != __l && __p != __f) |
| 1335 | { |
| 1336 | const_iterator __lm1 = __f; |
| 1337 | while (__lm1.__ptr_->__next_ != __l.__ptr_) |
| 1338 | ++__lm1; |
| 1339 | if (__f != __lm1) |
| 1340 | { |
| 1341 | const_cast<__node_pointer>(__lm1.__ptr_)->__next_ = |
| 1342 | const_cast<__node_pointer>(__p.__ptr_)->__next_; |
| 1343 | const_cast<__node_pointer>(__p.__ptr_)->__next_ = |
| 1344 | const_cast<__node_pointer>(__f.__ptr_)->__next_; |
| 1345 | const_cast<__node_pointer>(__f.__ptr_)->__next_ = |
| 1346 | const_cast<__node_pointer>(__l.__ptr_); |
| 1347 | } |
| 1348 | } |
| 1349 | } |
| 1350 | |
Howard Hinnant | eb92df7 | 2011-01-27 21:00:35 +0000 | [diff] [blame] | 1351 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1352 | |
| 1353 | template <class _Tp, class _Alloc> |
| 1354 | inline _LIBCPP_INLINE_VISIBILITY |
| 1355 | void |
| 1356 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
| 1357 | forward_list&& __x) |
| 1358 | { |
| 1359 | splice_after(__p, __x); |
| 1360 | } |
| 1361 | |
| 1362 | template <class _Tp, class _Alloc> |
| 1363 | inline _LIBCPP_INLINE_VISIBILITY |
| 1364 | void |
| 1365 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
| 1366 | forward_list&& __x, |
| 1367 | const_iterator __i) |
| 1368 | { |
| 1369 | splice_after(__p, __x, __i); |
| 1370 | } |
| 1371 | |
| 1372 | template <class _Tp, class _Alloc> |
| 1373 | inline _LIBCPP_INLINE_VISIBILITY |
| 1374 | void |
| 1375 | forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, |
| 1376 | forward_list&& __x, |
| 1377 | const_iterator __f, const_iterator __l) |
| 1378 | { |
| 1379 | splice_after(__p, __x, __f, __l); |
| 1380 | } |
| 1381 | |
| 1382 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1383 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1384 | template <class _Tp, class _Alloc> |
| 1385 | void |
| 1386 | forward_list<_Tp, _Alloc>::remove(const value_type& __v) |
| 1387 | { |
| 1388 | iterator __e = end(); |
| 1389 | for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) |
| 1390 | { |
| 1391 | if (__i.__ptr_->__next_->__value_ == __v) |
| 1392 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1393 | iterator __j = _VSTD::next(__i, 2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | for (; __j != __e && *__j == __v; ++__j) |
| 1395 | ; |
| 1396 | erase_after(__i, __j); |
| 1397 | if (__j == __e) |
| 1398 | break; |
| 1399 | __i = __j; |
| 1400 | } |
| 1401 | else |
| 1402 | ++__i; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | template <class _Tp, class _Alloc> |
| 1407 | template <class _Predicate> |
| 1408 | void |
| 1409 | forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) |
| 1410 | { |
| 1411 | iterator __e = end(); |
| 1412 | for (iterator __i = before_begin(); __i.__ptr_->__next_ != nullptr;) |
| 1413 | { |
| 1414 | if (__pred(__i.__ptr_->__next_->__value_)) |
| 1415 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1416 | iterator __j = _VSTD::next(__i, 2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1417 | for (; __j != __e && __pred(*__j); ++__j) |
| 1418 | ; |
| 1419 | erase_after(__i, __j); |
| 1420 | if (__j == __e) |
| 1421 | break; |
| 1422 | __i = __j; |
| 1423 | } |
| 1424 | else |
| 1425 | ++__i; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | template <class _Tp, class _Alloc> |
| 1430 | template <class _BinaryPredicate> |
| 1431 | void |
| 1432 | forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) |
| 1433 | { |
| 1434 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 1435 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1436 | iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | for (; __j != __e && __binary_pred(*__i, *__j); ++__j) |
| 1438 | ; |
| 1439 | if (__i.__ptr_->__next_ != __j.__ptr_) |
| 1440 | erase_after(__i, __j); |
| 1441 | __i = __j; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | template <class _Tp, class _Alloc> |
| 1446 | template <class _Compare> |
| 1447 | void |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | { |
| 1450 | if (this != &__x) |
| 1451 | { |
| 1452 | base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_, |
| 1453 | __x.__before_begin()->__next_, |
| 1454 | __comp); |
| 1455 | __x.__before_begin()->__next_ = nullptr; |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | template <class _Tp, class _Alloc> |
| 1460 | template <class _Compare> |
| 1461 | typename forward_list<_Tp, _Alloc>::__node_pointer |
| 1462 | forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2, |
| 1463 | _Compare& __comp) |
| 1464 | { |
| 1465 | if (__f1 == nullptr) |
| 1466 | return __f2; |
| 1467 | if (__f2 == nullptr) |
| 1468 | return __f1; |
| 1469 | __node_pointer __r; |
| 1470 | if (__comp(__f2->__value_, __f1->__value_)) |
| 1471 | { |
| 1472 | __node_pointer __t = __f2; |
| 1473 | while (__t->__next_ != nullptr && |
| 1474 | __comp(__t->__next_->__value_, __f1->__value_)) |
| 1475 | __t = __t->__next_; |
| 1476 | __r = __f2; |
| 1477 | __f2 = __t->__next_; |
| 1478 | __t->__next_ = __f1; |
| 1479 | } |
| 1480 | else |
| 1481 | __r = __f1; |
| 1482 | __node_pointer __p = __f1; |
| 1483 | __f1 = __f1->__next_; |
| 1484 | while (__f1 != nullptr && __f2 != nullptr) |
| 1485 | { |
| 1486 | if (__comp(__f2->__value_, __f1->__value_)) |
| 1487 | { |
| 1488 | __node_pointer __t = __f2; |
| 1489 | while (__t->__next_ != nullptr && |
| 1490 | __comp(__t->__next_->__value_, __f1->__value_)) |
| 1491 | __t = __t->__next_; |
| 1492 | __p->__next_ = __f2; |
| 1493 | __f2 = __t->__next_; |
| 1494 | __t->__next_ = __f1; |
| 1495 | } |
| 1496 | __p = __f1; |
| 1497 | __f1 = __f1->__next_; |
| 1498 | } |
| 1499 | if (__f2 != nullptr) |
| 1500 | __p->__next_ = __f2; |
| 1501 | return __r; |
| 1502 | } |
| 1503 | |
| 1504 | template <class _Tp, class _Alloc> |
| 1505 | template <class _Compare> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1506 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1507 | void |
| 1508 | forward_list<_Tp, _Alloc>::sort(_Compare __comp) |
| 1509 | { |
| 1510 | base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_, |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1511 | _VSTD::distance(begin(), end()), __comp); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | template <class _Tp, class _Alloc> |
| 1515 | template <class _Compare> |
| 1516 | typename forward_list<_Tp, _Alloc>::__node_pointer |
| 1517 | forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz, |
| 1518 | _Compare& __comp) |
| 1519 | { |
| 1520 | switch (__sz) |
| 1521 | { |
| 1522 | case 0: |
| 1523 | case 1: |
| 1524 | return __f1; |
| 1525 | case 2: |
| 1526 | if (__comp(__f1->__next_->__value_, __f1->__value_)) |
| 1527 | { |
| 1528 | __node_pointer __t = __f1->__next_; |
| 1529 | __t->__next_ = __f1; |
| 1530 | __f1->__next_ = nullptr; |
| 1531 | __f1 = __t; |
| 1532 | } |
| 1533 | return __f1; |
| 1534 | } |
| 1535 | difference_type __sz1 = __sz / 2; |
| 1536 | difference_type __sz2 = __sz - __sz1; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1537 | __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1538 | __node_pointer __f2 = __t->__next_; |
| 1539 | __t->__next_ = nullptr; |
| 1540 | return __merge(__sort(__f1, __sz1, __comp), |
| 1541 | __sort(__f2, __sz2, __comp), __comp); |
| 1542 | } |
| 1543 | |
| 1544 | template <class _Tp, class _Alloc> |
| 1545 | void |
Howard Hinnant | f9dc283 | 2011-06-02 16:44:28 +0000 | [diff] [blame] | 1546 | forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1547 | { |
| 1548 | __node_pointer __p = base::__before_begin()->__next_; |
| 1549 | if (__p != nullptr) |
| 1550 | { |
| 1551 | __node_pointer __f = __p->__next_; |
| 1552 | __p->__next_ = nullptr; |
| 1553 | while (__f != nullptr) |
| 1554 | { |
| 1555 | __node_pointer __t = __f->__next_; |
| 1556 | __f->__next_ = __p; |
| 1557 | __p = __f; |
| 1558 | __f = __t; |
| 1559 | } |
| 1560 | base::__before_begin()->__next_ = __p; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | template <class _Tp, class _Alloc> |
| 1565 | bool operator==(const forward_list<_Tp, _Alloc>& __x, |
| 1566 | const forward_list<_Tp, _Alloc>& __y) |
| 1567 | { |
| 1568 | typedef forward_list<_Tp, _Alloc> _C; |
| 1569 | typedef typename _C::const_iterator _I; |
| 1570 | _I __ix = __x.begin(); |
| 1571 | _I __ex = __x.end(); |
| 1572 | _I __iy = __y.begin(); |
| 1573 | _I __ey = __y.end(); |
| 1574 | for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy) |
| 1575 | if (!(*__ix == *__iy)) |
| 1576 | return false; |
| 1577 | return (__ix == __ex) == (__iy == __ey); |
| 1578 | } |
| 1579 | |
| 1580 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1581 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | bool operator!=(const forward_list<_Tp, _Alloc>& __x, |
| 1583 | const forward_list<_Tp, _Alloc>& __y) |
| 1584 | { |
| 1585 | return !(__x == __y); |
| 1586 | } |
| 1587 | |
| 1588 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1589 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1590 | bool operator< (const forward_list<_Tp, _Alloc>& __x, |
| 1591 | const forward_list<_Tp, _Alloc>& __y) |
| 1592 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1593 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | __y.begin(), __y.end()); |
| 1595 | } |
| 1596 | |
| 1597 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1598 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | bool operator> (const forward_list<_Tp, _Alloc>& __x, |
| 1600 | const forward_list<_Tp, _Alloc>& __y) |
| 1601 | { |
| 1602 | return __y < __x; |
| 1603 | } |
| 1604 | |
| 1605 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1606 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | bool operator>=(const forward_list<_Tp, _Alloc>& __x, |
| 1608 | const forward_list<_Tp, _Alloc>& __y) |
| 1609 | { |
| 1610 | return !(__x < __y); |
| 1611 | } |
| 1612 | |
| 1613 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1614 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | bool operator<=(const forward_list<_Tp, _Alloc>& __x, |
| 1616 | const forward_list<_Tp, _Alloc>& __y) |
| 1617 | { |
| 1618 | return !(__y < __x); |
| 1619 | } |
| 1620 | |
| 1621 | template <class _Tp, class _Alloc> |
Howard Hinnant | 0af133f | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1622 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1623 | void |
| 1624 | swap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y) |
Howard Hinnant | 91a4750 | 2011-06-03 16:20:53 +0000 | [diff] [blame] | 1625 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1626 | { |
| 1627 | __x.swap(__y); |
| 1628 | } |
| 1629 | |
| 1630 | _LIBCPP_END_NAMESPACE_STD |
| 1631 | |
| 1632 | #endif // _LIBCPP_FORWARD_LIST |