17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===----------------------- forward_list ---------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_FORWARD_LIST
127a984708SDavid Chisnall#define _LIBCPP_FORWARD_LIST
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    forward_list synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnallnamespace std
187a984708SDavid Chisnall{
197a984708SDavid Chisnall
207a984708SDavid Chisnalltemplate <class T, class Allocator = allocator<T>>
217a984708SDavid Chisnallclass forward_list
227a984708SDavid Chisnall{
237a984708SDavid Chisnallpublic:
247a984708SDavid Chisnall    typedef T         value_type;
257a984708SDavid Chisnall    typedef Allocator allocator_type;
267a984708SDavid Chisnall
277a984708SDavid Chisnall    typedef value_type&                                                reference;
287a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
297a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::pointer         pointer;
307a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
317a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::size_type       size_type;
327a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
337a984708SDavid Chisnall
347a984708SDavid Chisnall    typedef <details> iterator;
357a984708SDavid Chisnall    typedef <details> const_iterator;
367a984708SDavid Chisnall
377a984708SDavid Chisnall    forward_list()
387a984708SDavid Chisnall        noexcept(is_nothrow_default_constructible<allocator_type>::value);
397a984708SDavid Chisnall    explicit forward_list(const allocator_type& a);
407a984708SDavid Chisnall    explicit forward_list(size_type n);
414f7ab58eSDimitry Andric    explicit forward_list(size_type n, const allocator_type& a); // C++14
427a984708SDavid Chisnall    forward_list(size_type n, const value_type& v);
437a984708SDavid Chisnall    forward_list(size_type n, const value_type& v, const allocator_type& a);
447a984708SDavid Chisnall    template <class InputIterator>
457a984708SDavid Chisnall        forward_list(InputIterator first, InputIterator last);
467a984708SDavid Chisnall    template <class InputIterator>
477a984708SDavid Chisnall        forward_list(InputIterator first, InputIterator last, const allocator_type& a);
487a984708SDavid Chisnall    forward_list(const forward_list& x);
497a984708SDavid Chisnall    forward_list(const forward_list& x, const allocator_type& a);
507a984708SDavid Chisnall    forward_list(forward_list&& x)
517a984708SDavid Chisnall        noexcept(is_nothrow_move_constructible<allocator_type>::value);
527a984708SDavid Chisnall    forward_list(forward_list&& x, const allocator_type& a);
537a984708SDavid Chisnall    forward_list(initializer_list<value_type> il);
547a984708SDavid Chisnall    forward_list(initializer_list<value_type> il, const allocator_type& a);
557a984708SDavid Chisnall
567a984708SDavid Chisnall    ~forward_list();
577a984708SDavid Chisnall
587a984708SDavid Chisnall    forward_list& operator=(const forward_list& x);
597a984708SDavid Chisnall    forward_list& operator=(forward_list&& x)
607a984708SDavid Chisnall        noexcept(
617a984708SDavid Chisnall             allocator_type::propagate_on_container_move_assignment::value &&
627a984708SDavid Chisnall             is_nothrow_move_assignable<allocator_type>::value);
637a984708SDavid Chisnall    forward_list& operator=(initializer_list<value_type> il);
647a984708SDavid Chisnall
657a984708SDavid Chisnall    template <class InputIterator>
667a984708SDavid Chisnall        void assign(InputIterator first, InputIterator last);
677a984708SDavid Chisnall    void assign(size_type n, const value_type& v);
687a984708SDavid Chisnall    void assign(initializer_list<value_type> il);
697a984708SDavid Chisnall
707a984708SDavid Chisnall    allocator_type get_allocator() const noexcept;
717a984708SDavid Chisnall
727a984708SDavid Chisnall    iterator       begin() noexcept;
737a984708SDavid Chisnall    const_iterator begin() const noexcept;
747a984708SDavid Chisnall    iterator       end() noexcept;
757a984708SDavid Chisnall    const_iterator end() const noexcept;
767a984708SDavid Chisnall
777a984708SDavid Chisnall    const_iterator cbegin() const noexcept;
787a984708SDavid Chisnall    const_iterator cend() const noexcept;
797a984708SDavid Chisnall
807a984708SDavid Chisnall    iterator       before_begin() noexcept;
817a984708SDavid Chisnall    const_iterator before_begin() const noexcept;
827a984708SDavid Chisnall    const_iterator cbefore_begin() const noexcept;
837a984708SDavid Chisnall
847a984708SDavid Chisnall    bool empty() const noexcept;
857a984708SDavid Chisnall    size_type max_size() const noexcept;
867a984708SDavid Chisnall
877a984708SDavid Chisnall    reference       front();
887a984708SDavid Chisnall    const_reference front() const;
897a984708SDavid Chisnall
9098221d2eSDimitry Andric    template <class... Args> reference emplace_front(Args&&... args);  // reference in C++17
917a984708SDavid Chisnall    void push_front(const value_type& v);
927a984708SDavid Chisnall    void push_front(value_type&& v);
937a984708SDavid Chisnall
947a984708SDavid Chisnall    void pop_front();
957a984708SDavid Chisnall
967a984708SDavid Chisnall    template <class... Args>
977a984708SDavid Chisnall        iterator emplace_after(const_iterator p, Args&&... args);
987a984708SDavid Chisnall    iterator insert_after(const_iterator p, const value_type& v);
997a984708SDavid Chisnall    iterator insert_after(const_iterator p, value_type&& v);
1007a984708SDavid Chisnall    iterator insert_after(const_iterator p, size_type n, const value_type& v);
1017a984708SDavid Chisnall    template <class InputIterator>
1027a984708SDavid Chisnall        iterator insert_after(const_iterator p,
1037a984708SDavid Chisnall                              InputIterator first, InputIterator last);
1047a984708SDavid Chisnall    iterator insert_after(const_iterator p, initializer_list<value_type> il);
1057a984708SDavid Chisnall
1067a984708SDavid Chisnall    iterator erase_after(const_iterator p);
1077a984708SDavid Chisnall    iterator erase_after(const_iterator first, const_iterator last);
1087a984708SDavid Chisnall
1097a984708SDavid Chisnall    void swap(forward_list& x)
110854fa44bSDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1117a984708SDavid Chisnall
1127a984708SDavid Chisnall    void resize(size_type n);
1137a984708SDavid Chisnall    void resize(size_type n, const value_type& v);
1147a984708SDavid Chisnall    void clear() noexcept;
1157a984708SDavid Chisnall
1167a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list& x);
1177a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list&& x);
1187a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list& x, const_iterator i);
1197a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list&& x, const_iterator i);
1207a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list& x,
1217a984708SDavid Chisnall                      const_iterator first, const_iterator last);
1227a984708SDavid Chisnall    void splice_after(const_iterator p, forward_list&& x,
1237a984708SDavid Chisnall                      const_iterator first, const_iterator last);
1247a984708SDavid Chisnall    void remove(const value_type& v);
1257a984708SDavid Chisnall    template <class Predicate> void remove_if(Predicate pred);
1267a984708SDavid Chisnall    void unique();
1277a984708SDavid Chisnall    template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
1287a984708SDavid Chisnall    void merge(forward_list& x);
1297a984708SDavid Chisnall    void merge(forward_list&& x);
1307a984708SDavid Chisnall    template <class Compare> void merge(forward_list& x, Compare comp);
1317a984708SDavid Chisnall    template <class Compare> void merge(forward_list&& x, Compare comp);
1327a984708SDavid Chisnall    void sort();
1337a984708SDavid Chisnall    template <class Compare> void sort(Compare comp);
1347a984708SDavid Chisnall    void reverse() noexcept;
1357a984708SDavid Chisnall};
1367a984708SDavid Chisnall
1374ba319b5SDimitry Andric
1384ba319b5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1394ba319b5SDimitry Andric    forward_list(InputIterator, InputIterator, Allocator = Allocator())
1404ba319b5SDimitry Andric    -> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>;  // C++17
1414ba319b5SDimitry Andric
1427a984708SDavid Chisnalltemplate <class T, class Allocator>
1437a984708SDavid Chisnall    bool operator==(const forward_list<T, Allocator>& x,
1447a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1457a984708SDavid Chisnall
1467a984708SDavid Chisnalltemplate <class T, class Allocator>
1477a984708SDavid Chisnall    bool operator< (const forward_list<T, Allocator>& x,
1487a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1497a984708SDavid Chisnall
1507a984708SDavid Chisnalltemplate <class T, class Allocator>
1517a984708SDavid Chisnall    bool operator!=(const forward_list<T, Allocator>& x,
1527a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1537a984708SDavid Chisnall
1547a984708SDavid Chisnalltemplate <class T, class Allocator>
1557a984708SDavid Chisnall    bool operator> (const forward_list<T, Allocator>& x,
1567a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1577a984708SDavid Chisnall
1587a984708SDavid Chisnalltemplate <class T, class Allocator>
1597a984708SDavid Chisnall    bool operator>=(const forward_list<T, Allocator>& x,
1607a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1617a984708SDavid Chisnall
1627a984708SDavid Chisnalltemplate <class T, class Allocator>
1637a984708SDavid Chisnall    bool operator<=(const forward_list<T, Allocator>& x,
1647a984708SDavid Chisnall                    const forward_list<T, Allocator>& y);
1657a984708SDavid Chisnall
1667a984708SDavid Chisnalltemplate <class T, class Allocator>
1677a984708SDavid Chisnall    void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
1687a984708SDavid Chisnall         noexcept(noexcept(x.swap(y)));
1697a984708SDavid Chisnall
170*b5893f02SDimitry Andrictemplate <class T, class Allocator, class U>
171*b5893f02SDimitry Andric    void erase(forward_list<T, Allocator>& c, const U& value);       // C++20
172*b5893f02SDimitry Andrictemplate <class T, class Allocator, class Predicate>
173*b5893f02SDimitry Andric    void erase_if(forward_list<T, Allocator>& c, Predicate pred);    // C++20
174*b5893f02SDimitry Andric
1757a984708SDavid Chisnall}  // std
1767a984708SDavid Chisnall
1777a984708SDavid Chisnall*/
1787a984708SDavid Chisnall
1797a984708SDavid Chisnall#include <__config>
1807a984708SDavid Chisnall#include <initializer_list>
1817a984708SDavid Chisnall#include <memory>
1827a984708SDavid Chisnall#include <limits>
1837a984708SDavid Chisnall#include <iterator>
1847a984708SDavid Chisnall#include <algorithm>
185*b5893f02SDimitry Andric#include <version>
1867a984708SDavid Chisnall
1877a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1887a984708SDavid Chisnall#pragma GCC system_header
1897a984708SDavid Chisnall#endif
1907a984708SDavid Chisnall
191f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS
192f9448bf3SDimitry Andric#include <__undef_macros>
193f9448bf3SDimitry Andric
194f9448bf3SDimitry Andric
1957a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
1967a984708SDavid Chisnall
1977a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr> struct __forward_list_node;
1987c82a1ecSDimitry Andrictemplate <class _NodePtr> struct __forward_begin_node;
1997c82a1ecSDimitry Andric
2007c82a1ecSDimitry Andric
2017c82a1ecSDimitry Andrictemplate <class>
2027c82a1ecSDimitry Andricstruct __forward_list_node_value_type;
2037c82a1ecSDimitry Andric
2047c82a1ecSDimitry Andrictemplate <class _Tp, class _VoidPtr>
2057c82a1ecSDimitry Andricstruct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > {
2067c82a1ecSDimitry Andric  typedef _Tp type;
2077c82a1ecSDimitry Andric};
2087c82a1ecSDimitry Andric
2097c82a1ecSDimitry Andrictemplate <class _NodePtr>
2107c82a1ecSDimitry Andricstruct __forward_node_traits {
2117c82a1ecSDimitry Andric
2127c82a1ecSDimitry Andric  typedef typename remove_cv<
2137c82a1ecSDimitry Andric        typename pointer_traits<_NodePtr>::element_type>::type  __node;
2147c82a1ecSDimitry Andric  typedef typename __forward_list_node_value_type<__node>::type __node_value_type;
2157c82a1ecSDimitry Andric  typedef _NodePtr                                              __node_pointer;
2167c82a1ecSDimitry Andric  typedef __forward_begin_node<_NodePtr>                        __begin_node;
2177c82a1ecSDimitry Andric  typedef typename __rebind_pointer<_NodePtr, __begin_node>::type
2187c82a1ecSDimitry Andric                                                                __begin_node_pointer;
2197c82a1ecSDimitry Andric  typedef typename __rebind_pointer<_NodePtr, void>::type       __void_pointer;
2207c82a1ecSDimitry Andric
2217c82a1ecSDimitry Andric#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB)
2227c82a1ecSDimitry Andric  typedef __begin_node_pointer __iter_node_pointer;
2237c82a1ecSDimitry Andric#else
2247c82a1ecSDimitry Andric  typedef typename conditional<
2257c82a1ecSDimitry Andric          is_pointer<__void_pointer>::value,
2267c82a1ecSDimitry Andric          __begin_node_pointer,
2277c82a1ecSDimitry Andric          __node_pointer
2287c82a1ecSDimitry Andric    >::type __iter_node_pointer;
2297c82a1ecSDimitry Andric#endif
2307c82a1ecSDimitry Andric
2317c82a1ecSDimitry Andric  typedef typename conditional<
2327c82a1ecSDimitry Andric          is_same<__iter_node_pointer, __node_pointer>::value,
2337c82a1ecSDimitry Andric          __begin_node_pointer,
2347c82a1ecSDimitry Andric          __node_pointer
2357c82a1ecSDimitry Andric    >::type __non_iter_node_pointer;
2367c82a1ecSDimitry Andric
2377c82a1ecSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
2387c82a1ecSDimitry Andric  static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) {
2397c82a1ecSDimitry Andric      return __p;
2407c82a1ecSDimitry Andric  }
2417c82a1ecSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
2427c82a1ecSDimitry Andric  static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) {
2437c82a1ecSDimitry Andric      return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p));
2447c82a1ecSDimitry Andric  }
2457c82a1ecSDimitry Andric};
2467a984708SDavid Chisnall
2477a984708SDavid Chisnalltemplate <class _NodePtr>
2487a984708SDavid Chisnallstruct __forward_begin_node
2497a984708SDavid Chisnall{
2507a984708SDavid Chisnall    typedef _NodePtr pointer;
2517c82a1ecSDimitry Andric    typedef typename __rebind_pointer<_NodePtr, __forward_begin_node>::type __begin_node_pointer;
2527a984708SDavid Chisnall
2537a984708SDavid Chisnall    pointer __next_;
2547a984708SDavid Chisnall
2557a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
2567c82a1ecSDimitry Andric
2577c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2587c82a1ecSDimitry Andric    __begin_node_pointer __next_as_begin() const {
2597c82a1ecSDimitry Andric        return static_cast<__begin_node_pointer>(__next_);
2607c82a1ecSDimitry Andric    }
2617a984708SDavid Chisnall};
2627a984708SDavid Chisnall
2637a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr>
264d72607e9SDimitry Andricstruct _LIBCPP_HIDDEN __begin_node_of
265d72607e9SDimitry Andric{
2669729cf09SDimitry Andric    typedef __forward_begin_node<
2679729cf09SDimitry Andric        typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type
268d72607e9SDimitry Andric    > type;
269d72607e9SDimitry Andric};
270d72607e9SDimitry Andric
271d72607e9SDimitry Andrictemplate <class _Tp, class _VoidPtr>
272d72607e9SDimitry Andricstruct __forward_list_node
273d72607e9SDimitry Andric    : public __begin_node_of<_Tp, _VoidPtr>::type
2747a984708SDavid Chisnall{
2757a984708SDavid Chisnall    typedef _Tp value_type;
2767a984708SDavid Chisnall
2777a984708SDavid Chisnall    value_type __value_;
2787a984708SDavid Chisnall};
2797a984708SDavid Chisnall
2807c82a1ecSDimitry Andric
281aed8d94eSDimitry Andrictemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list;
282aed8d94eSDimitry Andrictemplate<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
2837a984708SDavid Chisnall
2847a984708SDavid Chisnalltemplate <class _NodePtr>
285aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __forward_list_iterator
2867a984708SDavid Chisnall{
2877c82a1ecSDimitry Andric    typedef __forward_node_traits<_NodePtr>         __traits;
2887c82a1ecSDimitry Andric    typedef typename __traits::__node_pointer       __node_pointer;
2897c82a1ecSDimitry Andric    typedef typename __traits::__begin_node_pointer __begin_node_pointer;
2907c82a1ecSDimitry Andric    typedef typename __traits::__iter_node_pointer  __iter_node_pointer;
2917c82a1ecSDimitry Andric    typedef typename __traits::__void_pointer       __void_pointer;
2927a984708SDavid Chisnall
2937c82a1ecSDimitry Andric    __iter_node_pointer __ptr_;
2947a984708SDavid Chisnall
2957a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2967c82a1ecSDimitry Andric    __begin_node_pointer __get_begin() const {
2977c82a1ecSDimitry Andric        return static_cast<__begin_node_pointer>(
2987c82a1ecSDimitry Andric                static_cast<__void_pointer>(__ptr_));
2997c82a1ecSDimitry Andric    }
3007c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3017c82a1ecSDimitry Andric    __node_pointer __get_unsafe_node_pointer() const {
3027c82a1ecSDimitry Andric        return static_cast<__node_pointer>(
3037c82a1ecSDimitry Andric                static_cast<__void_pointer>(__ptr_));
3047c82a1ecSDimitry Andric    }
3057c82a1ecSDimitry Andric
3067c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3077c82a1ecSDimitry Andric    explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
3087c82a1ecSDimitry Andric
3097c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3107c82a1ecSDimitry Andric    explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
3117c82a1ecSDimitry Andric        : __ptr_(__traits::__as_iter_node(__p)) {}
3127c82a1ecSDimitry Andric
3137c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3147c82a1ecSDimitry Andric    explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
3157c82a1ecSDimitry Andric        : __ptr_(__traits::__as_iter_node(__p)) {}
3167a984708SDavid Chisnall
317aed8d94eSDimitry Andric    template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list;
318aed8d94eSDimitry Andric    template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
3197a984708SDavid Chisnall
3207a984708SDavid Chisnallpublic:
3217a984708SDavid Chisnall    typedef forward_iterator_tag                              iterator_category;
3227c82a1ecSDimitry Andric    typedef typename __traits::__node_value_type              value_type;
3237a984708SDavid Chisnall    typedef value_type&                                       reference;
3247a984708SDavid Chisnall    typedef typename pointer_traits<__node_pointer>::difference_type
3257a984708SDavid Chisnall                                                              difference_type;
3269729cf09SDimitry Andric    typedef typename __rebind_pointer<__node_pointer, value_type>::type pointer;
3277a984708SDavid Chisnall
3287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3297a984708SDavid Chisnall    __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
3307a984708SDavid Chisnall
3317a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3327c82a1ecSDimitry Andric    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
3337a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3347c82a1ecSDimitry Andric    pointer operator->() const {
3357c82a1ecSDimitry Andric        return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_);
3367c82a1ecSDimitry Andric    }
3377a984708SDavid Chisnall
3387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3397a984708SDavid Chisnall    __forward_list_iterator& operator++()
3407a984708SDavid Chisnall    {
3417c82a1ecSDimitry Andric        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
3427a984708SDavid Chisnall        return *this;
3437a984708SDavid Chisnall    }
3447a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3457a984708SDavid Chisnall    __forward_list_iterator operator++(int)
3467a984708SDavid Chisnall    {
3477a984708SDavid Chisnall        __forward_list_iterator __t(*this);
3487a984708SDavid Chisnall        ++(*this);
3497a984708SDavid Chisnall        return __t;
3507a984708SDavid Chisnall    }
3517a984708SDavid Chisnall
3527a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
3537a984708SDavid Chisnall    bool operator==(const __forward_list_iterator& __x,
3547a984708SDavid Chisnall                    const __forward_list_iterator& __y)
3557a984708SDavid Chisnall        {return __x.__ptr_ == __y.__ptr_;}
3567a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
3577a984708SDavid Chisnall    bool operator!=(const __forward_list_iterator& __x,
3587a984708SDavid Chisnall                    const __forward_list_iterator& __y)
3597a984708SDavid Chisnall        {return !(__x == __y);}
3607a984708SDavid Chisnall};
3617a984708SDavid Chisnall
3627a984708SDavid Chisnalltemplate <class _NodeConstPtr>
363aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator
3647a984708SDavid Chisnall{
3657c82a1ecSDimitry Andric    static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), "");
3667c82a1ecSDimitry Andric    typedef _NodeConstPtr _NodePtr;
3677a984708SDavid Chisnall
3687c82a1ecSDimitry Andric    typedef __forward_node_traits<_NodePtr>         __traits;
3697c82a1ecSDimitry Andric    typedef typename __traits::__node               __node;
3707c82a1ecSDimitry Andric    typedef typename __traits::__node_pointer       __node_pointer;
3717c82a1ecSDimitry Andric    typedef typename __traits::__begin_node_pointer __begin_node_pointer;
3727c82a1ecSDimitry Andric    typedef typename __traits::__iter_node_pointer  __iter_node_pointer;
3737c82a1ecSDimitry Andric    typedef typename __traits::__void_pointer       __void_pointer;
3747c82a1ecSDimitry Andric
3757c82a1ecSDimitry Andric    __iter_node_pointer __ptr_;
3767c82a1ecSDimitry Andric
3777c82a1ecSDimitry Andric    __begin_node_pointer __get_begin() const {
3787c82a1ecSDimitry Andric        return static_cast<__begin_node_pointer>(
3797c82a1ecSDimitry Andric                static_cast<__void_pointer>(__ptr_));
3807c82a1ecSDimitry Andric    }
3817c82a1ecSDimitry Andric    __node_pointer __get_unsafe_node_pointer() const {
3827c82a1ecSDimitry Andric        return static_cast<__node_pointer>(
3837c82a1ecSDimitry Andric                static_cast<__void_pointer>(__ptr_));
3847c82a1ecSDimitry Andric    }
3857a984708SDavid Chisnall
3867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3877c82a1ecSDimitry Andric    explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
3887c82a1ecSDimitry Andric        : __ptr_(nullptr) {}
3897a984708SDavid Chisnall
3907c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3917c82a1ecSDimitry Andric    explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
3927c82a1ecSDimitry Andric        : __ptr_(__traits::__as_iter_node(__p)) {}
3937c82a1ecSDimitry Andric
3947c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3957c82a1ecSDimitry Andric    explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
3967c82a1ecSDimitry Andric        : __ptr_(__traits::__as_iter_node(__p)) {}
3977c82a1ecSDimitry Andric
3987a984708SDavid Chisnall
3997a984708SDavid Chisnall    template<class, class> friend class forward_list;
4007a984708SDavid Chisnall
4017a984708SDavid Chisnallpublic:
4027a984708SDavid Chisnall    typedef forward_iterator_tag                              iterator_category;
4037c82a1ecSDimitry Andric    typedef typename __traits::__node_value_type              value_type;
4047a984708SDavid Chisnall    typedef const value_type&                                 reference;
4057c82a1ecSDimitry Andric    typedef typename pointer_traits<__node_pointer>::difference_type
4067a984708SDavid Chisnall                                                              difference_type;
4077c82a1ecSDimitry Andric    typedef typename __rebind_pointer<__node_pointer, const value_type>::type
4087c82a1ecSDimitry Andric                                                              pointer;
4097a984708SDavid Chisnall
4107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4117a984708SDavid Chisnall    __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
4127a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4137a984708SDavid Chisnall    __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
4147a984708SDavid Chisnall        : __ptr_(__p.__ptr_) {}
4157a984708SDavid Chisnall
4167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4177c82a1ecSDimitry Andric    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
4187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4197c82a1ecSDimitry Andric    pointer operator->() const {return pointer_traits<pointer>::pointer_to(
4207c82a1ecSDimitry Andric                __get_unsafe_node_pointer()->__value_);}
4217a984708SDavid Chisnall
4227a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4237a984708SDavid Chisnall    __forward_list_const_iterator& operator++()
4247a984708SDavid Chisnall    {
4257c82a1ecSDimitry Andric        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
4267a984708SDavid Chisnall        return *this;
4277a984708SDavid Chisnall    }
4287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4297a984708SDavid Chisnall    __forward_list_const_iterator operator++(int)
4307a984708SDavid Chisnall    {
4317a984708SDavid Chisnall        __forward_list_const_iterator __t(*this);
4327a984708SDavid Chisnall        ++(*this);
4337a984708SDavid Chisnall        return __t;
4347a984708SDavid Chisnall    }
4357a984708SDavid Chisnall
4367a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
4377a984708SDavid Chisnall    bool operator==(const __forward_list_const_iterator& __x,
4387a984708SDavid Chisnall                    const __forward_list_const_iterator& __y)
4397a984708SDavid Chisnall        {return __x.__ptr_ == __y.__ptr_;}
4407a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
4417a984708SDavid Chisnall    bool operator!=(const __forward_list_const_iterator& __x,
4427a984708SDavid Chisnall                           const __forward_list_const_iterator& __y)
4437a984708SDavid Chisnall        {return !(__x == __y);}
4447a984708SDavid Chisnall};
4457a984708SDavid Chisnall
4467a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
4477a984708SDavid Chisnallclass __forward_list_base
4487a984708SDavid Chisnall{
4497a984708SDavid Chisnallprotected:
4507a984708SDavid Chisnall    typedef _Tp    value_type;
4517a984708SDavid Chisnall    typedef _Alloc allocator_type;
4527a984708SDavid Chisnall
4537a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::void_pointer  void_pointer;
4547a984708SDavid Chisnall    typedef __forward_list_node<value_type, void_pointer>            __node;
455d72607e9SDimitry Andric    typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
456854fa44bSDimitry Andric    typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
4577a984708SDavid Chisnall    typedef allocator_traits<__node_allocator>        __node_traits;
4587a984708SDavid Chisnall    typedef typename __node_traits::pointer           __node_pointer;
4594bab9fd9SDavid Chisnall
4607c82a1ecSDimitry Andric    typedef typename __rebind_alloc_helper<
4617c82a1ecSDimitry Andric        allocator_traits<allocator_type>, __begin_node
4627c82a1ecSDimitry Andric    >::type                                           __begin_node_allocator;
4637c82a1ecSDimitry Andric    typedef typename allocator_traits<__begin_node_allocator>::pointer
4647c82a1ecSDimitry Andric                                                      __begin_node_pointer;
4657a984708SDavid Chisnall
4664ba319b5SDimitry Andric    static_assert((!is_same<allocator_type, __node_allocator>::value),
4674ba319b5SDimitry Andric                  "internal allocator type must differ from user-specified "
4684ba319b5SDimitry Andric                  "type; otherwise overload resolution breaks");
4694ba319b5SDimitry Andric
4707a984708SDavid Chisnall    __compressed_pair<__begin_node, __node_allocator> __before_begin_;
4717a984708SDavid Chisnall
4727a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4737c82a1ecSDimitry Andric    __begin_node_pointer        __before_begin() _NOEXCEPT
4747c82a1ecSDimitry Andric        {return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());}
4757a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4767c82a1ecSDimitry Andric    __begin_node_pointer __before_begin() const _NOEXCEPT
4777c82a1ecSDimitry Andric        {return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));}
4787a984708SDavid Chisnall
4797a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4807a984708SDavid Chisnall          __node_allocator& __alloc() _NOEXCEPT
4817a984708SDavid Chisnall            {return __before_begin_.second();}
4827a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4837a984708SDavid Chisnall    const __node_allocator& __alloc() const _NOEXCEPT
4847a984708SDavid Chisnall        {return __before_begin_.second();}
4857a984708SDavid Chisnall
4867a984708SDavid Chisnall    typedef __forward_list_iterator<__node_pointer>             iterator;
4874bab9fd9SDavid Chisnall    typedef __forward_list_const_iterator<__node_pointer>       const_iterator;
4887a984708SDavid Chisnall
4897a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4907a984708SDavid Chisnall    __forward_list_base()
4917a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
4927a984708SDavid Chisnall        : __before_begin_(__begin_node()) {}
4937a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4944ba319b5SDimitry Andric    explicit __forward_list_base(const allocator_type& __a)
4957a984708SDavid Chisnall        : __before_begin_(__begin_node(), __node_allocator(__a)) {}
4964ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4974ba319b5SDimitry Andric    explicit __forward_list_base(const __node_allocator& __a)
4984ba319b5SDimitry Andric        : __before_begin_(__begin_node(), __a) {}
499540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5007a984708SDavid Chisnallpublic:
5017c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5027a984708SDavid Chisnall    __forward_list_base(__forward_list_base&& __x)
5037a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
5047c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5057a984708SDavid Chisnall    __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
506540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
5077a984708SDavid Chisnall
5087a984708SDavid Chisnallprivate:
5097a984708SDavid Chisnall    __forward_list_base(const __forward_list_base&);
5107a984708SDavid Chisnall    __forward_list_base& operator=(const __forward_list_base&);
5117a984708SDavid Chisnall
5127a984708SDavid Chisnallpublic:
5137a984708SDavid Chisnall    ~__forward_list_base();
5147a984708SDavid Chisnall
5157a984708SDavid Chisnallprotected:
5167a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5177a984708SDavid Chisnall    void __copy_assign_alloc(const __forward_list_base& __x)
5187a984708SDavid Chisnall        {__copy_assign_alloc(__x, integral_constant<bool,
5197a984708SDavid Chisnall              __node_traits::propagate_on_container_copy_assignment::value>());}
5207a984708SDavid Chisnall
5217a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5227a984708SDavid Chisnall    void __move_assign_alloc(__forward_list_base& __x)
5237a984708SDavid Chisnall        _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
5247a984708SDavid Chisnall                   is_nothrow_move_assignable<__node_allocator>::value)
5257a984708SDavid Chisnall        {__move_assign_alloc(__x, integral_constant<bool,
5267a984708SDavid Chisnall              __node_traits::propagate_on_container_move_assignment::value>());}
5277a984708SDavid Chisnall
5287a984708SDavid Chisnallpublic:
5297c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5307a984708SDavid Chisnall    void swap(__forward_list_base& __x)
531854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
532854fa44bSDimitry Andric        _NOEXCEPT;
533854fa44bSDimitry Andric#else
534854fa44bSDimitry Andric        _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
5357a984708SDavid Chisnall                    __is_nothrow_swappable<__node_allocator>::value);
536854fa44bSDimitry Andric#endif
5377a984708SDavid Chisnallprotected:
5387a984708SDavid Chisnall    void clear() _NOEXCEPT;
5397a984708SDavid Chisnall
5407a984708SDavid Chisnallprivate:
5417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5427a984708SDavid Chisnall    void __copy_assign_alloc(const __forward_list_base&, false_type) {}
5437a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5447a984708SDavid Chisnall    void __copy_assign_alloc(const __forward_list_base& __x, true_type)
5457a984708SDavid Chisnall    {
5467a984708SDavid Chisnall        if (__alloc() != __x.__alloc())
5477a984708SDavid Chisnall            clear();
5487a984708SDavid Chisnall        __alloc() = __x.__alloc();
5497a984708SDavid Chisnall    }
5507a984708SDavid Chisnall
5517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
552aed8d94eSDimitry Andric    void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT
5537a984708SDavid Chisnall        {}
5547a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5557a984708SDavid Chisnall    void __move_assign_alloc(__forward_list_base& __x, true_type)
5567a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
5577a984708SDavid Chisnall        {__alloc() = _VSTD::move(__x.__alloc());}
5587a984708SDavid Chisnall};
5597a984708SDavid Chisnall
560540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5617a984708SDavid Chisnall
5627a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
5637c82a1ecSDimitry Andricinline
5647a984708SDavid Chisnall__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
5657a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
5667a984708SDavid Chisnall    : __before_begin_(_VSTD::move(__x.__before_begin_))
5677a984708SDavid Chisnall{
5687a984708SDavid Chisnall    __x.__before_begin()->__next_ = nullptr;
5697a984708SDavid Chisnall}
5707a984708SDavid Chisnall
5717a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
5727c82a1ecSDimitry Andricinline
5737a984708SDavid Chisnall__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
5747a984708SDavid Chisnall                                                      const allocator_type& __a)
5757a984708SDavid Chisnall    : __before_begin_(__begin_node(), __node_allocator(__a))
5767a984708SDavid Chisnall{
5777a984708SDavid Chisnall    if (__alloc() == __x.__alloc())
5787a984708SDavid Chisnall    {
5797a984708SDavid Chisnall        __before_begin()->__next_ = __x.__before_begin()->__next_;
5807a984708SDavid Chisnall        __x.__before_begin()->__next_ = nullptr;
5817a984708SDavid Chisnall    }
5827a984708SDavid Chisnall}
5837a984708SDavid Chisnall
584540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
5857a984708SDavid Chisnall
5867a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
5877a984708SDavid Chisnall__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
5887a984708SDavid Chisnall{
5897a984708SDavid Chisnall    clear();
5907a984708SDavid Chisnall}
5917a984708SDavid Chisnall
5927a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
5937c82a1ecSDimitry Andricinline
5947a984708SDavid Chisnallvoid
5957a984708SDavid Chisnall__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
596854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
597854fa44bSDimitry Andric        _NOEXCEPT
598854fa44bSDimitry Andric#else
599854fa44bSDimitry Andric        _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
6007a984708SDavid Chisnall                    __is_nothrow_swappable<__node_allocator>::value)
601854fa44bSDimitry Andric#endif
6027a984708SDavid Chisnall{
603854fa44bSDimitry Andric    __swap_allocator(__alloc(), __x.__alloc(),
604854fa44bSDimitry Andric            integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
6057a984708SDavid Chisnall    using _VSTD::swap;
6067a984708SDavid Chisnall    swap(__before_begin()->__next_, __x.__before_begin()->__next_);
6077a984708SDavid Chisnall}
6087a984708SDavid Chisnall
6097a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
6107a984708SDavid Chisnallvoid
6117a984708SDavid Chisnall__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
6127a984708SDavid Chisnall{
6137a984708SDavid Chisnall    __node_allocator& __a = __alloc();
6147a984708SDavid Chisnall    for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
6157a984708SDavid Chisnall    {
6167a984708SDavid Chisnall        __node_pointer __next = __p->__next_;
6177a984708SDavid Chisnall        __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
6187a984708SDavid Chisnall        __node_traits::deallocate(__a, __p, 1);
6197a984708SDavid Chisnall        __p = __next;
6207a984708SDavid Chisnall    }
6217a984708SDavid Chisnall    __before_begin()->__next_ = nullptr;
6227a984708SDavid Chisnall}
6237a984708SDavid Chisnall
624854fa44bSDimitry Andrictemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/>
625aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS forward_list
6267a984708SDavid Chisnall    : private __forward_list_base<_Tp, _Alloc>
6277a984708SDavid Chisnall{
6287a984708SDavid Chisnall    typedef __forward_list_base<_Tp, _Alloc> base;
6297a984708SDavid Chisnall    typedef typename base::__node_allocator  __node_allocator;
6307a984708SDavid Chisnall    typedef typename base::__node               __node;
6317a984708SDavid Chisnall    typedef typename base::__node_traits        __node_traits;
6327a984708SDavid Chisnall    typedef typename base::__node_pointer       __node_pointer;
6337c82a1ecSDimitry Andric    typedef typename base::__begin_node_pointer __begin_node_pointer;
6347a984708SDavid Chisnall
6357a984708SDavid Chisnallpublic:
6367a984708SDavid Chisnall    typedef _Tp    value_type;
6377a984708SDavid Chisnall    typedef _Alloc allocator_type;
6387a984708SDavid Chisnall
6399729cf09SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
6409729cf09SDimitry Andric                  "Allocator::value_type must be same type as value_type");
6419729cf09SDimitry Andric
6427a984708SDavid Chisnall    typedef value_type&                                                reference;
6437a984708SDavid Chisnall    typedef const value_type&                                          const_reference;
6447a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::pointer         pointer;
6457a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
6467a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::size_type       size_type;
6477a984708SDavid Chisnall    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
6487a984708SDavid Chisnall
6497a984708SDavid Chisnall    typedef typename base::iterator       iterator;
6507a984708SDavid Chisnall    typedef typename base::const_iterator const_iterator;
6517a984708SDavid Chisnall
6527a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6537a984708SDavid Chisnall    forward_list()
6547a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
6557a984708SDavid Chisnall        {} // = default;
6567c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6577a984708SDavid Chisnall    explicit forward_list(const allocator_type& __a);
6587a984708SDavid Chisnall    explicit forward_list(size_type __n);
6594f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11
6604f7ab58eSDimitry Andric    explicit forward_list(size_type __n, const allocator_type& __a);
6614f7ab58eSDimitry Andric#endif
6627a984708SDavid Chisnall    forward_list(size_type __n, const value_type& __v);
6637a984708SDavid Chisnall    forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
6647a984708SDavid Chisnall    template <class _InputIterator>
6657a984708SDavid Chisnall        forward_list(_InputIterator __f, _InputIterator __l,
6667a984708SDavid Chisnall                     typename enable_if<
6677a984708SDavid Chisnall                       __is_input_iterator<_InputIterator>::value
6687a984708SDavid Chisnall                     >::type* = nullptr);
6697a984708SDavid Chisnall    template <class _InputIterator>
6707a984708SDavid Chisnall        forward_list(_InputIterator __f, _InputIterator __l,
6717a984708SDavid Chisnall                     const allocator_type& __a,
6727a984708SDavid Chisnall                     typename enable_if<
6737a984708SDavid Chisnall                       __is_input_iterator<_InputIterator>::value
6747a984708SDavid Chisnall                     >::type* = nullptr);
6757a984708SDavid Chisnall    forward_list(const forward_list& __x);
6767a984708SDavid Chisnall    forward_list(const forward_list& __x, const allocator_type& __a);
677540d2a8bSDimitry Andric
678540d2a8bSDimitry Andric    forward_list& operator=(const forward_list& __x);
679540d2a8bSDimitry Andric
680540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
6817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6827a984708SDavid Chisnall    forward_list(forward_list&& __x)
6837a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
6847a984708SDavid Chisnall        : base(_VSTD::move(__x)) {}
6857a984708SDavid Chisnall    forward_list(forward_list&& __x, const allocator_type& __a);
686540d2a8bSDimitry Andric
6877a984708SDavid Chisnall    forward_list(initializer_list<value_type> __il);
6887a984708SDavid Chisnall    forward_list(initializer_list<value_type> __il, const allocator_type& __a);
6897a984708SDavid Chisnall
6907c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6917a984708SDavid Chisnall    forward_list& operator=(forward_list&& __x)
6927a984708SDavid Chisnall        _NOEXCEPT_(
6937a984708SDavid Chisnall             __node_traits::propagate_on_container_move_assignment::value &&
6947a984708SDavid Chisnall             is_nothrow_move_assignable<allocator_type>::value);
695540d2a8bSDimitry Andric
6967c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6977a984708SDavid Chisnall    forward_list& operator=(initializer_list<value_type> __il);
698540d2a8bSDimitry Andric
699540d2a8bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
700540d2a8bSDimitry Andric    void assign(initializer_list<value_type> __il);
701540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
702540d2a8bSDimitry Andric
703540d2a8bSDimitry Andric    // ~forward_list() = default;
7047a984708SDavid Chisnall
7057a984708SDavid Chisnall    template <class _InputIterator>
7067a984708SDavid Chisnall        typename enable_if
7077a984708SDavid Chisnall        <
7087a984708SDavid Chisnall            __is_input_iterator<_InputIterator>::value,
7097a984708SDavid Chisnall            void
7107a984708SDavid Chisnall        >::type
7117a984708SDavid Chisnall        assign(_InputIterator __f, _InputIterator __l);
7127a984708SDavid Chisnall    void assign(size_type __n, const value_type& __v);
7137a984708SDavid Chisnall
7147a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7157a984708SDavid Chisnall    allocator_type get_allocator() const _NOEXCEPT
7167a984708SDavid Chisnall        {return allocator_type(base::__alloc());}
7177a984708SDavid Chisnall
7187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7197a984708SDavid Chisnall    iterator       begin() _NOEXCEPT
7207a984708SDavid Chisnall        {return       iterator(base::__before_begin()->__next_);}
7217a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7227a984708SDavid Chisnall    const_iterator begin() const _NOEXCEPT
7237a984708SDavid Chisnall        {return const_iterator(base::__before_begin()->__next_);}
7247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7257a984708SDavid Chisnall    iterator       end() _NOEXCEPT
7267a984708SDavid Chisnall        {return       iterator(nullptr);}
7277a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7287a984708SDavid Chisnall    const_iterator end() const _NOEXCEPT
7297a984708SDavid Chisnall        {return const_iterator(nullptr);}
7307a984708SDavid Chisnall
7317a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7327a984708SDavid Chisnall    const_iterator cbegin() const _NOEXCEPT
7337a984708SDavid Chisnall        {return const_iterator(base::__before_begin()->__next_);}
7347a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7357a984708SDavid Chisnall    const_iterator cend() const _NOEXCEPT
7367a984708SDavid Chisnall        {return const_iterator(nullptr);}
7377a984708SDavid Chisnall
7387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7397a984708SDavid Chisnall    iterator       before_begin() _NOEXCEPT
7407a984708SDavid Chisnall        {return       iterator(base::__before_begin());}
7417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7427a984708SDavid Chisnall    const_iterator before_begin() const _NOEXCEPT
7437a984708SDavid Chisnall        {return const_iterator(base::__before_begin());}
7447a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7457a984708SDavid Chisnall    const_iterator cbefore_begin() const _NOEXCEPT
7467a984708SDavid Chisnall        {return const_iterator(base::__before_begin());}
7477a984708SDavid Chisnall
748b2c7081bSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7497a984708SDavid Chisnall    bool empty() const _NOEXCEPT
7507a984708SDavid Chisnall        {return base::__before_begin()->__next_ == nullptr;}
7517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
752aed8d94eSDimitry Andric    size_type max_size() const _NOEXCEPT {
753aed8d94eSDimitry Andric        return std::min<size_type>(
754aed8d94eSDimitry Andric            __node_traits::max_size(base::__alloc()),
755aed8d94eSDimitry Andric            numeric_limits<difference_type>::max());
756aed8d94eSDimitry Andric    }
7577a984708SDavid Chisnall
7587a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7597a984708SDavid Chisnall    reference       front()       {return base::__before_begin()->__next_->__value_;}
7607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7617a984708SDavid Chisnall    const_reference front() const {return base::__before_begin()->__next_->__value_;}
7627a984708SDavid Chisnall
763540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
76498221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
765aed8d94eSDimitry Andric    template <class... _Args> reference emplace_front(_Args&&... __args);
76698221d2eSDimitry Andric#else
76798221d2eSDimitry Andric    template <class... _Args> void      emplace_front(_Args&&... __args);
76898221d2eSDimitry Andric#endif
7697a984708SDavid Chisnall    void push_front(value_type&& __v);
770540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
7717a984708SDavid Chisnall    void push_front(const value_type& __v);
7727a984708SDavid Chisnall
7737a984708SDavid Chisnall    void pop_front();
7747a984708SDavid Chisnall
775540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7767a984708SDavid Chisnall    template <class... _Args>
7777a984708SDavid Chisnall        iterator emplace_after(const_iterator __p, _Args&&... __args);
778540d2a8bSDimitry Andric
7797a984708SDavid Chisnall    iterator insert_after(const_iterator __p, value_type&& __v);
780540d2a8bSDimitry Andric    iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
781540d2a8bSDimitry Andric        {return insert_after(__p, __il.begin(), __il.end());}
782540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
7837a984708SDavid Chisnall    iterator insert_after(const_iterator __p, const value_type& __v);
7847a984708SDavid Chisnall    iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
7857a984708SDavid Chisnall    template <class _InputIterator>
7867a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
7877a984708SDavid Chisnall        typename enable_if
7887a984708SDavid Chisnall        <
7897a984708SDavid Chisnall            __is_input_iterator<_InputIterator>::value,
7907a984708SDavid Chisnall            iterator
7917a984708SDavid Chisnall        >::type
7927a984708SDavid Chisnall        insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
7937a984708SDavid Chisnall
7947a984708SDavid Chisnall    iterator erase_after(const_iterator __p);
7957a984708SDavid Chisnall    iterator erase_after(const_iterator __f, const_iterator __l);
7967a984708SDavid Chisnall
7977a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
7987a984708SDavid Chisnall    void swap(forward_list& __x)
799854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
800854fa44bSDimitry Andric        _NOEXCEPT
801854fa44bSDimitry Andric#else
8027a984708SDavid Chisnall        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
8037a984708SDavid Chisnall                   __is_nothrow_swappable<__node_allocator>::value)
804854fa44bSDimitry Andric#endif
8057a984708SDavid Chisnall        {base::swap(__x);}
8067a984708SDavid Chisnall
8077a984708SDavid Chisnall    void resize(size_type __n);
8087a984708SDavid Chisnall    void resize(size_type __n, const value_type& __v);
8097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8107a984708SDavid Chisnall    void clear() _NOEXCEPT {base::clear();}
8117a984708SDavid Chisnall
812540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8137a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8147a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list&& __x);
8157a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8167a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
8177a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8187a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list&& __x,
8197a984708SDavid Chisnall                      const_iterator __f, const_iterator __l);
820540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8217a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list& __x);
8227a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
8237a984708SDavid Chisnall    void splice_after(const_iterator __p, forward_list& __x,
8247a984708SDavid Chisnall                      const_iterator __f, const_iterator __l);
8257a984708SDavid Chisnall    void remove(const value_type& __v);
8267a984708SDavid Chisnall    template <class _Predicate> void remove_if(_Predicate __pred);
8277a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8287a984708SDavid Chisnall    void unique() {unique(__equal_to<value_type>());}
8297a984708SDavid Chisnall    template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred);
830540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8317a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8327a984708SDavid Chisnall    void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
8337a984708SDavid Chisnall    template <class _Compare>
8347a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY
8357a984708SDavid Chisnall        void merge(forward_list&& __x, _Compare __comp)
8367a984708SDavid Chisnall        {merge(__x, _VSTD::move(__comp));}
837540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8397a984708SDavid Chisnall    void merge(forward_list& __x) {merge(__x, __less<value_type>());}
8407a984708SDavid Chisnall    template <class _Compare> void merge(forward_list& __x, _Compare __comp);
8417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8427a984708SDavid Chisnall    void sort() {sort(__less<value_type>());}
8437c82a1ecSDimitry Andric    template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp);
8447a984708SDavid Chisnall    void reverse() _NOEXCEPT;
8457a984708SDavid Chisnall
8467a984708SDavid Chisnallprivate:
8477a984708SDavid Chisnall
848540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8497a984708SDavid Chisnall    void __move_assign(forward_list& __x, true_type)
8507a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
8517a984708SDavid Chisnall    void __move_assign(forward_list& __x, false_type);
852540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
8537a984708SDavid Chisnall
8547a984708SDavid Chisnall    template <class _Compare>
8557a984708SDavid Chisnall        static
8567a984708SDavid Chisnall        __node_pointer
8577a984708SDavid Chisnall        __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
8587a984708SDavid Chisnall
8597a984708SDavid Chisnall    template <class _Compare>
8607a984708SDavid Chisnall        static
8617a984708SDavid Chisnall        __node_pointer
8627a984708SDavid Chisnall        __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
8637a984708SDavid Chisnall};
8647a984708SDavid Chisnall
8654ba319b5SDimitry Andric
8664ba319b5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
8674ba319b5SDimitry Andrictemplate<class _InputIterator,
8684ba319b5SDimitry Andric         class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
8694ba319b5SDimitry Andric         class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
8704ba319b5SDimitry Andric         >
8714ba319b5SDimitry Andricforward_list(_InputIterator, _InputIterator)
8724ba319b5SDimitry Andric  -> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
8734ba319b5SDimitry Andric
8744ba319b5SDimitry Andrictemplate<class _InputIterator,
8754ba319b5SDimitry Andric         class _Alloc,
8764ba319b5SDimitry Andric         class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
8774ba319b5SDimitry Andric         >
8784ba319b5SDimitry Andricforward_list(_InputIterator, _InputIterator, _Alloc)
8794ba319b5SDimitry Andric  -> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
8804ba319b5SDimitry Andric#endif
8814ba319b5SDimitry Andric
8827a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
8837c82a1ecSDimitry Andricinline
8847a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
8857a984708SDavid Chisnall    : base(__a)
8867a984708SDavid Chisnall{
8877a984708SDavid Chisnall}
8887a984708SDavid Chisnall
8897a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
8907a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(size_type __n)
8917a984708SDavid Chisnall{
8927a984708SDavid Chisnall    if (__n > 0)
8937a984708SDavid Chisnall    {
8947a984708SDavid Chisnall        __node_allocator& __a = base::__alloc();
89594e3ee44SDavid Chisnall        typedef __allocator_destructor<__node_allocator> _Dp;
89694e3ee44SDavid Chisnall        unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
8977c82a1ecSDimitry Andric        for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
8987c82a1ecSDimitry Andric                                                             __p = __p->__next_as_begin())
8997a984708SDavid Chisnall        {
9007a984708SDavid Chisnall            __h.reset(__node_traits::allocate(__a, 1));
9017a984708SDavid Chisnall            __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
9027a984708SDavid Chisnall            __h->__next_ = nullptr;
9037a984708SDavid Chisnall            __p->__next_ = __h.release();
9047a984708SDavid Chisnall        }
9057a984708SDavid Chisnall    }
9067a984708SDavid Chisnall}
9077a984708SDavid Chisnall
9084f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11
9094f7ab58eSDimitry Andrictemplate <class _Tp, class _Alloc>
910aed8d94eSDimitry Andricforward_list<_Tp, _Alloc>::forward_list(size_type __n,
911aed8d94eSDimitry Andric                                        const allocator_type& __base_alloc)
912aed8d94eSDimitry Andric    : base ( __base_alloc )
9134f7ab58eSDimitry Andric{
9144f7ab58eSDimitry Andric    if (__n > 0)
9154f7ab58eSDimitry Andric    {
9164f7ab58eSDimitry Andric        __node_allocator& __a = base::__alloc();
9174f7ab58eSDimitry Andric        typedef __allocator_destructor<__node_allocator> _Dp;
9184f7ab58eSDimitry Andric        unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
9197c82a1ecSDimitry Andric        for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
9207c82a1ecSDimitry Andric                                                             __p = __p->__next_as_begin())
9214f7ab58eSDimitry Andric        {
9224f7ab58eSDimitry Andric            __h.reset(__node_traits::allocate(__a, 1));
9234f7ab58eSDimitry Andric            __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
9244f7ab58eSDimitry Andric            __h->__next_ = nullptr;
9254f7ab58eSDimitry Andric            __p->__next_ = __h.release();
9264f7ab58eSDimitry Andric        }
9274f7ab58eSDimitry Andric    }
9284f7ab58eSDimitry Andric}
9294f7ab58eSDimitry Andric#endif
9304f7ab58eSDimitry Andric
9317a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9327a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
9337a984708SDavid Chisnall{
9347a984708SDavid Chisnall    insert_after(cbefore_begin(), __n, __v);
9357a984708SDavid Chisnall}
9367a984708SDavid Chisnall
9377a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9387a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
9397a984708SDavid Chisnall                                        const allocator_type& __a)
9407a984708SDavid Chisnall    : base(__a)
9417a984708SDavid Chisnall{
9427a984708SDavid Chisnall    insert_after(cbefore_begin(), __n, __v);
9437a984708SDavid Chisnall}
9447a984708SDavid Chisnall
9457a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9467a984708SDavid Chisnalltemplate <class _InputIterator>
9477a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
9487a984708SDavid Chisnall                                        typename enable_if<
9497a984708SDavid Chisnall                                          __is_input_iterator<_InputIterator>::value
9507a984708SDavid Chisnall                                        >::type*)
9517a984708SDavid Chisnall{
9527a984708SDavid Chisnall    insert_after(cbefore_begin(), __f, __l);
9537a984708SDavid Chisnall}
9547a984708SDavid Chisnall
9557a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9567a984708SDavid Chisnalltemplate <class _InputIterator>
9577a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
9587a984708SDavid Chisnall                                        const allocator_type& __a,
9597a984708SDavid Chisnall                                        typename enable_if<
9607a984708SDavid Chisnall                                          __is_input_iterator<_InputIterator>::value
9617a984708SDavid Chisnall                                        >::type*)
9627a984708SDavid Chisnall    : base(__a)
9637a984708SDavid Chisnall{
9647a984708SDavid Chisnall    insert_after(cbefore_begin(), __f, __l);
9657a984708SDavid Chisnall}
9667a984708SDavid Chisnall
9677a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9687a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
9694ba319b5SDimitry Andric    : base(
9704ba319b5SDimitry Andric          __node_traits::select_on_container_copy_construction(__x.__alloc())) {
9717a984708SDavid Chisnall  insert_after(cbefore_begin(), __x.begin(), __x.end());
9727a984708SDavid Chisnall}
9737a984708SDavid Chisnall
9747a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9757a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
9767a984708SDavid Chisnall                                        const allocator_type& __a)
9777a984708SDavid Chisnall    : base(__a)
9787a984708SDavid Chisnall{
9797a984708SDavid Chisnall    insert_after(cbefore_begin(), __x.begin(), __x.end());
9807a984708SDavid Chisnall}
9817a984708SDavid Chisnall
982540d2a8bSDimitry Andrictemplate <class _Tp, class _Alloc>
983540d2a8bSDimitry Andricforward_list<_Tp, _Alloc>&
984540d2a8bSDimitry Andricforward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
985540d2a8bSDimitry Andric{
986540d2a8bSDimitry Andric    if (this != &__x)
987540d2a8bSDimitry Andric    {
988540d2a8bSDimitry Andric        base::__copy_assign_alloc(__x);
989540d2a8bSDimitry Andric        assign(__x.begin(), __x.end());
990540d2a8bSDimitry Andric    }
991540d2a8bSDimitry Andric    return *this;
992540d2a8bSDimitry Andric}
9937a984708SDavid Chisnall
994540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9957a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
9967a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
9977a984708SDavid Chisnall                                        const allocator_type& __a)
9987a984708SDavid Chisnall    : base(_VSTD::move(__x), __a)
9997a984708SDavid Chisnall{
10007a984708SDavid Chisnall    if (base::__alloc() != __x.__alloc())
10017a984708SDavid Chisnall    {
100294e3ee44SDavid Chisnall        typedef move_iterator<iterator> _Ip;
100394e3ee44SDavid Chisnall        insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
10047a984708SDavid Chisnall    }
10057a984708SDavid Chisnall}
10067a984708SDavid Chisnall
10077a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10087a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
10097a984708SDavid Chisnall{
10107a984708SDavid Chisnall    insert_after(cbefore_begin(), __il.begin(), __il.end());
10117a984708SDavid Chisnall}
10127a984708SDavid Chisnall
10137a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10147a984708SDavid Chisnallforward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
10157a984708SDavid Chisnall                                        const allocator_type& __a)
10167a984708SDavid Chisnall    : base(__a)
10177a984708SDavid Chisnall{
10187a984708SDavid Chisnall    insert_after(cbefore_begin(), __il.begin(), __il.end());
10197a984708SDavid Chisnall}
10207a984708SDavid Chisnall
10217a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10227a984708SDavid Chisnallvoid
10237a984708SDavid Chisnallforward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
10247a984708SDavid Chisnall    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
10257a984708SDavid Chisnall{
10267a984708SDavid Chisnall    clear();
10277a984708SDavid Chisnall    base::__move_assign_alloc(__x);
10287a984708SDavid Chisnall    base::__before_begin()->__next_ = __x.__before_begin()->__next_;
10297a984708SDavid Chisnall    __x.__before_begin()->__next_ = nullptr;
10307a984708SDavid Chisnall}
10317a984708SDavid Chisnall
10327a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10337a984708SDavid Chisnallvoid
10347a984708SDavid Chisnallforward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
10357a984708SDavid Chisnall{
10367a984708SDavid Chisnall    if (base::__alloc() == __x.__alloc())
10377a984708SDavid Chisnall        __move_assign(__x, true_type());
10387a984708SDavid Chisnall    else
10397a984708SDavid Chisnall    {
104094e3ee44SDavid Chisnall        typedef move_iterator<iterator> _Ip;
104194e3ee44SDavid Chisnall        assign(_Ip(__x.begin()), _Ip(__x.end()));
10427a984708SDavid Chisnall    }
10437a984708SDavid Chisnall}
10447a984708SDavid Chisnall
10457a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10467c82a1ecSDimitry Andricinline
10477a984708SDavid Chisnallforward_list<_Tp, _Alloc>&
10487a984708SDavid Chisnallforward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
10497a984708SDavid Chisnall    _NOEXCEPT_(
10507a984708SDavid Chisnall             __node_traits::propagate_on_container_move_assignment::value &&
10517a984708SDavid Chisnall             is_nothrow_move_assignable<allocator_type>::value)
10527a984708SDavid Chisnall{
10537a984708SDavid Chisnall    __move_assign(__x, integral_constant<bool,
10547a984708SDavid Chisnall          __node_traits::propagate_on_container_move_assignment::value>());
10557a984708SDavid Chisnall    return *this;
10567a984708SDavid Chisnall}
10577a984708SDavid Chisnall
10587a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10597c82a1ecSDimitry Andricinline
10607a984708SDavid Chisnallforward_list<_Tp, _Alloc>&
10617a984708SDavid Chisnallforward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
10627a984708SDavid Chisnall{
10637a984708SDavid Chisnall    assign(__il.begin(), __il.end());
10647a984708SDavid Chisnall    return *this;
10657a984708SDavid Chisnall}
10667a984708SDavid Chisnall
1067540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
10687a984708SDavid Chisnall
10697a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10707a984708SDavid Chisnalltemplate <class _InputIterator>
10717a984708SDavid Chisnalltypename enable_if
10727a984708SDavid Chisnall<
10737a984708SDavid Chisnall    __is_input_iterator<_InputIterator>::value,
10747a984708SDavid Chisnall    void
10757a984708SDavid Chisnall>::type
10767a984708SDavid Chisnallforward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
10777a984708SDavid Chisnall{
10787a984708SDavid Chisnall    iterator __i = before_begin();
10797a984708SDavid Chisnall    iterator __j = _VSTD::next(__i);
10807a984708SDavid Chisnall    iterator __e = end();
1081d72607e9SDimitry Andric    for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
10827a984708SDavid Chisnall        *__j = *__f;
10837a984708SDavid Chisnall    if (__j == __e)
10847a984708SDavid Chisnall        insert_after(__i, __f, __l);
10857a984708SDavid Chisnall    else
10867a984708SDavid Chisnall        erase_after(__i, __e);
10877a984708SDavid Chisnall}
10887a984708SDavid Chisnall
10897a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
10907a984708SDavid Chisnallvoid
10917a984708SDavid Chisnallforward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
10927a984708SDavid Chisnall{
10937a984708SDavid Chisnall    iterator __i = before_begin();
10947a984708SDavid Chisnall    iterator __j = _VSTD::next(__i);
10957a984708SDavid Chisnall    iterator __e = end();
10967a984708SDavid Chisnall    for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
10977a984708SDavid Chisnall        *__j = __v;
10987a984708SDavid Chisnall    if (__j == __e)
10997a984708SDavid Chisnall        insert_after(__i, __n, __v);
11007a984708SDavid Chisnall    else
11017a984708SDavid Chisnall        erase_after(__i, __e);
11027a984708SDavid Chisnall}
11037a984708SDavid Chisnall
1104540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11057a984708SDavid Chisnall
11067a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11077c82a1ecSDimitry Andricinline
11087a984708SDavid Chisnallvoid
11097a984708SDavid Chisnallforward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
11107a984708SDavid Chisnall{
11117a984708SDavid Chisnall    assign(__il.begin(), __il.end());
11127a984708SDavid Chisnall}
11137a984708SDavid Chisnall
11147a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11157a984708SDavid Chisnalltemplate <class... _Args>
111698221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1117aed8d94eSDimitry Andrictypename forward_list<_Tp, _Alloc>::reference
111898221d2eSDimitry Andric#else
111998221d2eSDimitry Andricvoid
112098221d2eSDimitry Andric#endif
11217a984708SDavid Chisnallforward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
11227a984708SDavid Chisnall{
11237a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
112494e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
112594e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
11267a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
11277a984708SDavid Chisnall                                  _VSTD::forward<_Args>(__args)...);
11287a984708SDavid Chisnall    __h->__next_ = base::__before_begin()->__next_;
11297a984708SDavid Chisnall    base::__before_begin()->__next_ = __h.release();
113098221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1131aed8d94eSDimitry Andric    return base::__before_begin()->__next_->__value_;
113298221d2eSDimitry Andric#endif
11337a984708SDavid Chisnall}
11347a984708SDavid Chisnall
11357a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11367a984708SDavid Chisnallvoid
11377a984708SDavid Chisnallforward_list<_Tp, _Alloc>::push_front(value_type&& __v)
11387a984708SDavid Chisnall{
11397a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
114094e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
114194e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
11427a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
11437a984708SDavid Chisnall    __h->__next_ = base::__before_begin()->__next_;
11447a984708SDavid Chisnall    base::__before_begin()->__next_ = __h.release();
11457a984708SDavid Chisnall}
11467a984708SDavid Chisnall
1147540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
11487a984708SDavid Chisnall
11497a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11507a984708SDavid Chisnallvoid
11517a984708SDavid Chisnallforward_list<_Tp, _Alloc>::push_front(const value_type& __v)
11527a984708SDavid Chisnall{
11537a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
115494e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
115594e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
11567a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
11577a984708SDavid Chisnall    __h->__next_ = base::__before_begin()->__next_;
11587a984708SDavid Chisnall    base::__before_begin()->__next_ = __h.release();
11597a984708SDavid Chisnall}
11607a984708SDavid Chisnall
11617a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11627a984708SDavid Chisnallvoid
11637a984708SDavid Chisnallforward_list<_Tp, _Alloc>::pop_front()
11647a984708SDavid Chisnall{
11657a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
11667a984708SDavid Chisnall    __node_pointer __p = base::__before_begin()->__next_;
11677a984708SDavid Chisnall    base::__before_begin()->__next_ = __p->__next_;
11687a984708SDavid Chisnall    __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
11697a984708SDavid Chisnall    __node_traits::deallocate(__a, __p, 1);
11707a984708SDavid Chisnall}
11717a984708SDavid Chisnall
1172540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11737a984708SDavid Chisnall
11747a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11757a984708SDavid Chisnalltemplate <class... _Args>
11767a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
11777a984708SDavid Chisnallforward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
11787a984708SDavid Chisnall{
11797c82a1ecSDimitry Andric    __begin_node_pointer const __r = __p.__get_begin();
11807a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
118194e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
118294e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
11837a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
11847a984708SDavid Chisnall                                  _VSTD::forward<_Args>(__args)...);
11857a984708SDavid Chisnall    __h->__next_ = __r->__next_;
11867a984708SDavid Chisnall    __r->__next_ = __h.release();
11877a984708SDavid Chisnall    return iterator(__r->__next_);
11887a984708SDavid Chisnall}
11897a984708SDavid Chisnall
11907a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11917a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
11927a984708SDavid Chisnallforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
11937a984708SDavid Chisnall{
11947c82a1ecSDimitry Andric    __begin_node_pointer const __r = __p.__get_begin();
11957a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
119694e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
119794e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
11987a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
11997a984708SDavid Chisnall    __h->__next_ = __r->__next_;
12007a984708SDavid Chisnall    __r->__next_ = __h.release();
12017a984708SDavid Chisnall    return iterator(__r->__next_);
12027a984708SDavid Chisnall}
12037a984708SDavid Chisnall
1204540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
12057a984708SDavid Chisnall
12067a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12077a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
12087a984708SDavid Chisnallforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
12097a984708SDavid Chisnall{
12107c82a1ecSDimitry Andric    __begin_node_pointer const __r = __p.__get_begin();
12117a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
121294e3ee44SDavid Chisnall    typedef __allocator_destructor<__node_allocator> _Dp;
121394e3ee44SDavid Chisnall    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
12147a984708SDavid Chisnall    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
12157a984708SDavid Chisnall    __h->__next_ = __r->__next_;
12167a984708SDavid Chisnall    __r->__next_ = __h.release();
12177a984708SDavid Chisnall    return iterator(__r->__next_);
12187a984708SDavid Chisnall}
12197a984708SDavid Chisnall
12207a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12217a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
12227a984708SDavid Chisnallforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
12237a984708SDavid Chisnall                                        const value_type& __v)
12247a984708SDavid Chisnall{
12257c82a1ecSDimitry Andric    __begin_node_pointer __r = __p.__get_begin();
12267a984708SDavid Chisnall    if (__n > 0)
12277a984708SDavid Chisnall    {
12287a984708SDavid Chisnall        __node_allocator& __a = base::__alloc();
122994e3ee44SDavid Chisnall        typedef __allocator_destructor<__node_allocator> _Dp;
123094e3ee44SDavid Chisnall        unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
12317a984708SDavid Chisnall        __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
12327a984708SDavid Chisnall        __node_pointer __first = __h.release();
12337a984708SDavid Chisnall        __node_pointer __last = __first;
12347a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
12357a984708SDavid Chisnall        try
12367a984708SDavid Chisnall        {
12377a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
12387a984708SDavid Chisnall            for (--__n; __n != 0; --__n, __last = __last->__next_)
12397a984708SDavid Chisnall            {
12407a984708SDavid Chisnall                __h.reset(__node_traits::allocate(__a, 1));
12417a984708SDavid Chisnall                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
12427a984708SDavid Chisnall                __last->__next_ = __h.release();
12437a984708SDavid Chisnall            }
12447a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
12457a984708SDavid Chisnall        }
12467a984708SDavid Chisnall        catch (...)
12477a984708SDavid Chisnall        {
12487a984708SDavid Chisnall            while (__first != nullptr)
12497a984708SDavid Chisnall            {
12507a984708SDavid Chisnall                __node_pointer __next = __first->__next_;
12517a984708SDavid Chisnall                __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
12527a984708SDavid Chisnall                __node_traits::deallocate(__a, __first, 1);
12537a984708SDavid Chisnall                __first = __next;
12547a984708SDavid Chisnall            }
12557a984708SDavid Chisnall            throw;
12567a984708SDavid Chisnall        }
12577a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
12587a984708SDavid Chisnall        __last->__next_ = __r->__next_;
12597a984708SDavid Chisnall        __r->__next_ = __first;
12607c82a1ecSDimitry Andric        __r = static_cast<__begin_node_pointer>(__last);
12617a984708SDavid Chisnall    }
12627a984708SDavid Chisnall    return iterator(__r);
12637a984708SDavid Chisnall}
12647a984708SDavid Chisnall
12657a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12667a984708SDavid Chisnalltemplate <class _InputIterator>
12677a984708SDavid Chisnalltypename enable_if
12687a984708SDavid Chisnall<
12697a984708SDavid Chisnall    __is_input_iterator<_InputIterator>::value,
12707a984708SDavid Chisnall    typename forward_list<_Tp, _Alloc>::iterator
12717a984708SDavid Chisnall>::type
12727a984708SDavid Chisnallforward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
12737a984708SDavid Chisnall                                        _InputIterator __f, _InputIterator __l)
12747a984708SDavid Chisnall{
12757c82a1ecSDimitry Andric    __begin_node_pointer __r = __p.__get_begin();
12767a984708SDavid Chisnall    if (__f != __l)
12777a984708SDavid Chisnall    {
12787a984708SDavid Chisnall        __node_allocator& __a = base::__alloc();
127994e3ee44SDavid Chisnall        typedef __allocator_destructor<__node_allocator> _Dp;
128094e3ee44SDavid Chisnall        unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
12817a984708SDavid Chisnall        __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
12827a984708SDavid Chisnall        __node_pointer __first = __h.release();
12837a984708SDavid Chisnall        __node_pointer __last = __first;
12847a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
12857a984708SDavid Chisnall        try
12867a984708SDavid Chisnall        {
12877a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
1288d72607e9SDimitry Andric            for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
12897a984708SDavid Chisnall            {
12907a984708SDavid Chisnall                __h.reset(__node_traits::allocate(__a, 1));
12917a984708SDavid Chisnall                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
12927a984708SDavid Chisnall                __last->__next_ = __h.release();
12937a984708SDavid Chisnall            }
12947a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
12957a984708SDavid Chisnall        }
12967a984708SDavid Chisnall        catch (...)
12977a984708SDavid Chisnall        {
12987a984708SDavid Chisnall            while (__first != nullptr)
12997a984708SDavid Chisnall            {
13007a984708SDavid Chisnall                __node_pointer __next = __first->__next_;
13017a984708SDavid Chisnall                __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
13027a984708SDavid Chisnall                __node_traits::deallocate(__a, __first, 1);
13037a984708SDavid Chisnall                __first = __next;
13047a984708SDavid Chisnall            }
13057a984708SDavid Chisnall            throw;
13067a984708SDavid Chisnall        }
13077a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
13087a984708SDavid Chisnall        __last->__next_ = __r->__next_;
13097a984708SDavid Chisnall        __r->__next_ = __first;
13107c82a1ecSDimitry Andric        __r = static_cast<__begin_node_pointer>(__last);
13117a984708SDavid Chisnall    }
13127a984708SDavid Chisnall    return iterator(__r);
13137a984708SDavid Chisnall}
13147a984708SDavid Chisnall
13157a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13167a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
13177a984708SDavid Chisnallforward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
13187a984708SDavid Chisnall{
13197c82a1ecSDimitry Andric    __begin_node_pointer __p = __f.__get_begin();
13207a984708SDavid Chisnall    __node_pointer __n = __p->__next_;
13217a984708SDavid Chisnall    __p->__next_ = __n->__next_;
13227a984708SDavid Chisnall    __node_allocator& __a = base::__alloc();
13237a984708SDavid Chisnall    __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
13247a984708SDavid Chisnall    __node_traits::deallocate(__a, __n, 1);
13257a984708SDavid Chisnall    return iterator(__p->__next_);
13267a984708SDavid Chisnall}
13277a984708SDavid Chisnall
13287a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13297a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::iterator
13307a984708SDavid Chisnallforward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
13317a984708SDavid Chisnall{
13327c82a1ecSDimitry Andric    __node_pointer __e = __l.__get_unsafe_node_pointer();
13337a984708SDavid Chisnall    if (__f != __l)
13347a984708SDavid Chisnall    {
13357c82a1ecSDimitry Andric        __begin_node_pointer __bp = __f.__get_begin();
13367c82a1ecSDimitry Andric
13377c82a1ecSDimitry Andric        __node_pointer __n = __bp->__next_;
13387a984708SDavid Chisnall        if (__n != __e)
13397a984708SDavid Chisnall        {
13407c82a1ecSDimitry Andric            __bp->__next_ = __e;
13417a984708SDavid Chisnall            __node_allocator& __a = base::__alloc();
13427a984708SDavid Chisnall            do
13437a984708SDavid Chisnall            {
13447c82a1ecSDimitry Andric                __node_pointer __tmp = __n->__next_;
13457a984708SDavid Chisnall                __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
13467a984708SDavid Chisnall                __node_traits::deallocate(__a, __n, 1);
13477c82a1ecSDimitry Andric                __n = __tmp;
13487a984708SDavid Chisnall            } while (__n != __e);
13497a984708SDavid Chisnall        }
13507a984708SDavid Chisnall    }
13517a984708SDavid Chisnall    return iterator(__e);
13527a984708SDavid Chisnall}
13537a984708SDavid Chisnall
13547a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13557a984708SDavid Chisnallvoid
13567a984708SDavid Chisnallforward_list<_Tp, _Alloc>::resize(size_type __n)
13577a984708SDavid Chisnall{
13587a984708SDavid Chisnall    size_type __sz = 0;
13597a984708SDavid Chisnall    iterator __p = before_begin();
13607a984708SDavid Chisnall    iterator __i = begin();
13617a984708SDavid Chisnall    iterator __e = end();
13627a984708SDavid Chisnall    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
13637a984708SDavid Chisnall        ;
13647a984708SDavid Chisnall    if (__i != __e)
13657a984708SDavid Chisnall        erase_after(__p, __e);
13667a984708SDavid Chisnall    else
13677a984708SDavid Chisnall    {
13687a984708SDavid Chisnall        __n -= __sz;
13697a984708SDavid Chisnall        if (__n > 0)
13707a984708SDavid Chisnall        {
13717a984708SDavid Chisnall            __node_allocator& __a = base::__alloc();
137294e3ee44SDavid Chisnall            typedef __allocator_destructor<__node_allocator> _Dp;
137394e3ee44SDavid Chisnall            unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
13747c82a1ecSDimitry Andric            for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
13757c82a1ecSDimitry Andric                                                         __ptr = __ptr->__next_as_begin())
13767a984708SDavid Chisnall            {
13777a984708SDavid Chisnall                __h.reset(__node_traits::allocate(__a, 1));
13787a984708SDavid Chisnall                __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
13797a984708SDavid Chisnall                __h->__next_ = nullptr;
13807a984708SDavid Chisnall                __ptr->__next_ = __h.release();
13817a984708SDavid Chisnall            }
13827a984708SDavid Chisnall        }
13837a984708SDavid Chisnall    }
13847a984708SDavid Chisnall}
13857a984708SDavid Chisnall
13867a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13877a984708SDavid Chisnallvoid
13887a984708SDavid Chisnallforward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
13897a984708SDavid Chisnall{
13907a984708SDavid Chisnall    size_type __sz = 0;
13917a984708SDavid Chisnall    iterator __p = before_begin();
13927a984708SDavid Chisnall    iterator __i = begin();
13937a984708SDavid Chisnall    iterator __e = end();
13947a984708SDavid Chisnall    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
13957a984708SDavid Chisnall        ;
13967a984708SDavid Chisnall    if (__i != __e)
13977a984708SDavid Chisnall        erase_after(__p, __e);
13987a984708SDavid Chisnall    else
13997a984708SDavid Chisnall    {
14007a984708SDavid Chisnall        __n -= __sz;
14017a984708SDavid Chisnall        if (__n > 0)
14027a984708SDavid Chisnall        {
14037a984708SDavid Chisnall            __node_allocator& __a = base::__alloc();
140494e3ee44SDavid Chisnall            typedef __allocator_destructor<__node_allocator> _Dp;
140594e3ee44SDavid Chisnall            unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
14067c82a1ecSDimitry Andric            for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
14077c82a1ecSDimitry Andric                                                         __ptr = __ptr->__next_as_begin())
14087a984708SDavid Chisnall            {
14097a984708SDavid Chisnall                __h.reset(__node_traits::allocate(__a, 1));
14107a984708SDavid Chisnall                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
14117a984708SDavid Chisnall                __h->__next_ = nullptr;
14127a984708SDavid Chisnall                __ptr->__next_ = __h.release();
14137a984708SDavid Chisnall            }
14147a984708SDavid Chisnall        }
14157a984708SDavid Chisnall    }
14167a984708SDavid Chisnall}
14177a984708SDavid Chisnall
14187a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14197a984708SDavid Chisnallvoid
14207a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
14217a984708SDavid Chisnall                                        forward_list& __x)
14227a984708SDavid Chisnall{
14237a984708SDavid Chisnall    if (!__x.empty())
14247a984708SDavid Chisnall    {
14257c82a1ecSDimitry Andric        if (__p.__get_begin()->__next_ != nullptr)
14267a984708SDavid Chisnall        {
14277a984708SDavid Chisnall            const_iterator __lm1 = __x.before_begin();
14287c82a1ecSDimitry Andric            while (__lm1.__get_begin()->__next_ != nullptr)
14297a984708SDavid Chisnall                ++__lm1;
14307c82a1ecSDimitry Andric            __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
14317a984708SDavid Chisnall        }
14327c82a1ecSDimitry Andric        __p.__get_begin()->__next_ = __x.__before_begin()->__next_;
14334bab9fd9SDavid Chisnall        __x.__before_begin()->__next_ = nullptr;
14347a984708SDavid Chisnall    }
14357a984708SDavid Chisnall}
14367a984708SDavid Chisnall
14377a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14387a984708SDavid Chisnallvoid
14397a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1440aed8d94eSDimitry Andric                                        forward_list& /*__other*/,
14417a984708SDavid Chisnall                                        const_iterator __i)
14427a984708SDavid Chisnall{
14437a984708SDavid Chisnall    const_iterator __lm1 = _VSTD::next(__i);
14447a984708SDavid Chisnall    if (__p != __i && __p != __lm1)
14457a984708SDavid Chisnall    {
14467c82a1ecSDimitry Andric        __i.__get_begin()->__next_ = __lm1.__get_begin()->__next_;
14477c82a1ecSDimitry Andric        __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
14487c82a1ecSDimitry Andric        __p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer();
14497a984708SDavid Chisnall    }
14507a984708SDavid Chisnall}
14517a984708SDavid Chisnall
14527a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14537a984708SDavid Chisnallvoid
14547a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
1455aed8d94eSDimitry Andric                                        forward_list& /*__other*/,
14567a984708SDavid Chisnall                                        const_iterator __f, const_iterator __l)
14577a984708SDavid Chisnall{
14587a984708SDavid Chisnall    if (__f != __l && __p != __f)
14597a984708SDavid Chisnall    {
14607a984708SDavid Chisnall        const_iterator __lm1 = __f;
14617c82a1ecSDimitry Andric        while (__lm1.__get_begin()->__next_ != __l.__get_begin())
14627a984708SDavid Chisnall            ++__lm1;
14637a984708SDavid Chisnall        if (__f != __lm1)
14647a984708SDavid Chisnall        {
14657c82a1ecSDimitry Andric            __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
14667c82a1ecSDimitry Andric            __p.__get_begin()->__next_ = __f.__get_begin()->__next_;
14677c82a1ecSDimitry Andric            __f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer();
14687a984708SDavid Chisnall        }
14697a984708SDavid Chisnall    }
14707a984708SDavid Chisnall}
14717a984708SDavid Chisnall
1472540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
14737a984708SDavid Chisnall
14747a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14757a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
14767a984708SDavid Chisnallvoid
14777a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
14787a984708SDavid Chisnall                                        forward_list&& __x)
14797a984708SDavid Chisnall{
14807a984708SDavid Chisnall    splice_after(__p, __x);
14817a984708SDavid Chisnall}
14827a984708SDavid Chisnall
14837a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14847a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
14857a984708SDavid Chisnallvoid
14867a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
14877a984708SDavid Chisnall                                        forward_list&& __x,
14887a984708SDavid Chisnall                                        const_iterator __i)
14897a984708SDavid Chisnall{
14907a984708SDavid Chisnall    splice_after(__p, __x, __i);
14917a984708SDavid Chisnall}
14927a984708SDavid Chisnall
14937a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14947a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
14957a984708SDavid Chisnallvoid
14967a984708SDavid Chisnallforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
14977a984708SDavid Chisnall                                        forward_list&& __x,
14987a984708SDavid Chisnall                                        const_iterator __f, const_iterator __l)
14997a984708SDavid Chisnall{
15007a984708SDavid Chisnall    splice_after(__p, __x, __f, __l);
15017a984708SDavid Chisnall}
15027a984708SDavid Chisnall
1503540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
15047a984708SDavid Chisnall
15057a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15067a984708SDavid Chisnallvoid
15077a984708SDavid Chisnallforward_list<_Tp, _Alloc>::remove(const value_type& __v)
15087a984708SDavid Chisnall{
1509d72607e9SDimitry Andric    forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
15107a984708SDavid Chisnall    iterator __e = end();
15117c82a1ecSDimitry Andric    for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
15127a984708SDavid Chisnall    {
15137c82a1ecSDimitry Andric        if (__i.__get_begin()->__next_->__value_ == __v)
15147a984708SDavid Chisnall        {
15157a984708SDavid Chisnall            iterator __j = _VSTD::next(__i, 2);
15167a984708SDavid Chisnall            for (; __j != __e && *__j == __v; ++__j)
15177a984708SDavid Chisnall                ;
1518d72607e9SDimitry Andric            __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
15197a984708SDavid Chisnall            if (__j == __e)
15207a984708SDavid Chisnall                break;
15217a984708SDavid Chisnall            __i = __j;
15227a984708SDavid Chisnall        }
15237a984708SDavid Chisnall        else
15247a984708SDavid Chisnall            ++__i;
15257a984708SDavid Chisnall    }
15267a984708SDavid Chisnall}
15277a984708SDavid Chisnall
15287a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15297a984708SDavid Chisnalltemplate <class _Predicate>
15307a984708SDavid Chisnallvoid
15317a984708SDavid Chisnallforward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
15327a984708SDavid Chisnall{
15337a984708SDavid Chisnall    iterator __e = end();
15347c82a1ecSDimitry Andric    for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
15357a984708SDavid Chisnall    {
15367c82a1ecSDimitry Andric        if (__pred(__i.__get_begin()->__next_->__value_))
15377a984708SDavid Chisnall        {
15387a984708SDavid Chisnall            iterator __j = _VSTD::next(__i, 2);
15397a984708SDavid Chisnall            for (; __j != __e && __pred(*__j); ++__j)
15407a984708SDavid Chisnall                ;
15417a984708SDavid Chisnall            erase_after(__i, __j);
15427a984708SDavid Chisnall            if (__j == __e)
15437a984708SDavid Chisnall                break;
15447a984708SDavid Chisnall            __i = __j;
15457a984708SDavid Chisnall        }
15467a984708SDavid Chisnall        else
15477a984708SDavid Chisnall            ++__i;
15487a984708SDavid Chisnall    }
15497a984708SDavid Chisnall}
15507a984708SDavid Chisnall
15517a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15527a984708SDavid Chisnalltemplate <class _BinaryPredicate>
15537a984708SDavid Chisnallvoid
15547a984708SDavid Chisnallforward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
15557a984708SDavid Chisnall{
15567a984708SDavid Chisnall    for (iterator __i = begin(), __e = end(); __i != __e;)
15577a984708SDavid Chisnall    {
15587a984708SDavid Chisnall        iterator __j = _VSTD::next(__i);
15597a984708SDavid Chisnall        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
15607a984708SDavid Chisnall            ;
15617c82a1ecSDimitry Andric        if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
15627a984708SDavid Chisnall            erase_after(__i, __j);
15637a984708SDavid Chisnall        __i = __j;
15647a984708SDavid Chisnall    }
15657a984708SDavid Chisnall}
15667a984708SDavid Chisnall
15677a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15687a984708SDavid Chisnalltemplate <class _Compare>
15697a984708SDavid Chisnallvoid
15707a984708SDavid Chisnallforward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
15717a984708SDavid Chisnall{
15727a984708SDavid Chisnall    if (this != &__x)
15737a984708SDavid Chisnall    {
15747a984708SDavid Chisnall        base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
15757a984708SDavid Chisnall                                                    __x.__before_begin()->__next_,
15767a984708SDavid Chisnall                                                    __comp);
15777a984708SDavid Chisnall        __x.__before_begin()->__next_ = nullptr;
15787a984708SDavid Chisnall    }
15797a984708SDavid Chisnall}
15807a984708SDavid Chisnall
15817a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15827a984708SDavid Chisnalltemplate <class _Compare>
15837a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::__node_pointer
15847a984708SDavid Chisnallforward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
15857a984708SDavid Chisnall                                   _Compare& __comp)
15867a984708SDavid Chisnall{
15877a984708SDavid Chisnall    if (__f1 == nullptr)
15887a984708SDavid Chisnall        return __f2;
15897a984708SDavid Chisnall    if (__f2 == nullptr)
15907a984708SDavid Chisnall        return __f1;
15917a984708SDavid Chisnall    __node_pointer __r;
15927a984708SDavid Chisnall    if (__comp(__f2->__value_, __f1->__value_))
15937a984708SDavid Chisnall    {
15947a984708SDavid Chisnall        __node_pointer __t = __f2;
15957a984708SDavid Chisnall        while (__t->__next_ != nullptr &&
15967a984708SDavid Chisnall                             __comp(__t->__next_->__value_, __f1->__value_))
15977a984708SDavid Chisnall            __t = __t->__next_;
15987a984708SDavid Chisnall        __r = __f2;
15997a984708SDavid Chisnall        __f2 = __t->__next_;
16007a984708SDavid Chisnall        __t->__next_ = __f1;
16017a984708SDavid Chisnall    }
16027a984708SDavid Chisnall    else
16037a984708SDavid Chisnall        __r = __f1;
16047a984708SDavid Chisnall    __node_pointer __p = __f1;
16057a984708SDavid Chisnall    __f1 = __f1->__next_;
16067a984708SDavid Chisnall    while (__f1 != nullptr && __f2 != nullptr)
16077a984708SDavid Chisnall    {
16087a984708SDavid Chisnall        if (__comp(__f2->__value_, __f1->__value_))
16097a984708SDavid Chisnall        {
16107a984708SDavid Chisnall            __node_pointer __t = __f2;
16117a984708SDavid Chisnall            while (__t->__next_ != nullptr &&
16127a984708SDavid Chisnall                                 __comp(__t->__next_->__value_, __f1->__value_))
16137a984708SDavid Chisnall                __t = __t->__next_;
16147a984708SDavid Chisnall            __p->__next_ = __f2;
16157a984708SDavid Chisnall            __f2 = __t->__next_;
16167a984708SDavid Chisnall            __t->__next_ = __f1;
16177a984708SDavid Chisnall        }
16187a984708SDavid Chisnall        __p = __f1;
16197a984708SDavid Chisnall        __f1 = __f1->__next_;
16207a984708SDavid Chisnall    }
16217a984708SDavid Chisnall    if (__f2 != nullptr)
16227a984708SDavid Chisnall        __p->__next_ = __f2;
16237a984708SDavid Chisnall    return __r;
16247a984708SDavid Chisnall}
16257a984708SDavid Chisnall
16267a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16277a984708SDavid Chisnalltemplate <class _Compare>
16287c82a1ecSDimitry Andricinline
16297a984708SDavid Chisnallvoid
16307a984708SDavid Chisnallforward_list<_Tp, _Alloc>::sort(_Compare __comp)
16317a984708SDavid Chisnall{
16327a984708SDavid Chisnall    base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
16337a984708SDavid Chisnall                                       _VSTD::distance(begin(), end()), __comp);
16347a984708SDavid Chisnall}
16357a984708SDavid Chisnall
16367a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16377a984708SDavid Chisnalltemplate <class _Compare>
16387a984708SDavid Chisnalltypename forward_list<_Tp, _Alloc>::__node_pointer
16397a984708SDavid Chisnallforward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
16407a984708SDavid Chisnall                                  _Compare& __comp)
16417a984708SDavid Chisnall{
16427a984708SDavid Chisnall    switch (__sz)
16437a984708SDavid Chisnall    {
16447a984708SDavid Chisnall    case 0:
16457a984708SDavid Chisnall    case 1:
16467a984708SDavid Chisnall        return __f1;
16477a984708SDavid Chisnall    case 2:
16487a984708SDavid Chisnall        if (__comp(__f1->__next_->__value_, __f1->__value_))
16497a984708SDavid Chisnall        {
16507a984708SDavid Chisnall            __node_pointer __t = __f1->__next_;
16517a984708SDavid Chisnall            __t->__next_ = __f1;
16527a984708SDavid Chisnall            __f1->__next_ = nullptr;
16537a984708SDavid Chisnall            __f1 = __t;
16547a984708SDavid Chisnall        }
16557a984708SDavid Chisnall        return __f1;
16567a984708SDavid Chisnall    }
16577a984708SDavid Chisnall    difference_type __sz1 = __sz / 2;
16587a984708SDavid Chisnall    difference_type __sz2 = __sz - __sz1;
16597c82a1ecSDimitry Andric    __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer();
16607a984708SDavid Chisnall    __node_pointer __f2 = __t->__next_;
16617a984708SDavid Chisnall    __t->__next_ = nullptr;
16627a984708SDavid Chisnall    return __merge(__sort(__f1, __sz1, __comp),
16637a984708SDavid Chisnall                   __sort(__f2, __sz2, __comp), __comp);
16647a984708SDavid Chisnall}
16657a984708SDavid Chisnall
16667a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16677a984708SDavid Chisnallvoid
16687a984708SDavid Chisnallforward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
16697a984708SDavid Chisnall{
16707a984708SDavid Chisnall    __node_pointer __p = base::__before_begin()->__next_;
16717a984708SDavid Chisnall    if (__p != nullptr)
16727a984708SDavid Chisnall    {
16737a984708SDavid Chisnall        __node_pointer __f = __p->__next_;
16747a984708SDavid Chisnall        __p->__next_ = nullptr;
16757a984708SDavid Chisnall        while (__f != nullptr)
16767a984708SDavid Chisnall        {
16777a984708SDavid Chisnall            __node_pointer __t = __f->__next_;
16787a984708SDavid Chisnall            __f->__next_ = __p;
16797a984708SDavid Chisnall            __p = __f;
16807a984708SDavid Chisnall            __f = __t;
16817a984708SDavid Chisnall        }
16827a984708SDavid Chisnall        base::__before_begin()->__next_ = __p;
16837a984708SDavid Chisnall    }
16847a984708SDavid Chisnall}
16857a984708SDavid Chisnall
16867a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16877a984708SDavid Chisnallbool operator==(const forward_list<_Tp, _Alloc>& __x,
16887a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
16897a984708SDavid Chisnall{
169094e3ee44SDavid Chisnall    typedef forward_list<_Tp, _Alloc> _Cp;
169194e3ee44SDavid Chisnall    typedef typename _Cp::const_iterator _Ip;
169294e3ee44SDavid Chisnall    _Ip __ix = __x.begin();
169394e3ee44SDavid Chisnall    _Ip __ex = __x.end();
169494e3ee44SDavid Chisnall    _Ip __iy = __y.begin();
169594e3ee44SDavid Chisnall    _Ip __ey = __y.end();
16967a984708SDavid Chisnall    for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
16977a984708SDavid Chisnall        if (!(*__ix == *__iy))
16987a984708SDavid Chisnall            return false;
16997a984708SDavid Chisnall    return (__ix == __ex) == (__iy == __ey);
17007a984708SDavid Chisnall}
17017a984708SDavid Chisnall
17027a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17037a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17047a984708SDavid Chisnallbool operator!=(const forward_list<_Tp, _Alloc>& __x,
17057a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
17067a984708SDavid Chisnall{
17077a984708SDavid Chisnall    return !(__x == __y);
17087a984708SDavid Chisnall}
17097a984708SDavid Chisnall
17107a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17117a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17127a984708SDavid Chisnallbool operator< (const forward_list<_Tp, _Alloc>& __x,
17137a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
17147a984708SDavid Chisnall{
17157a984708SDavid Chisnall    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
17167a984708SDavid Chisnall                                         __y.begin(), __y.end());
17177a984708SDavid Chisnall}
17187a984708SDavid Chisnall
17197a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17207a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17217a984708SDavid Chisnallbool operator> (const forward_list<_Tp, _Alloc>& __x,
17227a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
17237a984708SDavid Chisnall{
17247a984708SDavid Chisnall    return __y < __x;
17257a984708SDavid Chisnall}
17267a984708SDavid Chisnall
17277a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17287a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17297a984708SDavid Chisnallbool operator>=(const forward_list<_Tp, _Alloc>& __x,
17307a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
17317a984708SDavid Chisnall{
17327a984708SDavid Chisnall    return !(__x < __y);
17337a984708SDavid Chisnall}
17347a984708SDavid Chisnall
17357a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17367a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17377a984708SDavid Chisnallbool operator<=(const forward_list<_Tp, _Alloc>& __x,
17387a984708SDavid Chisnall                const forward_list<_Tp, _Alloc>& __y)
17397a984708SDavid Chisnall{
17407a984708SDavid Chisnall    return !(__y < __x);
17417a984708SDavid Chisnall}
17427a984708SDavid Chisnall
17437a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17447a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
17457a984708SDavid Chisnallvoid
17467a984708SDavid Chisnallswap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
17477a984708SDavid Chisnall    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
17487a984708SDavid Chisnall{
17497a984708SDavid Chisnall    __x.swap(__y);
17507a984708SDavid Chisnall}
17517a984708SDavid Chisnall
1752*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17
1753*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
1754*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1755*b5893f02SDimitry Andricvoid erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred)
1756*b5893f02SDimitry Andric{ __c.remove_if(__pred); }
1757*b5893f02SDimitry Andric
1758*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
1759*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1760*b5893f02SDimitry Andricvoid erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v)
1761*b5893f02SDimitry Andric{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
1762*b5893f02SDimitry Andric#endif
1763*b5893f02SDimitry Andric
17647a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
17657a984708SDavid Chisnall
1766f9448bf3SDimitry Andric_LIBCPP_POP_MACROS
1767f9448bf3SDimitry Andric
17687a984708SDavid Chisnall#endif  // _LIBCPP_FORWARD_LIST
1769