xref: /minix3/external/bsd/libc++/dist/libcxx/include/list (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
14684ddb6SLionel Sambuc// -*- C++ -*-
24684ddb6SLionel Sambuc//===---------------------------- list ------------------------------------===//
34684ddb6SLionel Sambuc//
44684ddb6SLionel Sambuc//                     The LLVM Compiler Infrastructure
54684ddb6SLionel Sambuc//
64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open
74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details.
84684ddb6SLionel Sambuc//
94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===//
104684ddb6SLionel Sambuc
114684ddb6SLionel Sambuc#ifndef _LIBCPP_LIST
124684ddb6SLionel Sambuc#define _LIBCPP_LIST
134684ddb6SLionel Sambuc
144684ddb6SLionel Sambuc/*
154684ddb6SLionel Sambuc    list synopsis
164684ddb6SLionel Sambuc
174684ddb6SLionel Sambucnamespace std
184684ddb6SLionel Sambuc{
194684ddb6SLionel Sambuc
204684ddb6SLionel Sambuctemplate <class T, class Alloc = allocator<T> >
214684ddb6SLionel Sambucclass list
224684ddb6SLionel Sambuc{
234684ddb6SLionel Sambucpublic:
244684ddb6SLionel Sambuc
254684ddb6SLionel Sambuc    // types:
264684ddb6SLionel Sambuc    typedef T value_type;
274684ddb6SLionel Sambuc    typedef Alloc allocator_type;
284684ddb6SLionel Sambuc    typedef typename allocator_type::reference reference;
294684ddb6SLionel Sambuc    typedef typename allocator_type::const_reference const_reference;
304684ddb6SLionel Sambuc    typedef typename allocator_type::pointer pointer;
314684ddb6SLionel Sambuc    typedef typename allocator_type::const_pointer const_pointer;
324684ddb6SLionel Sambuc    typedef implementation-defined iterator;
334684ddb6SLionel Sambuc    typedef implementation-defined const_iterator;
344684ddb6SLionel Sambuc    typedef implementation-defined size_type;
354684ddb6SLionel Sambuc    typedef implementation-defined difference_type;
364684ddb6SLionel Sambuc    typedef reverse_iterator<iterator> reverse_iterator;
374684ddb6SLionel Sambuc    typedef reverse_iterator<const_iterator> const_reverse_iterator;
384684ddb6SLionel Sambuc
394684ddb6SLionel Sambuc    list()
404684ddb6SLionel Sambuc        noexcept(is_nothrow_default_constructible<allocator_type>::value);
414684ddb6SLionel Sambuc    explicit list(const allocator_type& a);
424684ddb6SLionel Sambuc    explicit list(size_type n);
434684ddb6SLionel Sambuc    explicit list(size_type n, const allocator_type& a); // C++14
444684ddb6SLionel Sambuc    list(size_type n, const value_type& value);
454684ddb6SLionel Sambuc    list(size_type n, const value_type& value, const allocator_type& a);
464684ddb6SLionel Sambuc    template <class Iter>
474684ddb6SLionel Sambuc        list(Iter first, Iter last);
484684ddb6SLionel Sambuc    template <class Iter>
494684ddb6SLionel Sambuc        list(Iter first, Iter last, const allocator_type& a);
504684ddb6SLionel Sambuc    list(const list& x);
514684ddb6SLionel Sambuc    list(const list&, const allocator_type& a);
524684ddb6SLionel Sambuc    list(list&& x)
534684ddb6SLionel Sambuc        noexcept(is_nothrow_move_constructible<allocator_type>::value);
544684ddb6SLionel Sambuc    list(list&&, const allocator_type& a);
554684ddb6SLionel Sambuc    list(initializer_list<value_type>);
564684ddb6SLionel Sambuc    list(initializer_list<value_type>, const allocator_type& a);
574684ddb6SLionel Sambuc
584684ddb6SLionel Sambuc    ~list();
594684ddb6SLionel Sambuc
604684ddb6SLionel Sambuc    list& operator=(const list& x);
614684ddb6SLionel Sambuc    list& operator=(list&& x)
624684ddb6SLionel Sambuc        noexcept(
634684ddb6SLionel Sambuc             allocator_type::propagate_on_container_move_assignment::value &&
644684ddb6SLionel Sambuc             is_nothrow_move_assignable<allocator_type>::value);
654684ddb6SLionel Sambuc    list& operator=(initializer_list<value_type>);
664684ddb6SLionel Sambuc    template <class Iter>
674684ddb6SLionel Sambuc        void assign(Iter first, Iter last);
684684ddb6SLionel Sambuc    void assign(size_type n, const value_type& t);
694684ddb6SLionel Sambuc    void assign(initializer_list<value_type>);
704684ddb6SLionel Sambuc
714684ddb6SLionel Sambuc    allocator_type get_allocator() const noexcept;
724684ddb6SLionel Sambuc
734684ddb6SLionel Sambuc    iterator begin() noexcept;
744684ddb6SLionel Sambuc    const_iterator begin() const noexcept;
754684ddb6SLionel Sambuc    iterator end() noexcept;
764684ddb6SLionel Sambuc    const_iterator end() const noexcept;
774684ddb6SLionel Sambuc    reverse_iterator rbegin() noexcept;
784684ddb6SLionel Sambuc    const_reverse_iterator rbegin() const noexcept;
794684ddb6SLionel Sambuc    reverse_iterator rend() noexcept;
804684ddb6SLionel Sambuc    const_reverse_iterator rend() const noexcept;
814684ddb6SLionel Sambuc    const_iterator cbegin() const noexcept;
824684ddb6SLionel Sambuc    const_iterator cend() const noexcept;
834684ddb6SLionel Sambuc    const_reverse_iterator crbegin() const noexcept;
844684ddb6SLionel Sambuc    const_reverse_iterator crend() const noexcept;
854684ddb6SLionel Sambuc
864684ddb6SLionel Sambuc    reference front();
874684ddb6SLionel Sambuc    const_reference front() const;
884684ddb6SLionel Sambuc    reference back();
894684ddb6SLionel Sambuc    const_reference back() const;
904684ddb6SLionel Sambuc
914684ddb6SLionel Sambuc    bool empty() const noexcept;
924684ddb6SLionel Sambuc    size_type size() const noexcept;
934684ddb6SLionel Sambuc    size_type max_size() const noexcept;
944684ddb6SLionel Sambuc
954684ddb6SLionel Sambuc    template <class... Args>
964684ddb6SLionel Sambuc        void emplace_front(Args&&... args);
974684ddb6SLionel Sambuc    void pop_front();
984684ddb6SLionel Sambuc    template <class... Args>
994684ddb6SLionel Sambuc        void emplace_back(Args&&... args);
1004684ddb6SLionel Sambuc    void pop_back();
1014684ddb6SLionel Sambuc    void push_front(const value_type& x);
1024684ddb6SLionel Sambuc    void push_front(value_type&& x);
1034684ddb6SLionel Sambuc    void push_back(const value_type& x);
1044684ddb6SLionel Sambuc    void push_back(value_type&& x);
1054684ddb6SLionel Sambuc    template <class... Args>
1064684ddb6SLionel Sambuc        iterator emplace(const_iterator position, Args&&... args);
1074684ddb6SLionel Sambuc    iterator insert(const_iterator position, const value_type& x);
1084684ddb6SLionel Sambuc    iterator insert(const_iterator position, value_type&& x);
1094684ddb6SLionel Sambuc    iterator insert(const_iterator position, size_type n, const value_type& x);
1104684ddb6SLionel Sambuc    template <class Iter>
1114684ddb6SLionel Sambuc        iterator insert(const_iterator position, Iter first, Iter last);
1124684ddb6SLionel Sambuc    iterator insert(const_iterator position, initializer_list<value_type> il);
1134684ddb6SLionel Sambuc
1144684ddb6SLionel Sambuc    iterator erase(const_iterator position);
1154684ddb6SLionel Sambuc    iterator erase(const_iterator position, const_iterator last);
1164684ddb6SLionel Sambuc
1174684ddb6SLionel Sambuc    void resize(size_type sz);
1184684ddb6SLionel Sambuc    void resize(size_type sz, const value_type& c);
1194684ddb6SLionel Sambuc
1204684ddb6SLionel Sambuc    void swap(list&)
121*0a6a1f1dSLionel Sambuc        noexcept(allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1224684ddb6SLionel Sambuc    void clear() noexcept;
1234684ddb6SLionel Sambuc
1244684ddb6SLionel Sambuc    void splice(const_iterator position, list& x);
1254684ddb6SLionel Sambuc    void splice(const_iterator position, list&& x);
1264684ddb6SLionel Sambuc    void splice(const_iterator position, list& x, const_iterator i);
1274684ddb6SLionel Sambuc    void splice(const_iterator position, list&& x, const_iterator i);
1284684ddb6SLionel Sambuc    void splice(const_iterator position, list& x, const_iterator first,
1294684ddb6SLionel Sambuc                                                  const_iterator last);
1304684ddb6SLionel Sambuc    void splice(const_iterator position, list&& x, const_iterator first,
1314684ddb6SLionel Sambuc                                                  const_iterator last);
1324684ddb6SLionel Sambuc
1334684ddb6SLionel Sambuc    void remove(const value_type& value);
1344684ddb6SLionel Sambuc    template <class Pred> void remove_if(Pred pred);
1354684ddb6SLionel Sambuc    void unique();
1364684ddb6SLionel Sambuc    template <class BinaryPredicate>
1374684ddb6SLionel Sambuc        void unique(BinaryPredicate binary_pred);
1384684ddb6SLionel Sambuc    void merge(list& x);
1394684ddb6SLionel Sambuc    void merge(list&& x);
1404684ddb6SLionel Sambuc    template <class Compare>
1414684ddb6SLionel Sambuc        void merge(list& x, Compare comp);
1424684ddb6SLionel Sambuc    template <class Compare>
1434684ddb6SLionel Sambuc        void merge(list&& x, Compare comp);
1444684ddb6SLionel Sambuc    void sort();
1454684ddb6SLionel Sambuc    template <class Compare>
1464684ddb6SLionel Sambuc        void sort(Compare comp);
1474684ddb6SLionel Sambuc    void reverse() noexcept;
1484684ddb6SLionel Sambuc};
1494684ddb6SLionel Sambuc
1504684ddb6SLionel Sambuctemplate <class T, class Alloc>
1514684ddb6SLionel Sambuc    bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
1524684ddb6SLionel Sambuctemplate <class T, class Alloc>
1534684ddb6SLionel Sambuc    bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
1544684ddb6SLionel Sambuctemplate <class T, class Alloc>
1554684ddb6SLionel Sambuc    bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1564684ddb6SLionel Sambuctemplate <class T, class Alloc>
1574684ddb6SLionel Sambuc    bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
1584684ddb6SLionel Sambuctemplate <class T, class Alloc>
1594684ddb6SLionel Sambuc    bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1604684ddb6SLionel Sambuctemplate <class T, class Alloc>
1614684ddb6SLionel Sambuc    bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1624684ddb6SLionel Sambuc
1634684ddb6SLionel Sambuctemplate <class T, class Alloc>
1644684ddb6SLionel Sambuc    void swap(list<T,Alloc>& x, list<T,Alloc>& y)
1654684ddb6SLionel Sambuc         noexcept(noexcept(x.swap(y)));
1664684ddb6SLionel Sambuc
1674684ddb6SLionel Sambuc}  // std
1684684ddb6SLionel Sambuc
1694684ddb6SLionel Sambuc*/
1704684ddb6SLionel Sambuc
1714684ddb6SLionel Sambuc#include <__config>
1724684ddb6SLionel Sambuc
1734684ddb6SLionel Sambuc#include <memory>
1744684ddb6SLionel Sambuc#include <limits>
1754684ddb6SLionel Sambuc#include <initializer_list>
1764684ddb6SLionel Sambuc#include <iterator>
1774684ddb6SLionel Sambuc#include <algorithm>
1784684ddb6SLionel Sambuc
1794684ddb6SLionel Sambuc#include <__undef_min_max>
1804684ddb6SLionel Sambuc
1814684ddb6SLionel Sambuc#include <__debug>
1824684ddb6SLionel Sambuc
1834684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1844684ddb6SLionel Sambuc#pragma GCC system_header
1854684ddb6SLionel Sambuc#endif
1864684ddb6SLionel Sambuc
1874684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD
1884684ddb6SLionel Sambuc
1894684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr> struct __list_node;
1904684ddb6SLionel Sambuc
1914684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr>
1924684ddb6SLionel Sambucstruct __list_node_base
1934684ddb6SLionel Sambuc{
1944684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
1954684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1964684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> > pointer;
1974684ddb6SLionel Sambuc#else
1984684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
1994684ddb6SLionel Sambuc#endif
2004684ddb6SLionel Sambuc
2014684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
2024684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2034684ddb6SLionel Sambuc        rebind<__list_node_base> __base_pointer;
2044684ddb6SLionel Sambuc#else
2054684ddb6SLionel Sambuc        rebind<__list_node_base>::other __base_pointer;
2064684ddb6SLionel Sambuc#endif
2074684ddb6SLionel Sambuc
2084684ddb6SLionel Sambuc    pointer __prev_;
2094684ddb6SLionel Sambuc    pointer __next_;
2104684ddb6SLionel Sambuc
2114684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
212*0a6a1f1dSLionel Sambuc    __list_node_base() : __prev_(__self()), __next_(__self()) {}
213*0a6a1f1dSLionel Sambuc
214*0a6a1f1dSLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
215*0a6a1f1dSLionel Sambuc    pointer __self()
216*0a6a1f1dSLionel Sambuc    {
217*0a6a1f1dSLionel Sambuc        return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
218*0a6a1f1dSLionel Sambuc    }
2194684ddb6SLionel Sambuc};
2204684ddb6SLionel Sambuc
2214684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr>
2224684ddb6SLionel Sambucstruct __list_node
2234684ddb6SLionel Sambuc    : public __list_node_base<_Tp, _VoidPtr>
2244684ddb6SLionel Sambuc{
2254684ddb6SLionel Sambuc    _Tp __value_;
2264684ddb6SLionel Sambuc};
2274684ddb6SLionel Sambuc
228*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
2294684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc> class __list_imp;
2304684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
2314684ddb6SLionel Sambuc
2324684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr>
2334684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __list_iterator
2344684ddb6SLionel Sambuc{
2354684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
2364684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2374684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
2384684ddb6SLionel Sambuc#else
2394684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
2404684ddb6SLionel Sambuc#endif
2414684ddb6SLionel Sambuc
2424684ddb6SLionel Sambuc    __node_pointer __ptr_;
2434684ddb6SLionel Sambuc
2444684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
2454684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2464684ddb6SLionel Sambuc    explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
2474684ddb6SLionel Sambuc        : __ptr_(__p)
2484684ddb6SLionel Sambuc    {
2494684ddb6SLionel Sambuc        __get_db()->__insert_ic(this, __c);
2504684ddb6SLionel Sambuc    }
2514684ddb6SLionel Sambuc#else
2524684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2534684ddb6SLionel Sambuc    explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
2544684ddb6SLionel Sambuc#endif
2554684ddb6SLionel Sambuc
2564684ddb6SLionel Sambuc
2574684ddb6SLionel Sambuc
2584684ddb6SLionel Sambuc    template<class, class> friend class list;
2594684ddb6SLionel Sambuc    template<class, class> friend class __list_imp;
2604684ddb6SLionel Sambuc    template<class, class> friend class __list_const_iterator;
2614684ddb6SLionel Sambucpublic:
2624684ddb6SLionel Sambuc    typedef bidirectional_iterator_tag       iterator_category;
2634684ddb6SLionel Sambuc    typedef _Tp                              value_type;
2644684ddb6SLionel Sambuc    typedef value_type&                      reference;
2654684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
2664684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
2674684ddb6SLionel Sambuc            rebind<value_type>
2684684ddb6SLionel Sambuc#else
2694684ddb6SLionel Sambuc            rebind<value_type>::other
2704684ddb6SLionel Sambuc#endif
2714684ddb6SLionel Sambuc                                             pointer;
2724684ddb6SLionel Sambuc    typedef typename pointer_traits<pointer>::difference_type difference_type;
2734684ddb6SLionel Sambuc
2744684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2754684ddb6SLionel Sambuc    __list_iterator() _NOEXCEPT : __ptr_(nullptr)
2764684ddb6SLionel Sambuc    {
2774684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
2784684ddb6SLionel Sambuc        __get_db()->__insert_i(this);
2794684ddb6SLionel Sambuc#endif
2804684ddb6SLionel Sambuc    }
2814684ddb6SLionel Sambuc
2824684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
2834684ddb6SLionel Sambuc
2844684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2854684ddb6SLionel Sambuc    __list_iterator(const __list_iterator& __p)
2864684ddb6SLionel Sambuc        : __ptr_(__p.__ptr_)
2874684ddb6SLionel Sambuc    {
2884684ddb6SLionel Sambuc        __get_db()->__iterator_copy(this, &__p);
2894684ddb6SLionel Sambuc    }
2904684ddb6SLionel Sambuc
2914684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2924684ddb6SLionel Sambuc    ~__list_iterator()
2934684ddb6SLionel Sambuc    {
2944684ddb6SLionel Sambuc        __get_db()->__erase_i(this);
2954684ddb6SLionel Sambuc    }
2964684ddb6SLionel Sambuc
2974684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
2984684ddb6SLionel Sambuc    __list_iterator& operator=(const __list_iterator& __p)
2994684ddb6SLionel Sambuc    {
3004684ddb6SLionel Sambuc        if (this != &__p)
3014684ddb6SLionel Sambuc        {
3024684ddb6SLionel Sambuc            __get_db()->__iterator_copy(this, &__p);
3034684ddb6SLionel Sambuc            __ptr_ = __p.__ptr_;
3044684ddb6SLionel Sambuc        }
3054684ddb6SLionel Sambuc        return *this;
3064684ddb6SLionel Sambuc    }
3074684ddb6SLionel Sambuc
3084684ddb6SLionel Sambuc#endif  // _LIBCPP_DEBUG_LEVEL >= 2
3094684ddb6SLionel Sambuc
3104684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3114684ddb6SLionel Sambuc    reference operator*() const
3124684ddb6SLionel Sambuc    {
3134684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
3144684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3154684ddb6SLionel Sambuc                       "Attempted to dereference a non-dereferenceable list::iterator");
3164684ddb6SLionel Sambuc#endif
3174684ddb6SLionel Sambuc        return __ptr_->__value_;
3184684ddb6SLionel Sambuc    }
3194684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3204684ddb6SLionel Sambuc    pointer operator->() const
3214684ddb6SLionel Sambuc    {
3224684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
3234684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3244684ddb6SLionel Sambuc                       "Attempted to dereference a non-dereferenceable list::iterator");
3254684ddb6SLionel Sambuc#endif
3264684ddb6SLionel Sambuc        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
3274684ddb6SLionel Sambuc    }
3284684ddb6SLionel Sambuc
3294684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3304684ddb6SLionel Sambuc    __list_iterator& operator++()
3314684ddb6SLionel Sambuc    {
3324684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
3334684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3344684ddb6SLionel Sambuc                       "Attempted to increment non-incrementable list::iterator");
3354684ddb6SLionel Sambuc#endif
3364684ddb6SLionel Sambuc        __ptr_ = __ptr_->__next_;
3374684ddb6SLionel Sambuc        return *this;
3384684ddb6SLionel Sambuc    }
3394684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3404684ddb6SLionel Sambuc    __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
3414684ddb6SLionel Sambuc
3424684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3434684ddb6SLionel Sambuc    __list_iterator& operator--()
3444684ddb6SLionel Sambuc    {
3454684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
3464684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
3474684ddb6SLionel Sambuc                       "Attempted to decrement non-decrementable list::iterator");
3484684ddb6SLionel Sambuc#endif
3494684ddb6SLionel Sambuc        __ptr_ = __ptr_->__prev_;
3504684ddb6SLionel Sambuc        return *this;
3514684ddb6SLionel Sambuc    }
3524684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3534684ddb6SLionel Sambuc    __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
3544684ddb6SLionel Sambuc
3554684ddb6SLionel Sambuc    friend _LIBCPP_INLINE_VISIBILITY
3564684ddb6SLionel Sambuc    bool operator==(const __list_iterator& __x, const __list_iterator& __y)
3574684ddb6SLionel Sambuc    {
3584684ddb6SLionel Sambuc        return __x.__ptr_ == __y.__ptr_;
3594684ddb6SLionel Sambuc    }
3604684ddb6SLionel Sambuc    friend _LIBCPP_INLINE_VISIBILITY
3614684ddb6SLionel Sambuc     bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
3624684ddb6SLionel Sambuc        {return !(__x == __y);}
3634684ddb6SLionel Sambuc};
3644684ddb6SLionel Sambuc
3654684ddb6SLionel Sambuctemplate <class _Tp, class _VoidPtr>
3664684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
3674684ddb6SLionel Sambuc{
3684684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
3694684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
3704684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
3714684ddb6SLionel Sambuc#else
3724684ddb6SLionel Sambuc        rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
3734684ddb6SLionel Sambuc#endif
3744684ddb6SLionel Sambuc
3754684ddb6SLionel Sambuc    __node_pointer __ptr_;
3764684ddb6SLionel Sambuc
3774684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
3784684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3794684ddb6SLionel Sambuc    explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
3804684ddb6SLionel Sambuc        : __ptr_(__p)
3814684ddb6SLionel Sambuc    {
3824684ddb6SLionel Sambuc        __get_db()->__insert_ic(this, __c);
3834684ddb6SLionel Sambuc    }
3844684ddb6SLionel Sambuc#else
3854684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
3864684ddb6SLionel Sambuc    explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
3874684ddb6SLionel Sambuc#endif
3884684ddb6SLionel Sambuc
3894684ddb6SLionel Sambuc    template<class, class> friend class list;
3904684ddb6SLionel Sambuc    template<class, class> friend class __list_imp;
3914684ddb6SLionel Sambucpublic:
3924684ddb6SLionel Sambuc    typedef bidirectional_iterator_tag       iterator_category;
3934684ddb6SLionel Sambuc    typedef _Tp                              value_type;
3944684ddb6SLionel Sambuc    typedef const value_type&                reference;
3954684ddb6SLionel Sambuc    typedef typename pointer_traits<_VoidPtr>::template
3964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
3974684ddb6SLionel Sambuc            rebind<const value_type>
3984684ddb6SLionel Sambuc#else
3994684ddb6SLionel Sambuc            rebind<const value_type>::other
4004684ddb6SLionel Sambuc#endif
4014684ddb6SLionel Sambuc                                             pointer;
4024684ddb6SLionel Sambuc    typedef typename pointer_traits<pointer>::difference_type difference_type;
4034684ddb6SLionel Sambuc
4044684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4054684ddb6SLionel Sambuc    __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
4064684ddb6SLionel Sambuc    {
4074684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4084684ddb6SLionel Sambuc        __get_db()->__insert_i(this);
4094684ddb6SLionel Sambuc#endif
4104684ddb6SLionel Sambuc    }
4114684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4124684ddb6SLionel Sambuc    __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
4134684ddb6SLionel Sambuc        : __ptr_(__p.__ptr_)
4144684ddb6SLionel Sambuc    {
4154684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4164684ddb6SLionel Sambuc        __get_db()->__iterator_copy(this, &__p);
4174684ddb6SLionel Sambuc#endif
4184684ddb6SLionel Sambuc    }
4194684ddb6SLionel Sambuc
4204684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4214684ddb6SLionel Sambuc
4224684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4234684ddb6SLionel Sambuc    __list_const_iterator(const __list_const_iterator& __p)
4244684ddb6SLionel Sambuc        : __ptr_(__p.__ptr_)
4254684ddb6SLionel Sambuc    {
4264684ddb6SLionel Sambuc        __get_db()->__iterator_copy(this, &__p);
4274684ddb6SLionel Sambuc    }
4284684ddb6SLionel Sambuc
4294684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4304684ddb6SLionel Sambuc    ~__list_const_iterator()
4314684ddb6SLionel Sambuc    {
4324684ddb6SLionel Sambuc        __get_db()->__erase_i(this);
4334684ddb6SLionel Sambuc    }
4344684ddb6SLionel Sambuc
4354684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4364684ddb6SLionel Sambuc    __list_const_iterator& operator=(const __list_const_iterator& __p)
4374684ddb6SLionel Sambuc    {
4384684ddb6SLionel Sambuc        if (this != &__p)
4394684ddb6SLionel Sambuc        {
4404684ddb6SLionel Sambuc            __get_db()->__iterator_copy(this, &__p);
4414684ddb6SLionel Sambuc            __ptr_ = __p.__ptr_;
4424684ddb6SLionel Sambuc        }
4434684ddb6SLionel Sambuc        return *this;
4444684ddb6SLionel Sambuc    }
4454684ddb6SLionel Sambuc
4464684ddb6SLionel Sambuc#endif  // _LIBCPP_DEBUG_LEVEL >= 2
4474684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4484684ddb6SLionel Sambuc    reference operator*() const
4494684ddb6SLionel Sambuc    {
4504684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4514684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
4524684ddb6SLionel Sambuc                       "Attempted to dereference a non-dereferenceable list::const_iterator");
4534684ddb6SLionel Sambuc#endif
4544684ddb6SLionel Sambuc        return __ptr_->__value_;
4554684ddb6SLionel Sambuc    }
4564684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4574684ddb6SLionel Sambuc    pointer operator->() const
4584684ddb6SLionel Sambuc    {
4594684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4604684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
4614684ddb6SLionel Sambuc                       "Attempted to dereference a non-dereferenceable list::iterator");
4624684ddb6SLionel Sambuc#endif
4634684ddb6SLionel Sambuc        return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
4644684ddb6SLionel Sambuc    }
4654684ddb6SLionel Sambuc
4664684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4674684ddb6SLionel Sambuc    __list_const_iterator& operator++()
4684684ddb6SLionel Sambuc    {
4694684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4704684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
4714684ddb6SLionel Sambuc                       "Attempted to increment non-incrementable list::const_iterator");
4724684ddb6SLionel Sambuc#endif
4734684ddb6SLionel Sambuc        __ptr_ = __ptr_->__next_;
4744684ddb6SLionel Sambuc        return *this;
4754684ddb6SLionel Sambuc    }
4764684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4774684ddb6SLionel Sambuc    __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
4784684ddb6SLionel Sambuc
4794684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4804684ddb6SLionel Sambuc    __list_const_iterator& operator--()
4814684ddb6SLionel Sambuc    {
4824684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
4834684ddb6SLionel Sambuc        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
4844684ddb6SLionel Sambuc                       "Attempted to decrement non-decrementable list::const_iterator");
4854684ddb6SLionel Sambuc#endif
4864684ddb6SLionel Sambuc        __ptr_ = __ptr_->__prev_;
4874684ddb6SLionel Sambuc        return *this;
4884684ddb6SLionel Sambuc    }
4894684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
4904684ddb6SLionel Sambuc    __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
4914684ddb6SLionel Sambuc
4924684ddb6SLionel Sambuc    friend _LIBCPP_INLINE_VISIBILITY
4934684ddb6SLionel Sambuc    bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
4944684ddb6SLionel Sambuc    {
4954684ddb6SLionel Sambuc        return __x.__ptr_ == __y.__ptr_;
4964684ddb6SLionel Sambuc    }
4974684ddb6SLionel Sambuc    friend _LIBCPP_INLINE_VISIBILITY
4984684ddb6SLionel Sambuc    bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
4994684ddb6SLionel Sambuc        {return !(__x == __y);}
5004684ddb6SLionel Sambuc};
5014684ddb6SLionel Sambuc
5024684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
5034684ddb6SLionel Sambucclass __list_imp
5044684ddb6SLionel Sambuc{
5054684ddb6SLionel Sambuc    __list_imp(const __list_imp&);
5064684ddb6SLionel Sambuc    __list_imp& operator=(const __list_imp&);
5074684ddb6SLionel Sambucprotected:
5084684ddb6SLionel Sambuc    typedef _Tp                                                     value_type;
5094684ddb6SLionel Sambuc    typedef _Alloc                                                  allocator_type;
5104684ddb6SLionel Sambuc    typedef allocator_traits<allocator_type>                        __alloc_traits;
5114684ddb6SLionel Sambuc    typedef typename __alloc_traits::size_type                      size_type;
5124684ddb6SLionel Sambuc    typedef typename __alloc_traits::void_pointer                   __void_pointer;
5134684ddb6SLionel Sambuc    typedef __list_iterator<value_type, __void_pointer>             iterator;
5144684ddb6SLionel Sambuc    typedef __list_const_iterator<value_type, __void_pointer>       const_iterator;
5154684ddb6SLionel Sambuc    typedef __list_node_base<value_type, __void_pointer>            __node_base;
5164684ddb6SLionel Sambuc    typedef __list_node<value_type, __void_pointer>                 __node;
517*0a6a1f1dSLionel Sambuc    typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
5184684ddb6SLionel Sambuc    typedef allocator_traits<__node_allocator>                       __node_alloc_traits;
5194684ddb6SLionel Sambuc    typedef typename __node_alloc_traits::pointer                    __node_pointer;
5204684ddb6SLionel Sambuc    typedef typename __node_alloc_traits::pointer                    __node_const_pointer;
5214684ddb6SLionel Sambuc    typedef typename __alloc_traits::pointer                         pointer;
5224684ddb6SLionel Sambuc    typedef typename __alloc_traits::const_pointer                   const_pointer;
5234684ddb6SLionel Sambuc    typedef typename __alloc_traits::difference_type                 difference_type;
5244684ddb6SLionel Sambuc
525*0a6a1f1dSLionel Sambuc    typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
5264684ddb6SLionel Sambuc    typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
5274684ddb6SLionel Sambuc
5284684ddb6SLionel Sambuc    __node_base __end_;
5294684ddb6SLionel Sambuc    __compressed_pair<size_type, __node_allocator> __size_alloc_;
5304684ddb6SLionel Sambuc
5314684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5324684ddb6SLionel Sambuc          size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
5334684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5344684ddb6SLionel Sambuc    const size_type& __sz() const _NOEXCEPT
5354684ddb6SLionel Sambuc        {return __size_alloc_.first();}
5364684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5374684ddb6SLionel Sambuc          __node_allocator& __node_alloc() _NOEXCEPT
5384684ddb6SLionel Sambuc          {return __size_alloc_.second();}
5394684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5404684ddb6SLionel Sambuc    const __node_allocator& __node_alloc() const _NOEXCEPT
5414684ddb6SLionel Sambuc        {return __size_alloc_.second();}
5424684ddb6SLionel Sambuc
5434684ddb6SLionel Sambuc    static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
5444684ddb6SLionel Sambuc
5454684ddb6SLionel Sambuc    __list_imp()
5464684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
5474684ddb6SLionel Sambuc    __list_imp(const allocator_type& __a);
5484684ddb6SLionel Sambuc    ~__list_imp();
5494684ddb6SLionel Sambuc    void clear() _NOEXCEPT;
5504684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5514684ddb6SLionel Sambuc    bool empty() const _NOEXCEPT {return __sz() == 0;}
5524684ddb6SLionel Sambuc
5534684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5544684ddb6SLionel Sambuc    iterator begin() _NOEXCEPT
5554684ddb6SLionel Sambuc    {
5564684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
5574684ddb6SLionel Sambuc        return iterator(__end_.__next_, this);
5584684ddb6SLionel Sambuc#else
5594684ddb6SLionel Sambuc        return iterator(__end_.__next_);
5604684ddb6SLionel Sambuc#endif
5614684ddb6SLionel Sambuc    }
5624684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5634684ddb6SLionel Sambuc    const_iterator begin() const  _NOEXCEPT
5644684ddb6SLionel Sambuc    {
5654684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
5664684ddb6SLionel Sambuc        return const_iterator(__end_.__next_, this);
5674684ddb6SLionel Sambuc#else
5684684ddb6SLionel Sambuc        return const_iterator(__end_.__next_);
5694684ddb6SLionel Sambuc#endif
5704684ddb6SLionel Sambuc    }
5714684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5724684ddb6SLionel Sambuc    iterator end() _NOEXCEPT
5734684ddb6SLionel Sambuc    {
5744684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
5754684ddb6SLionel Sambuc        return iterator(static_cast<__node_pointer>(
5764684ddb6SLionel Sambuc                pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
5774684ddb6SLionel Sambuc#else
5784684ddb6SLionel Sambuc        return iterator(static_cast<__node_pointer>(
5794684ddb6SLionel Sambuc                      pointer_traits<__node_base_pointer>::pointer_to(__end_)));
5804684ddb6SLionel Sambuc#endif
5814684ddb6SLionel Sambuc    }
5824684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
5834684ddb6SLionel Sambuc    const_iterator end() const _NOEXCEPT
5844684ddb6SLionel Sambuc    {
5854684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
5864684ddb6SLionel Sambuc        return const_iterator(static_cast<__node_const_pointer>(
5874684ddb6SLionel Sambuc        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
5884684ddb6SLionel Sambuc#else
5894684ddb6SLionel Sambuc        return const_iterator(static_cast<__node_const_pointer>(
5904684ddb6SLionel Sambuc        pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
5914684ddb6SLionel Sambuc#endif
5924684ddb6SLionel Sambuc    }
5934684ddb6SLionel Sambuc
5944684ddb6SLionel Sambuc    void swap(__list_imp& __c)
595*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14
596*0a6a1f1dSLionel Sambuc        _NOEXCEPT;
597*0a6a1f1dSLionel Sambuc#else
598*0a6a1f1dSLionel Sambuc        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
599*0a6a1f1dSLionel Sambuc                    __is_nothrow_swappable<allocator_type>::value);
600*0a6a1f1dSLionel Sambuc#endif
6014684ddb6SLionel Sambuc
6024684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6034684ddb6SLionel Sambuc    void __copy_assign_alloc(const __list_imp& __c)
6044684ddb6SLionel Sambuc        {__copy_assign_alloc(__c, integral_constant<bool,
6054684ddb6SLionel Sambuc                      __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
6064684ddb6SLionel Sambuc
6074684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6084684ddb6SLionel Sambuc    void __move_assign_alloc(__list_imp& __c)
6094684ddb6SLionel Sambuc        _NOEXCEPT_(
6104684ddb6SLionel Sambuc            !__node_alloc_traits::propagate_on_container_move_assignment::value ||
6114684ddb6SLionel Sambuc            is_nothrow_move_assignable<__node_allocator>::value)
6124684ddb6SLionel Sambuc        {__move_assign_alloc(__c, integral_constant<bool,
6134684ddb6SLionel Sambuc                      __node_alloc_traits::propagate_on_container_move_assignment::value>());}
6144684ddb6SLionel Sambuc
6154684ddb6SLionel Sambucprivate:
6164684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6174684ddb6SLionel Sambuc    void __copy_assign_alloc(const __list_imp& __c, true_type)
6184684ddb6SLionel Sambuc        {
6194684ddb6SLionel Sambuc            if (__node_alloc() != __c.__node_alloc())
6204684ddb6SLionel Sambuc                clear();
6214684ddb6SLionel Sambuc            __node_alloc() = __c.__node_alloc();
6224684ddb6SLionel Sambuc        }
6234684ddb6SLionel Sambuc
6244684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6254684ddb6SLionel Sambuc    void __copy_assign_alloc(const __list_imp& __c, false_type)
6264684ddb6SLionel Sambuc        {}
6274684ddb6SLionel Sambuc
6284684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6294684ddb6SLionel Sambuc    void __move_assign_alloc(__list_imp& __c, true_type)
6304684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
6314684ddb6SLionel Sambuc        {
6324684ddb6SLionel Sambuc            __node_alloc() = _VSTD::move(__c.__node_alloc());
6334684ddb6SLionel Sambuc        }
6344684ddb6SLionel Sambuc
6354684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
6364684ddb6SLionel Sambuc    void __move_assign_alloc(__list_imp& __c, false_type)
6374684ddb6SLionel Sambuc        _NOEXCEPT
6384684ddb6SLionel Sambuc        {}
6394684ddb6SLionel Sambuc};
6404684ddb6SLionel Sambuc
6414684ddb6SLionel Sambuc// Unlink nodes [__f, __l]
6424684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
6434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
6444684ddb6SLionel Sambucvoid
6454684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
6464684ddb6SLionel Sambuc    _NOEXCEPT
6474684ddb6SLionel Sambuc{
6484684ddb6SLionel Sambuc    __f->__prev_->__next_ = __l->__next_;
6494684ddb6SLionel Sambuc    __l->__next_->__prev_ = __f->__prev_;
6504684ddb6SLionel Sambuc}
6514684ddb6SLionel Sambuc
6524684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
6534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
6544684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::__list_imp()
6554684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
6564684ddb6SLionel Sambuc    : __size_alloc_(0)
6574684ddb6SLionel Sambuc{
6584684ddb6SLionel Sambuc}
6594684ddb6SLionel Sambuc
6604684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
6614684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
6624684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
6634684ddb6SLionel Sambuc    : __size_alloc_(0, __node_allocator(__a))
6644684ddb6SLionel Sambuc{
6654684ddb6SLionel Sambuc}
6664684ddb6SLionel Sambuc
6674684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
6684684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::~__list_imp()
6694684ddb6SLionel Sambuc{
6704684ddb6SLionel Sambuc    clear();
6714684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
6724684ddb6SLionel Sambuc    __get_db()->__erase_c(this);
6734684ddb6SLionel Sambuc#endif
6744684ddb6SLionel Sambuc}
6754684ddb6SLionel Sambuc
6764684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
6774684ddb6SLionel Sambucvoid
6784684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
6794684ddb6SLionel Sambuc{
6804684ddb6SLionel Sambuc    if (!empty())
6814684ddb6SLionel Sambuc    {
6824684ddb6SLionel Sambuc        __node_allocator& __na = __node_alloc();
6834684ddb6SLionel Sambuc        __node_pointer __f = __end_.__next_;
6844684ddb6SLionel Sambuc        __node_pointer __l = static_cast<__node_pointer>(
6854684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(__end_));
6864684ddb6SLionel Sambuc        __unlink_nodes(__f, __l->__prev_);
6874684ddb6SLionel Sambuc        __sz() = 0;
6884684ddb6SLionel Sambuc        while (__f != __l)
6894684ddb6SLionel Sambuc        {
6904684ddb6SLionel Sambuc            __node_pointer __n = __f;
6914684ddb6SLionel Sambuc            __f = __f->__next_;
6924684ddb6SLionel Sambuc            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
6934684ddb6SLionel Sambuc            __node_alloc_traits::deallocate(__na, __n, 1);
6944684ddb6SLionel Sambuc        }
6954684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
6964684ddb6SLionel Sambuc        __c_node* __c = __get_db()->__find_c_and_lock(this);
6974684ddb6SLionel Sambuc        for (__i_node** __p = __c->end_; __p != __c->beg_; )
6984684ddb6SLionel Sambuc        {
6994684ddb6SLionel Sambuc            --__p;
7004684ddb6SLionel Sambuc            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
7014684ddb6SLionel Sambuc            if (__i->__ptr_ != __l)
7024684ddb6SLionel Sambuc            {
7034684ddb6SLionel Sambuc                (*__p)->__c_ = nullptr;
7044684ddb6SLionel Sambuc                if (--__c->end_ != __p)
7054684ddb6SLionel Sambuc                    memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
7064684ddb6SLionel Sambuc            }
7074684ddb6SLionel Sambuc        }
7084684ddb6SLionel Sambuc        __get_db()->unlock();
7094684ddb6SLionel Sambuc#endif
7104684ddb6SLionel Sambuc    }
7114684ddb6SLionel Sambuc}
7124684ddb6SLionel Sambuc
7134684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
7144684ddb6SLionel Sambucvoid
7154684ddb6SLionel Sambuc__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
716*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14
717*0a6a1f1dSLionel Sambuc        _NOEXCEPT
718*0a6a1f1dSLionel Sambuc#else
719*0a6a1f1dSLionel Sambuc        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
720*0a6a1f1dSLionel Sambuc                    __is_nothrow_swappable<allocator_type>::value)
721*0a6a1f1dSLionel Sambuc#endif
7224684ddb6SLionel Sambuc{
7234684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
7244684ddb6SLionel Sambuc                   this->__node_alloc() == __c.__node_alloc(),
7254684ddb6SLionel Sambuc                   "list::swap: Either propagate_on_container_swap must be true"
7264684ddb6SLionel Sambuc                   " or the allocators must compare equal");
7274684ddb6SLionel Sambuc    using _VSTD::swap;
728*0a6a1f1dSLionel Sambuc    __swap_allocator(__node_alloc(), __c.__node_alloc());
7294684ddb6SLionel Sambuc    swap(__sz(), __c.__sz());
7304684ddb6SLionel Sambuc    swap(__end_, __c.__end_);
7314684ddb6SLionel Sambuc    if (__sz() == 0)
732*0a6a1f1dSLionel Sambuc        __end_.__next_ = __end_.__prev_ = __end_.__self();
7334684ddb6SLionel Sambuc    else
734*0a6a1f1dSLionel Sambuc        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
7354684ddb6SLionel Sambuc    if (__c.__sz() == 0)
736*0a6a1f1dSLionel Sambuc        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
7374684ddb6SLionel Sambuc    else
738*0a6a1f1dSLionel Sambuc        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
739*0a6a1f1dSLionel Sambuc
7404684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
7414684ddb6SLionel Sambuc    __libcpp_db* __db = __get_db();
7424684ddb6SLionel Sambuc    __c_node* __cn1 = __db->__find_c_and_lock(this);
7434684ddb6SLionel Sambuc    __c_node* __cn2 = __db->__find_c(&__c);
7444684ddb6SLionel Sambuc    std::swap(__cn1->beg_, __cn2->beg_);
7454684ddb6SLionel Sambuc    std::swap(__cn1->end_, __cn2->end_);
7464684ddb6SLionel Sambuc    std::swap(__cn1->cap_, __cn2->cap_);
7474684ddb6SLionel Sambuc    for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
7484684ddb6SLionel Sambuc    {
7494684ddb6SLionel Sambuc        --__p;
7504684ddb6SLionel Sambuc        const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
7514684ddb6SLionel Sambuc        if (__i->__ptr_ == static_cast<__node_pointer>(
7524684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
7534684ddb6SLionel Sambuc        {
7544684ddb6SLionel Sambuc            __cn2->__add(*__p);
7554684ddb6SLionel Sambuc            if (--__cn1->end_ != __p)
7564684ddb6SLionel Sambuc                memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
7574684ddb6SLionel Sambuc        }
7584684ddb6SLionel Sambuc        else
7594684ddb6SLionel Sambuc            (*__p)->__c_ = __cn1;
7604684ddb6SLionel Sambuc    }
7614684ddb6SLionel Sambuc    for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
7624684ddb6SLionel Sambuc    {
7634684ddb6SLionel Sambuc        --__p;
7644684ddb6SLionel Sambuc        const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
7654684ddb6SLionel Sambuc        if (__i->__ptr_ == static_cast<__node_pointer>(
7664684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(__end_)))
7674684ddb6SLionel Sambuc        {
7684684ddb6SLionel Sambuc            __cn1->__add(*__p);
7694684ddb6SLionel Sambuc            if (--__cn2->end_ != __p)
7704684ddb6SLionel Sambuc                memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
7714684ddb6SLionel Sambuc        }
7724684ddb6SLionel Sambuc        else
7734684ddb6SLionel Sambuc            (*__p)->__c_ = __cn2;
7744684ddb6SLionel Sambuc    }
7754684ddb6SLionel Sambuc    __db->unlock();
7764684ddb6SLionel Sambuc#endif
7774684ddb6SLionel Sambuc}
7784684ddb6SLionel Sambuc
779*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/>
7804684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY list
7814684ddb6SLionel Sambuc    : private __list_imp<_Tp, _Alloc>
7824684ddb6SLionel Sambuc{
7834684ddb6SLionel Sambuc    typedef __list_imp<_Tp, _Alloc> base;
7844684ddb6SLionel Sambuc    typedef typename base::__node              __node;
7854684ddb6SLionel Sambuc    typedef typename base::__node_allocator    __node_allocator;
7864684ddb6SLionel Sambuc    typedef typename base::__node_pointer      __node_pointer;
7874684ddb6SLionel Sambuc    typedef typename base::__node_alloc_traits __node_alloc_traits;
7884684ddb6SLionel Sambuc    typedef typename base::__node_base         __node_base;
7894684ddb6SLionel Sambuc    typedef typename base::__node_base_pointer __node_base_pointer;
7904684ddb6SLionel Sambuc
7914684ddb6SLionel Sambucpublic:
7924684ddb6SLionel Sambuc    typedef _Tp                                      value_type;
7934684ddb6SLionel Sambuc    typedef _Alloc                                   allocator_type;
7944684ddb6SLionel Sambuc    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
7954684ddb6SLionel Sambuc                  "Invalid allocator::value_type");
7964684ddb6SLionel Sambuc    typedef value_type&                              reference;
7974684ddb6SLionel Sambuc    typedef const value_type&                        const_reference;
7984684ddb6SLionel Sambuc    typedef typename base::pointer                   pointer;
7994684ddb6SLionel Sambuc    typedef typename base::const_pointer             const_pointer;
8004684ddb6SLionel Sambuc    typedef typename base::size_type                 size_type;
8014684ddb6SLionel Sambuc    typedef typename base::difference_type           difference_type;
8024684ddb6SLionel Sambuc    typedef typename base::iterator                  iterator;
8034684ddb6SLionel Sambuc    typedef typename base::const_iterator            const_iterator;
8044684ddb6SLionel Sambuc    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
8054684ddb6SLionel Sambuc    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
8064684ddb6SLionel Sambuc
8074684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8084684ddb6SLionel Sambuc    list()
8094684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
8104684ddb6SLionel Sambuc    {
8114684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
8124684ddb6SLionel Sambuc        __get_db()->__insert_c(this);
8134684ddb6SLionel Sambuc#endif
8144684ddb6SLionel Sambuc    }
8154684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8164684ddb6SLionel Sambuc    explicit list(const allocator_type& __a) : base(__a)
8174684ddb6SLionel Sambuc    {
8184684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
8194684ddb6SLionel Sambuc        __get_db()->__insert_c(this);
8204684ddb6SLionel Sambuc#endif
8214684ddb6SLionel Sambuc    }
8224684ddb6SLionel Sambuc    explicit list(size_type __n);
8234684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11
8244684ddb6SLionel Sambuc    explicit list(size_type __n, const allocator_type& __a);
8254684ddb6SLionel Sambuc#endif
8264684ddb6SLionel Sambuc    list(size_type __n, const value_type& __x);
8274684ddb6SLionel Sambuc    list(size_type __n, const value_type& __x, const allocator_type& __a);
8284684ddb6SLionel Sambuc    template <class _InpIter>
8294684ddb6SLionel Sambuc        list(_InpIter __f, _InpIter __l,
8304684ddb6SLionel Sambuc             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
8314684ddb6SLionel Sambuc    template <class _InpIter>
8324684ddb6SLionel Sambuc        list(_InpIter __f, _InpIter __l, const allocator_type& __a,
8334684ddb6SLionel Sambuc             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
8344684ddb6SLionel Sambuc
8354684ddb6SLionel Sambuc    list(const list& __c);
8364684ddb6SLionel Sambuc    list(const list& __c, const allocator_type& __a);
8374684ddb6SLionel Sambuc    list& operator=(const list& __c);
8384684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8394684ddb6SLionel Sambuc    list(initializer_list<value_type> __il);
8404684ddb6SLionel Sambuc    list(initializer_list<value_type> __il, const allocator_type& __a);
8414684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8424684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
8434684ddb6SLionel Sambuc    list(list&& __c)
8444684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
8454684ddb6SLionel Sambuc    list(list&& __c, const allocator_type& __a);
8464684ddb6SLionel Sambuc    list& operator=(list&& __c)
8474684ddb6SLionel Sambuc        _NOEXCEPT_(
8484684ddb6SLionel Sambuc            __node_alloc_traits::propagate_on_container_move_assignment::value &&
8494684ddb6SLionel Sambuc            is_nothrow_move_assignable<__node_allocator>::value);
8504684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
8514684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8524684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8534684ddb6SLionel Sambuc    list& operator=(initializer_list<value_type> __il)
8544684ddb6SLionel Sambuc        {assign(__il.begin(), __il.end()); return *this;}
8554684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8564684ddb6SLionel Sambuc
8574684ddb6SLionel Sambuc    template <class _InpIter>
8584684ddb6SLionel Sambuc        void assign(_InpIter __f, _InpIter __l,
8594684ddb6SLionel Sambuc             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
8604684ddb6SLionel Sambuc    void assign(size_type __n, const value_type& __x);
8614684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8624684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8634684ddb6SLionel Sambuc    void assign(initializer_list<value_type> __il)
8644684ddb6SLionel Sambuc        {assign(__il.begin(), __il.end());}
8654684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
8664684ddb6SLionel Sambuc
8674684ddb6SLionel Sambuc    allocator_type get_allocator() const _NOEXCEPT;
8684684ddb6SLionel Sambuc
8694684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8704684ddb6SLionel Sambuc    size_type size() const _NOEXCEPT     {return base::__sz();}
8714684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8724684ddb6SLionel Sambuc    bool empty() const _NOEXCEPT         {return base::empty();}
8734684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8744684ddb6SLionel Sambuc    size_type max_size() const _NOEXCEPT
8754684ddb6SLionel Sambuc        {return numeric_limits<difference_type>::max();}
8764684ddb6SLionel Sambuc
8774684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8784684ddb6SLionel Sambuc          iterator begin() _NOEXCEPT        {return base::begin();}
8794684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8804684ddb6SLionel Sambuc    const_iterator begin()  const _NOEXCEPT {return base::begin();}
8814684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8824684ddb6SLionel Sambuc          iterator end() _NOEXCEPT          {return base::end();}
8834684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8844684ddb6SLionel Sambuc    const_iterator end()    const _NOEXCEPT {return base::end();}
8854684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8864684ddb6SLionel Sambuc    const_iterator cbegin() const _NOEXCEPT {return base::begin();}
8874684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8884684ddb6SLionel Sambuc    const_iterator cend()   const _NOEXCEPT {return base::end();}
8894684ddb6SLionel Sambuc
8904684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8914684ddb6SLionel Sambuc          reverse_iterator rbegin() _NOEXCEPT
8924684ddb6SLionel Sambuc            {return       reverse_iterator(end());}
8934684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8944684ddb6SLionel Sambuc    const_reverse_iterator rbegin()  const _NOEXCEPT
8954684ddb6SLionel Sambuc        {return const_reverse_iterator(end());}
8964684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
8974684ddb6SLionel Sambuc          reverse_iterator rend() _NOEXCEPT
8984684ddb6SLionel Sambuc            {return       reverse_iterator(begin());}
8994684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9004684ddb6SLionel Sambuc    const_reverse_iterator rend()    const _NOEXCEPT
9014684ddb6SLionel Sambuc        {return const_reverse_iterator(begin());}
9024684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9034684ddb6SLionel Sambuc    const_reverse_iterator crbegin() const _NOEXCEPT
9044684ddb6SLionel Sambuc        {return const_reverse_iterator(end());}
9054684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9064684ddb6SLionel Sambuc    const_reverse_iterator crend()   const _NOEXCEPT
9074684ddb6SLionel Sambuc        {return const_reverse_iterator(begin());}
9084684ddb6SLionel Sambuc
9094684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9104684ddb6SLionel Sambuc    reference front()
9114684ddb6SLionel Sambuc    {
9124684ddb6SLionel Sambuc        _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
9134684ddb6SLionel Sambuc        return base::__end_.__next_->__value_;
9144684ddb6SLionel Sambuc    }
9154684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9164684ddb6SLionel Sambuc    const_reference front() const
9174684ddb6SLionel Sambuc    {
9184684ddb6SLionel Sambuc        _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
9194684ddb6SLionel Sambuc        return base::__end_.__next_->__value_;
9204684ddb6SLionel Sambuc    }
9214684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9224684ddb6SLionel Sambuc    reference back()
9234684ddb6SLionel Sambuc    {
9244684ddb6SLionel Sambuc        _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
9254684ddb6SLionel Sambuc        return base::__end_.__prev_->__value_;
9264684ddb6SLionel Sambuc    }
9274684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9284684ddb6SLionel Sambuc    const_reference back() const
9294684ddb6SLionel Sambuc    {
9304684ddb6SLionel Sambuc        _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
9314684ddb6SLionel Sambuc        return base::__end_.__prev_->__value_;
9324684ddb6SLionel Sambuc    }
9334684ddb6SLionel Sambuc
9344684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
9354684ddb6SLionel Sambuc    void push_front(value_type&& __x);
9364684ddb6SLionel Sambuc    void push_back(value_type&& __x);
9374684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS
9384684ddb6SLionel Sambuc    template <class... _Args>
9394684ddb6SLionel Sambuc       void emplace_front(_Args&&... __args);
9404684ddb6SLionel Sambuc    template <class... _Args>
9414684ddb6SLionel Sambuc        void emplace_back(_Args&&... __args);
9424684ddb6SLionel Sambuc    template <class... _Args>
9434684ddb6SLionel Sambuc        iterator emplace(const_iterator __p, _Args&&... __args);
9444684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_VARIADICS
9454684ddb6SLionel Sambuc    iterator insert(const_iterator __p, value_type&& __x);
9464684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
9474684ddb6SLionel Sambuc
9484684ddb6SLionel Sambuc    void push_front(const value_type& __x);
9494684ddb6SLionel Sambuc    void push_back(const value_type& __x);
9504684ddb6SLionel Sambuc
9514684ddb6SLionel Sambuc    iterator insert(const_iterator __p, const value_type& __x);
9524684ddb6SLionel Sambuc    iterator insert(const_iterator __p, size_type __n, const value_type& __x);
9534684ddb6SLionel Sambuc    template <class _InpIter>
9544684ddb6SLionel Sambuc        iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
9554684ddb6SLionel Sambuc             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
9564684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
9574684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9584684ddb6SLionel Sambuc    iterator insert(const_iterator __p, initializer_list<value_type> __il)
9594684ddb6SLionel Sambuc        {return insert(__p, __il.begin(), __il.end());}
9604684ddb6SLionel Sambuc#endif   // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
9614684ddb6SLionel Sambuc
9624684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9634684ddb6SLionel Sambuc    void swap(list& __c)
964*0a6a1f1dSLionel Sambuc#if _LIBCPP_STD_VER >= 14
965*0a6a1f1dSLionel Sambuc        _NOEXCEPT
966*0a6a1f1dSLionel Sambuc#else
9674684ddb6SLionel Sambuc        _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
9684684ddb6SLionel Sambuc                   __is_nothrow_swappable<__node_allocator>::value)
969*0a6a1f1dSLionel Sambuc#endif
9704684ddb6SLionel Sambuc        {base::swap(__c);}
9714684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9724684ddb6SLionel Sambuc    void clear() _NOEXCEPT {base::clear();}
9734684ddb6SLionel Sambuc
9744684ddb6SLionel Sambuc    void pop_front();
9754684ddb6SLionel Sambuc    void pop_back();
9764684ddb6SLionel Sambuc
9774684ddb6SLionel Sambuc    iterator erase(const_iterator __p);
9784684ddb6SLionel Sambuc    iterator erase(const_iterator __f, const_iterator __l);
9794684ddb6SLionel Sambuc
9804684ddb6SLionel Sambuc    void resize(size_type __n);
9814684ddb6SLionel Sambuc    void resize(size_type __n, const value_type& __x);
9824684ddb6SLionel Sambuc
9834684ddb6SLionel Sambuc    void splice(const_iterator __p, list& __c);
9844684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
9854684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9864684ddb6SLionel Sambuc    void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
9874684ddb6SLionel Sambuc#endif
9884684ddb6SLionel Sambuc    void splice(const_iterator __p, list& __c, const_iterator __i);
9894684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
9904684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9914684ddb6SLionel Sambuc    void splice(const_iterator __p, list&& __c, const_iterator __i)
9924684ddb6SLionel Sambuc        {splice(__p, __c, __i);}
9934684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
9944684ddb6SLionel Sambuc    void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
9954684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
9964684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
9974684ddb6SLionel Sambuc    void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
9984684ddb6SLionel Sambuc        {splice(__p, __c, __f, __l);}
9994684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
10004684ddb6SLionel Sambuc
10014684ddb6SLionel Sambuc    void remove(const value_type& __x);
10024684ddb6SLionel Sambuc    template <class _Pred> void remove_if(_Pred __pred);
10034684ddb6SLionel Sambuc    void unique();
10044684ddb6SLionel Sambuc    template <class _BinaryPred>
10054684ddb6SLionel Sambuc        void unique(_BinaryPred __binary_pred);
10064684ddb6SLionel Sambuc    void merge(list& __c);
10074684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
10084684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
10094684ddb6SLionel Sambuc    void merge(list&& __c) {merge(__c);}
10104684ddb6SLionel Sambuc#endif
10114684ddb6SLionel Sambuc    template <class _Comp>
10124684ddb6SLionel Sambuc        void merge(list& __c, _Comp __comp);
10134684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
10144684ddb6SLionel Sambuc    template <class _Comp>
10154684ddb6SLionel Sambuc    _LIBCPP_INLINE_VISIBILITY
10164684ddb6SLionel Sambuc        void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
10174684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
10184684ddb6SLionel Sambuc    void sort();
10194684ddb6SLionel Sambuc    template <class _Comp>
10204684ddb6SLionel Sambuc        void sort(_Comp __comp);
10214684ddb6SLionel Sambuc
10224684ddb6SLionel Sambuc    void reverse() _NOEXCEPT;
10234684ddb6SLionel Sambuc
10244684ddb6SLionel Sambuc    bool __invariants() const;
10254684ddb6SLionel Sambuc
10264684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
10274684ddb6SLionel Sambuc
10284684ddb6SLionel Sambuc    bool __dereferenceable(const const_iterator* __i) const;
10294684ddb6SLionel Sambuc    bool __decrementable(const const_iterator* __i) const;
10304684ddb6SLionel Sambuc    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
10314684ddb6SLionel Sambuc    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
10324684ddb6SLionel Sambuc
10334684ddb6SLionel Sambuc#endif  // _LIBCPP_DEBUG_LEVEL >= 2
10344684ddb6SLionel Sambuc
10354684ddb6SLionel Sambucprivate:
10364684ddb6SLionel Sambuc    static void __link_nodes  (__node_pointer __p, __node_pointer __f, __node_pointer __l);
1037*0a6a1f1dSLionel Sambuc    void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
1038*0a6a1f1dSLionel Sambuc    void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
10394684ddb6SLionel Sambuc    iterator __iterator(size_type __n);
10404684ddb6SLionel Sambuc    template <class _Comp>
10414684ddb6SLionel Sambuc        static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
10424684ddb6SLionel Sambuc
10434684ddb6SLionel Sambuc    void __move_assign(list& __c, true_type)
10444684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
10454684ddb6SLionel Sambuc    void __move_assign(list& __c, false_type);
10464684ddb6SLionel Sambuc};
10474684ddb6SLionel Sambuc
10484684ddb6SLionel Sambuc// Link in nodes [__f, __l] just prior to __p
10494684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
10504684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
10514684ddb6SLionel Sambucvoid
10524684ddb6SLionel Sambuclist<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
10534684ddb6SLionel Sambuc{
10544684ddb6SLionel Sambuc    __p->__prev_->__next_ = __f;
10554684ddb6SLionel Sambuc    __f->__prev_ = __p->__prev_;
10564684ddb6SLionel Sambuc    __p->__prev_ = __l;
10574684ddb6SLionel Sambuc    __l->__next_ = __p;
10584684ddb6SLionel Sambuc}
10594684ddb6SLionel Sambuc
1060*0a6a1f1dSLionel Sambuc// Link in nodes [__f, __l] at the front of the list
1061*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Alloc>
1062*0a6a1f1dSLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
1063*0a6a1f1dSLionel Sambucvoid
1064*0a6a1f1dSLionel Sambuclist<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
1065*0a6a1f1dSLionel Sambuc{
1066*0a6a1f1dSLionel Sambuc    __f->__prev_ = base::__end_.__self();
1067*0a6a1f1dSLionel Sambuc    __l->__next_ = base::__end_.__next_;
1068*0a6a1f1dSLionel Sambuc    __l->__next_->__prev_ = __l;
1069*0a6a1f1dSLionel Sambuc    base::__end_.__next_ = __f;
1070*0a6a1f1dSLionel Sambuc}
1071*0a6a1f1dSLionel Sambuc
1072*0a6a1f1dSLionel Sambuc// Link in nodes [__f, __l] at the front of the list
1073*0a6a1f1dSLionel Sambuctemplate <class _Tp, class _Alloc>
1074*0a6a1f1dSLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
1075*0a6a1f1dSLionel Sambucvoid
1076*0a6a1f1dSLionel Sambuclist<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
1077*0a6a1f1dSLionel Sambuc{
1078*0a6a1f1dSLionel Sambuc    __l->__next_ = base::__end_.__self();
1079*0a6a1f1dSLionel Sambuc    __f->__prev_ = base::__end_.__prev_;
1080*0a6a1f1dSLionel Sambuc    __f->__prev_->__next_ = __f;
1081*0a6a1f1dSLionel Sambuc    base::__end_.__prev_ = __l;
1082*0a6a1f1dSLionel Sambuc}
1083*0a6a1f1dSLionel Sambuc
1084*0a6a1f1dSLionel Sambuc
10854684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
10864684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
10874684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
10884684ddb6SLionel Sambuclist<_Tp, _Alloc>::__iterator(size_type __n)
10894684ddb6SLionel Sambuc{
10904684ddb6SLionel Sambuc    return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
10914684ddb6SLionel Sambuc                                   : _VSTD::prev(end(), base::__sz() - __n);
10924684ddb6SLionel Sambuc}
10934684ddb6SLionel Sambuc
10944684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
10954684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(size_type __n)
10964684ddb6SLionel Sambuc{
10974684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
10984684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
10994684ddb6SLionel Sambuc#endif
11004684ddb6SLionel Sambuc    for (; __n > 0; --__n)
11014684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
11024684ddb6SLionel Sambuc        emplace_back();
11034684ddb6SLionel Sambuc#else
11044684ddb6SLionel Sambuc        push_back(value_type());
11054684ddb6SLionel Sambuc#endif
11064684ddb6SLionel Sambuc}
11074684ddb6SLionel Sambuc
11084684ddb6SLionel Sambuc#if _LIBCPP_STD_VER > 11
11094684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11104684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
11114684ddb6SLionel Sambuc{
11124684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11134684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11144684ddb6SLionel Sambuc#endif
11154684ddb6SLionel Sambuc    for (; __n > 0; --__n)
11164684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
11174684ddb6SLionel Sambuc        emplace_back();
11184684ddb6SLionel Sambuc#else
11194684ddb6SLionel Sambuc        push_back(value_type());
11204684ddb6SLionel Sambuc#endif
11214684ddb6SLionel Sambuc}
11224684ddb6SLionel Sambuc#endif
11234684ddb6SLionel Sambuc
11244684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11254684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
11264684ddb6SLionel Sambuc{
11274684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11284684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11294684ddb6SLionel Sambuc#endif
11304684ddb6SLionel Sambuc    for (; __n > 0; --__n)
11314684ddb6SLionel Sambuc        push_back(__x);
11324684ddb6SLionel Sambuc}
11334684ddb6SLionel Sambuc
11344684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11354684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
11364684ddb6SLionel Sambuc    : base(__a)
11374684ddb6SLionel Sambuc{
11384684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11394684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11404684ddb6SLionel Sambuc#endif
11414684ddb6SLionel Sambuc    for (; __n > 0; --__n)
11424684ddb6SLionel Sambuc        push_back(__x);
11434684ddb6SLionel Sambuc}
11444684ddb6SLionel Sambuc
11454684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11464684ddb6SLionel Sambuctemplate <class _InpIter>
11474684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
11484684ddb6SLionel Sambuc                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
11494684ddb6SLionel Sambuc{
11504684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11514684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11524684ddb6SLionel Sambuc#endif
11534684ddb6SLionel Sambuc    for (; __f != __l; ++__f)
11544684ddb6SLionel Sambuc        push_back(*__f);
11554684ddb6SLionel Sambuc}
11564684ddb6SLionel Sambuc
11574684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11584684ddb6SLionel Sambuctemplate <class _InpIter>
11594684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
11604684ddb6SLionel Sambuc                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
11614684ddb6SLionel Sambuc    : base(__a)
11624684ddb6SLionel Sambuc{
11634684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11644684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11654684ddb6SLionel Sambuc#endif
11664684ddb6SLionel Sambuc    for (; __f != __l; ++__f)
11674684ddb6SLionel Sambuc        push_back(*__f);
11684684ddb6SLionel Sambuc}
11694684ddb6SLionel Sambuc
11704684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11714684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(const list& __c)
11724684ddb6SLionel Sambuc    : base(allocator_type(
11734684ddb6SLionel Sambuc           __node_alloc_traits::select_on_container_copy_construction(
11744684ddb6SLionel Sambuc                __c.__node_alloc())))
11754684ddb6SLionel Sambuc{
11764684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11774684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11784684ddb6SLionel Sambuc#endif
11794684ddb6SLionel Sambuc    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
11804684ddb6SLionel Sambuc        push_back(*__i);
11814684ddb6SLionel Sambuc}
11824684ddb6SLionel Sambuc
11834684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11844684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
11854684ddb6SLionel Sambuc    : base(__a)
11864684ddb6SLionel Sambuc{
11874684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
11884684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
11894684ddb6SLionel Sambuc#endif
11904684ddb6SLionel Sambuc    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
11914684ddb6SLionel Sambuc        push_back(*__i);
11924684ddb6SLionel Sambuc}
11934684ddb6SLionel Sambuc
11944684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
11954684ddb6SLionel Sambuc
11964684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
11974684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
11984684ddb6SLionel Sambuc    : base(__a)
11994684ddb6SLionel Sambuc{
12004684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
12014684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
12024684ddb6SLionel Sambuc#endif
12034684ddb6SLionel Sambuc    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
12044684ddb6SLionel Sambuc            __e = __il.end(); __i != __e; ++__i)
12054684ddb6SLionel Sambuc        push_back(*__i);
12064684ddb6SLionel Sambuc}
12074684ddb6SLionel Sambuc
12084684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12094684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(initializer_list<value_type> __il)
12104684ddb6SLionel Sambuc{
12114684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
12124684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
12134684ddb6SLionel Sambuc#endif
12144684ddb6SLionel Sambuc    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
12154684ddb6SLionel Sambuc            __e = __il.end(); __i != __e; ++__i)
12164684ddb6SLionel Sambuc        push_back(*__i);
12174684ddb6SLionel Sambuc}
12184684ddb6SLionel Sambuc
12194684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
12204684ddb6SLionel Sambuc
12214684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12224684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
12234684ddb6SLionel Sambuclist<_Tp, _Alloc>&
12244684ddb6SLionel Sambuclist<_Tp, _Alloc>::operator=(const list& __c)
12254684ddb6SLionel Sambuc{
12264684ddb6SLionel Sambuc    if (this != &__c)
12274684ddb6SLionel Sambuc    {
12284684ddb6SLionel Sambuc        base::__copy_assign_alloc(__c);
12294684ddb6SLionel Sambuc        assign(__c.begin(), __c.end());
12304684ddb6SLionel Sambuc    }
12314684ddb6SLionel Sambuc    return *this;
12324684ddb6SLionel Sambuc}
12334684ddb6SLionel Sambuc
12344684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
12354684ddb6SLionel Sambuc
12364684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12374684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
12384684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(list&& __c)
12394684ddb6SLionel Sambuc    _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
12404684ddb6SLionel Sambuc    : base(allocator_type(_VSTD::move(__c.__node_alloc())))
12414684ddb6SLionel Sambuc{
12424684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
12434684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
12444684ddb6SLionel Sambuc#endif
12454684ddb6SLionel Sambuc    splice(end(), __c);
12464684ddb6SLionel Sambuc}
12474684ddb6SLionel Sambuc
12484684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12494684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
12504684ddb6SLionel Sambuclist<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
12514684ddb6SLionel Sambuc    : base(__a)
12524684ddb6SLionel Sambuc{
12534684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
12544684ddb6SLionel Sambuc    __get_db()->__insert_c(this);
12554684ddb6SLionel Sambuc#endif
12564684ddb6SLionel Sambuc    if (__a == __c.get_allocator())
12574684ddb6SLionel Sambuc        splice(end(), __c);
12584684ddb6SLionel Sambuc    else
12594684ddb6SLionel Sambuc    {
12604684ddb6SLionel Sambuc        typedef move_iterator<iterator> _Ip;
12614684ddb6SLionel Sambuc        assign(_Ip(__c.begin()), _Ip(__c.end()));
12624684ddb6SLionel Sambuc    }
12634684ddb6SLionel Sambuc}
12644684ddb6SLionel Sambuc
12654684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12664684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
12674684ddb6SLionel Sambuclist<_Tp, _Alloc>&
12684684ddb6SLionel Sambuclist<_Tp, _Alloc>::operator=(list&& __c)
12694684ddb6SLionel Sambuc        _NOEXCEPT_(
12704684ddb6SLionel Sambuc            __node_alloc_traits::propagate_on_container_move_assignment::value &&
12714684ddb6SLionel Sambuc            is_nothrow_move_assignable<__node_allocator>::value)
12724684ddb6SLionel Sambuc{
12734684ddb6SLionel Sambuc    __move_assign(__c, integral_constant<bool,
12744684ddb6SLionel Sambuc          __node_alloc_traits::propagate_on_container_move_assignment::value>());
12754684ddb6SLionel Sambuc    return *this;
12764684ddb6SLionel Sambuc}
12774684ddb6SLionel Sambuc
12784684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12794684ddb6SLionel Sambucvoid
12804684ddb6SLionel Sambuclist<_Tp, _Alloc>::__move_assign(list& __c, false_type)
12814684ddb6SLionel Sambuc{
12824684ddb6SLionel Sambuc    if (base::__node_alloc() != __c.__node_alloc())
12834684ddb6SLionel Sambuc    {
12844684ddb6SLionel Sambuc        typedef move_iterator<iterator> _Ip;
12854684ddb6SLionel Sambuc        assign(_Ip(__c.begin()), _Ip(__c.end()));
12864684ddb6SLionel Sambuc    }
12874684ddb6SLionel Sambuc    else
12884684ddb6SLionel Sambuc        __move_assign(__c, true_type());
12894684ddb6SLionel Sambuc}
12904684ddb6SLionel Sambuc
12914684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
12924684ddb6SLionel Sambucvoid
12934684ddb6SLionel Sambuclist<_Tp, _Alloc>::__move_assign(list& __c, true_type)
12944684ddb6SLionel Sambuc        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
12954684ddb6SLionel Sambuc{
12964684ddb6SLionel Sambuc    clear();
12974684ddb6SLionel Sambuc    base::__move_assign_alloc(__c);
12984684ddb6SLionel Sambuc    splice(end(), __c);
12994684ddb6SLionel Sambuc}
13004684ddb6SLionel Sambuc
13014684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
13024684ddb6SLionel Sambuc
13034684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
13044684ddb6SLionel Sambuctemplate <class _InpIter>
13054684ddb6SLionel Sambucvoid
13064684ddb6SLionel Sambuclist<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
13074684ddb6SLionel Sambuc                          typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
13084684ddb6SLionel Sambuc{
13094684ddb6SLionel Sambuc    iterator __i = begin();
13104684ddb6SLionel Sambuc    iterator __e = end();
13114684ddb6SLionel Sambuc    for (; __f != __l && __i != __e; ++__f, ++__i)
13124684ddb6SLionel Sambuc        *__i = *__f;
13134684ddb6SLionel Sambuc    if (__i == __e)
13144684ddb6SLionel Sambuc        insert(__e, __f, __l);
13154684ddb6SLionel Sambuc    else
13164684ddb6SLionel Sambuc        erase(__i, __e);
13174684ddb6SLionel Sambuc}
13184684ddb6SLionel Sambuc
13194684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
13204684ddb6SLionel Sambucvoid
13214684ddb6SLionel Sambuclist<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
13224684ddb6SLionel Sambuc{
13234684ddb6SLionel Sambuc    iterator __i = begin();
13244684ddb6SLionel Sambuc    iterator __e = end();
13254684ddb6SLionel Sambuc    for (; __n > 0 && __i != __e; --__n, ++__i)
13264684ddb6SLionel Sambuc        *__i = __x;
13274684ddb6SLionel Sambuc    if (__i == __e)
13284684ddb6SLionel Sambuc        insert(__e, __n, __x);
13294684ddb6SLionel Sambuc    else
13304684ddb6SLionel Sambuc        erase(__i, __e);
13314684ddb6SLionel Sambuc}
13324684ddb6SLionel Sambuc
13334684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
13344684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
13354684ddb6SLionel Sambuc_Alloc
13364684ddb6SLionel Sambuclist<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
13374684ddb6SLionel Sambuc{
13384684ddb6SLionel Sambuc    return allocator_type(base::__node_alloc());
13394684ddb6SLionel Sambuc}
13404684ddb6SLionel Sambuc
13414684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
13424684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
13434684ddb6SLionel Sambuclist<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
13444684ddb6SLionel Sambuc{
13454684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
13464684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
13474684ddb6SLionel Sambuc        "list::insert(iterator, x) called with an iterator not"
13484684ddb6SLionel Sambuc        " referring to this list");
13494684ddb6SLionel Sambuc#endif
13504684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
13514684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
13524684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
13534684ddb6SLionel Sambuc    __hold->__prev_ = 0;
13544684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
13554684ddb6SLionel Sambuc    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
13564684ddb6SLionel Sambuc    ++base::__sz();
13574684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
13584684ddb6SLionel Sambuc    return iterator(__hold.release(), this);
13594684ddb6SLionel Sambuc#else
13604684ddb6SLionel Sambuc    return iterator(__hold.release());
13614684ddb6SLionel Sambuc#endif
13624684ddb6SLionel Sambuc}
13634684ddb6SLionel Sambuc
13644684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
13654684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
13664684ddb6SLionel Sambuclist<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
13674684ddb6SLionel Sambuc{
13684684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
13694684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
13704684ddb6SLionel Sambuc        "list::insert(iterator, n, x) called with an iterator not"
13714684ddb6SLionel Sambuc        " referring to this list");
13724684ddb6SLionel Sambuc    iterator __r(__p.__ptr_, this);
13734684ddb6SLionel Sambuc#else
13744684ddb6SLionel Sambuc    iterator __r(__p.__ptr_);
13754684ddb6SLionel Sambuc#endif
13764684ddb6SLionel Sambuc    if (__n > 0)
13774684ddb6SLionel Sambuc    {
13784684ddb6SLionel Sambuc        size_type __ds = 0;
13794684ddb6SLionel Sambuc        __node_allocator& __na = base::__node_alloc();
13804684ddb6SLionel Sambuc        typedef __allocator_destructor<__node_allocator> _Dp;
13814684ddb6SLionel Sambuc        unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
13824684ddb6SLionel Sambuc        __hold->__prev_ = 0;
13834684ddb6SLionel Sambuc        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
13844684ddb6SLionel Sambuc        ++__ds;
13854684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
13864684ddb6SLionel Sambuc        __r = iterator(__hold.get(), this);
13874684ddb6SLionel Sambuc#else
13884684ddb6SLionel Sambuc        __r = iterator(__hold.get());
13894684ddb6SLionel Sambuc#endif
13904684ddb6SLionel Sambuc        __hold.release();
13914684ddb6SLionel Sambuc        iterator __e = __r;
13924684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
13934684ddb6SLionel Sambuc        try
13944684ddb6SLionel Sambuc        {
13954684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
13964684ddb6SLionel Sambuc            for (--__n; __n != 0; --__n, ++__e, ++__ds)
13974684ddb6SLionel Sambuc            {
13984684ddb6SLionel Sambuc                __hold.reset(__node_alloc_traits::allocate(__na, 1));
13994684ddb6SLionel Sambuc                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14004684ddb6SLionel Sambuc                __e.__ptr_->__next_ = __hold.get();
14014684ddb6SLionel Sambuc                __hold->__prev_ = __e.__ptr_;
14024684ddb6SLionel Sambuc                __hold.release();
14034684ddb6SLionel Sambuc            }
14044684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
14054684ddb6SLionel Sambuc        }
14064684ddb6SLionel Sambuc        catch (...)
14074684ddb6SLionel Sambuc        {
14084684ddb6SLionel Sambuc            while (true)
14094684ddb6SLionel Sambuc            {
14104684ddb6SLionel Sambuc                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
14114684ddb6SLionel Sambuc                __node_pointer __prev = __e.__ptr_->__prev_;
14124684ddb6SLionel Sambuc                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
14134684ddb6SLionel Sambuc                if (__prev == 0)
14144684ddb6SLionel Sambuc                    break;
14154684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
14164684ddb6SLionel Sambuc                __e = iterator(__prev, this);
14174684ddb6SLionel Sambuc#else
14184684ddb6SLionel Sambuc                __e = iterator(__prev);
14194684ddb6SLionel Sambuc#endif
14204684ddb6SLionel Sambuc            }
14214684ddb6SLionel Sambuc            throw;
14224684ddb6SLionel Sambuc        }
14234684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
14244684ddb6SLionel Sambuc        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
14254684ddb6SLionel Sambuc        base::__sz() += __ds;
14264684ddb6SLionel Sambuc    }
14274684ddb6SLionel Sambuc    return __r;
14284684ddb6SLionel Sambuc}
14294684ddb6SLionel Sambuc
14304684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
14314684ddb6SLionel Sambuctemplate <class _InpIter>
14324684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
14334684ddb6SLionel Sambuclist<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
14344684ddb6SLionel Sambuc             typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
14354684ddb6SLionel Sambuc{
14364684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
14374684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
14384684ddb6SLionel Sambuc        "list::insert(iterator, range) called with an iterator not"
14394684ddb6SLionel Sambuc        " referring to this list");
14404684ddb6SLionel Sambuc    iterator __r(__p.__ptr_, this);
14414684ddb6SLionel Sambuc#else
14424684ddb6SLionel Sambuc    iterator __r(__p.__ptr_);
14434684ddb6SLionel Sambuc#endif
14444684ddb6SLionel Sambuc    if (__f != __l)
14454684ddb6SLionel Sambuc    {
14464684ddb6SLionel Sambuc        size_type __ds = 0;
14474684ddb6SLionel Sambuc        __node_allocator& __na = base::__node_alloc();
14484684ddb6SLionel Sambuc        typedef __allocator_destructor<__node_allocator> _Dp;
14494684ddb6SLionel Sambuc        unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
14504684ddb6SLionel Sambuc        __hold->__prev_ = 0;
14514684ddb6SLionel Sambuc        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
14524684ddb6SLionel Sambuc        ++__ds;
14534684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
14544684ddb6SLionel Sambuc        __r = iterator(__hold.get(), this);
14554684ddb6SLionel Sambuc#else
14564684ddb6SLionel Sambuc        __r = iterator(__hold.get());
14574684ddb6SLionel Sambuc#endif
14584684ddb6SLionel Sambuc        __hold.release();
14594684ddb6SLionel Sambuc        iterator __e = __r;
14604684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
14614684ddb6SLionel Sambuc        try
14624684ddb6SLionel Sambuc        {
14634684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
1464*0a6a1f1dSLionel Sambuc            for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
14654684ddb6SLionel Sambuc            {
14664684ddb6SLionel Sambuc                __hold.reset(__node_alloc_traits::allocate(__na, 1));
14674684ddb6SLionel Sambuc                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
14684684ddb6SLionel Sambuc                __e.__ptr_->__next_ = __hold.get();
14694684ddb6SLionel Sambuc                __hold->__prev_ = __e.__ptr_;
14704684ddb6SLionel Sambuc                __hold.release();
14714684ddb6SLionel Sambuc            }
14724684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
14734684ddb6SLionel Sambuc        }
14744684ddb6SLionel Sambuc        catch (...)
14754684ddb6SLionel Sambuc        {
14764684ddb6SLionel Sambuc            while (true)
14774684ddb6SLionel Sambuc            {
14784684ddb6SLionel Sambuc                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
14794684ddb6SLionel Sambuc                __node_pointer __prev = __e.__ptr_->__prev_;
14804684ddb6SLionel Sambuc                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
14814684ddb6SLionel Sambuc                if (__prev == 0)
14824684ddb6SLionel Sambuc                    break;
14834684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
14844684ddb6SLionel Sambuc                __e = iterator(__prev, this);
14854684ddb6SLionel Sambuc#else
14864684ddb6SLionel Sambuc                __e = iterator(__prev);
14874684ddb6SLionel Sambuc#endif
14884684ddb6SLionel Sambuc            }
14894684ddb6SLionel Sambuc            throw;
14904684ddb6SLionel Sambuc        }
14914684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
14924684ddb6SLionel Sambuc        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
14934684ddb6SLionel Sambuc        base::__sz() += __ds;
14944684ddb6SLionel Sambuc    }
14954684ddb6SLionel Sambuc    return __r;
14964684ddb6SLionel Sambuc}
14974684ddb6SLionel Sambuc
14984684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
14994684ddb6SLionel Sambucvoid
15004684ddb6SLionel Sambuclist<_Tp, _Alloc>::push_front(const value_type& __x)
15014684ddb6SLionel Sambuc{
15024684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15034684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15044684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15054684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1506*0a6a1f1dSLionel Sambuc    __link_nodes_at_front(__hold.get(), __hold.get());
15074684ddb6SLionel Sambuc    ++base::__sz();
15084684ddb6SLionel Sambuc    __hold.release();
15094684ddb6SLionel Sambuc}
15104684ddb6SLionel Sambuc
15114684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15124684ddb6SLionel Sambucvoid
15134684ddb6SLionel Sambuclist<_Tp, _Alloc>::push_back(const value_type& __x)
15144684ddb6SLionel Sambuc{
15154684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15164684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15174684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15184684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1519*0a6a1f1dSLionel Sambuc    __link_nodes_at_back(__hold.get(), __hold.get());
15204684ddb6SLionel Sambuc    ++base::__sz();
15214684ddb6SLionel Sambuc    __hold.release();
15224684ddb6SLionel Sambuc}
15234684ddb6SLionel Sambuc
15244684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
15254684ddb6SLionel Sambuc
15264684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15274684ddb6SLionel Sambucvoid
15284684ddb6SLionel Sambuclist<_Tp, _Alloc>::push_front(value_type&& __x)
15294684ddb6SLionel Sambuc{
15304684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15314684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15324684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15334684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1534*0a6a1f1dSLionel Sambuc    __link_nodes_at_front(__hold.get(), __hold.get());
15354684ddb6SLionel Sambuc    ++base::__sz();
15364684ddb6SLionel Sambuc    __hold.release();
15374684ddb6SLionel Sambuc}
15384684ddb6SLionel Sambuc
15394684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15404684ddb6SLionel Sambucvoid
15414684ddb6SLionel Sambuclist<_Tp, _Alloc>::push_back(value_type&& __x)
15424684ddb6SLionel Sambuc{
15434684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15444684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15454684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15464684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1547*0a6a1f1dSLionel Sambuc    __link_nodes_at_back(__hold.get(), __hold.get());
15484684ddb6SLionel Sambuc    ++base::__sz();
15494684ddb6SLionel Sambuc    __hold.release();
15504684ddb6SLionel Sambuc}
15514684ddb6SLionel Sambuc
15524684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_VARIADICS
15534684ddb6SLionel Sambuc
15544684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15554684ddb6SLionel Sambuctemplate <class... _Args>
15564684ddb6SLionel Sambucvoid
15574684ddb6SLionel Sambuclist<_Tp, _Alloc>::emplace_front(_Args&&... __args)
15584684ddb6SLionel Sambuc{
15594684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15604684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15614684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15624684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1563*0a6a1f1dSLionel Sambuc    __link_nodes_at_front(__hold.get(), __hold.get());
15644684ddb6SLionel Sambuc    ++base::__sz();
15654684ddb6SLionel Sambuc    __hold.release();
15664684ddb6SLionel Sambuc}
15674684ddb6SLionel Sambuc
15684684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15694684ddb6SLionel Sambuctemplate <class... _Args>
15704684ddb6SLionel Sambucvoid
15714684ddb6SLionel Sambuclist<_Tp, _Alloc>::emplace_back(_Args&&... __args)
15724684ddb6SLionel Sambuc{
15734684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15744684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15754684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15764684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1577*0a6a1f1dSLionel Sambuc    __link_nodes_at_back(__hold.get(), __hold.get());
15784684ddb6SLionel Sambuc    ++base::__sz();
15794684ddb6SLionel Sambuc    __hold.release();
15804684ddb6SLionel Sambuc}
15814684ddb6SLionel Sambuc
15824684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
15834684ddb6SLionel Sambuctemplate <class... _Args>
15844684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
15854684ddb6SLionel Sambuclist<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
15864684ddb6SLionel Sambuc{
15874684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
15884684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
15894684ddb6SLionel Sambuc        "list::emplace(iterator, args...) called with an iterator not"
15904684ddb6SLionel Sambuc        " referring to this list");
15914684ddb6SLionel Sambuc#endif
15924684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
15934684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
15944684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
15954684ddb6SLionel Sambuc    __hold->__prev_ = 0;
15964684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
15974684ddb6SLionel Sambuc    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
15984684ddb6SLionel Sambuc    ++base::__sz();
15994684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16004684ddb6SLionel Sambuc    return iterator(__hold.release(), this);
16014684ddb6SLionel Sambuc#else
16024684ddb6SLionel Sambuc    return iterator(__hold.release());
16034684ddb6SLionel Sambuc#endif
16044684ddb6SLionel Sambuc}
16054684ddb6SLionel Sambuc
16064684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_VARIADICS
16074684ddb6SLionel Sambuc
16084684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
16094684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
16104684ddb6SLionel Sambuclist<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
16114684ddb6SLionel Sambuc{
16124684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16134684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
16144684ddb6SLionel Sambuc        "list::insert(iterator, x) called with an iterator not"
16154684ddb6SLionel Sambuc        " referring to this list");
16164684ddb6SLionel Sambuc#endif
16174684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
16184684ddb6SLionel Sambuc    typedef __allocator_destructor<__node_allocator> _Dp;
16194684ddb6SLionel Sambuc    unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
16204684ddb6SLionel Sambuc    __hold->__prev_ = 0;
16214684ddb6SLionel Sambuc    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
16224684ddb6SLionel Sambuc    __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
16234684ddb6SLionel Sambuc    ++base::__sz();
16244684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16254684ddb6SLionel Sambuc    return iterator(__hold.release(), this);
16264684ddb6SLionel Sambuc#else
16274684ddb6SLionel Sambuc    return iterator(__hold.release());
16284684ddb6SLionel Sambuc#endif
16294684ddb6SLionel Sambuc}
16304684ddb6SLionel Sambuc
16314684ddb6SLionel Sambuc#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
16324684ddb6SLionel Sambuc
16334684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
16344684ddb6SLionel Sambucvoid
16354684ddb6SLionel Sambuclist<_Tp, _Alloc>::pop_front()
16364684ddb6SLionel Sambuc{
16374684ddb6SLionel Sambuc    _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
16384684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
16394684ddb6SLionel Sambuc    __node_pointer __n = base::__end_.__next_;
16404684ddb6SLionel Sambuc    base::__unlink_nodes(__n, __n);
16414684ddb6SLionel Sambuc    --base::__sz();
16424684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16434684ddb6SLionel Sambuc    __c_node* __c = __get_db()->__find_c_and_lock(this);
16444684ddb6SLionel Sambuc    for (__i_node** __p = __c->end_; __p != __c->beg_; )
16454684ddb6SLionel Sambuc    {
16464684ddb6SLionel Sambuc        --__p;
16474684ddb6SLionel Sambuc        iterator* __i = static_cast<iterator*>((*__p)->__i_);
16484684ddb6SLionel Sambuc        if (__i->__ptr_ == __n)
16494684ddb6SLionel Sambuc        {
16504684ddb6SLionel Sambuc            (*__p)->__c_ = nullptr;
16514684ddb6SLionel Sambuc            if (--__c->end_ != __p)
16524684ddb6SLionel Sambuc                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
16534684ddb6SLionel Sambuc        }
16544684ddb6SLionel Sambuc    }
16554684ddb6SLionel Sambuc    __get_db()->unlock();
16564684ddb6SLionel Sambuc#endif
16574684ddb6SLionel Sambuc    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
16584684ddb6SLionel Sambuc    __node_alloc_traits::deallocate(__na, __n, 1);
16594684ddb6SLionel Sambuc}
16604684ddb6SLionel Sambuc
16614684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
16624684ddb6SLionel Sambucvoid
16634684ddb6SLionel Sambuclist<_Tp, _Alloc>::pop_back()
16644684ddb6SLionel Sambuc{
16654684ddb6SLionel Sambuc    _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
16664684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
16674684ddb6SLionel Sambuc    __node_pointer __n = base::__end_.__prev_;
16684684ddb6SLionel Sambuc    base::__unlink_nodes(__n, __n);
16694684ddb6SLionel Sambuc    --base::__sz();
16704684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16714684ddb6SLionel Sambuc    __c_node* __c = __get_db()->__find_c_and_lock(this);
16724684ddb6SLionel Sambuc    for (__i_node** __p = __c->end_; __p != __c->beg_; )
16734684ddb6SLionel Sambuc    {
16744684ddb6SLionel Sambuc        --__p;
16754684ddb6SLionel Sambuc        iterator* __i = static_cast<iterator*>((*__p)->__i_);
16764684ddb6SLionel Sambuc        if (__i->__ptr_ == __n)
16774684ddb6SLionel Sambuc        {
16784684ddb6SLionel Sambuc            (*__p)->__c_ = nullptr;
16794684ddb6SLionel Sambuc            if (--__c->end_ != __p)
16804684ddb6SLionel Sambuc                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
16814684ddb6SLionel Sambuc        }
16824684ddb6SLionel Sambuc    }
16834684ddb6SLionel Sambuc    __get_db()->unlock();
16844684ddb6SLionel Sambuc#endif
16854684ddb6SLionel Sambuc    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
16864684ddb6SLionel Sambuc    __node_alloc_traits::deallocate(__na, __n, 1);
16874684ddb6SLionel Sambuc}
16884684ddb6SLionel Sambuc
16894684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
16904684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
16914684ddb6SLionel Sambuclist<_Tp, _Alloc>::erase(const_iterator __p)
16924684ddb6SLionel Sambuc{
16934684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
16944684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
16954684ddb6SLionel Sambuc        "list::erase(iterator) called with an iterator not"
16964684ddb6SLionel Sambuc        " referring to this list");
16974684ddb6SLionel Sambuc#endif
16984684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__p != end(),
16994684ddb6SLionel Sambuc        "list::erase(iterator) called with a non-dereferenceable iterator");
17004684ddb6SLionel Sambuc    __node_allocator& __na = base::__node_alloc();
17014684ddb6SLionel Sambuc    __node_pointer __n = __p.__ptr_;
17024684ddb6SLionel Sambuc    __node_pointer __r = __n->__next_;
17034684ddb6SLionel Sambuc    base::__unlink_nodes(__n, __n);
17044684ddb6SLionel Sambuc    --base::__sz();
17054684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17064684ddb6SLionel Sambuc    __c_node* __c = __get_db()->__find_c_and_lock(this);
17074684ddb6SLionel Sambuc    for (__i_node** __p = __c->end_; __p != __c->beg_; )
17084684ddb6SLionel Sambuc    {
17094684ddb6SLionel Sambuc        --__p;
17104684ddb6SLionel Sambuc        iterator* __i = static_cast<iterator*>((*__p)->__i_);
17114684ddb6SLionel Sambuc        if (__i->__ptr_ == __n)
17124684ddb6SLionel Sambuc        {
17134684ddb6SLionel Sambuc            (*__p)->__c_ = nullptr;
17144684ddb6SLionel Sambuc            if (--__c->end_ != __p)
17154684ddb6SLionel Sambuc                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
17164684ddb6SLionel Sambuc        }
17174684ddb6SLionel Sambuc    }
17184684ddb6SLionel Sambuc    __get_db()->unlock();
17194684ddb6SLionel Sambuc#endif
17204684ddb6SLionel Sambuc    __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
17214684ddb6SLionel Sambuc    __node_alloc_traits::deallocate(__na, __n, 1);
17224684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17234684ddb6SLionel Sambuc    return iterator(__r, this);
17244684ddb6SLionel Sambuc#else
17254684ddb6SLionel Sambuc    return iterator(__r);
17264684ddb6SLionel Sambuc#endif
17274684ddb6SLionel Sambuc}
17284684ddb6SLionel Sambuc
17294684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
17304684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
17314684ddb6SLionel Sambuclist<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
17324684ddb6SLionel Sambuc{
17334684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17344684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
17354684ddb6SLionel Sambuc        "list::erase(iterator, iterator) called with an iterator not"
17364684ddb6SLionel Sambuc        " referring to this list");
17374684ddb6SLionel Sambuc#endif
17384684ddb6SLionel Sambuc    if (__f != __l)
17394684ddb6SLionel Sambuc    {
17404684ddb6SLionel Sambuc        __node_allocator& __na = base::__node_alloc();
17414684ddb6SLionel Sambuc        base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
17424684ddb6SLionel Sambuc        while (__f != __l)
17434684ddb6SLionel Sambuc        {
17444684ddb6SLionel Sambuc            __node_pointer __n = __f.__ptr_;
17454684ddb6SLionel Sambuc            ++__f;
17464684ddb6SLionel Sambuc            --base::__sz();
17474684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17484684ddb6SLionel Sambuc            __c_node* __c = __get_db()->__find_c_and_lock(this);
17494684ddb6SLionel Sambuc            for (__i_node** __p = __c->end_; __p != __c->beg_; )
17504684ddb6SLionel Sambuc            {
17514684ddb6SLionel Sambuc                --__p;
17524684ddb6SLionel Sambuc                iterator* __i = static_cast<iterator*>((*__p)->__i_);
17534684ddb6SLionel Sambuc                if (__i->__ptr_ == __n)
17544684ddb6SLionel Sambuc                {
17554684ddb6SLionel Sambuc                    (*__p)->__c_ = nullptr;
17564684ddb6SLionel Sambuc                    if (--__c->end_ != __p)
17574684ddb6SLionel Sambuc                        memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
17584684ddb6SLionel Sambuc                }
17594684ddb6SLionel Sambuc            }
17604684ddb6SLionel Sambuc            __get_db()->unlock();
17614684ddb6SLionel Sambuc#endif
17624684ddb6SLionel Sambuc            __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
17634684ddb6SLionel Sambuc            __node_alloc_traits::deallocate(__na, __n, 1);
17644684ddb6SLionel Sambuc        }
17654684ddb6SLionel Sambuc    }
17664684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17674684ddb6SLionel Sambuc    return iterator(__l.__ptr_, this);
17684684ddb6SLionel Sambuc#else
17694684ddb6SLionel Sambuc    return iterator(__l.__ptr_);
17704684ddb6SLionel Sambuc#endif
17714684ddb6SLionel Sambuc}
17724684ddb6SLionel Sambuc
17734684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
17744684ddb6SLionel Sambucvoid
17754684ddb6SLionel Sambuclist<_Tp, _Alloc>::resize(size_type __n)
17764684ddb6SLionel Sambuc{
17774684ddb6SLionel Sambuc    if (__n < base::__sz())
17784684ddb6SLionel Sambuc        erase(__iterator(__n), end());
17794684ddb6SLionel Sambuc    else if (__n > base::__sz())
17804684ddb6SLionel Sambuc    {
17814684ddb6SLionel Sambuc        __n -= base::__sz();
17824684ddb6SLionel Sambuc        size_type __ds = 0;
17834684ddb6SLionel Sambuc        __node_allocator& __na = base::__node_alloc();
17844684ddb6SLionel Sambuc        typedef __allocator_destructor<__node_allocator> _Dp;
17854684ddb6SLionel Sambuc        unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
17864684ddb6SLionel Sambuc        __hold->__prev_ = 0;
17874684ddb6SLionel Sambuc        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
17884684ddb6SLionel Sambuc        ++__ds;
17894684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
17904684ddb6SLionel Sambuc        iterator __r = iterator(__hold.release(), this);
17914684ddb6SLionel Sambuc#else
17924684ddb6SLionel Sambuc        iterator __r = iterator(__hold.release());
17934684ddb6SLionel Sambuc#endif
17944684ddb6SLionel Sambuc        iterator __e = __r;
17954684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
17964684ddb6SLionel Sambuc        try
17974684ddb6SLionel Sambuc        {
17984684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
17994684ddb6SLionel Sambuc            for (--__n; __n != 0; --__n, ++__e, ++__ds)
18004684ddb6SLionel Sambuc            {
18014684ddb6SLionel Sambuc                __hold.reset(__node_alloc_traits::allocate(__na, 1));
18024684ddb6SLionel Sambuc                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
18034684ddb6SLionel Sambuc                __e.__ptr_->__next_ = __hold.get();
18044684ddb6SLionel Sambuc                __hold->__prev_ = __e.__ptr_;
18054684ddb6SLionel Sambuc                __hold.release();
18064684ddb6SLionel Sambuc            }
18074684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
18084684ddb6SLionel Sambuc        }
18094684ddb6SLionel Sambuc        catch (...)
18104684ddb6SLionel Sambuc        {
18114684ddb6SLionel Sambuc            while (true)
18124684ddb6SLionel Sambuc            {
18134684ddb6SLionel Sambuc                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
18144684ddb6SLionel Sambuc                __node_pointer __prev = __e.__ptr_->__prev_;
18154684ddb6SLionel Sambuc                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
18164684ddb6SLionel Sambuc                if (__prev == 0)
18174684ddb6SLionel Sambuc                    break;
18184684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
18194684ddb6SLionel Sambuc                __e = iterator(__prev, this);
18204684ddb6SLionel Sambuc#else
18214684ddb6SLionel Sambuc                __e = iterator(__prev);
18224684ddb6SLionel Sambuc#endif
18234684ddb6SLionel Sambuc            }
18244684ddb6SLionel Sambuc            throw;
18254684ddb6SLionel Sambuc        }
18264684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
1827*0a6a1f1dSLionel Sambuc        __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
18284684ddb6SLionel Sambuc        base::__sz() += __ds;
18294684ddb6SLionel Sambuc    }
18304684ddb6SLionel Sambuc}
18314684ddb6SLionel Sambuc
18324684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
18334684ddb6SLionel Sambucvoid
18344684ddb6SLionel Sambuclist<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
18354684ddb6SLionel Sambuc{
18364684ddb6SLionel Sambuc    if (__n < base::__sz())
18374684ddb6SLionel Sambuc        erase(__iterator(__n), end());
18384684ddb6SLionel Sambuc    else if (__n > base::__sz())
18394684ddb6SLionel Sambuc    {
18404684ddb6SLionel Sambuc        __n -= base::__sz();
18414684ddb6SLionel Sambuc        size_type __ds = 0;
18424684ddb6SLionel Sambuc        __node_allocator& __na = base::__node_alloc();
18434684ddb6SLionel Sambuc        typedef __allocator_destructor<__node_allocator> _Dp;
18444684ddb6SLionel Sambuc        unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
18454684ddb6SLionel Sambuc        __hold->__prev_ = 0;
18464684ddb6SLionel Sambuc        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
18474684ddb6SLionel Sambuc        ++__ds;
18484684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
18494684ddb6SLionel Sambuc        iterator __r = iterator(__hold.release(), this);
18504684ddb6SLionel Sambuc#else
18514684ddb6SLionel Sambuc        iterator __r = iterator(__hold.release());
18524684ddb6SLionel Sambuc#endif
18534684ddb6SLionel Sambuc        iterator __e = __r;
18544684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
18554684ddb6SLionel Sambuc        try
18564684ddb6SLionel Sambuc        {
18574684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
18584684ddb6SLionel Sambuc            for (--__n; __n != 0; --__n, ++__e, ++__ds)
18594684ddb6SLionel Sambuc            {
18604684ddb6SLionel Sambuc                __hold.reset(__node_alloc_traits::allocate(__na, 1));
18614684ddb6SLionel Sambuc                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
18624684ddb6SLionel Sambuc                __e.__ptr_->__next_ = __hold.get();
18634684ddb6SLionel Sambuc                __hold->__prev_ = __e.__ptr_;
18644684ddb6SLionel Sambuc                __hold.release();
18654684ddb6SLionel Sambuc            }
18664684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS
18674684ddb6SLionel Sambuc        }
18684684ddb6SLionel Sambuc        catch (...)
18694684ddb6SLionel Sambuc        {
18704684ddb6SLionel Sambuc            while (true)
18714684ddb6SLionel Sambuc            {
18724684ddb6SLionel Sambuc                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
18734684ddb6SLionel Sambuc                __node_pointer __prev = __e.__ptr_->__prev_;
18744684ddb6SLionel Sambuc                __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
18754684ddb6SLionel Sambuc                if (__prev == 0)
18764684ddb6SLionel Sambuc                    break;
18774684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
18784684ddb6SLionel Sambuc                __e = iterator(__prev, this);
18794684ddb6SLionel Sambuc#else
18804684ddb6SLionel Sambuc                __e = iterator(__prev);
18814684ddb6SLionel Sambuc#endif
18824684ddb6SLionel Sambuc            }
18834684ddb6SLionel Sambuc            throw;
18844684ddb6SLionel Sambuc        }
18854684ddb6SLionel Sambuc#endif  // _LIBCPP_NO_EXCEPTIONS
18864684ddb6SLionel Sambuc        __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
18874684ddb6SLionel Sambuc                         pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
18884684ddb6SLionel Sambuc        base::__sz() += __ds;
18894684ddb6SLionel Sambuc    }
18904684ddb6SLionel Sambuc}
18914684ddb6SLionel Sambuc
18924684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
18934684ddb6SLionel Sambucvoid
18944684ddb6SLionel Sambuclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
18954684ddb6SLionel Sambuc{
18964684ddb6SLionel Sambuc    _LIBCPP_ASSERT(this != &__c,
18974684ddb6SLionel Sambuc                   "list::splice(iterator, list) called with this == &list");
18984684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
18994684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
19004684ddb6SLionel Sambuc        "list::splice(iterator, list) called with an iterator not"
19014684ddb6SLionel Sambuc        " referring to this list");
19024684ddb6SLionel Sambuc#endif
19034684ddb6SLionel Sambuc    if (!__c.empty())
19044684ddb6SLionel Sambuc    {
19054684ddb6SLionel Sambuc        __node_pointer __f = __c.__end_.__next_;
19064684ddb6SLionel Sambuc        __node_pointer __l = __c.__end_.__prev_;
19074684ddb6SLionel Sambuc        base::__unlink_nodes(__f, __l);
19084684ddb6SLionel Sambuc        __link_nodes(__p.__ptr_, __f, __l);
19094684ddb6SLionel Sambuc        base::__sz() += __c.__sz();
19104684ddb6SLionel Sambuc        __c.__sz() = 0;
19114684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
19124684ddb6SLionel Sambuc        __libcpp_db* __db = __get_db();
19134684ddb6SLionel Sambuc        __c_node* __cn1 = __db->__find_c_and_lock(this);
19144684ddb6SLionel Sambuc        __c_node* __cn2 = __db->__find_c(&__c);
19154684ddb6SLionel Sambuc        for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
19164684ddb6SLionel Sambuc        {
19174684ddb6SLionel Sambuc            --__p;
19184684ddb6SLionel Sambuc            iterator* __i = static_cast<iterator*>((*__p)->__i_);
19194684ddb6SLionel Sambuc            if (__i->__ptr_ != static_cast<__node_pointer>(
19204684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
19214684ddb6SLionel Sambuc            {
19224684ddb6SLionel Sambuc                __cn1->__add(*__p);
19234684ddb6SLionel Sambuc                (*__p)->__c_ = __cn1;
19244684ddb6SLionel Sambuc                if (--__cn2->end_ != __p)
19254684ddb6SLionel Sambuc                    memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
19264684ddb6SLionel Sambuc            }
19274684ddb6SLionel Sambuc        }
19284684ddb6SLionel Sambuc        __db->unlock();
19294684ddb6SLionel Sambuc#endif
19304684ddb6SLionel Sambuc    }
19314684ddb6SLionel Sambuc}
19324684ddb6SLionel Sambuc
19334684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
19344684ddb6SLionel Sambucvoid
19354684ddb6SLionel Sambuclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
19364684ddb6SLionel Sambuc{
19374684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
19384684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
19394684ddb6SLionel Sambuc        "list::splice(iterator, list, iterator) called with first iterator not"
19404684ddb6SLionel Sambuc        " referring to this list");
19414684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
19424684ddb6SLionel Sambuc        "list::splice(iterator, list, iterator) called with second iterator not"
19434684ddb6SLionel Sambuc        " referring to list argument");
19444684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
19454684ddb6SLionel Sambuc        "list::splice(iterator, list, iterator) called with second iterator not"
19464684ddb6SLionel Sambuc        " derefereceable");
19474684ddb6SLionel Sambuc#endif
19484684ddb6SLionel Sambuc    if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
19494684ddb6SLionel Sambuc    {
19504684ddb6SLionel Sambuc        __node_pointer __f = __i.__ptr_;
19514684ddb6SLionel Sambuc        base::__unlink_nodes(__f, __f);
19524684ddb6SLionel Sambuc        __link_nodes(__p.__ptr_, __f, __f);
19534684ddb6SLionel Sambuc        --__c.__sz();
19544684ddb6SLionel Sambuc        ++base::__sz();
19554684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
19564684ddb6SLionel Sambuc        __libcpp_db* __db = __get_db();
19574684ddb6SLionel Sambuc        __c_node* __cn1 = __db->__find_c_and_lock(this);
19584684ddb6SLionel Sambuc        __c_node* __cn2 = __db->__find_c(&__c);
19594684ddb6SLionel Sambuc        for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
19604684ddb6SLionel Sambuc        {
19614684ddb6SLionel Sambuc            --__p;
19624684ddb6SLionel Sambuc            iterator* __j = static_cast<iterator*>((*__p)->__i_);
19634684ddb6SLionel Sambuc            if (__j->__ptr_ == __f)
19644684ddb6SLionel Sambuc            {
19654684ddb6SLionel Sambuc                __cn1->__add(*__p);
19664684ddb6SLionel Sambuc                (*__p)->__c_ = __cn1;
19674684ddb6SLionel Sambuc                if (--__cn2->end_ != __p)
19684684ddb6SLionel Sambuc                    memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
19694684ddb6SLionel Sambuc            }
19704684ddb6SLionel Sambuc        }
19714684ddb6SLionel Sambuc        __db->unlock();
19724684ddb6SLionel Sambuc#endif
19734684ddb6SLionel Sambuc    }
19744684ddb6SLionel Sambuc}
19754684ddb6SLionel Sambuc
19764684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
19774684ddb6SLionel Sambucvoid
19784684ddb6SLionel Sambuclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
19794684ddb6SLionel Sambuc{
19804684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
19814684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
19824684ddb6SLionel Sambuc        "list::splice(iterator, list, iterator, iterator) called with first iterator not"
19834684ddb6SLionel Sambuc        " referring to this list");
19844684ddb6SLionel Sambuc    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
19854684ddb6SLionel Sambuc        "list::splice(iterator, list, iterator, iterator) called with second iterator not"
19864684ddb6SLionel Sambuc        " referring to list argument");
19874684ddb6SLionel Sambuc    if (this == &__c)
19884684ddb6SLionel Sambuc    {
19894684ddb6SLionel Sambuc        for (const_iterator __i = __f; __i != __l; ++__i)
19904684ddb6SLionel Sambuc            _LIBCPP_ASSERT(__i != __p,
19914684ddb6SLionel Sambuc                           "list::splice(iterator, list, iterator, iterator)"
19924684ddb6SLionel Sambuc                           " called with the first iterator within the range"
19934684ddb6SLionel Sambuc                           " of the second and third iterators");
19944684ddb6SLionel Sambuc    }
19954684ddb6SLionel Sambuc#endif
19964684ddb6SLionel Sambuc    if (__f != __l)
19974684ddb6SLionel Sambuc    {
19984684ddb6SLionel Sambuc        if (this != &__c)
19994684ddb6SLionel Sambuc        {
20004684ddb6SLionel Sambuc            size_type __s = _VSTD::distance(__f, __l);
20014684ddb6SLionel Sambuc            __c.__sz() -= __s;
20024684ddb6SLionel Sambuc            base::__sz() += __s;
20034684ddb6SLionel Sambuc        }
20044684ddb6SLionel Sambuc        __node_pointer __first = __f.__ptr_;
20054684ddb6SLionel Sambuc        --__l;
20064684ddb6SLionel Sambuc        __node_pointer __last = __l.__ptr_;
20074684ddb6SLionel Sambuc        base::__unlink_nodes(__first, __last);
20084684ddb6SLionel Sambuc        __link_nodes(__p.__ptr_, __first, __last);
20094684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
20104684ddb6SLionel Sambuc        __libcpp_db* __db = __get_db();
20114684ddb6SLionel Sambuc        __c_node* __cn1 = __db->__find_c_and_lock(this);
20124684ddb6SLionel Sambuc        __c_node* __cn2 = __db->__find_c(&__c);
20134684ddb6SLionel Sambuc        for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
20144684ddb6SLionel Sambuc        {
20154684ddb6SLionel Sambuc            --__p;
20164684ddb6SLionel Sambuc            iterator* __j = static_cast<iterator*>((*__p)->__i_);
20174684ddb6SLionel Sambuc            for (__node_pointer __k = __f.__ptr_;
20184684ddb6SLionel Sambuc                                          __k != __l.__ptr_; __k = __k->__next_)
20194684ddb6SLionel Sambuc            {
20204684ddb6SLionel Sambuc                if (__j->__ptr_ == __k)
20214684ddb6SLionel Sambuc                {
20224684ddb6SLionel Sambuc                    __cn1->__add(*__p);
20234684ddb6SLionel Sambuc                    (*__p)->__c_ = __cn1;
20244684ddb6SLionel Sambuc                    if (--__cn2->end_ != __p)
20254684ddb6SLionel Sambuc                        memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
20264684ddb6SLionel Sambuc                }
20274684ddb6SLionel Sambuc            }
20284684ddb6SLionel Sambuc        }
20294684ddb6SLionel Sambuc        __db->unlock();
20304684ddb6SLionel Sambuc#endif
20314684ddb6SLionel Sambuc    }
20324684ddb6SLionel Sambuc}
20334684ddb6SLionel Sambuc
20344684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
20354684ddb6SLionel Sambucvoid
20364684ddb6SLionel Sambuclist<_Tp, _Alloc>::remove(const value_type& __x)
20374684ddb6SLionel Sambuc{
2038*0a6a1f1dSLionel Sambuc    list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2039*0a6a1f1dSLionel Sambuc    for (const_iterator __i = begin(), __e = end(); __i != __e;)
20404684ddb6SLionel Sambuc    {
20414684ddb6SLionel Sambuc        if (*__i == __x)
20424684ddb6SLionel Sambuc        {
2043*0a6a1f1dSLionel Sambuc            const_iterator __j = _VSTD::next(__i);
20444684ddb6SLionel Sambuc            for (; __j != __e && *__j == __x; ++__j)
20454684ddb6SLionel Sambuc                ;
2046*0a6a1f1dSLionel Sambuc            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2047*0a6a1f1dSLionel Sambuc            __i = __j;
2048*0a6a1f1dSLionel Sambuc            if (__i != __e)
2049*0a6a1f1dSLionel Sambuc                ++__i;
20504684ddb6SLionel Sambuc        }
20514684ddb6SLionel Sambuc        else
20524684ddb6SLionel Sambuc            ++__i;
20534684ddb6SLionel Sambuc    }
20544684ddb6SLionel Sambuc}
20554684ddb6SLionel Sambuc
20564684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
20574684ddb6SLionel Sambuctemplate <class _Pred>
20584684ddb6SLionel Sambucvoid
20594684ddb6SLionel Sambuclist<_Tp, _Alloc>::remove_if(_Pred __pred)
20604684ddb6SLionel Sambuc{
20614684ddb6SLionel Sambuc    for (iterator __i = begin(), __e = end(); __i != __e;)
20624684ddb6SLionel Sambuc    {
20634684ddb6SLionel Sambuc        if (__pred(*__i))
20644684ddb6SLionel Sambuc        {
20654684ddb6SLionel Sambuc            iterator __j = _VSTD::next(__i);
20664684ddb6SLionel Sambuc            for (; __j != __e && __pred(*__j); ++__j)
20674684ddb6SLionel Sambuc                ;
20684684ddb6SLionel Sambuc            __i = erase(__i, __j);
2069*0a6a1f1dSLionel Sambuc            if (__i != __e)
2070*0a6a1f1dSLionel Sambuc                ++__i;
20714684ddb6SLionel Sambuc        }
20724684ddb6SLionel Sambuc        else
20734684ddb6SLionel Sambuc            ++__i;
20744684ddb6SLionel Sambuc    }
20754684ddb6SLionel Sambuc}
20764684ddb6SLionel Sambuc
20774684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
20784684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
20794684ddb6SLionel Sambucvoid
20804684ddb6SLionel Sambuclist<_Tp, _Alloc>::unique()
20814684ddb6SLionel Sambuc{
20824684ddb6SLionel Sambuc    unique(__equal_to<value_type>());
20834684ddb6SLionel Sambuc}
20844684ddb6SLionel Sambuc
20854684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
20864684ddb6SLionel Sambuctemplate <class _BinaryPred>
20874684ddb6SLionel Sambucvoid
20884684ddb6SLionel Sambuclist<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
20894684ddb6SLionel Sambuc{
20904684ddb6SLionel Sambuc    for (iterator __i = begin(), __e = end(); __i != __e;)
20914684ddb6SLionel Sambuc    {
20924684ddb6SLionel Sambuc        iterator __j = _VSTD::next(__i);
20934684ddb6SLionel Sambuc        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
20944684ddb6SLionel Sambuc            ;
20954684ddb6SLionel Sambuc        if (++__i != __j)
20964684ddb6SLionel Sambuc            __i = erase(__i, __j);
20974684ddb6SLionel Sambuc    }
20984684ddb6SLionel Sambuc}
20994684ddb6SLionel Sambuc
21004684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
21014684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
21024684ddb6SLionel Sambucvoid
21034684ddb6SLionel Sambuclist<_Tp, _Alloc>::merge(list& __c)
21044684ddb6SLionel Sambuc{
21054684ddb6SLionel Sambuc    merge(__c, __less<value_type>());
21064684ddb6SLionel Sambuc}
21074684ddb6SLionel Sambuc
21084684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
21094684ddb6SLionel Sambuctemplate <class _Comp>
21104684ddb6SLionel Sambucvoid
21114684ddb6SLionel Sambuclist<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
21124684ddb6SLionel Sambuc{
21134684ddb6SLionel Sambuc    if (this != &__c)
21144684ddb6SLionel Sambuc    {
21154684ddb6SLionel Sambuc        iterator __f1 = begin();
21164684ddb6SLionel Sambuc        iterator __e1 = end();
21174684ddb6SLionel Sambuc        iterator __f2 = __c.begin();
21184684ddb6SLionel Sambuc        iterator __e2 = __c.end();
21194684ddb6SLionel Sambuc        while (__f1 != __e1 && __f2 != __e2)
21204684ddb6SLionel Sambuc        {
21214684ddb6SLionel Sambuc            if (__comp(*__f2, *__f1))
21224684ddb6SLionel Sambuc            {
21234684ddb6SLionel Sambuc                size_type __ds = 1;
21244684ddb6SLionel Sambuc                iterator __m2 = _VSTD::next(__f2);
21254684ddb6SLionel Sambuc                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
21264684ddb6SLionel Sambuc                    ;
21274684ddb6SLionel Sambuc                base::__sz() += __ds;
21284684ddb6SLionel Sambuc                __c.__sz() -= __ds;
21294684ddb6SLionel Sambuc                __node_pointer __f = __f2.__ptr_;
21304684ddb6SLionel Sambuc                __node_pointer __l = __m2.__ptr_->__prev_;
21314684ddb6SLionel Sambuc                __f2 = __m2;
21324684ddb6SLionel Sambuc                base::__unlink_nodes(__f, __l);
21334684ddb6SLionel Sambuc                __m2 = _VSTD::next(__f1);
21344684ddb6SLionel Sambuc                __link_nodes(__f1.__ptr_, __f, __l);
21354684ddb6SLionel Sambuc                __f1 = __m2;
21364684ddb6SLionel Sambuc            }
21374684ddb6SLionel Sambuc            else
21384684ddb6SLionel Sambuc                ++__f1;
21394684ddb6SLionel Sambuc        }
21404684ddb6SLionel Sambuc        splice(__e1, __c);
21414684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
21424684ddb6SLionel Sambuc        __libcpp_db* __db = __get_db();
21434684ddb6SLionel Sambuc        __c_node* __cn1 = __db->__find_c_and_lock(this);
21444684ddb6SLionel Sambuc        __c_node* __cn2 = __db->__find_c(&__c);
21454684ddb6SLionel Sambuc        for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
21464684ddb6SLionel Sambuc        {
21474684ddb6SLionel Sambuc            --__p;
21484684ddb6SLionel Sambuc            iterator* __i = static_cast<iterator*>((*__p)->__i_);
21494684ddb6SLionel Sambuc            if (__i->__ptr_ != static_cast<__node_pointer>(
21504684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
21514684ddb6SLionel Sambuc            {
21524684ddb6SLionel Sambuc                __cn1->__add(*__p);
21534684ddb6SLionel Sambuc                (*__p)->__c_ = __cn1;
21544684ddb6SLionel Sambuc                if (--__cn2->end_ != __p)
21554684ddb6SLionel Sambuc                    memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
21564684ddb6SLionel Sambuc            }
21574684ddb6SLionel Sambuc        }
21584684ddb6SLionel Sambuc        __db->unlock();
21594684ddb6SLionel Sambuc#endif
21604684ddb6SLionel Sambuc    }
21614684ddb6SLionel Sambuc}
21624684ddb6SLionel Sambuc
21634684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
21644684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
21654684ddb6SLionel Sambucvoid
21664684ddb6SLionel Sambuclist<_Tp, _Alloc>::sort()
21674684ddb6SLionel Sambuc{
21684684ddb6SLionel Sambuc    sort(__less<value_type>());
21694684ddb6SLionel Sambuc}
21704684ddb6SLionel Sambuc
21714684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
21724684ddb6SLionel Sambuctemplate <class _Comp>
21734684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
21744684ddb6SLionel Sambucvoid
21754684ddb6SLionel Sambuclist<_Tp, _Alloc>::sort(_Comp __comp)
21764684ddb6SLionel Sambuc{
21774684ddb6SLionel Sambuc    __sort(begin(), end(), base::__sz(), __comp);
21784684ddb6SLionel Sambuc}
21794684ddb6SLionel Sambuc
21804684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
21814684ddb6SLionel Sambuctemplate <class _Comp>
21824684ddb6SLionel Sambuctypename list<_Tp, _Alloc>::iterator
21834684ddb6SLionel Sambuclist<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
21844684ddb6SLionel Sambuc{
21854684ddb6SLionel Sambuc    switch (__n)
21864684ddb6SLionel Sambuc    {
21874684ddb6SLionel Sambuc    case 0:
21884684ddb6SLionel Sambuc    case 1:
21894684ddb6SLionel Sambuc        return __f1;
21904684ddb6SLionel Sambuc    case 2:
21914684ddb6SLionel Sambuc        if (__comp(*--__e2, *__f1))
21924684ddb6SLionel Sambuc        {
21934684ddb6SLionel Sambuc            __node_pointer __f = __e2.__ptr_;
21944684ddb6SLionel Sambuc            base::__unlink_nodes(__f, __f);
21954684ddb6SLionel Sambuc            __link_nodes(__f1.__ptr_, __f, __f);
21964684ddb6SLionel Sambuc            return __e2;
21974684ddb6SLionel Sambuc        }
21984684ddb6SLionel Sambuc        return __f1;
21994684ddb6SLionel Sambuc    }
22004684ddb6SLionel Sambuc    size_type __n2 = __n / 2;
22014684ddb6SLionel Sambuc    iterator __e1 = _VSTD::next(__f1, __n2);
22024684ddb6SLionel Sambuc    iterator  __r = __f1 = __sort(__f1, __e1, __n2, __comp);
22034684ddb6SLionel Sambuc    iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
22044684ddb6SLionel Sambuc    if (__comp(*__f2, *__f1))
22054684ddb6SLionel Sambuc    {
22064684ddb6SLionel Sambuc        iterator __m2 = _VSTD::next(__f2);
22074684ddb6SLionel Sambuc        for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
22084684ddb6SLionel Sambuc            ;
22094684ddb6SLionel Sambuc        __node_pointer __f = __f2.__ptr_;
22104684ddb6SLionel Sambuc        __node_pointer __l = __m2.__ptr_->__prev_;
22114684ddb6SLionel Sambuc        __r = __f2;
22124684ddb6SLionel Sambuc        __e1 = __f2 = __m2;
22134684ddb6SLionel Sambuc        base::__unlink_nodes(__f, __l);
22144684ddb6SLionel Sambuc        __m2 = _VSTD::next(__f1);
22154684ddb6SLionel Sambuc        __link_nodes(__f1.__ptr_, __f, __l);
22164684ddb6SLionel Sambuc        __f1 = __m2;
22174684ddb6SLionel Sambuc    }
22184684ddb6SLionel Sambuc    else
22194684ddb6SLionel Sambuc        ++__f1;
22204684ddb6SLionel Sambuc    while (__f1 != __e1 && __f2 != __e2)
22214684ddb6SLionel Sambuc    {
22224684ddb6SLionel Sambuc        if (__comp(*__f2, *__f1))
22234684ddb6SLionel Sambuc        {
22244684ddb6SLionel Sambuc            iterator __m2 = _VSTD::next(__f2);
22254684ddb6SLionel Sambuc            for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
22264684ddb6SLionel Sambuc                ;
22274684ddb6SLionel Sambuc            __node_pointer __f = __f2.__ptr_;
22284684ddb6SLionel Sambuc            __node_pointer __l = __m2.__ptr_->__prev_;
22294684ddb6SLionel Sambuc            if (__e1 == __f2)
22304684ddb6SLionel Sambuc                __e1 = __m2;
22314684ddb6SLionel Sambuc            __f2 = __m2;
22324684ddb6SLionel Sambuc            base::__unlink_nodes(__f, __l);
22334684ddb6SLionel Sambuc            __m2 = _VSTD::next(__f1);
22344684ddb6SLionel Sambuc            __link_nodes(__f1.__ptr_, __f, __l);
22354684ddb6SLionel Sambuc            __f1 = __m2;
22364684ddb6SLionel Sambuc        }
22374684ddb6SLionel Sambuc        else
22384684ddb6SLionel Sambuc            ++__f1;
22394684ddb6SLionel Sambuc    }
22404684ddb6SLionel Sambuc    return __r;
22414684ddb6SLionel Sambuc}
22424684ddb6SLionel Sambuc
22434684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22444684ddb6SLionel Sambucvoid
22454684ddb6SLionel Sambuclist<_Tp, _Alloc>::reverse() _NOEXCEPT
22464684ddb6SLionel Sambuc{
22474684ddb6SLionel Sambuc    if (base::__sz() > 1)
22484684ddb6SLionel Sambuc    {
22494684ddb6SLionel Sambuc        iterator __e = end();
22504684ddb6SLionel Sambuc        for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
22514684ddb6SLionel Sambuc        {
22524684ddb6SLionel Sambuc            _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
22534684ddb6SLionel Sambuc            __i.__ptr_ = __i.__ptr_->__prev_;
22544684ddb6SLionel Sambuc        }
22554684ddb6SLionel Sambuc        _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
22564684ddb6SLionel Sambuc    }
22574684ddb6SLionel Sambuc}
22584684ddb6SLionel Sambuc
22594684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22604684ddb6SLionel Sambucbool
22614684ddb6SLionel Sambuclist<_Tp, _Alloc>::__invariants() const
22624684ddb6SLionel Sambuc{
22634684ddb6SLionel Sambuc    return size() == _VSTD::distance(begin(), end());
22644684ddb6SLionel Sambuc}
22654684ddb6SLionel Sambuc
22664684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2
22674684ddb6SLionel Sambuc
22684684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22694684ddb6SLionel Sambucbool
22704684ddb6SLionel Sambuclist<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
22714684ddb6SLionel Sambuc{
22724684ddb6SLionel Sambuc    return __i->__ptr_ != static_cast<__node_pointer>(
22734684ddb6SLionel Sambuc                       pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
22744684ddb6SLionel Sambuc}
22754684ddb6SLionel Sambuc
22764684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22774684ddb6SLionel Sambucbool
22784684ddb6SLionel Sambuclist<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
22794684ddb6SLionel Sambuc{
22804684ddb6SLionel Sambuc    return !empty() &&  __i->__ptr_ != base::__end_.__next_;
22814684ddb6SLionel Sambuc}
22824684ddb6SLionel Sambuc
22834684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22844684ddb6SLionel Sambucbool
22854684ddb6SLionel Sambuclist<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
22864684ddb6SLionel Sambuc{
22874684ddb6SLionel Sambuc    return false;
22884684ddb6SLionel Sambuc}
22894684ddb6SLionel Sambuc
22904684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
22914684ddb6SLionel Sambucbool
22924684ddb6SLionel Sambuclist<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
22934684ddb6SLionel Sambuc{
22944684ddb6SLionel Sambuc    return false;
22954684ddb6SLionel Sambuc}
22964684ddb6SLionel Sambuc
22974684ddb6SLionel Sambuc#endif  // _LIBCPP_DEBUG_LEVEL >= 2
22984684ddb6SLionel Sambuc
22994684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23004684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23014684ddb6SLionel Sambucbool
23024684ddb6SLionel Sambucoperator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23034684ddb6SLionel Sambuc{
23044684ddb6SLionel Sambuc    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
23054684ddb6SLionel Sambuc}
23064684ddb6SLionel Sambuc
23074684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23084684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23094684ddb6SLionel Sambucbool
23104684ddb6SLionel Sambucoperator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23114684ddb6SLionel Sambuc{
23124684ddb6SLionel Sambuc    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
23134684ddb6SLionel Sambuc}
23144684ddb6SLionel Sambuc
23154684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23164684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23174684ddb6SLionel Sambucbool
23184684ddb6SLionel Sambucoperator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23194684ddb6SLionel Sambuc{
23204684ddb6SLionel Sambuc    return !(__x == __y);
23214684ddb6SLionel Sambuc}
23224684ddb6SLionel Sambuc
23234684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23244684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23254684ddb6SLionel Sambucbool
23264684ddb6SLionel Sambucoperator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23274684ddb6SLionel Sambuc{
23284684ddb6SLionel Sambuc    return __y < __x;
23294684ddb6SLionel Sambuc}
23304684ddb6SLionel Sambuc
23314684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23324684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23334684ddb6SLionel Sambucbool
23344684ddb6SLionel Sambucoperator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23354684ddb6SLionel Sambuc{
23364684ddb6SLionel Sambuc    return !(__x < __y);
23374684ddb6SLionel Sambuc}
23384684ddb6SLionel Sambuc
23394684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23404684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23414684ddb6SLionel Sambucbool
23424684ddb6SLionel Sambucoperator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
23434684ddb6SLionel Sambuc{
23444684ddb6SLionel Sambuc    return !(__y < __x);
23454684ddb6SLionel Sambuc}
23464684ddb6SLionel Sambuc
23474684ddb6SLionel Sambuctemplate <class _Tp, class _Alloc>
23484684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY
23494684ddb6SLionel Sambucvoid
23504684ddb6SLionel Sambucswap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
23514684ddb6SLionel Sambuc    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
23524684ddb6SLionel Sambuc{
23534684ddb6SLionel Sambuc    __x.swap(__y);
23544684ddb6SLionel Sambuc}
23554684ddb6SLionel Sambuc
23564684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD
23574684ddb6SLionel Sambuc
23584684ddb6SLionel Sambuc#endif  // _LIBCPP_LIST
2359