xref: /openbsd-src/gnu/llvm/libcxx/include/forward_list (revision 4bdff4bed0e3d54e55670334c7d0077db4170f86)
146035553Spatrick// -*- C++ -*-
2*4bdff4beSrobert//===----------------------------------------------------------------------===//
346035553Spatrick//
446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
546035553Spatrick// See https://llvm.org/LICENSE.txt for license information.
646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
746035553Spatrick//
846035553Spatrick//===----------------------------------------------------------------------===//
946035553Spatrick
1046035553Spatrick#ifndef _LIBCPP_FORWARD_LIST
1146035553Spatrick#define _LIBCPP_FORWARD_LIST
1246035553Spatrick
1346035553Spatrick/*
1446035553Spatrick    forward_list synopsis
1546035553Spatrick
1646035553Spatricknamespace std
1746035553Spatrick{
1846035553Spatrick
1946035553Spatricktemplate <class T, class Allocator = allocator<T>>
2046035553Spatrickclass forward_list
2146035553Spatrick{
2246035553Spatrickpublic:
2346035553Spatrick    typedef T         value_type;
2446035553Spatrick    typedef Allocator allocator_type;
2546035553Spatrick
2646035553Spatrick    typedef value_type&                                                reference;
2746035553Spatrick    typedef const value_type&                                          const_reference;
2846035553Spatrick    typedef typename allocator_traits<allocator_type>::pointer         pointer;
2946035553Spatrick    typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
3046035553Spatrick    typedef typename allocator_traits<allocator_type>::size_type       size_type;
3146035553Spatrick    typedef typename allocator_traits<allocator_type>::difference_type difference_type;
3246035553Spatrick
3346035553Spatrick    typedef <details> iterator;
3446035553Spatrick    typedef <details> const_iterator;
3546035553Spatrick
3646035553Spatrick    forward_list()
3746035553Spatrick        noexcept(is_nothrow_default_constructible<allocator_type>::value);
3846035553Spatrick    explicit forward_list(const allocator_type& a);
3946035553Spatrick    explicit forward_list(size_type n);
4046035553Spatrick    explicit forward_list(size_type n, const allocator_type& a); // C++14
4146035553Spatrick    forward_list(size_type n, const value_type& v);
4246035553Spatrick    forward_list(size_type n, const value_type& v, const allocator_type& a);
4346035553Spatrick    template <class InputIterator>
4446035553Spatrick        forward_list(InputIterator first, InputIterator last);
4546035553Spatrick    template <class InputIterator>
4646035553Spatrick        forward_list(InputIterator first, InputIterator last, const allocator_type& a);
4746035553Spatrick    forward_list(const forward_list& x);
4846035553Spatrick    forward_list(const forward_list& x, const allocator_type& a);
4946035553Spatrick    forward_list(forward_list&& x)
5046035553Spatrick        noexcept(is_nothrow_move_constructible<allocator_type>::value);
5146035553Spatrick    forward_list(forward_list&& x, const allocator_type& a);
5246035553Spatrick    forward_list(initializer_list<value_type> il);
5346035553Spatrick    forward_list(initializer_list<value_type> il, const allocator_type& a);
5446035553Spatrick
5546035553Spatrick    ~forward_list();
5646035553Spatrick
5746035553Spatrick    forward_list& operator=(const forward_list& x);
5846035553Spatrick    forward_list& operator=(forward_list&& x)
5946035553Spatrick        noexcept(
6046035553Spatrick             allocator_type::propagate_on_container_move_assignment::value &&
6146035553Spatrick             is_nothrow_move_assignable<allocator_type>::value);
6246035553Spatrick    forward_list& operator=(initializer_list<value_type> il);
6346035553Spatrick
6446035553Spatrick    template <class InputIterator>
6546035553Spatrick        void assign(InputIterator first, InputIterator last);
6646035553Spatrick    void assign(size_type n, const value_type& v);
6746035553Spatrick    void assign(initializer_list<value_type> il);
6846035553Spatrick
6946035553Spatrick    allocator_type get_allocator() const noexcept;
7046035553Spatrick
7146035553Spatrick    iterator       begin() noexcept;
7246035553Spatrick    const_iterator begin() const noexcept;
7346035553Spatrick    iterator       end() noexcept;
7446035553Spatrick    const_iterator end() const noexcept;
7546035553Spatrick
7646035553Spatrick    const_iterator cbegin() const noexcept;
7746035553Spatrick    const_iterator cend() const noexcept;
7846035553Spatrick
7946035553Spatrick    iterator       before_begin() noexcept;
8046035553Spatrick    const_iterator before_begin() const noexcept;
8146035553Spatrick    const_iterator cbefore_begin() const noexcept;
8246035553Spatrick
8346035553Spatrick    bool empty() const noexcept;
8446035553Spatrick    size_type max_size() const noexcept;
8546035553Spatrick
8646035553Spatrick    reference       front();
8746035553Spatrick    const_reference front() const;
8846035553Spatrick
8946035553Spatrick    template <class... Args> reference emplace_front(Args&&... args);  // reference in C++17
9046035553Spatrick    void push_front(const value_type& v);
9146035553Spatrick    void push_front(value_type&& v);
9246035553Spatrick
9346035553Spatrick    void pop_front();
9446035553Spatrick
9546035553Spatrick    template <class... Args>
9646035553Spatrick        iterator emplace_after(const_iterator p, Args&&... args);
9746035553Spatrick    iterator insert_after(const_iterator p, const value_type& v);
9846035553Spatrick    iterator insert_after(const_iterator p, value_type&& v);
9946035553Spatrick    iterator insert_after(const_iterator p, size_type n, const value_type& v);
10046035553Spatrick    template <class InputIterator>
10146035553Spatrick        iterator insert_after(const_iterator p,
10246035553Spatrick                              InputIterator first, InputIterator last);
10346035553Spatrick    iterator insert_after(const_iterator p, initializer_list<value_type> il);
10446035553Spatrick
10546035553Spatrick    iterator erase_after(const_iterator p);
10646035553Spatrick    iterator erase_after(const_iterator first, const_iterator last);
10746035553Spatrick
10846035553Spatrick    void swap(forward_list& x)
10946035553Spatrick        noexcept(allocator_traits<allocator_type>::is_always_equal::value);  // C++17
11046035553Spatrick
11146035553Spatrick    void resize(size_type n);
11246035553Spatrick    void resize(size_type n, const value_type& v);
11346035553Spatrick    void clear() noexcept;
11446035553Spatrick
11546035553Spatrick    void splice_after(const_iterator p, forward_list& x);
11646035553Spatrick    void splice_after(const_iterator p, forward_list&& x);
11746035553Spatrick    void splice_after(const_iterator p, forward_list& x, const_iterator i);
11846035553Spatrick    void splice_after(const_iterator p, forward_list&& x, const_iterator i);
11946035553Spatrick    void splice_after(const_iterator p, forward_list& x,
12046035553Spatrick                      const_iterator first, const_iterator last);
12146035553Spatrick    void splice_after(const_iterator p, forward_list&& x,
12246035553Spatrick                      const_iterator first, const_iterator last);
12346035553Spatrick    size_type remove(const value_type& v);           // void before C++20
12446035553Spatrick    template <class Predicate>
12546035553Spatrick      size_type remove_if(Predicate pred);           // void before C++20
12646035553Spatrick    size_type unique();                              // void before C++20
12746035553Spatrick    template <class BinaryPredicate>
12846035553Spatrick      size_type unique(BinaryPredicate binary_pred); // void before C++20
12946035553Spatrick    void merge(forward_list& x);
13046035553Spatrick    void merge(forward_list&& x);
13146035553Spatrick    template <class Compare> void merge(forward_list& x, Compare comp);
13246035553Spatrick    template <class Compare> void merge(forward_list&& x, Compare comp);
13346035553Spatrick    void sort();
13446035553Spatrick    template <class Compare> void sort(Compare comp);
13546035553Spatrick    void reverse() noexcept;
13646035553Spatrick};
13746035553Spatrick
13846035553Spatrick
13946035553Spatricktemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
14046035553Spatrick    forward_list(InputIterator, InputIterator, Allocator = Allocator())
14146035553Spatrick    -> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>;  // C++17
14246035553Spatrick
14346035553Spatricktemplate <class T, class Allocator>
14446035553Spatrick    bool operator==(const forward_list<T, Allocator>& x,
14546035553Spatrick                    const forward_list<T, Allocator>& y);
14646035553Spatrick
14746035553Spatricktemplate <class T, class Allocator>
14846035553Spatrick    bool operator< (const forward_list<T, Allocator>& x,
14946035553Spatrick                    const forward_list<T, Allocator>& y);
15046035553Spatrick
15146035553Spatricktemplate <class T, class Allocator>
15246035553Spatrick    bool operator!=(const forward_list<T, Allocator>& x,
15346035553Spatrick                    const forward_list<T, Allocator>& y);
15446035553Spatrick
15546035553Spatricktemplate <class T, class Allocator>
15646035553Spatrick    bool operator> (const forward_list<T, Allocator>& x,
15746035553Spatrick                    const forward_list<T, Allocator>& y);
15846035553Spatrick
15946035553Spatricktemplate <class T, class Allocator>
16046035553Spatrick    bool operator>=(const forward_list<T, Allocator>& x,
16146035553Spatrick                    const forward_list<T, Allocator>& y);
16246035553Spatrick
16346035553Spatricktemplate <class T, class Allocator>
16446035553Spatrick    bool operator<=(const forward_list<T, Allocator>& x,
16546035553Spatrick                    const forward_list<T, Allocator>& y);
16646035553Spatrick
16746035553Spatricktemplate <class T, class Allocator>
16846035553Spatrick    void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
16946035553Spatrick         noexcept(noexcept(x.swap(y)));
17046035553Spatrick
17146035553Spatricktemplate <class T, class Allocator, class U>
172037e7968Spatrick    typename forward_list<T, Allocator>::size_type
173037e7968Spatrick    erase(forward_list<T, Allocator>& c, const U& value);       // C++20
17446035553Spatricktemplate <class T, class Allocator, class Predicate>
175037e7968Spatrick    typename forward_list<T, Allocator>::size_type
176037e7968Spatrick    erase_if(forward_list<T, Allocator>& c, Predicate pred);    // C++20
17746035553Spatrick
17846035553Spatrick}  // std
17946035553Spatrick
18046035553Spatrick*/
18146035553Spatrick
182*4bdff4beSrobert#include <__algorithm/comp.h>
183*4bdff4beSrobert#include <__algorithm/lexicographical_compare.h>
184*4bdff4beSrobert#include <__algorithm/min.h>
185*4bdff4beSrobert#include <__assert> // all public C++ headers provide the assertion handler
18646035553Spatrick#include <__config>
187*4bdff4beSrobert#include <__iterator/distance.h>
188*4bdff4beSrobert#include <__iterator/iterator_traits.h>
189*4bdff4beSrobert#include <__iterator/move_iterator.h>
190*4bdff4beSrobert#include <__iterator/next.h>
191*4bdff4beSrobert#include <__memory/addressof.h>
192*4bdff4beSrobert#include <__memory/allocator.h>
193*4bdff4beSrobert#include <__memory/allocator_destructor.h>
194*4bdff4beSrobert#include <__memory/allocator_traits.h>
195*4bdff4beSrobert#include <__memory/compressed_pair.h>
196*4bdff4beSrobert#include <__memory/pointer_traits.h>
197*4bdff4beSrobert#include <__memory/swap_allocator.h>
198*4bdff4beSrobert#include <__memory/unique_ptr.h>
199*4bdff4beSrobert#include <__memory_resource/polymorphic_allocator.h>
200*4bdff4beSrobert#include <__type_traits/is_allocator.h>
20176d0caaeSpatrick#include <__utility/forward.h>
202*4bdff4beSrobert#include <__utility/move.h>
20376d0caaeSpatrick#include <limits>
204*4bdff4beSrobert#include <type_traits>
20546035553Spatrick#include <version>
20646035553Spatrick
207*4bdff4beSrobert// standard-mandated includes
208*4bdff4beSrobert
209*4bdff4beSrobert// [iterator.range]
210*4bdff4beSrobert#include <__iterator/access.h>
211*4bdff4beSrobert#include <__iterator/data.h>
212*4bdff4beSrobert#include <__iterator/empty.h>
213*4bdff4beSrobert#include <__iterator/reverse_access.h>
214*4bdff4beSrobert#include <__iterator/size.h>
215*4bdff4beSrobert
216*4bdff4beSrobert// [forward.list.syn]
217*4bdff4beSrobert#include <compare>
218*4bdff4beSrobert#include <initializer_list>
219*4bdff4beSrobert
22046035553Spatrick#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22146035553Spatrick#  pragma GCC system_header
22246035553Spatrick#endif
22346035553Spatrick
22446035553Spatrick_LIBCPP_PUSH_MACROS
22546035553Spatrick#include <__undef_macros>
22646035553Spatrick
22746035553Spatrick
22846035553Spatrick_LIBCPP_BEGIN_NAMESPACE_STD
22946035553Spatrick
23046035553Spatricktemplate <class _Tp, class _VoidPtr> struct __forward_list_node;
23146035553Spatricktemplate <class _NodePtr> struct __forward_begin_node;
23246035553Spatrick
23346035553Spatrick
23446035553Spatricktemplate <class>
23546035553Spatrickstruct __forward_list_node_value_type;
23646035553Spatrick
23746035553Spatricktemplate <class _Tp, class _VoidPtr>
23846035553Spatrickstruct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > {
23946035553Spatrick  typedef _Tp type;
24046035553Spatrick};
24146035553Spatrick
24246035553Spatricktemplate <class _NodePtr>
24346035553Spatrickstruct __forward_node_traits {
24446035553Spatrick
245*4bdff4beSrobert  typedef __remove_cv_t<
246*4bdff4beSrobert        typename pointer_traits<_NodePtr>::element_type>        __node;
24746035553Spatrick  typedef typename __forward_list_node_value_type<__node>::type __node_value_type;
24846035553Spatrick  typedef _NodePtr                                              __node_pointer;
24946035553Spatrick  typedef __forward_begin_node<_NodePtr>                        __begin_node;
250*4bdff4beSrobert  typedef __rebind_pointer_t<_NodePtr, __begin_node>            __begin_node_pointer;
251*4bdff4beSrobert  typedef __rebind_pointer_t<_NodePtr, void>                    __void_pointer;
25246035553Spatrick
25346035553Spatrick#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB)
25446035553Spatrick  typedef __begin_node_pointer __iter_node_pointer;
25546035553Spatrick#else
256*4bdff4beSrobert  typedef __conditional_t<is_pointer<__void_pointer>::value, __begin_node_pointer, __node_pointer>
257*4bdff4beSrobert      __iter_node_pointer;
25846035553Spatrick#endif
25946035553Spatrick
260*4bdff4beSrobert  typedef __conditional_t<is_same<__iter_node_pointer, __node_pointer>::value, __begin_node_pointer, __node_pointer>
261*4bdff4beSrobert      __non_iter_node_pointer;
26246035553Spatrick
26346035553Spatrick  _LIBCPP_INLINE_VISIBILITY
26446035553Spatrick  static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) {
26546035553Spatrick      return __p;
26646035553Spatrick  }
26746035553Spatrick  _LIBCPP_INLINE_VISIBILITY
26846035553Spatrick  static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) {
26946035553Spatrick      return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p));
27046035553Spatrick  }
27146035553Spatrick};
27246035553Spatrick
27346035553Spatricktemplate <class _NodePtr>
27446035553Spatrickstruct __forward_begin_node
27546035553Spatrick{
27646035553Spatrick    typedef _NodePtr pointer;
277*4bdff4beSrobert    typedef __rebind_pointer_t<_NodePtr, __forward_begin_node> __begin_node_pointer;
27846035553Spatrick
27946035553Spatrick    pointer __next_;
28046035553Spatrick
28146035553Spatrick    _LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
28246035553Spatrick
28346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28446035553Spatrick    __begin_node_pointer __next_as_begin() const {
28546035553Spatrick        return static_cast<__begin_node_pointer>(__next_);
28646035553Spatrick    }
28746035553Spatrick};
28846035553Spatrick
28946035553Spatricktemplate <class _Tp, class _VoidPtr>
290*4bdff4beSrobertusing __begin_node_of = __forward_begin_node<__rebind_pointer_t<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> > >;
29146035553Spatrick
29246035553Spatricktemplate <class _Tp, class _VoidPtr>
29376d0caaeSpatrickstruct _LIBCPP_STANDALONE_DEBUG __forward_list_node
294*4bdff4beSrobert    : public __begin_node_of<_Tp, _VoidPtr>
29546035553Spatrick{
29646035553Spatrick    typedef _Tp value_type;
29746035553Spatrick
29846035553Spatrick    value_type __value_;
29946035553Spatrick};
30046035553Spatrick
30146035553Spatrick
30246035553Spatricktemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list;
30346035553Spatricktemplate<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
30446035553Spatrick
30546035553Spatricktemplate <class _NodePtr>
30646035553Spatrickclass _LIBCPP_TEMPLATE_VIS __forward_list_iterator
30746035553Spatrick{
30846035553Spatrick    typedef __forward_node_traits<_NodePtr>         __traits;
30946035553Spatrick    typedef typename __traits::__node_pointer       __node_pointer;
31046035553Spatrick    typedef typename __traits::__begin_node_pointer __begin_node_pointer;
31146035553Spatrick    typedef typename __traits::__iter_node_pointer  __iter_node_pointer;
31246035553Spatrick    typedef typename __traits::__void_pointer       __void_pointer;
31346035553Spatrick
31446035553Spatrick    __iter_node_pointer __ptr_;
31546035553Spatrick
31646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
31746035553Spatrick    __begin_node_pointer __get_begin() const {
31846035553Spatrick        return static_cast<__begin_node_pointer>(
31946035553Spatrick                static_cast<__void_pointer>(__ptr_));
32046035553Spatrick    }
32146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32246035553Spatrick    __node_pointer __get_unsafe_node_pointer() const {
32346035553Spatrick        return static_cast<__node_pointer>(
32446035553Spatrick                static_cast<__void_pointer>(__ptr_));
32546035553Spatrick    }
32646035553Spatrick
32746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
32846035553Spatrick    explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
32946035553Spatrick
33046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
33146035553Spatrick    explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
33246035553Spatrick        : __ptr_(__traits::__as_iter_node(__p)) {}
33346035553Spatrick
33446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
33546035553Spatrick    explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
33646035553Spatrick        : __ptr_(__traits::__as_iter_node(__p)) {}
33746035553Spatrick
33846035553Spatrick    template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list;
33946035553Spatrick    template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
34046035553Spatrick
34146035553Spatrickpublic:
34246035553Spatrick    typedef forward_iterator_tag                              iterator_category;
34346035553Spatrick    typedef typename __traits::__node_value_type              value_type;
34446035553Spatrick    typedef value_type&                                       reference;
34546035553Spatrick    typedef typename pointer_traits<__node_pointer>::difference_type
34646035553Spatrick                                                              difference_type;
347*4bdff4beSrobert    typedef __rebind_pointer_t<__node_pointer, value_type> pointer;
34846035553Spatrick
34946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
35046035553Spatrick    __forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
35146035553Spatrick
35246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
35346035553Spatrick    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
35446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
35546035553Spatrick    pointer operator->() const {
35646035553Spatrick        return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_);
35746035553Spatrick    }
35846035553Spatrick
35946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
36046035553Spatrick    __forward_list_iterator& operator++()
36146035553Spatrick    {
36246035553Spatrick        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
36346035553Spatrick        return *this;
36446035553Spatrick    }
36546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
36646035553Spatrick    __forward_list_iterator operator++(int)
36746035553Spatrick    {
36846035553Spatrick        __forward_list_iterator __t(*this);
36946035553Spatrick        ++(*this);
37046035553Spatrick        return __t;
37146035553Spatrick    }
37246035553Spatrick
37346035553Spatrick    friend _LIBCPP_INLINE_VISIBILITY
37446035553Spatrick    bool operator==(const __forward_list_iterator& __x,
37546035553Spatrick                    const __forward_list_iterator& __y)
37646035553Spatrick        {return __x.__ptr_ == __y.__ptr_;}
37746035553Spatrick    friend _LIBCPP_INLINE_VISIBILITY
37846035553Spatrick    bool operator!=(const __forward_list_iterator& __x,
37946035553Spatrick                    const __forward_list_iterator& __y)
38046035553Spatrick        {return !(__x == __y);}
38146035553Spatrick};
38246035553Spatrick
38346035553Spatricktemplate <class _NodeConstPtr>
38446035553Spatrickclass _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator
38546035553Spatrick{
38646035553Spatrick    static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), "");
38746035553Spatrick    typedef _NodeConstPtr _NodePtr;
38846035553Spatrick
38946035553Spatrick    typedef __forward_node_traits<_NodePtr>         __traits;
39046035553Spatrick    typedef typename __traits::__node               __node;
39146035553Spatrick    typedef typename __traits::__node_pointer       __node_pointer;
39246035553Spatrick    typedef typename __traits::__begin_node_pointer __begin_node_pointer;
39346035553Spatrick    typedef typename __traits::__iter_node_pointer  __iter_node_pointer;
39446035553Spatrick    typedef typename __traits::__void_pointer       __void_pointer;
39546035553Spatrick
39646035553Spatrick    __iter_node_pointer __ptr_;
39746035553Spatrick
39846035553Spatrick    __begin_node_pointer __get_begin() const {
39946035553Spatrick        return static_cast<__begin_node_pointer>(
40046035553Spatrick                static_cast<__void_pointer>(__ptr_));
40146035553Spatrick    }
40246035553Spatrick    __node_pointer __get_unsafe_node_pointer() const {
40346035553Spatrick        return static_cast<__node_pointer>(
40446035553Spatrick                static_cast<__void_pointer>(__ptr_));
40546035553Spatrick    }
40646035553Spatrick
40746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
40846035553Spatrick    explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
40946035553Spatrick        : __ptr_(nullptr) {}
41046035553Spatrick
41146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
41246035553Spatrick    explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
41346035553Spatrick        : __ptr_(__traits::__as_iter_node(__p)) {}
41446035553Spatrick
41546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
41646035553Spatrick    explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
41746035553Spatrick        : __ptr_(__traits::__as_iter_node(__p)) {}
41846035553Spatrick
41946035553Spatrick
42046035553Spatrick    template<class, class> friend class forward_list;
42146035553Spatrick
42246035553Spatrickpublic:
42346035553Spatrick    typedef forward_iterator_tag                              iterator_category;
42446035553Spatrick    typedef typename __traits::__node_value_type              value_type;
42546035553Spatrick    typedef const value_type&                                 reference;
42646035553Spatrick    typedef typename pointer_traits<__node_pointer>::difference_type
42746035553Spatrick                                                              difference_type;
428*4bdff4beSrobert    typedef __rebind_pointer_t<__node_pointer, const value_type>
42946035553Spatrick                                                              pointer;
43046035553Spatrick
43146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
43246035553Spatrick    __forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
43346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
43446035553Spatrick    __forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
43546035553Spatrick        : __ptr_(__p.__ptr_) {}
43646035553Spatrick
43746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
43846035553Spatrick    reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
43946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
44046035553Spatrick    pointer operator->() const {return pointer_traits<pointer>::pointer_to(
44146035553Spatrick                __get_unsafe_node_pointer()->__value_);}
44246035553Spatrick
44346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
44446035553Spatrick    __forward_list_const_iterator& operator++()
44546035553Spatrick    {
44646035553Spatrick        __ptr_ = __traits::__as_iter_node(__ptr_->__next_);
44746035553Spatrick        return *this;
44846035553Spatrick    }
44946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
45046035553Spatrick    __forward_list_const_iterator operator++(int)
45146035553Spatrick    {
45246035553Spatrick        __forward_list_const_iterator __t(*this);
45346035553Spatrick        ++(*this);
45446035553Spatrick        return __t;
45546035553Spatrick    }
45646035553Spatrick
45746035553Spatrick    friend _LIBCPP_INLINE_VISIBILITY
45846035553Spatrick    bool operator==(const __forward_list_const_iterator& __x,
45946035553Spatrick                    const __forward_list_const_iterator& __y)
46046035553Spatrick        {return __x.__ptr_ == __y.__ptr_;}
46146035553Spatrick    friend _LIBCPP_INLINE_VISIBILITY
46246035553Spatrick    bool operator!=(const __forward_list_const_iterator& __x,
46346035553Spatrick                           const __forward_list_const_iterator& __y)
46446035553Spatrick        {return !(__x == __y);}
46546035553Spatrick};
46646035553Spatrick
46746035553Spatricktemplate <class _Tp, class _Alloc>
46846035553Spatrickclass __forward_list_base
46946035553Spatrick{
47046035553Spatrickprotected:
47146035553Spatrick    typedef _Tp    value_type;
47246035553Spatrick    typedef _Alloc allocator_type;
47346035553Spatrick
47446035553Spatrick    typedef typename allocator_traits<allocator_type>::void_pointer  void_pointer;
47546035553Spatrick    typedef __forward_list_node<value_type, void_pointer>            __node;
476*4bdff4beSrobert    typedef __begin_node_of<value_type, void_pointer>                __begin_node;
477*4bdff4beSrobert    typedef __rebind_alloc<allocator_traits<allocator_type>, __node> __node_allocator;
47846035553Spatrick    typedef allocator_traits<__node_allocator>        __node_traits;
47946035553Spatrick    typedef typename __node_traits::pointer           __node_pointer;
48046035553Spatrick
481*4bdff4beSrobert    typedef __rebind_alloc<allocator_traits<allocator_type>, __begin_node> __begin_node_allocator;
48246035553Spatrick    typedef typename allocator_traits<__begin_node_allocator>::pointer
48346035553Spatrick                                                      __begin_node_pointer;
48446035553Spatrick
48546035553Spatrick    static_assert((!is_same<allocator_type, __node_allocator>::value),
48646035553Spatrick                  "internal allocator type must differ from user-specified "
48746035553Spatrick                  "type; otherwise overload resolution breaks");
48846035553Spatrick
489*4bdff4beSrobert    static_assert(is_same<allocator_type, __rebind_alloc<__node_traits, value_type> >::value,
490*4bdff4beSrobert                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
491*4bdff4beSrobert                  "original allocator");
492*4bdff4beSrobert
49346035553Spatrick    __compressed_pair<__begin_node, __node_allocator> __before_begin_;
49446035553Spatrick
49546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49646035553Spatrick    __begin_node_pointer        __before_begin() _NOEXCEPT
49746035553Spatrick        {return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());}
49846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
49946035553Spatrick    __begin_node_pointer __before_begin() const _NOEXCEPT
50046035553Spatrick        {return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));}
50146035553Spatrick
50246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50346035553Spatrick          __node_allocator& __alloc() _NOEXCEPT
50446035553Spatrick            {return __before_begin_.second();}
50546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
50646035553Spatrick    const __node_allocator& __alloc() const _NOEXCEPT
50746035553Spatrick        {return __before_begin_.second();}
50846035553Spatrick
50946035553Spatrick    typedef __forward_list_iterator<__node_pointer>             iterator;
51046035553Spatrick    typedef __forward_list_const_iterator<__node_pointer>       const_iterator;
51146035553Spatrick
51246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
51346035553Spatrick    __forward_list_base()
51446035553Spatrick        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
51546035553Spatrick        : __before_begin_(__begin_node(), __default_init_tag()) {}
51646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
51746035553Spatrick    explicit __forward_list_base(const allocator_type& __a)
51846035553Spatrick        : __before_begin_(__begin_node(), __node_allocator(__a)) {}
51946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52046035553Spatrick    explicit __forward_list_base(const __node_allocator& __a)
52146035553Spatrick        : __before_begin_(__begin_node(), __a) {}
52246035553Spatrick#ifndef _LIBCPP_CXX03_LANG
52346035553Spatrickpublic:
52446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52546035553Spatrick    __forward_list_base(__forward_list_base&& __x)
52646035553Spatrick        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
52746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
52846035553Spatrick    __forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
52946035553Spatrick#endif // _LIBCPP_CXX03_LANG
53046035553Spatrick
53146035553Spatrickprivate:
53246035553Spatrick    __forward_list_base(const __forward_list_base&);
53346035553Spatrick    __forward_list_base& operator=(const __forward_list_base&);
53446035553Spatrick
53546035553Spatrickpublic:
53646035553Spatrick    ~__forward_list_base();
53746035553Spatrick
53846035553Spatrickprotected:
53946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54046035553Spatrick    void __copy_assign_alloc(const __forward_list_base& __x)
54146035553Spatrick        {__copy_assign_alloc(__x, integral_constant<bool,
54246035553Spatrick              __node_traits::propagate_on_container_copy_assignment::value>());}
54346035553Spatrick
54446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
54546035553Spatrick    void __move_assign_alloc(__forward_list_base& __x)
54646035553Spatrick        _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
54746035553Spatrick                   is_nothrow_move_assignable<__node_allocator>::value)
54846035553Spatrick        {__move_assign_alloc(__x, integral_constant<bool,
54946035553Spatrick              __node_traits::propagate_on_container_move_assignment::value>());}
55046035553Spatrick
55146035553Spatrickpublic:
55246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
55346035553Spatrick    void swap(__forward_list_base& __x)
55446035553Spatrick#if _LIBCPP_STD_VER >= 14
55546035553Spatrick        _NOEXCEPT;
55646035553Spatrick#else
55776d0caaeSpatrick        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
55846035553Spatrick                    __is_nothrow_swappable<__node_allocator>::value);
55946035553Spatrick#endif
56046035553Spatrickprotected:
56146035553Spatrick    void clear() _NOEXCEPT;
56246035553Spatrick
56346035553Spatrickprivate:
56446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
56546035553Spatrick    void __copy_assign_alloc(const __forward_list_base&, false_type) {}
56646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
56746035553Spatrick    void __copy_assign_alloc(const __forward_list_base& __x, true_type)
56846035553Spatrick    {
56946035553Spatrick        if (__alloc() != __x.__alloc())
57046035553Spatrick            clear();
57146035553Spatrick        __alloc() = __x.__alloc();
57246035553Spatrick    }
57346035553Spatrick
57446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
57546035553Spatrick    void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT
57646035553Spatrick        {}
57746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
57846035553Spatrick    void __move_assign_alloc(__forward_list_base& __x, true_type)
57946035553Spatrick        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
58046035553Spatrick        {__alloc() = _VSTD::move(__x.__alloc());}
58146035553Spatrick};
58246035553Spatrick
58346035553Spatrick#ifndef _LIBCPP_CXX03_LANG
58446035553Spatrick
58546035553Spatricktemplate <class _Tp, class _Alloc>
58646035553Spatrickinline
58746035553Spatrick__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
58846035553Spatrick        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
58946035553Spatrick    : __before_begin_(_VSTD::move(__x.__before_begin_))
59046035553Spatrick{
59146035553Spatrick    __x.__before_begin()->__next_ = nullptr;
59246035553Spatrick}
59346035553Spatrick
59446035553Spatricktemplate <class _Tp, class _Alloc>
59546035553Spatrickinline
59646035553Spatrick__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
59746035553Spatrick                                                      const allocator_type& __a)
59846035553Spatrick    : __before_begin_(__begin_node(), __node_allocator(__a))
59946035553Spatrick{
60046035553Spatrick    if (__alloc() == __x.__alloc())
60146035553Spatrick    {
60246035553Spatrick        __before_begin()->__next_ = __x.__before_begin()->__next_;
60346035553Spatrick        __x.__before_begin()->__next_ = nullptr;
60446035553Spatrick    }
60546035553Spatrick}
60646035553Spatrick
60746035553Spatrick#endif // _LIBCPP_CXX03_LANG
60846035553Spatrick
60946035553Spatricktemplate <class _Tp, class _Alloc>
61046035553Spatrick__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
61146035553Spatrick{
61246035553Spatrick    clear();
61346035553Spatrick}
61446035553Spatrick
61546035553Spatricktemplate <class _Tp, class _Alloc>
61646035553Spatrickinline
61746035553Spatrickvoid
61846035553Spatrick__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
61946035553Spatrick#if _LIBCPP_STD_VER >= 14
62046035553Spatrick        _NOEXCEPT
62146035553Spatrick#else
62276d0caaeSpatrick        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
62346035553Spatrick                    __is_nothrow_swappable<__node_allocator>::value)
62446035553Spatrick#endif
62546035553Spatrick{
62676d0caaeSpatrick    _VSTD::__swap_allocator(__alloc(), __x.__alloc(),
62746035553Spatrick            integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
62846035553Spatrick    using _VSTD::swap;
62946035553Spatrick    swap(__before_begin()->__next_, __x.__before_begin()->__next_);
63046035553Spatrick}
63146035553Spatrick
63246035553Spatricktemplate <class _Tp, class _Alloc>
63346035553Spatrickvoid
63446035553Spatrick__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
63546035553Spatrick{
63646035553Spatrick    __node_allocator& __a = __alloc();
63746035553Spatrick    for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
63846035553Spatrick    {
63946035553Spatrick        __node_pointer __next = __p->__next_;
64046035553Spatrick        __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
64146035553Spatrick        __node_traits::deallocate(__a, __p, 1);
64246035553Spatrick        __p = __next;
64346035553Spatrick    }
64446035553Spatrick    __before_begin()->__next_ = nullptr;
64546035553Spatrick}
64646035553Spatrick
64746035553Spatricktemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/>
64846035553Spatrickclass _LIBCPP_TEMPLATE_VIS forward_list
64946035553Spatrick    : private __forward_list_base<_Tp, _Alloc>
65046035553Spatrick{
65146035553Spatrick    typedef __forward_list_base<_Tp, _Alloc> base;
65246035553Spatrick    typedef typename base::__node_allocator  __node_allocator;
65346035553Spatrick    typedef typename base::__node               __node;
65446035553Spatrick    typedef typename base::__node_traits        __node_traits;
65546035553Spatrick    typedef typename base::__node_pointer       __node_pointer;
65646035553Spatrick    typedef typename base::__begin_node_pointer __begin_node_pointer;
65746035553Spatrick
65846035553Spatrickpublic:
65946035553Spatrick    typedef _Tp    value_type;
66046035553Spatrick    typedef _Alloc allocator_type;
66146035553Spatrick
66246035553Spatrick    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
66346035553Spatrick                  "Allocator::value_type must be same type as value_type");
66446035553Spatrick
66546035553Spatrick    typedef value_type&                                                 reference;
66646035553Spatrick    typedef const value_type&                                           const_reference;
66746035553Spatrick    typedef typename allocator_traits<allocator_type>::pointer          pointer;
66846035553Spatrick    typedef typename allocator_traits<allocator_type>::const_pointer    const_pointer;
66946035553Spatrick    typedef typename allocator_traits<allocator_type>::size_type        size_type;
67046035553Spatrick    typedef typename allocator_traits<allocator_type>::difference_type  difference_type;
67146035553Spatrick
67246035553Spatrick    typedef typename base::iterator       iterator;
67346035553Spatrick    typedef typename base::const_iterator const_iterator;
67446035553Spatrick#if _LIBCPP_STD_VER > 17
67546035553Spatrick    typedef size_type                                __remove_return_type;
67646035553Spatrick#else
67746035553Spatrick    typedef void                                     __remove_return_type;
67846035553Spatrick#endif
67946035553Spatrick
68046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
68146035553Spatrick    forward_list()
68246035553Spatrick        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
68346035553Spatrick        {} // = default;
68446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
68546035553Spatrick    explicit forward_list(const allocator_type& __a);
68646035553Spatrick    explicit forward_list(size_type __n);
68746035553Spatrick#if _LIBCPP_STD_VER > 11
68846035553Spatrick    explicit forward_list(size_type __n, const allocator_type& __a);
68946035553Spatrick#endif
69046035553Spatrick    forward_list(size_type __n, const value_type& __v);
691*4bdff4beSrobert
692*4bdff4beSrobert    template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
693*4bdff4beSrobert    forward_list(size_type __n, const value_type& __v, const allocator_type& __a) : base(__a)
694*4bdff4beSrobert    {
695*4bdff4beSrobert        insert_after(cbefore_begin(), __n, __v);
696*4bdff4beSrobert    }
697*4bdff4beSrobert
69846035553Spatrick    template <class _InputIterator>
69946035553Spatrick        forward_list(_InputIterator __f, _InputIterator __l,
700*4bdff4beSrobert                     __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>* = nullptr);
70146035553Spatrick    template <class _InputIterator>
70246035553Spatrick        forward_list(_InputIterator __f, _InputIterator __l,
70346035553Spatrick                     const allocator_type& __a,
704*4bdff4beSrobert                     __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>* = nullptr);
70546035553Spatrick    forward_list(const forward_list& __x);
706*4bdff4beSrobert    forward_list(const forward_list& __x, const __type_identity_t<allocator_type>& __a);
70746035553Spatrick
70846035553Spatrick    forward_list& operator=(const forward_list& __x);
70946035553Spatrick
71046035553Spatrick#ifndef _LIBCPP_CXX03_LANG
71146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
71246035553Spatrick    forward_list(forward_list&& __x)
71346035553Spatrick        _NOEXCEPT_(is_nothrow_move_constructible<base>::value)
71446035553Spatrick        : base(_VSTD::move(__x)) {}
715*4bdff4beSrobert    forward_list(forward_list&& __x, const __type_identity_t<allocator_type>& __a);
71646035553Spatrick
71746035553Spatrick    forward_list(initializer_list<value_type> __il);
71846035553Spatrick    forward_list(initializer_list<value_type> __il, const allocator_type& __a);
71946035553Spatrick
72046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
72146035553Spatrick    forward_list& operator=(forward_list&& __x)
72246035553Spatrick        _NOEXCEPT_(
72346035553Spatrick             __node_traits::propagate_on_container_move_assignment::value &&
72446035553Spatrick             is_nothrow_move_assignable<allocator_type>::value);
72546035553Spatrick
72646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
72746035553Spatrick    forward_list& operator=(initializer_list<value_type> __il);
72846035553Spatrick
72946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
73046035553Spatrick    void assign(initializer_list<value_type> __il);
73146035553Spatrick#endif // _LIBCPP_CXX03_LANG
73246035553Spatrick
73346035553Spatrick    // ~forward_list() = default;
73446035553Spatrick
73546035553Spatrick    template <class _InputIterator>
736*4bdff4beSrobert    __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>
73746035553Spatrick        assign(_InputIterator __f, _InputIterator __l);
73846035553Spatrick    void assign(size_type __n, const value_type& __v);
73946035553Spatrick
74046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
74146035553Spatrick    allocator_type get_allocator() const _NOEXCEPT
74246035553Spatrick        {return allocator_type(base::__alloc());}
74346035553Spatrick
74446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
74546035553Spatrick    iterator       begin() _NOEXCEPT
74646035553Spatrick        {return       iterator(base::__before_begin()->__next_);}
74746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
74846035553Spatrick    const_iterator begin() const _NOEXCEPT
74946035553Spatrick        {return const_iterator(base::__before_begin()->__next_);}
75046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
75146035553Spatrick    iterator       end() _NOEXCEPT
75246035553Spatrick        {return       iterator(nullptr);}
75346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
75446035553Spatrick    const_iterator end() const _NOEXCEPT
75546035553Spatrick        {return const_iterator(nullptr);}
75646035553Spatrick
75746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
75846035553Spatrick    const_iterator cbegin() const _NOEXCEPT
75946035553Spatrick        {return const_iterator(base::__before_begin()->__next_);}
76046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
76146035553Spatrick    const_iterator cend() const _NOEXCEPT
76246035553Spatrick        {return const_iterator(nullptr);}
76346035553Spatrick
76446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
76546035553Spatrick    iterator       before_begin() _NOEXCEPT
76646035553Spatrick        {return       iterator(base::__before_begin());}
76746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
76846035553Spatrick    const_iterator before_begin() const _NOEXCEPT
76946035553Spatrick        {return const_iterator(base::__before_begin());}
77046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
77146035553Spatrick    const_iterator cbefore_begin() const _NOEXCEPT
77246035553Spatrick        {return const_iterator(base::__before_begin());}
77346035553Spatrick
77446035553Spatrick    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
77546035553Spatrick    bool empty() const _NOEXCEPT
77646035553Spatrick        {return base::__before_begin()->__next_ == nullptr;}
77746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
77846035553Spatrick    size_type max_size() const _NOEXCEPT {
77976d0caaeSpatrick        return _VSTD::min<size_type>(
78046035553Spatrick            __node_traits::max_size(base::__alloc()),
78146035553Spatrick            numeric_limits<difference_type>::max());
78246035553Spatrick    }
78346035553Spatrick
78446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
78546035553Spatrick    reference       front()       {return base::__before_begin()->__next_->__value_;}
78646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
78746035553Spatrick    const_reference front() const {return base::__before_begin()->__next_->__value_;}
78846035553Spatrick
78946035553Spatrick#ifndef _LIBCPP_CXX03_LANG
79046035553Spatrick#if _LIBCPP_STD_VER > 14
79146035553Spatrick    template <class... _Args> reference emplace_front(_Args&&... __args);
79246035553Spatrick#else
79346035553Spatrick    template <class... _Args> void      emplace_front(_Args&&... __args);
79446035553Spatrick#endif
79546035553Spatrick    void push_front(value_type&& __v);
79646035553Spatrick#endif // _LIBCPP_CXX03_LANG
79746035553Spatrick    void push_front(const value_type& __v);
79846035553Spatrick
79946035553Spatrick    void pop_front();
80046035553Spatrick
80146035553Spatrick#ifndef _LIBCPP_CXX03_LANG
80246035553Spatrick    template <class... _Args>
80346035553Spatrick        iterator emplace_after(const_iterator __p, _Args&&... __args);
80446035553Spatrick
80546035553Spatrick    iterator insert_after(const_iterator __p, value_type&& __v);
80646035553Spatrick    iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
80746035553Spatrick        {return insert_after(__p, __il.begin(), __il.end());}
80846035553Spatrick#endif // _LIBCPP_CXX03_LANG
80946035553Spatrick    iterator insert_after(const_iterator __p, const value_type& __v);
81046035553Spatrick    iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
81146035553Spatrick    template <class _InputIterator>
81246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
813*4bdff4beSrobert    __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, iterator>
81446035553Spatrick        insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
81546035553Spatrick
81646035553Spatrick    iterator erase_after(const_iterator __p);
81746035553Spatrick    iterator erase_after(const_iterator __f, const_iterator __l);
81846035553Spatrick
81946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
82046035553Spatrick    void swap(forward_list& __x)
82146035553Spatrick#if _LIBCPP_STD_VER >= 14
82246035553Spatrick        _NOEXCEPT
82346035553Spatrick#else
82446035553Spatrick        _NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
82546035553Spatrick                   __is_nothrow_swappable<__node_allocator>::value)
82646035553Spatrick#endif
82746035553Spatrick        {base::swap(__x);}
82846035553Spatrick
82946035553Spatrick    void resize(size_type __n);
83046035553Spatrick    void resize(size_type __n, const value_type& __v);
83146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
83246035553Spatrick    void clear() _NOEXCEPT {base::clear();}
83346035553Spatrick
83446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
83546035553Spatrick    void splice_after(const_iterator __p, forward_list&& __x);
83646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
83746035553Spatrick    void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
83846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
83946035553Spatrick    void splice_after(const_iterator __p, forward_list&& __x,
84046035553Spatrick                      const_iterator __f, const_iterator __l);
84146035553Spatrick    void splice_after(const_iterator __p, forward_list& __x);
84246035553Spatrick    void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
84346035553Spatrick    void splice_after(const_iterator __p, forward_list& __x,
84446035553Spatrick                      const_iterator __f, const_iterator __l);
84546035553Spatrick    __remove_return_type remove(const value_type& __v);
84646035553Spatrick    template <class _Predicate> __remove_return_type remove_if(_Predicate __pred);
84746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
848*4bdff4beSrobert    __remove_return_type unique() { return unique(__equal_to()); }
84946035553Spatrick    template <class _BinaryPredicate> __remove_return_type unique(_BinaryPredicate __binary_pred);
85046035553Spatrick#ifndef _LIBCPP_CXX03_LANG
85146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
85246035553Spatrick    void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
85346035553Spatrick    template <class _Compare>
85446035553Spatrick        _LIBCPP_INLINE_VISIBILITY
85546035553Spatrick        void merge(forward_list&& __x, _Compare __comp)
85646035553Spatrick        {merge(__x, _VSTD::move(__comp));}
85746035553Spatrick#endif // _LIBCPP_CXX03_LANG
85846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
85946035553Spatrick    void merge(forward_list& __x) {merge(__x, __less<value_type>());}
86046035553Spatrick    template <class _Compare> void merge(forward_list& __x, _Compare __comp);
86146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
86246035553Spatrick    void sort() {sort(__less<value_type>());}
86346035553Spatrick    template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp);
86446035553Spatrick    void reverse() _NOEXCEPT;
86546035553Spatrick
86646035553Spatrickprivate:
86746035553Spatrick
86846035553Spatrick#ifndef _LIBCPP_CXX03_LANG
86946035553Spatrick    void __move_assign(forward_list& __x, true_type)
87046035553Spatrick        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
87146035553Spatrick    void __move_assign(forward_list& __x, false_type);
87246035553Spatrick#endif // _LIBCPP_CXX03_LANG
87346035553Spatrick
87446035553Spatrick    template <class _Compare>
87546035553Spatrick        static
87646035553Spatrick        __node_pointer
87746035553Spatrick        __merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
87846035553Spatrick
87946035553Spatrick    template <class _Compare>
88046035553Spatrick        static
88146035553Spatrick        __node_pointer
88246035553Spatrick        __sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
88346035553Spatrick};
88446035553Spatrick
88546035553Spatrick
886*4bdff4beSrobert#if _LIBCPP_STD_VER >= 17
88746035553Spatricktemplate<class _InputIterator,
88876d0caaeSpatrick         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
889*4bdff4beSrobert         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
890*4bdff4beSrobert         class = enable_if_t<__is_allocator<_Alloc>::value>
89146035553Spatrick         >
89246035553Spatrickforward_list(_InputIterator, _InputIterator)
89376d0caaeSpatrick  -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
89446035553Spatrick
89546035553Spatricktemplate<class _InputIterator,
89646035553Spatrick         class _Alloc,
897*4bdff4beSrobert         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
898*4bdff4beSrobert         class = enable_if_t<__is_allocator<_Alloc>::value>
89946035553Spatrick         >
90046035553Spatrickforward_list(_InputIterator, _InputIterator, _Alloc)
90176d0caaeSpatrick  -> forward_list<__iter_value_type<_InputIterator>, _Alloc>;
90246035553Spatrick#endif
90346035553Spatrick
90446035553Spatricktemplate <class _Tp, class _Alloc>
90546035553Spatrickinline
90646035553Spatrickforward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
90746035553Spatrick    : base(__a)
90846035553Spatrick{
90946035553Spatrick}
91046035553Spatrick
91146035553Spatricktemplate <class _Tp, class _Alloc>
91246035553Spatrickforward_list<_Tp, _Alloc>::forward_list(size_type __n)
91346035553Spatrick{
91446035553Spatrick    if (__n > 0)
91546035553Spatrick    {
91646035553Spatrick        __node_allocator& __a = base::__alloc();
91746035553Spatrick        typedef __allocator_destructor<__node_allocator> _Dp;
91846035553Spatrick        unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
91946035553Spatrick        for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
92046035553Spatrick                                                             __p = __p->__next_as_begin())
92146035553Spatrick        {
92246035553Spatrick            __h.reset(__node_traits::allocate(__a, 1));
92346035553Spatrick            __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
92446035553Spatrick            __h->__next_ = nullptr;
92546035553Spatrick            __p->__next_ = __h.release();
92646035553Spatrick        }
92746035553Spatrick    }
92846035553Spatrick}
92946035553Spatrick
93046035553Spatrick#if _LIBCPP_STD_VER > 11
93146035553Spatricktemplate <class _Tp, class _Alloc>
93246035553Spatrickforward_list<_Tp, _Alloc>::forward_list(size_type __n,
93346035553Spatrick                                        const allocator_type& __base_alloc)
93446035553Spatrick    : base ( __base_alloc )
93546035553Spatrick{
93646035553Spatrick    if (__n > 0)
93746035553Spatrick    {
93846035553Spatrick        __node_allocator& __a = base::__alloc();
93946035553Spatrick        typedef __allocator_destructor<__node_allocator> _Dp;
94046035553Spatrick        unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
94146035553Spatrick        for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
94246035553Spatrick                                                             __p = __p->__next_as_begin())
94346035553Spatrick        {
94446035553Spatrick            __h.reset(__node_traits::allocate(__a, 1));
94546035553Spatrick            __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
94646035553Spatrick            __h->__next_ = nullptr;
94746035553Spatrick            __p->__next_ = __h.release();
94846035553Spatrick        }
94946035553Spatrick    }
95046035553Spatrick}
95146035553Spatrick#endif
95246035553Spatrick
95346035553Spatricktemplate <class _Tp, class _Alloc>
95446035553Spatrickforward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
95546035553Spatrick{
95646035553Spatrick    insert_after(cbefore_begin(), __n, __v);
95746035553Spatrick}
95846035553Spatrick
95946035553Spatricktemplate <class _Tp, class _Alloc>
96046035553Spatricktemplate <class _InputIterator>
96146035553Spatrickforward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
962*4bdff4beSrobert                                        __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>*)
96346035553Spatrick{
96446035553Spatrick    insert_after(cbefore_begin(), __f, __l);
96546035553Spatrick}
96646035553Spatrick
96746035553Spatricktemplate <class _Tp, class _Alloc>
96846035553Spatricktemplate <class _InputIterator>
96946035553Spatrickforward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
97046035553Spatrick                                        const allocator_type& __a,
971*4bdff4beSrobert                                        __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>*)
97246035553Spatrick    : base(__a)
97346035553Spatrick{
97446035553Spatrick    insert_after(cbefore_begin(), __f, __l);
97546035553Spatrick}
97646035553Spatrick
97746035553Spatricktemplate <class _Tp, class _Alloc>
97846035553Spatrickforward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
97946035553Spatrick    : base(
98046035553Spatrick          __node_traits::select_on_container_copy_construction(__x.__alloc())) {
98146035553Spatrick  insert_after(cbefore_begin(), __x.begin(), __x.end());
98246035553Spatrick}
98346035553Spatrick
98446035553Spatricktemplate <class _Tp, class _Alloc>
98546035553Spatrickforward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
986*4bdff4beSrobert                                        const __type_identity_t<allocator_type>& __a)
98746035553Spatrick    : base(__a)
98846035553Spatrick{
98946035553Spatrick    insert_after(cbefore_begin(), __x.begin(), __x.end());
99046035553Spatrick}
99146035553Spatrick
99246035553Spatricktemplate <class _Tp, class _Alloc>
99346035553Spatrickforward_list<_Tp, _Alloc>&
99446035553Spatrickforward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
99546035553Spatrick{
996*4bdff4beSrobert    if (this != _VSTD::addressof(__x))
99746035553Spatrick    {
99846035553Spatrick        base::__copy_assign_alloc(__x);
99946035553Spatrick        assign(__x.begin(), __x.end());
100046035553Spatrick    }
100146035553Spatrick    return *this;
100246035553Spatrick}
100346035553Spatrick
100446035553Spatrick#ifndef _LIBCPP_CXX03_LANG
100546035553Spatricktemplate <class _Tp, class _Alloc>
100646035553Spatrickforward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
1007*4bdff4beSrobert                                        const __type_identity_t<allocator_type>& __a)
100846035553Spatrick    : base(_VSTD::move(__x), __a)
100946035553Spatrick{
101046035553Spatrick    if (base::__alloc() != __x.__alloc())
101146035553Spatrick    {
101246035553Spatrick        typedef move_iterator<iterator> _Ip;
101346035553Spatrick        insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
101446035553Spatrick    }
101546035553Spatrick}
101646035553Spatrick
101746035553Spatricktemplate <class _Tp, class _Alloc>
101846035553Spatrickforward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
101946035553Spatrick{
102046035553Spatrick    insert_after(cbefore_begin(), __il.begin(), __il.end());
102146035553Spatrick}
102246035553Spatrick
102346035553Spatricktemplate <class _Tp, class _Alloc>
102446035553Spatrickforward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
102546035553Spatrick                                        const allocator_type& __a)
102646035553Spatrick    : base(__a)
102746035553Spatrick{
102846035553Spatrick    insert_after(cbefore_begin(), __il.begin(), __il.end());
102946035553Spatrick}
103046035553Spatrick
103146035553Spatricktemplate <class _Tp, class _Alloc>
103246035553Spatrickvoid
103346035553Spatrickforward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
103446035553Spatrick    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
103546035553Spatrick{
103646035553Spatrick    clear();
103746035553Spatrick    base::__move_assign_alloc(__x);
103846035553Spatrick    base::__before_begin()->__next_ = __x.__before_begin()->__next_;
103946035553Spatrick    __x.__before_begin()->__next_ = nullptr;
104046035553Spatrick}
104146035553Spatrick
104246035553Spatricktemplate <class _Tp, class _Alloc>
104346035553Spatrickvoid
104446035553Spatrickforward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
104546035553Spatrick{
104646035553Spatrick    if (base::__alloc() == __x.__alloc())
104746035553Spatrick        __move_assign(__x, true_type());
104846035553Spatrick    else
104946035553Spatrick    {
105046035553Spatrick        typedef move_iterator<iterator> _Ip;
105146035553Spatrick        assign(_Ip(__x.begin()), _Ip(__x.end()));
105246035553Spatrick    }
105346035553Spatrick}
105446035553Spatrick
105546035553Spatricktemplate <class _Tp, class _Alloc>
105646035553Spatrickinline
105746035553Spatrickforward_list<_Tp, _Alloc>&
105846035553Spatrickforward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
105946035553Spatrick    _NOEXCEPT_(
106046035553Spatrick             __node_traits::propagate_on_container_move_assignment::value &&
106146035553Spatrick             is_nothrow_move_assignable<allocator_type>::value)
106246035553Spatrick{
106346035553Spatrick    __move_assign(__x, integral_constant<bool,
106446035553Spatrick          __node_traits::propagate_on_container_move_assignment::value>());
106546035553Spatrick    return *this;
106646035553Spatrick}
106746035553Spatrick
106846035553Spatricktemplate <class _Tp, class _Alloc>
106946035553Spatrickinline
107046035553Spatrickforward_list<_Tp, _Alloc>&
107146035553Spatrickforward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
107246035553Spatrick{
107346035553Spatrick    assign(__il.begin(), __il.end());
107446035553Spatrick    return *this;
107546035553Spatrick}
107646035553Spatrick
107746035553Spatrick#endif // _LIBCPP_CXX03_LANG
107846035553Spatrick
107946035553Spatricktemplate <class _Tp, class _Alloc>
108046035553Spatricktemplate <class _InputIterator>
1081*4bdff4beSrobert__enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>
108246035553Spatrickforward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
108346035553Spatrick{
108446035553Spatrick    iterator __i = before_begin();
108546035553Spatrick    iterator __j = _VSTD::next(__i);
108646035553Spatrick    iterator __e = end();
108746035553Spatrick    for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
108846035553Spatrick        *__j = *__f;
108946035553Spatrick    if (__j == __e)
109046035553Spatrick        insert_after(__i, __f, __l);
109146035553Spatrick    else
109246035553Spatrick        erase_after(__i, __e);
109346035553Spatrick}
109446035553Spatrick
109546035553Spatricktemplate <class _Tp, class _Alloc>
109646035553Spatrickvoid
109746035553Spatrickforward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
109846035553Spatrick{
109946035553Spatrick    iterator __i = before_begin();
110046035553Spatrick    iterator __j = _VSTD::next(__i);
110146035553Spatrick    iterator __e = end();
110246035553Spatrick    for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
110346035553Spatrick        *__j = __v;
110446035553Spatrick    if (__j == __e)
110546035553Spatrick        insert_after(__i, __n, __v);
110646035553Spatrick    else
110746035553Spatrick        erase_after(__i, __e);
110846035553Spatrick}
110946035553Spatrick
111046035553Spatrick#ifndef _LIBCPP_CXX03_LANG
111146035553Spatrick
111246035553Spatricktemplate <class _Tp, class _Alloc>
111346035553Spatrickinline
111446035553Spatrickvoid
111546035553Spatrickforward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
111646035553Spatrick{
111746035553Spatrick    assign(__il.begin(), __il.end());
111846035553Spatrick}
111946035553Spatrick
112046035553Spatricktemplate <class _Tp, class _Alloc>
112146035553Spatricktemplate <class... _Args>
112246035553Spatrick#if _LIBCPP_STD_VER > 14
112346035553Spatricktypename forward_list<_Tp, _Alloc>::reference
112446035553Spatrick#else
112546035553Spatrickvoid
112646035553Spatrick#endif
112746035553Spatrickforward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
112846035553Spatrick{
112946035553Spatrick    __node_allocator& __a = base::__alloc();
113046035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
113146035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
113246035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
113346035553Spatrick                                  _VSTD::forward<_Args>(__args)...);
113446035553Spatrick    __h->__next_ = base::__before_begin()->__next_;
113546035553Spatrick    base::__before_begin()->__next_ = __h.release();
113646035553Spatrick#if _LIBCPP_STD_VER > 14
113746035553Spatrick    return base::__before_begin()->__next_->__value_;
113846035553Spatrick#endif
113946035553Spatrick}
114046035553Spatrick
114146035553Spatricktemplate <class _Tp, class _Alloc>
114246035553Spatrickvoid
114346035553Spatrickforward_list<_Tp, _Alloc>::push_front(value_type&& __v)
114446035553Spatrick{
114546035553Spatrick    __node_allocator& __a = base::__alloc();
114646035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
114746035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
114846035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
114946035553Spatrick    __h->__next_ = base::__before_begin()->__next_;
115046035553Spatrick    base::__before_begin()->__next_ = __h.release();
115146035553Spatrick}
115246035553Spatrick
115346035553Spatrick#endif // _LIBCPP_CXX03_LANG
115446035553Spatrick
115546035553Spatricktemplate <class _Tp, class _Alloc>
115646035553Spatrickvoid
115746035553Spatrickforward_list<_Tp, _Alloc>::push_front(const value_type& __v)
115846035553Spatrick{
115946035553Spatrick    __node_allocator& __a = base::__alloc();
116046035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
116146035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
116246035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
116346035553Spatrick    __h->__next_ = base::__before_begin()->__next_;
116446035553Spatrick    base::__before_begin()->__next_ = __h.release();
116546035553Spatrick}
116646035553Spatrick
116746035553Spatricktemplate <class _Tp, class _Alloc>
116846035553Spatrickvoid
116946035553Spatrickforward_list<_Tp, _Alloc>::pop_front()
117046035553Spatrick{
117146035553Spatrick    __node_allocator& __a = base::__alloc();
117246035553Spatrick    __node_pointer __p = base::__before_begin()->__next_;
117346035553Spatrick    base::__before_begin()->__next_ = __p->__next_;
117446035553Spatrick    __node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
117546035553Spatrick    __node_traits::deallocate(__a, __p, 1);
117646035553Spatrick}
117746035553Spatrick
117846035553Spatrick#ifndef _LIBCPP_CXX03_LANG
117946035553Spatrick
118046035553Spatricktemplate <class _Tp, class _Alloc>
118146035553Spatricktemplate <class... _Args>
118246035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
118346035553Spatrickforward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
118446035553Spatrick{
118546035553Spatrick    __begin_node_pointer const __r = __p.__get_begin();
118646035553Spatrick    __node_allocator& __a = base::__alloc();
118746035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
118846035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
118946035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_),
119046035553Spatrick                                  _VSTD::forward<_Args>(__args)...);
119146035553Spatrick    __h->__next_ = __r->__next_;
119246035553Spatrick    __r->__next_ = __h.release();
119346035553Spatrick    return iterator(__r->__next_);
119446035553Spatrick}
119546035553Spatrick
119646035553Spatricktemplate <class _Tp, class _Alloc>
119746035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
119846035553Spatrickforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
119946035553Spatrick{
120046035553Spatrick    __begin_node_pointer const __r = __p.__get_begin();
120146035553Spatrick    __node_allocator& __a = base::__alloc();
120246035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
120346035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
120446035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
120546035553Spatrick    __h->__next_ = __r->__next_;
120646035553Spatrick    __r->__next_ = __h.release();
120746035553Spatrick    return iterator(__r->__next_);
120846035553Spatrick}
120946035553Spatrick
121046035553Spatrick#endif // _LIBCPP_CXX03_LANG
121146035553Spatrick
121246035553Spatricktemplate <class _Tp, class _Alloc>
121346035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
121446035553Spatrickforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
121546035553Spatrick{
121646035553Spatrick    __begin_node_pointer const __r = __p.__get_begin();
121746035553Spatrick    __node_allocator& __a = base::__alloc();
121846035553Spatrick    typedef __allocator_destructor<__node_allocator> _Dp;
121946035553Spatrick    unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
122046035553Spatrick    __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
122146035553Spatrick    __h->__next_ = __r->__next_;
122246035553Spatrick    __r->__next_ = __h.release();
122346035553Spatrick    return iterator(__r->__next_);
122446035553Spatrick}
122546035553Spatrick
122646035553Spatricktemplate <class _Tp, class _Alloc>
122746035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
122846035553Spatrickforward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
122946035553Spatrick                                        const value_type& __v)
123046035553Spatrick{
123146035553Spatrick    __begin_node_pointer __r = __p.__get_begin();
123246035553Spatrick    if (__n > 0)
123346035553Spatrick    {
123446035553Spatrick        __node_allocator& __a = base::__alloc();
123546035553Spatrick        typedef __allocator_destructor<__node_allocator> _Dp;
123646035553Spatrick        unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
123746035553Spatrick        __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
123846035553Spatrick        __node_pointer __first = __h.release();
123946035553Spatrick        __node_pointer __last = __first;
124046035553Spatrick#ifndef _LIBCPP_NO_EXCEPTIONS
124146035553Spatrick        try
124246035553Spatrick        {
124346035553Spatrick#endif // _LIBCPP_NO_EXCEPTIONS
124446035553Spatrick            for (--__n; __n != 0; --__n, __last = __last->__next_)
124546035553Spatrick            {
124646035553Spatrick                __h.reset(__node_traits::allocate(__a, 1));
124746035553Spatrick                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
124846035553Spatrick                __last->__next_ = __h.release();
124946035553Spatrick            }
125046035553Spatrick#ifndef _LIBCPP_NO_EXCEPTIONS
125146035553Spatrick        }
125246035553Spatrick        catch (...)
125346035553Spatrick        {
125446035553Spatrick            while (__first != nullptr)
125546035553Spatrick            {
125646035553Spatrick                __node_pointer __next = __first->__next_;
125746035553Spatrick                __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
125846035553Spatrick                __node_traits::deallocate(__a, __first, 1);
125946035553Spatrick                __first = __next;
126046035553Spatrick            }
126146035553Spatrick            throw;
126246035553Spatrick        }
126346035553Spatrick#endif // _LIBCPP_NO_EXCEPTIONS
126446035553Spatrick        __last->__next_ = __r->__next_;
126546035553Spatrick        __r->__next_ = __first;
126646035553Spatrick        __r = static_cast<__begin_node_pointer>(__last);
126746035553Spatrick    }
126846035553Spatrick    return iterator(__r);
126946035553Spatrick}
127046035553Spatrick
127146035553Spatricktemplate <class _Tp, class _Alloc>
127246035553Spatricktemplate <class _InputIterator>
1273*4bdff4beSrobert__enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, typename forward_list<_Tp, _Alloc>::iterator>
127446035553Spatrickforward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
127546035553Spatrick                                        _InputIterator __f, _InputIterator __l)
127646035553Spatrick{
127746035553Spatrick    __begin_node_pointer __r = __p.__get_begin();
127846035553Spatrick    if (__f != __l)
127946035553Spatrick    {
128046035553Spatrick        __node_allocator& __a = base::__alloc();
128146035553Spatrick        typedef __allocator_destructor<__node_allocator> _Dp;
128246035553Spatrick        unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
128346035553Spatrick        __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
128446035553Spatrick        __node_pointer __first = __h.release();
128546035553Spatrick        __node_pointer __last = __first;
128646035553Spatrick#ifndef _LIBCPP_NO_EXCEPTIONS
128746035553Spatrick        try
128846035553Spatrick        {
128946035553Spatrick#endif // _LIBCPP_NO_EXCEPTIONS
129046035553Spatrick            for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
129146035553Spatrick            {
129246035553Spatrick                __h.reset(__node_traits::allocate(__a, 1));
129346035553Spatrick                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
129446035553Spatrick                __last->__next_ = __h.release();
129546035553Spatrick            }
129646035553Spatrick#ifndef _LIBCPP_NO_EXCEPTIONS
129746035553Spatrick        }
129846035553Spatrick        catch (...)
129946035553Spatrick        {
130046035553Spatrick            while (__first != nullptr)
130146035553Spatrick            {
130246035553Spatrick                __node_pointer __next = __first->__next_;
130346035553Spatrick                __node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
130446035553Spatrick                __node_traits::deallocate(__a, __first, 1);
130546035553Spatrick                __first = __next;
130646035553Spatrick            }
130746035553Spatrick            throw;
130846035553Spatrick        }
130946035553Spatrick#endif // _LIBCPP_NO_EXCEPTIONS
131046035553Spatrick        __last->__next_ = __r->__next_;
131146035553Spatrick        __r->__next_ = __first;
131246035553Spatrick        __r = static_cast<__begin_node_pointer>(__last);
131346035553Spatrick    }
131446035553Spatrick    return iterator(__r);
131546035553Spatrick}
131646035553Spatrick
131746035553Spatricktemplate <class _Tp, class _Alloc>
131846035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
131946035553Spatrickforward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
132046035553Spatrick{
132146035553Spatrick    __begin_node_pointer __p = __f.__get_begin();
132246035553Spatrick    __node_pointer __n = __p->__next_;
132346035553Spatrick    __p->__next_ = __n->__next_;
132446035553Spatrick    __node_allocator& __a = base::__alloc();
132546035553Spatrick    __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
132646035553Spatrick    __node_traits::deallocate(__a, __n, 1);
132746035553Spatrick    return iterator(__p->__next_);
132846035553Spatrick}
132946035553Spatrick
133046035553Spatricktemplate <class _Tp, class _Alloc>
133146035553Spatricktypename forward_list<_Tp, _Alloc>::iterator
133246035553Spatrickforward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
133346035553Spatrick{
133446035553Spatrick    __node_pointer __e = __l.__get_unsafe_node_pointer();
133546035553Spatrick    if (__f != __l)
133646035553Spatrick    {
133746035553Spatrick        __begin_node_pointer __bp = __f.__get_begin();
133846035553Spatrick
133946035553Spatrick        __node_pointer __n = __bp->__next_;
134046035553Spatrick        if (__n != __e)
134146035553Spatrick        {
134246035553Spatrick            __bp->__next_ = __e;
134346035553Spatrick            __node_allocator& __a = base::__alloc();
134446035553Spatrick            do
134546035553Spatrick            {
134646035553Spatrick                __node_pointer __tmp = __n->__next_;
134746035553Spatrick                __node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
134846035553Spatrick                __node_traits::deallocate(__a, __n, 1);
134946035553Spatrick                __n = __tmp;
135046035553Spatrick            } while (__n != __e);
135146035553Spatrick        }
135246035553Spatrick    }
135346035553Spatrick    return iterator(__e);
135446035553Spatrick}
135546035553Spatrick
135646035553Spatricktemplate <class _Tp, class _Alloc>
135746035553Spatrickvoid
135846035553Spatrickforward_list<_Tp, _Alloc>::resize(size_type __n)
135946035553Spatrick{
136046035553Spatrick    size_type __sz = 0;
136146035553Spatrick    iterator __p = before_begin();
136246035553Spatrick    iterator __i = begin();
136346035553Spatrick    iterator __e = end();
136446035553Spatrick    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
136546035553Spatrick        ;
136646035553Spatrick    if (__i != __e)
136746035553Spatrick        erase_after(__p, __e);
136846035553Spatrick    else
136946035553Spatrick    {
137046035553Spatrick        __n -= __sz;
137146035553Spatrick        if (__n > 0)
137246035553Spatrick        {
137346035553Spatrick            __node_allocator& __a = base::__alloc();
137446035553Spatrick            typedef __allocator_destructor<__node_allocator> _Dp;
137546035553Spatrick            unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
137646035553Spatrick            for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
137746035553Spatrick                                                         __ptr = __ptr->__next_as_begin())
137846035553Spatrick            {
137946035553Spatrick                __h.reset(__node_traits::allocate(__a, 1));
138046035553Spatrick                __node_traits::construct(__a, _VSTD::addressof(__h->__value_));
138146035553Spatrick                __h->__next_ = nullptr;
138246035553Spatrick                __ptr->__next_ = __h.release();
138346035553Spatrick            }
138446035553Spatrick        }
138546035553Spatrick    }
138646035553Spatrick}
138746035553Spatrick
138846035553Spatricktemplate <class _Tp, class _Alloc>
138946035553Spatrickvoid
139046035553Spatrickforward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
139146035553Spatrick{
139246035553Spatrick    size_type __sz = 0;
139346035553Spatrick    iterator __p = before_begin();
139446035553Spatrick    iterator __i = begin();
139546035553Spatrick    iterator __e = end();
139646035553Spatrick    for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
139746035553Spatrick        ;
139846035553Spatrick    if (__i != __e)
139946035553Spatrick        erase_after(__p, __e);
140046035553Spatrick    else
140146035553Spatrick    {
140246035553Spatrick        __n -= __sz;
140346035553Spatrick        if (__n > 0)
140446035553Spatrick        {
140546035553Spatrick            __node_allocator& __a = base::__alloc();
140646035553Spatrick            typedef __allocator_destructor<__node_allocator> _Dp;
140746035553Spatrick            unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
140846035553Spatrick            for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
140946035553Spatrick                                                         __ptr = __ptr->__next_as_begin())
141046035553Spatrick            {
141146035553Spatrick                __h.reset(__node_traits::allocate(__a, 1));
141246035553Spatrick                __node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
141346035553Spatrick                __h->__next_ = nullptr;
141446035553Spatrick                __ptr->__next_ = __h.release();
141546035553Spatrick            }
141646035553Spatrick        }
141746035553Spatrick    }
141846035553Spatrick}
141946035553Spatrick
142046035553Spatricktemplate <class _Tp, class _Alloc>
142146035553Spatrickvoid
142246035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
142346035553Spatrick                                        forward_list& __x)
142446035553Spatrick{
142546035553Spatrick    if (!__x.empty())
142646035553Spatrick    {
142746035553Spatrick        if (__p.__get_begin()->__next_ != nullptr)
142846035553Spatrick        {
142946035553Spatrick            const_iterator __lm1 = __x.before_begin();
143046035553Spatrick            while (__lm1.__get_begin()->__next_ != nullptr)
143146035553Spatrick                ++__lm1;
143246035553Spatrick            __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
143346035553Spatrick        }
143446035553Spatrick        __p.__get_begin()->__next_ = __x.__before_begin()->__next_;
143546035553Spatrick        __x.__before_begin()->__next_ = nullptr;
143646035553Spatrick    }
143746035553Spatrick}
143846035553Spatrick
143946035553Spatricktemplate <class _Tp, class _Alloc>
144046035553Spatrickvoid
144146035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
144246035553Spatrick                                        forward_list& /*__other*/,
144346035553Spatrick                                        const_iterator __i)
144446035553Spatrick{
144546035553Spatrick    const_iterator __lm1 = _VSTD::next(__i);
144646035553Spatrick    if (__p != __i && __p != __lm1)
144746035553Spatrick    {
144846035553Spatrick        __i.__get_begin()->__next_ = __lm1.__get_begin()->__next_;
144946035553Spatrick        __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
145046035553Spatrick        __p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer();
145146035553Spatrick    }
145246035553Spatrick}
145346035553Spatrick
145446035553Spatricktemplate <class _Tp, class _Alloc>
145546035553Spatrickvoid
145646035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
145746035553Spatrick                                        forward_list& /*__other*/,
145846035553Spatrick                                        const_iterator __f, const_iterator __l)
145946035553Spatrick{
146046035553Spatrick    if (__f != __l && __p != __f)
146146035553Spatrick    {
146246035553Spatrick        const_iterator __lm1 = __f;
146346035553Spatrick        while (__lm1.__get_begin()->__next_ != __l.__get_begin())
146446035553Spatrick            ++__lm1;
146546035553Spatrick        if (__f != __lm1)
146646035553Spatrick        {
146746035553Spatrick            __lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
146846035553Spatrick            __p.__get_begin()->__next_ = __f.__get_begin()->__next_;
146946035553Spatrick            __f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer();
147046035553Spatrick        }
147146035553Spatrick    }
147246035553Spatrick}
147346035553Spatrick
147446035553Spatricktemplate <class _Tp, class _Alloc>
147546035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
147646035553Spatrickvoid
147746035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
147846035553Spatrick                                        forward_list&& __x)
147946035553Spatrick{
148046035553Spatrick    splice_after(__p, __x);
148146035553Spatrick}
148246035553Spatrick
148346035553Spatricktemplate <class _Tp, class _Alloc>
148446035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
148546035553Spatrickvoid
148646035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
148746035553Spatrick                                        forward_list&& __x,
148846035553Spatrick                                        const_iterator __i)
148946035553Spatrick{
149046035553Spatrick    splice_after(__p, __x, __i);
149146035553Spatrick}
149246035553Spatrick
149346035553Spatricktemplate <class _Tp, class _Alloc>
149446035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
149546035553Spatrickvoid
149646035553Spatrickforward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
149746035553Spatrick                                        forward_list&& __x,
149846035553Spatrick                                        const_iterator __f, const_iterator __l)
149946035553Spatrick{
150046035553Spatrick    splice_after(__p, __x, __f, __l);
150146035553Spatrick}
150246035553Spatrick
150346035553Spatricktemplate <class _Tp, class _Alloc>
150446035553Spatricktypename forward_list<_Tp, _Alloc>::__remove_return_type
150546035553Spatrickforward_list<_Tp, _Alloc>::remove(const value_type& __v)
150646035553Spatrick{
150746035553Spatrick    forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
150846035553Spatrick    typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
150946035553Spatrick    const iterator __e = end();
151046035553Spatrick    for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
151146035553Spatrick    {
151246035553Spatrick        if (__i.__get_begin()->__next_->__value_ == __v)
151346035553Spatrick        {
151446035553Spatrick            ++__count_removed;
151546035553Spatrick            iterator __j = _VSTD::next(__i, 2);
151646035553Spatrick            for (; __j != __e && *__j == __v; ++__j)
151746035553Spatrick                ++__count_removed;
151846035553Spatrick            __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
151946035553Spatrick            if (__j == __e)
152046035553Spatrick                break;
152146035553Spatrick            __i = __j;
152246035553Spatrick        }
152346035553Spatrick        else
152446035553Spatrick            ++__i;
152546035553Spatrick    }
152646035553Spatrick
152746035553Spatrick    return (__remove_return_type) __count_removed;
152846035553Spatrick}
152946035553Spatrick
153046035553Spatricktemplate <class _Tp, class _Alloc>
153146035553Spatricktemplate <class _Predicate>
153246035553Spatricktypename forward_list<_Tp, _Alloc>::__remove_return_type
153346035553Spatrickforward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
153446035553Spatrick{
153546035553Spatrick    forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
153646035553Spatrick    typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
153746035553Spatrick    const iterator __e = end();
153846035553Spatrick    for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
153946035553Spatrick    {
154046035553Spatrick        if (__pred(__i.__get_begin()->__next_->__value_))
154146035553Spatrick        {
154246035553Spatrick            ++__count_removed;
154346035553Spatrick            iterator __j = _VSTD::next(__i, 2);
154446035553Spatrick            for (; __j != __e && __pred(*__j); ++__j)
154546035553Spatrick                ++__count_removed;
154646035553Spatrick            __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
154746035553Spatrick            if (__j == __e)
154846035553Spatrick                break;
154946035553Spatrick            __i = __j;
155046035553Spatrick        }
155146035553Spatrick        else
155246035553Spatrick            ++__i;
155346035553Spatrick    }
155446035553Spatrick
155546035553Spatrick    return (__remove_return_type) __count_removed;
155646035553Spatrick}
155746035553Spatrick
155846035553Spatricktemplate <class _Tp, class _Alloc>
155946035553Spatricktemplate <class _BinaryPredicate>
156046035553Spatricktypename forward_list<_Tp, _Alloc>::__remove_return_type
156146035553Spatrickforward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
156246035553Spatrick{
156346035553Spatrick    forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
156446035553Spatrick    typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
156546035553Spatrick    for (iterator __i = begin(), __e = end(); __i != __e;)
156646035553Spatrick    {
156746035553Spatrick        iterator __j = _VSTD::next(__i);
156846035553Spatrick        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
156946035553Spatrick            ++__count_removed;
157046035553Spatrick        if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
157146035553Spatrick            __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
157246035553Spatrick        __i = __j;
157346035553Spatrick    }
157446035553Spatrick
157546035553Spatrick    return (__remove_return_type) __count_removed;
157646035553Spatrick}
157746035553Spatrick
157846035553Spatricktemplate <class _Tp, class _Alloc>
157946035553Spatricktemplate <class _Compare>
158046035553Spatrickvoid
158146035553Spatrickforward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
158246035553Spatrick{
1583*4bdff4beSrobert    if (this != _VSTD::addressof(__x))
158446035553Spatrick    {
158546035553Spatrick        base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
158646035553Spatrick                                                    __x.__before_begin()->__next_,
158746035553Spatrick                                                    __comp);
158846035553Spatrick        __x.__before_begin()->__next_ = nullptr;
158946035553Spatrick    }
159046035553Spatrick}
159146035553Spatrick
159246035553Spatricktemplate <class _Tp, class _Alloc>
159346035553Spatricktemplate <class _Compare>
159446035553Spatricktypename forward_list<_Tp, _Alloc>::__node_pointer
159546035553Spatrickforward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
159646035553Spatrick                                   _Compare& __comp)
159746035553Spatrick{
159846035553Spatrick    if (__f1 == nullptr)
159946035553Spatrick        return __f2;
160046035553Spatrick    if (__f2 == nullptr)
160146035553Spatrick        return __f1;
160246035553Spatrick    __node_pointer __r;
160346035553Spatrick    if (__comp(__f2->__value_, __f1->__value_))
160446035553Spatrick    {
160546035553Spatrick        __node_pointer __t = __f2;
160646035553Spatrick        while (__t->__next_ != nullptr &&
160746035553Spatrick                             __comp(__t->__next_->__value_, __f1->__value_))
160846035553Spatrick            __t = __t->__next_;
160946035553Spatrick        __r = __f2;
161046035553Spatrick        __f2 = __t->__next_;
161146035553Spatrick        __t->__next_ = __f1;
161246035553Spatrick    }
161346035553Spatrick    else
161446035553Spatrick        __r = __f1;
161546035553Spatrick    __node_pointer __p = __f1;
161646035553Spatrick    __f1 = __f1->__next_;
161746035553Spatrick    while (__f1 != nullptr && __f2 != nullptr)
161846035553Spatrick    {
161946035553Spatrick        if (__comp(__f2->__value_, __f1->__value_))
162046035553Spatrick        {
162146035553Spatrick            __node_pointer __t = __f2;
162246035553Spatrick            while (__t->__next_ != nullptr &&
162346035553Spatrick                                 __comp(__t->__next_->__value_, __f1->__value_))
162446035553Spatrick                __t = __t->__next_;
162546035553Spatrick            __p->__next_ = __f2;
162646035553Spatrick            __f2 = __t->__next_;
162746035553Spatrick            __t->__next_ = __f1;
162846035553Spatrick        }
162946035553Spatrick        __p = __f1;
163046035553Spatrick        __f1 = __f1->__next_;
163146035553Spatrick    }
163246035553Spatrick    if (__f2 != nullptr)
163346035553Spatrick        __p->__next_ = __f2;
163446035553Spatrick    return __r;
163546035553Spatrick}
163646035553Spatrick
163746035553Spatricktemplate <class _Tp, class _Alloc>
163846035553Spatricktemplate <class _Compare>
163946035553Spatrickinline
164046035553Spatrickvoid
164146035553Spatrickforward_list<_Tp, _Alloc>::sort(_Compare __comp)
164246035553Spatrick{
164346035553Spatrick    base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
164446035553Spatrick                                       _VSTD::distance(begin(), end()), __comp);
164546035553Spatrick}
164646035553Spatrick
164746035553Spatricktemplate <class _Tp, class _Alloc>
164846035553Spatricktemplate <class _Compare>
164946035553Spatricktypename forward_list<_Tp, _Alloc>::__node_pointer
165046035553Spatrickforward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
165146035553Spatrick                                  _Compare& __comp)
165246035553Spatrick{
165346035553Spatrick    switch (__sz)
165446035553Spatrick    {
165546035553Spatrick    case 0:
165646035553Spatrick    case 1:
165746035553Spatrick        return __f1;
165846035553Spatrick    case 2:
165946035553Spatrick        if (__comp(__f1->__next_->__value_, __f1->__value_))
166046035553Spatrick        {
166146035553Spatrick            __node_pointer __t = __f1->__next_;
166246035553Spatrick            __t->__next_ = __f1;
166346035553Spatrick            __f1->__next_ = nullptr;
166446035553Spatrick            __f1 = __t;
166546035553Spatrick        }
166646035553Spatrick        return __f1;
166746035553Spatrick    }
166846035553Spatrick    difference_type __sz1 = __sz / 2;
166946035553Spatrick    difference_type __sz2 = __sz - __sz1;
167046035553Spatrick    __node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer();
167146035553Spatrick    __node_pointer __f2 = __t->__next_;
167246035553Spatrick    __t->__next_ = nullptr;
167346035553Spatrick    return __merge(__sort(__f1, __sz1, __comp),
167446035553Spatrick                   __sort(__f2, __sz2, __comp), __comp);
167546035553Spatrick}
167646035553Spatrick
167746035553Spatricktemplate <class _Tp, class _Alloc>
167846035553Spatrickvoid
167946035553Spatrickforward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
168046035553Spatrick{
168146035553Spatrick    __node_pointer __p = base::__before_begin()->__next_;
168246035553Spatrick    if (__p != nullptr)
168346035553Spatrick    {
168446035553Spatrick        __node_pointer __f = __p->__next_;
168546035553Spatrick        __p->__next_ = nullptr;
168646035553Spatrick        while (__f != nullptr)
168746035553Spatrick        {
168846035553Spatrick            __node_pointer __t = __f->__next_;
168946035553Spatrick            __f->__next_ = __p;
169046035553Spatrick            __p = __f;
169146035553Spatrick            __f = __t;
169246035553Spatrick        }
169346035553Spatrick        base::__before_begin()->__next_ = __p;
169446035553Spatrick    }
169546035553Spatrick}
169646035553Spatrick
169746035553Spatricktemplate <class _Tp, class _Alloc>
1698*4bdff4beSrobert_LIBCPP_HIDE_FROM_ABI
169946035553Spatrickbool operator==(const forward_list<_Tp, _Alloc>& __x,
170046035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
170146035553Spatrick{
170246035553Spatrick    typedef forward_list<_Tp, _Alloc> _Cp;
170346035553Spatrick    typedef typename _Cp::const_iterator _Ip;
170446035553Spatrick    _Ip __ix = __x.begin();
170546035553Spatrick    _Ip __ex = __x.end();
170646035553Spatrick    _Ip __iy = __y.begin();
170746035553Spatrick    _Ip __ey = __y.end();
170846035553Spatrick    for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
170946035553Spatrick        if (!(*__ix == *__iy))
171046035553Spatrick            return false;
171146035553Spatrick    return (__ix == __ex) == (__iy == __ey);
171246035553Spatrick}
171346035553Spatrick
171446035553Spatricktemplate <class _Tp, class _Alloc>
171546035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
171646035553Spatrickbool operator!=(const forward_list<_Tp, _Alloc>& __x,
171746035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
171846035553Spatrick{
171946035553Spatrick    return !(__x == __y);
172046035553Spatrick}
172146035553Spatrick
172246035553Spatricktemplate <class _Tp, class _Alloc>
172346035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
172446035553Spatrickbool operator< (const forward_list<_Tp, _Alloc>& __x,
172546035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
172646035553Spatrick{
172746035553Spatrick    return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
172846035553Spatrick                                         __y.begin(), __y.end());
172946035553Spatrick}
173046035553Spatrick
173146035553Spatricktemplate <class _Tp, class _Alloc>
173246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
173346035553Spatrickbool operator> (const forward_list<_Tp, _Alloc>& __x,
173446035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
173546035553Spatrick{
173646035553Spatrick    return __y < __x;
173746035553Spatrick}
173846035553Spatrick
173946035553Spatricktemplate <class _Tp, class _Alloc>
174046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
174146035553Spatrickbool operator>=(const forward_list<_Tp, _Alloc>& __x,
174246035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
174346035553Spatrick{
174446035553Spatrick    return !(__x < __y);
174546035553Spatrick}
174646035553Spatrick
174746035553Spatricktemplate <class _Tp, class _Alloc>
174846035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
174946035553Spatrickbool operator<=(const forward_list<_Tp, _Alloc>& __x,
175046035553Spatrick                const forward_list<_Tp, _Alloc>& __y)
175146035553Spatrick{
175246035553Spatrick    return !(__y < __x);
175346035553Spatrick}
175446035553Spatrick
175546035553Spatricktemplate <class _Tp, class _Alloc>
175646035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
175746035553Spatrickvoid
175846035553Spatrickswap(forward_list<_Tp, _Alloc>& __x, forward_list<_Tp, _Alloc>& __y)
175946035553Spatrick    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
176046035553Spatrick{
176146035553Spatrick    __x.swap(__y);
176246035553Spatrick}
176346035553Spatrick
176446035553Spatrick#if _LIBCPP_STD_VER > 17
176546035553Spatricktemplate <class _Tp, class _Allocator, class _Predicate>
176646035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
1767037e7968Spatrick    typename forward_list<_Tp, _Allocator>::size_type
1768037e7968Spatrick    erase_if(forward_list<_Tp, _Allocator>& __c, _Predicate __pred) {
1769037e7968Spatrick  return __c.remove_if(__pred);
1770037e7968Spatrick}
177146035553Spatrick
177246035553Spatricktemplate <class _Tp, class _Allocator, class _Up>
177346035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
1774037e7968Spatrick    typename forward_list<_Tp, _Allocator>::size_type
1775037e7968Spatrick    erase(forward_list<_Tp, _Allocator>& __c, const _Up& __v) {
1776037e7968Spatrick  return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1777037e7968Spatrick}
177846035553Spatrick#endif
177946035553Spatrick
178046035553Spatrick_LIBCPP_END_NAMESPACE_STD
178146035553Spatrick
1782*4bdff4beSrobert#if _LIBCPP_STD_VER > 14
1783*4bdff4beSrobert_LIBCPP_BEGIN_NAMESPACE_STD
1784*4bdff4beSrobertnamespace pmr {
1785*4bdff4beSroberttemplate <class _ValueT>
1786*4bdff4beSrobertusing forward_list = std::forward_list<_ValueT, polymorphic_allocator<_ValueT>>;
1787*4bdff4beSrobert} // namespace pmr
1788*4bdff4beSrobert_LIBCPP_END_NAMESPACE_STD
1789*4bdff4beSrobert#endif
1790*4bdff4beSrobert
179146035553Spatrick_LIBCPP_POP_MACROS
179246035553Spatrick
1793*4bdff4beSrobert#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1794*4bdff4beSrobert#  include <algorithm>
1795*4bdff4beSrobert#  include <atomic>
1796*4bdff4beSrobert#  include <concepts>
1797*4bdff4beSrobert#  include <functional>
1798*4bdff4beSrobert#  include <iosfwd>
1799*4bdff4beSrobert#  include <iterator>
1800*4bdff4beSrobert#  include <typeinfo>
1801*4bdff4beSrobert#endif
1802*4bdff4beSrobert
180346035553Spatrick#endif // _LIBCPP_FORWARD_LIST
1804