xref: /freebsd-12.1/contrib/libc++/include/list (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===---------------------------- list ------------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_LIST
127a984708SDavid Chisnall#define _LIBCPP_LIST
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    list synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnallnamespace std
187a984708SDavid Chisnall{
197a984708SDavid Chisnall
207a984708SDavid Chisnalltemplate <class T, class Alloc = allocator<T> >
217a984708SDavid Chisnallclass list
227a984708SDavid Chisnall{
237a984708SDavid Chisnallpublic:
247a984708SDavid Chisnall
257a984708SDavid Chisnall    // types:
267a984708SDavid Chisnall    typedef T value_type;
277a984708SDavid Chisnall    typedef Alloc allocator_type;
287a984708SDavid Chisnall    typedef typename allocator_type::reference reference;
297a984708SDavid Chisnall    typedef typename allocator_type::const_reference const_reference;
307a984708SDavid Chisnall    typedef typename allocator_type::pointer pointer;
317a984708SDavid Chisnall    typedef typename allocator_type::const_pointer const_pointer;
327a984708SDavid Chisnall    typedef implementation-defined iterator;
337a984708SDavid Chisnall    typedef implementation-defined const_iterator;
347a984708SDavid Chisnall    typedef implementation-defined size_type;
357a984708SDavid Chisnall    typedef implementation-defined difference_type;
367a984708SDavid Chisnall    typedef reverse_iterator<iterator> reverse_iterator;
377a984708SDavid Chisnall    typedef reverse_iterator<const_iterator> const_reverse_iterator;
387a984708SDavid Chisnall
397a984708SDavid Chisnall    list()
407a984708SDavid Chisnall        noexcept(is_nothrow_default_constructible<allocator_type>::value);
417a984708SDavid Chisnall    explicit list(const allocator_type& a);
427a984708SDavid Chisnall    explicit list(size_type n);
434f7ab58eSDimitry Andric    explicit list(size_type n, const allocator_type& a); // C++14
447a984708SDavid Chisnall    list(size_type n, const value_type& value);
457a984708SDavid Chisnall    list(size_type n, const value_type& value, const allocator_type& a);
467a984708SDavid Chisnall    template <class Iter>
477a984708SDavid Chisnall        list(Iter first, Iter last);
487a984708SDavid Chisnall    template <class Iter>
497a984708SDavid Chisnall        list(Iter first, Iter last, const allocator_type& a);
507a984708SDavid Chisnall    list(const list& x);
517a984708SDavid Chisnall    list(const list&, const allocator_type& a);
527a984708SDavid Chisnall    list(list&& x)
537a984708SDavid Chisnall        noexcept(is_nothrow_move_constructible<allocator_type>::value);
547a984708SDavid Chisnall    list(list&&, const allocator_type& a);
557a984708SDavid Chisnall    list(initializer_list<value_type>);
567a984708SDavid Chisnall    list(initializer_list<value_type>, const allocator_type& a);
577a984708SDavid Chisnall
587a984708SDavid Chisnall    ~list();
597a984708SDavid Chisnall
607a984708SDavid Chisnall    list& operator=(const list& x);
617a984708SDavid Chisnall    list& operator=(list&& x)
627a984708SDavid Chisnall        noexcept(
637a984708SDavid Chisnall             allocator_type::propagate_on_container_move_assignment::value &&
647a984708SDavid Chisnall             is_nothrow_move_assignable<allocator_type>::value);
657a984708SDavid Chisnall    list& operator=(initializer_list<value_type>);
667a984708SDavid Chisnall    template <class Iter>
677a984708SDavid Chisnall        void assign(Iter first, Iter last);
687a984708SDavid Chisnall    void assign(size_type n, const value_type& t);
697a984708SDavid Chisnall    void assign(initializer_list<value_type>);
707a984708SDavid Chisnall
717a984708SDavid Chisnall    allocator_type get_allocator() const noexcept;
727a984708SDavid Chisnall
737a984708SDavid Chisnall    iterator begin() noexcept;
747a984708SDavid Chisnall    const_iterator begin() const noexcept;
757a984708SDavid Chisnall    iterator end() noexcept;
767a984708SDavid Chisnall    const_iterator end() const noexcept;
777a984708SDavid Chisnall    reverse_iterator rbegin() noexcept;
787a984708SDavid Chisnall    const_reverse_iterator rbegin() const noexcept;
797a984708SDavid Chisnall    reverse_iterator rend() noexcept;
807a984708SDavid Chisnall    const_reverse_iterator rend() const noexcept;
817a984708SDavid Chisnall    const_iterator cbegin() const noexcept;
827a984708SDavid Chisnall    const_iterator cend() const noexcept;
837a984708SDavid Chisnall    const_reverse_iterator crbegin() const noexcept;
847a984708SDavid Chisnall    const_reverse_iterator crend() const noexcept;
857a984708SDavid Chisnall
867a984708SDavid Chisnall    reference front();
877a984708SDavid Chisnall    const_reference front() const;
887a984708SDavid Chisnall    reference back();
897a984708SDavid Chisnall    const_reference back() const;
907a984708SDavid Chisnall
917a984708SDavid Chisnall    bool empty() const noexcept;
927a984708SDavid Chisnall    size_type size() const noexcept;
937a984708SDavid Chisnall    size_type max_size() const noexcept;
947a984708SDavid Chisnall
957a984708SDavid Chisnall    template <class... Args>
9698221d2eSDimitry Andric        reference emplace_front(Args&&... args); // reference in C++17
977a984708SDavid Chisnall    void pop_front();
987a984708SDavid Chisnall    template <class... Args>
9998221d2eSDimitry Andric        reference emplace_back(Args&&... args);  // reference in C++17
1007a984708SDavid Chisnall    void pop_back();
1017a984708SDavid Chisnall    void push_front(const value_type& x);
1027a984708SDavid Chisnall    void push_front(value_type&& x);
1037a984708SDavid Chisnall    void push_back(const value_type& x);
1047a984708SDavid Chisnall    void push_back(value_type&& x);
1057a984708SDavid Chisnall    template <class... Args>
1067a984708SDavid Chisnall        iterator emplace(const_iterator position, Args&&... args);
1077a984708SDavid Chisnall    iterator insert(const_iterator position, const value_type& x);
1087a984708SDavid Chisnall    iterator insert(const_iterator position, value_type&& x);
1097a984708SDavid Chisnall    iterator insert(const_iterator position, size_type n, const value_type& x);
1107a984708SDavid Chisnall    template <class Iter>
1117a984708SDavid Chisnall        iterator insert(const_iterator position, Iter first, Iter last);
1127a984708SDavid Chisnall    iterator insert(const_iterator position, initializer_list<value_type> il);
1137a984708SDavid Chisnall
1147a984708SDavid Chisnall    iterator erase(const_iterator position);
1157a984708SDavid Chisnall    iterator erase(const_iterator position, const_iterator last);
1167a984708SDavid Chisnall
1177a984708SDavid Chisnall    void resize(size_type sz);
1187a984708SDavid Chisnall    void resize(size_type sz, const value_type& c);
1197a984708SDavid Chisnall
1207a984708SDavid Chisnall    void swap(list&)
121854fa44bSDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1227a984708SDavid Chisnall    void clear() noexcept;
1237a984708SDavid Chisnall
1247a984708SDavid Chisnall    void splice(const_iterator position, list& x);
1257a984708SDavid Chisnall    void splice(const_iterator position, list&& x);
1267a984708SDavid Chisnall    void splice(const_iterator position, list& x, const_iterator i);
1277a984708SDavid Chisnall    void splice(const_iterator position, list&& x, const_iterator i);
1287a984708SDavid Chisnall    void splice(const_iterator position, list& x, const_iterator first,
1297a984708SDavid Chisnall                                                  const_iterator last);
1307a984708SDavid Chisnall    void splice(const_iterator position, list&& x, const_iterator first,
1317a984708SDavid Chisnall                                                  const_iterator last);
1327a984708SDavid Chisnall
1337a984708SDavid Chisnall    void remove(const value_type& value);
1347a984708SDavid Chisnall    template <class Pred> void remove_if(Pred pred);
1357a984708SDavid Chisnall    void unique();
1367a984708SDavid Chisnall    template <class BinaryPredicate>
1377a984708SDavid Chisnall        void unique(BinaryPredicate binary_pred);
1387a984708SDavid Chisnall    void merge(list& x);
1397a984708SDavid Chisnall    void merge(list&& x);
1407a984708SDavid Chisnall    template <class Compare>
1417a984708SDavid Chisnall        void merge(list& x, Compare comp);
1427a984708SDavid Chisnall    template <class Compare>
1437a984708SDavid Chisnall        void merge(list&& x, Compare comp);
1447a984708SDavid Chisnall    void sort();
1457a984708SDavid Chisnall    template <class Compare>
1467a984708SDavid Chisnall        void sort(Compare comp);
1477a984708SDavid Chisnall    void reverse() noexcept;
1487a984708SDavid Chisnall};
1497a984708SDavid Chisnall
1504ba319b5SDimitry Andric
1514ba319b5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1524ba319b5SDimitry Andric    list(InputIterator, InputIterator, Allocator = Allocator())
1534ba319b5SDimitry Andric    -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;  // C++17
1544ba319b5SDimitry Andric
1557a984708SDavid Chisnalltemplate <class T, class Alloc>
1567a984708SDavid Chisnall    bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
1577a984708SDavid Chisnalltemplate <class T, class Alloc>
1587a984708SDavid Chisnall    bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
1597a984708SDavid Chisnalltemplate <class T, class Alloc>
1607a984708SDavid Chisnall    bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1617a984708SDavid Chisnalltemplate <class T, class Alloc>
1627a984708SDavid Chisnall    bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
1637a984708SDavid Chisnalltemplate <class T, class Alloc>
1647a984708SDavid Chisnall    bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1657a984708SDavid Chisnalltemplate <class T, class Alloc>
1667a984708SDavid Chisnall    bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
1677a984708SDavid Chisnall
1687a984708SDavid Chisnalltemplate <class T, class Alloc>
1697a984708SDavid Chisnall    void swap(list<T,Alloc>& x, list<T,Alloc>& y)
1707a984708SDavid Chisnall         noexcept(noexcept(x.swap(y)));
1717a984708SDavid Chisnall
172*b5893f02SDimitry Andrictemplate <class T, class Allocator, class U>
173*b5893f02SDimitry Andric    void erase(list<T, Allocator>& c, const U& value);       // C++20
174*b5893f02SDimitry Andrictemplate <class T, class Allocator, class Predicate>
175*b5893f02SDimitry Andric    void erase_if(list<T, Allocator>& c, Predicate pred);    // C++20
176*b5893f02SDimitry Andric
1777a984708SDavid Chisnall}  // std
1787a984708SDavid Chisnall
1797a984708SDavid Chisnall*/
1807a984708SDavid Chisnall
1817a984708SDavid Chisnall#include <__config>
1827a984708SDavid Chisnall
1837a984708SDavid Chisnall#include <memory>
1847a984708SDavid Chisnall#include <limits>
1857a984708SDavid Chisnall#include <initializer_list>
1867a984708SDavid Chisnall#include <iterator>
1877a984708SDavid Chisnall#include <algorithm>
1889729cf09SDimitry Andric#include <type_traits>
189*b5893f02SDimitry Andric#include <version>
1907a984708SDavid Chisnall
1914f7ab58eSDimitry Andric#include <__debug>
1924f7ab58eSDimitry Andric
1937a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1947a984708SDavid Chisnall#pragma GCC system_header
1957a984708SDavid Chisnall#endif
1967a984708SDavid Chisnall
197f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS
198f9448bf3SDimitry Andric#include <__undef_macros>
199f9448bf3SDimitry Andric
200f9448bf3SDimitry Andric
2017a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
2027a984708SDavid Chisnall
2037a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr> struct __list_node;
2049729cf09SDimitry Andrictemplate <class _Tp, class _VoidPtr> struct __list_node_base;
2059729cf09SDimitry Andric
2069729cf09SDimitry Andrictemplate <class _Tp, class _VoidPtr>
2079729cf09SDimitry Andricstruct __list_node_pointer_traits {
2089729cf09SDimitry Andric  typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
2099729cf09SDimitry Andric        __node_pointer;
2109729cf09SDimitry Andric  typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
2119729cf09SDimitry Andric        __base_pointer;
2129729cf09SDimitry Andric
2139729cf09SDimitry Andric#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
2149729cf09SDimitry Andric  typedef __base_pointer __link_pointer;
2159729cf09SDimitry Andric#else
2169729cf09SDimitry Andric  typedef typename conditional<
2179729cf09SDimitry Andric          is_pointer<_VoidPtr>::value,
2189729cf09SDimitry Andric          __base_pointer,
2199729cf09SDimitry Andric          __node_pointer
2209729cf09SDimitry Andric  >::type __link_pointer;
2219729cf09SDimitry Andric#endif
2229729cf09SDimitry Andric
2239729cf09SDimitry Andric  typedef typename conditional<
2249729cf09SDimitry Andric          is_same<__link_pointer, __node_pointer>::value,
2259729cf09SDimitry Andric          __base_pointer,
2269729cf09SDimitry Andric          __node_pointer
2279729cf09SDimitry Andric  >::type __non_link_pointer;
2289729cf09SDimitry Andric
2299729cf09SDimitry Andric  static _LIBCPP_INLINE_VISIBILITY
2309729cf09SDimitry Andric  __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
2319729cf09SDimitry Andric      return __p;
2329729cf09SDimitry Andric  }
2339729cf09SDimitry Andric
2349729cf09SDimitry Andric  static _LIBCPP_INLINE_VISIBILITY
2359729cf09SDimitry Andric  __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
2369729cf09SDimitry Andric      return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
2379729cf09SDimitry Andric  }
2389729cf09SDimitry Andric
2399729cf09SDimitry Andric};
2407a984708SDavid Chisnall
2417a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr>
2427a984708SDavid Chisnallstruct __list_node_base
2437a984708SDavid Chisnall{
2449729cf09SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
2459729cf09SDimitry Andric    typedef typename _NodeTraits::__node_pointer __node_pointer;
2469729cf09SDimitry Andric    typedef typename _NodeTraits::__base_pointer __base_pointer;
2479729cf09SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
2487a984708SDavid Chisnall
2499729cf09SDimitry Andric    __link_pointer __prev_;
2509729cf09SDimitry Andric    __link_pointer __next_;
2517a984708SDavid Chisnall
2527a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2539729cf09SDimitry Andric    __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
2549729cf09SDimitry Andric                         __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
255d72607e9SDimitry Andric
256d72607e9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2579729cf09SDimitry Andric    __base_pointer __self() {
2589729cf09SDimitry Andric        return pointer_traits<__base_pointer>::pointer_to(*this);
2599729cf09SDimitry Andric    }
2609729cf09SDimitry Andric
2619729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2629729cf09SDimitry Andric    __node_pointer __as_node() {
2639729cf09SDimitry Andric        return static_cast<__node_pointer>(__self());
264d72607e9SDimitry Andric    }
2657a984708SDavid Chisnall};
2667a984708SDavid Chisnall
2677a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr>
2687a984708SDavid Chisnallstruct __list_node
2697a984708SDavid Chisnall    : public __list_node_base<_Tp, _VoidPtr>
2707a984708SDavid Chisnall{
2717a984708SDavid Chisnall    _Tp __value_;
2729729cf09SDimitry Andric
2739729cf09SDimitry Andric    typedef __list_node_base<_Tp, _VoidPtr> __base;
2749729cf09SDimitry Andric    typedef typename __base::__link_pointer __link_pointer;
2759729cf09SDimitry Andric
2769729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2779729cf09SDimitry Andric    __link_pointer __as_link() {
2789729cf09SDimitry Andric        return static_cast<__link_pointer>(__base::__self());
2799729cf09SDimitry Andric    }
2807a984708SDavid Chisnall};
2817a984708SDavid Chisnall
282aed8d94eSDimitry Andrictemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
2837a984708SDavid Chisnalltemplate <class _Tp, class _Alloc> class __list_imp;
284aed8d94eSDimitry Andrictemplate <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
2857a984708SDavid Chisnall
2867a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr>
287aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_iterator
2887a984708SDavid Chisnall{
2899729cf09SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
2909729cf09SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
2917a984708SDavid Chisnall
2929729cf09SDimitry Andric    __link_pointer __ptr_;
2937a984708SDavid Chisnall
2947a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
2957a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2969729cf09SDimitry Andric    explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
2977a984708SDavid Chisnall        : __ptr_(__p)
2987a984708SDavid Chisnall    {
2997a984708SDavid Chisnall        __get_db()->__insert_ic(this, __c);
3007a984708SDavid Chisnall    }
3017a984708SDavid Chisnall#else
3027a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3039729cf09SDimitry Andric    explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
3047a984708SDavid Chisnall#endif
3057a984708SDavid Chisnall
3067a984708SDavid Chisnall
3077a984708SDavid Chisnall
3087a984708SDavid Chisnall    template<class, class> friend class list;
3097a984708SDavid Chisnall    template<class, class> friend class __list_imp;
3107a984708SDavid Chisnall    template<class, class> friend class __list_const_iterator;
3117a984708SDavid Chisnallpublic:
3127a984708SDavid Chisnall    typedef bidirectional_iterator_tag       iterator_category;
3137a984708SDavid Chisnall    typedef _Tp                              value_type;
3147a984708SDavid Chisnall    typedef value_type&                      reference;
3159729cf09SDimitry Andric    typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
3167a984708SDavid Chisnall    typedef typename pointer_traits<pointer>::difference_type difference_type;
3177a984708SDavid Chisnall
3187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3194f7ab58eSDimitry Andric    __list_iterator() _NOEXCEPT : __ptr_(nullptr)
3207a984708SDavid Chisnall    {
3217a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3227a984708SDavid Chisnall        __get_db()->__insert_i(this);
3237a984708SDavid Chisnall#endif
3247a984708SDavid Chisnall    }
3257a984708SDavid Chisnall
3267a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3277a984708SDavid Chisnall
3287a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3297a984708SDavid Chisnall    __list_iterator(const __list_iterator& __p)
3307a984708SDavid Chisnall        : __ptr_(__p.__ptr_)
3317a984708SDavid Chisnall    {
3327a984708SDavid Chisnall        __get_db()->__iterator_copy(this, &__p);
3337a984708SDavid Chisnall    }
3347a984708SDavid Chisnall
3357a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3367a984708SDavid Chisnall    ~__list_iterator()
3377a984708SDavid Chisnall    {
3387a984708SDavid Chisnall        __get_db()->__erase_i(this);
3397a984708SDavid Chisnall    }
3407a984708SDavid Chisnall
3417a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3427a984708SDavid Chisnall    __list_iterator& operator=(const __list_iterator& __p)
3437a984708SDavid Chisnall    {
3447a984708SDavid Chisnall        if (this != &__p)
3457a984708SDavid Chisnall        {
3467a984708SDavid Chisnall            __get_db()->__iterator_copy(this, &__p);
3477a984708SDavid Chisnall            __ptr_ = __p.__ptr_;
3487a984708SDavid Chisnall        }
3497a984708SDavid Chisnall        return *this;
3507a984708SDavid Chisnall    }
3517a984708SDavid Chisnall
3527a984708SDavid Chisnall#endif  // _LIBCPP_DEBUG_LEVEL >= 2
3537a984708SDavid Chisnall
3547a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3557a984708SDavid Chisnall    reference operator*() const
3567a984708SDavid Chisnall    {
3577a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3587a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3597a984708SDavid Chisnall                       "Attempted to dereference a non-dereferenceable list::iterator");
3607a984708SDavid Chisnall#endif
3619729cf09SDimitry Andric        return __ptr_->__as_node()->__value_;
3627a984708SDavid Chisnall    }
3637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3644bab9fd9SDavid Chisnall    pointer operator->() const
3654bab9fd9SDavid Chisnall    {
3664bab9fd9SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3674bab9fd9SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3684bab9fd9SDavid Chisnall                       "Attempted to dereference a non-dereferenceable list::iterator");
3694bab9fd9SDavid Chisnall#endif
3709729cf09SDimitry Andric        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
3714bab9fd9SDavid Chisnall    }
3727a984708SDavid Chisnall
3737a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3747a984708SDavid Chisnall    __list_iterator& operator++()
3757a984708SDavid Chisnall    {
3767a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3777a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
3787a984708SDavid Chisnall                       "Attempted to increment non-incrementable list::iterator");
3797a984708SDavid Chisnall#endif
3807a984708SDavid Chisnall        __ptr_ = __ptr_->__next_;
3817a984708SDavid Chisnall        return *this;
3827a984708SDavid Chisnall    }
3837a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3847a984708SDavid Chisnall    __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
3857a984708SDavid Chisnall
3867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3877a984708SDavid Chisnall    __list_iterator& operator--()
3887a984708SDavid Chisnall    {
3897a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
3907a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
3917a984708SDavid Chisnall                       "Attempted to decrement non-decrementable list::iterator");
3927a984708SDavid Chisnall#endif
3937a984708SDavid Chisnall        __ptr_ = __ptr_->__prev_;
3947a984708SDavid Chisnall        return *this;
3957a984708SDavid Chisnall    }
3967a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3977a984708SDavid Chisnall    __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
3987a984708SDavid Chisnall
3997a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
4007a984708SDavid Chisnall    bool operator==(const __list_iterator& __x, const __list_iterator& __y)
4017a984708SDavid Chisnall    {
4027a984708SDavid Chisnall        return __x.__ptr_ == __y.__ptr_;
4037a984708SDavid Chisnall    }
4047a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
4057a984708SDavid Chisnall     bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
4067a984708SDavid Chisnall        {return !(__x == __y);}
4077a984708SDavid Chisnall};
4087a984708SDavid Chisnall
4097a984708SDavid Chisnalltemplate <class _Tp, class _VoidPtr>
410aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_const_iterator
4117a984708SDavid Chisnall{
4129729cf09SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
4139729cf09SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
4147a984708SDavid Chisnall
4159729cf09SDimitry Andric    __link_pointer __ptr_;
4167a984708SDavid Chisnall
4177a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4187a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4199729cf09SDimitry Andric    explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
4207a984708SDavid Chisnall        : __ptr_(__p)
4217a984708SDavid Chisnall    {
4227a984708SDavid Chisnall        __get_db()->__insert_ic(this, __c);
4237a984708SDavid Chisnall    }
4247a984708SDavid Chisnall#else
4257a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4269729cf09SDimitry Andric    explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
4277a984708SDavid Chisnall#endif
4287a984708SDavid Chisnall
4297a984708SDavid Chisnall    template<class, class> friend class list;
4307a984708SDavid Chisnall    template<class, class> friend class __list_imp;
4317a984708SDavid Chisnallpublic:
4327a984708SDavid Chisnall    typedef bidirectional_iterator_tag       iterator_category;
4337a984708SDavid Chisnall    typedef _Tp                              value_type;
4347a984708SDavid Chisnall    typedef const value_type&                reference;
4359729cf09SDimitry Andric    typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
4367a984708SDavid Chisnall    typedef typename pointer_traits<pointer>::difference_type difference_type;
4377a984708SDavid Chisnall
4387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4394f7ab58eSDimitry Andric    __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
4407a984708SDavid Chisnall    {
4417a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4427a984708SDavid Chisnall        __get_db()->__insert_i(this);
4437a984708SDavid Chisnall#endif
4447a984708SDavid Chisnall    }
4457a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4461bf9f7c1SDimitry Andric    __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
4477a984708SDavid Chisnall        : __ptr_(__p.__ptr_)
4487a984708SDavid Chisnall    {
4497a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4507a984708SDavid Chisnall        __get_db()->__iterator_copy(this, &__p);
4517a984708SDavid Chisnall#endif
4527a984708SDavid Chisnall    }
4537a984708SDavid Chisnall
4547a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4557a984708SDavid Chisnall
4567a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4577a984708SDavid Chisnall    __list_const_iterator(const __list_const_iterator& __p)
4587a984708SDavid Chisnall        : __ptr_(__p.__ptr_)
4597a984708SDavid Chisnall    {
4607a984708SDavid Chisnall        __get_db()->__iterator_copy(this, &__p);
4617a984708SDavid Chisnall    }
4627a984708SDavid Chisnall
4637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4647a984708SDavid Chisnall    ~__list_const_iterator()
4657a984708SDavid Chisnall    {
4667a984708SDavid Chisnall        __get_db()->__erase_i(this);
4677a984708SDavid Chisnall    }
4687a984708SDavid Chisnall
4697a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4707a984708SDavid Chisnall    __list_const_iterator& operator=(const __list_const_iterator& __p)
4717a984708SDavid Chisnall    {
4727a984708SDavid Chisnall        if (this != &__p)
4737a984708SDavid Chisnall        {
4747a984708SDavid Chisnall            __get_db()->__iterator_copy(this, &__p);
4757a984708SDavid Chisnall            __ptr_ = __p.__ptr_;
4767a984708SDavid Chisnall        }
4777a984708SDavid Chisnall        return *this;
4787a984708SDavid Chisnall    }
4797a984708SDavid Chisnall
4807a984708SDavid Chisnall#endif  // _LIBCPP_DEBUG_LEVEL >= 2
4817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4827a984708SDavid Chisnall    reference operator*() const
4837a984708SDavid Chisnall    {
4847a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4857a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
4867a984708SDavid Chisnall                       "Attempted to dereference a non-dereferenceable list::const_iterator");
4877a984708SDavid Chisnall#endif
4889729cf09SDimitry Andric        return __ptr_->__as_node()->__value_;
4897a984708SDavid Chisnall    }
4907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4914bab9fd9SDavid Chisnall    pointer operator->() const
4924bab9fd9SDavid Chisnall    {
4934bab9fd9SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
4944bab9fd9SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
495b2c7081bSDimitry Andric                       "Attempted to dereference a non-dereferenceable list::const_iterator");
4964bab9fd9SDavid Chisnall#endif
4979729cf09SDimitry Andric        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
4984bab9fd9SDavid Chisnall    }
4997a984708SDavid Chisnall
5007a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5017a984708SDavid Chisnall    __list_const_iterator& operator++()
5027a984708SDavid Chisnall    {
5037a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
5047a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
5057a984708SDavid Chisnall                       "Attempted to increment non-incrementable list::const_iterator");
5067a984708SDavid Chisnall#endif
5077a984708SDavid Chisnall        __ptr_ = __ptr_->__next_;
5087a984708SDavid Chisnall        return *this;
5097a984708SDavid Chisnall    }
5107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5117a984708SDavid Chisnall    __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
5127a984708SDavid Chisnall
5137a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5147a984708SDavid Chisnall    __list_const_iterator& operator--()
5157a984708SDavid Chisnall    {
5167a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
5177a984708SDavid Chisnall        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
5187a984708SDavid Chisnall                       "Attempted to decrement non-decrementable list::const_iterator");
5197a984708SDavid Chisnall#endif
5207a984708SDavid Chisnall        __ptr_ = __ptr_->__prev_;
5217a984708SDavid Chisnall        return *this;
5227a984708SDavid Chisnall    }
5237a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5247a984708SDavid Chisnall    __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
5257a984708SDavid Chisnall
5267a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
5277a984708SDavid Chisnall    bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
5287a984708SDavid Chisnall    {
5297a984708SDavid Chisnall        return __x.__ptr_ == __y.__ptr_;
5307a984708SDavid Chisnall    }
5317a984708SDavid Chisnall    friend _LIBCPP_INLINE_VISIBILITY
5327a984708SDavid Chisnall    bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
5337a984708SDavid Chisnall        {return !(__x == __y);}
5347a984708SDavid Chisnall};
5357a984708SDavid Chisnall
5367a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
5377a984708SDavid Chisnallclass __list_imp
5387a984708SDavid Chisnall{
5397a984708SDavid Chisnall    __list_imp(const __list_imp&);
5407a984708SDavid Chisnall    __list_imp& operator=(const __list_imp&);
5414ba319b5SDimitry Andricpublic:
5427a984708SDavid Chisnall    typedef _Alloc                                                  allocator_type;
5437a984708SDavid Chisnall    typedef allocator_traits<allocator_type>                        __alloc_traits;
5447a984708SDavid Chisnall    typedef typename __alloc_traits::size_type                      size_type;
5454ba319b5SDimitry Andricprotected:
5464ba319b5SDimitry Andric    typedef _Tp                                                     value_type;
5477a984708SDavid Chisnall    typedef typename __alloc_traits::void_pointer                   __void_pointer;
5487a984708SDavid Chisnall    typedef __list_iterator<value_type, __void_pointer>             iterator;
5497a984708SDavid Chisnall    typedef __list_const_iterator<value_type, __void_pointer>       const_iterator;
5507a984708SDavid Chisnall    typedef __list_node_base<value_type, __void_pointer>            __node_base;
5517a984708SDavid Chisnall    typedef __list_node<value_type, __void_pointer>                 __node;
552854fa44bSDimitry Andric    typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
5537a984708SDavid Chisnall    typedef allocator_traits<__node_allocator>                       __node_alloc_traits;
5547a984708SDavid Chisnall    typedef typename __node_alloc_traits::pointer                    __node_pointer;
5554bab9fd9SDavid Chisnall    typedef typename __node_alloc_traits::pointer                    __node_const_pointer;
5569729cf09SDimitry Andric    typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
5579729cf09SDimitry Andric    typedef typename __node_pointer_traits::__link_pointer __link_pointer;
5589729cf09SDimitry Andric    typedef __link_pointer __link_const_pointer;
5597a984708SDavid Chisnall    typedef typename __alloc_traits::pointer                         pointer;
5607a984708SDavid Chisnall    typedef typename __alloc_traits::const_pointer                   const_pointer;
5617a984708SDavid Chisnall    typedef typename __alloc_traits::difference_type                 difference_type;
5627a984708SDavid Chisnall
563854fa44bSDimitry Andric    typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
5644bab9fd9SDavid Chisnall    typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
5654ba319b5SDimitry Andric    static_assert((!is_same<allocator_type, __node_allocator>::value),
5664ba319b5SDimitry Andric                  "internal allocator type must differ from user-specified "
5674ba319b5SDimitry Andric                  "type; otherwise overload resolution breaks");
5684bab9fd9SDavid Chisnall
5697a984708SDavid Chisnall    __node_base __end_;
5707a984708SDavid Chisnall    __compressed_pair<size_type, __node_allocator> __size_alloc_;
5717a984708SDavid Chisnall
5727a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5739729cf09SDimitry Andric    __link_pointer __end_as_link() const _NOEXCEPT {
5749729cf09SDimitry Andric        return __node_pointer_traits::__unsafe_link_pointer_cast(
5759729cf09SDimitry Andric                const_cast<__node_base&>(__end_).__self());
5769729cf09SDimitry Andric    }
5779729cf09SDimitry Andric
5789729cf09SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5797a984708SDavid Chisnall          size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
5807a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5817a984708SDavid Chisnall    const size_type& __sz() const _NOEXCEPT
5827a984708SDavid Chisnall        {return __size_alloc_.first();}
5837a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5847a984708SDavid Chisnall          __node_allocator& __node_alloc() _NOEXCEPT
5857a984708SDavid Chisnall          {return __size_alloc_.second();}
5867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
5877a984708SDavid Chisnall    const __node_allocator& __node_alloc() const _NOEXCEPT
5887a984708SDavid Chisnall        {return __size_alloc_.second();}
5897a984708SDavid Chisnall
5907c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
591aed8d94eSDimitry Andric    size_type __node_alloc_max_size() const _NOEXCEPT {
592aed8d94eSDimitry Andric        return __node_alloc_traits::max_size(__node_alloc());
593aed8d94eSDimitry Andric    }
594aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5959729cf09SDimitry Andric    static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
5967a984708SDavid Chisnall
5977c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5987a984708SDavid Chisnall    __list_imp()
5997a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
6007c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6017a984708SDavid Chisnall    __list_imp(const allocator_type& __a);
6024ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6034ba319b5SDimitry Andric    __list_imp(const __node_allocator& __a);
6044ba319b5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
6054ba319b5SDimitry Andric    __list_imp(__node_allocator&& __a) _NOEXCEPT;
6064ba319b5SDimitry Andric#endif
6077a984708SDavid Chisnall    ~__list_imp();
6087a984708SDavid Chisnall    void clear() _NOEXCEPT;
6097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6107a984708SDavid Chisnall    bool empty() const _NOEXCEPT {return __sz() == 0;}
6117a984708SDavid Chisnall
6127a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6137a984708SDavid Chisnall    iterator begin() _NOEXCEPT
6147a984708SDavid Chisnall    {
6157a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
6167a984708SDavid Chisnall        return iterator(__end_.__next_, this);
6177a984708SDavid Chisnall#else
6187a984708SDavid Chisnall        return iterator(__end_.__next_);
6197a984708SDavid Chisnall#endif
6207a984708SDavid Chisnall    }
6217a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6227a984708SDavid Chisnall    const_iterator begin() const  _NOEXCEPT
6237a984708SDavid Chisnall    {
6247a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
6257a984708SDavid Chisnall        return const_iterator(__end_.__next_, this);
6267a984708SDavid Chisnall#else
6277a984708SDavid Chisnall        return const_iterator(__end_.__next_);
6287a984708SDavid Chisnall#endif
6297a984708SDavid Chisnall    }
6307a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6317a984708SDavid Chisnall    iterator end() _NOEXCEPT
6327a984708SDavid Chisnall    {
6337a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
6349729cf09SDimitry Andric        return iterator(__end_as_link(), this);
6357a984708SDavid Chisnall#else
6369729cf09SDimitry Andric        return iterator(__end_as_link());
6377a984708SDavid Chisnall#endif
6387a984708SDavid Chisnall    }
6397a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6407a984708SDavid Chisnall    const_iterator end() const _NOEXCEPT
6417a984708SDavid Chisnall    {
6427a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
6439729cf09SDimitry Andric        return const_iterator(__end_as_link(), this);
6447a984708SDavid Chisnall#else
6459729cf09SDimitry Andric        return const_iterator(__end_as_link());
6467a984708SDavid Chisnall#endif
6477a984708SDavid Chisnall    }
6487a984708SDavid Chisnall
6497a984708SDavid Chisnall    void swap(__list_imp& __c)
650854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
651aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG;
652854fa44bSDimitry Andric#else
653aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
654854fa44bSDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
655854fa44bSDimitry Andric#endif
6567a984708SDavid Chisnall
6577a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6587a984708SDavid Chisnall    void __copy_assign_alloc(const __list_imp& __c)
6597a984708SDavid Chisnall        {__copy_assign_alloc(__c, integral_constant<bool,
6607a984708SDavid Chisnall                      __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
6617a984708SDavid Chisnall
6627a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6637a984708SDavid Chisnall    void __move_assign_alloc(__list_imp& __c)
6647a984708SDavid Chisnall        _NOEXCEPT_(
6657a984708SDavid Chisnall            !__node_alloc_traits::propagate_on_container_move_assignment::value ||
6667a984708SDavid Chisnall            is_nothrow_move_assignable<__node_allocator>::value)
6677a984708SDavid Chisnall        {__move_assign_alloc(__c, integral_constant<bool,
6687a984708SDavid Chisnall                      __node_alloc_traits::propagate_on_container_move_assignment::value>());}
6697a984708SDavid Chisnall
6707a984708SDavid Chisnallprivate:
6717a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6727a984708SDavid Chisnall    void __copy_assign_alloc(const __list_imp& __c, true_type)
6737a984708SDavid Chisnall        {
6747a984708SDavid Chisnall            if (__node_alloc() != __c.__node_alloc())
6757a984708SDavid Chisnall                clear();
6767a984708SDavid Chisnall            __node_alloc() = __c.__node_alloc();
6777a984708SDavid Chisnall        }
6787a984708SDavid Chisnall
6797a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
680aed8d94eSDimitry Andric    void __copy_assign_alloc(const __list_imp&, false_type)
6817a984708SDavid Chisnall        {}
6827a984708SDavid Chisnall
6837a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
6847a984708SDavid Chisnall    void __move_assign_alloc(__list_imp& __c, true_type)
6857a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
6867a984708SDavid Chisnall        {
6877a984708SDavid Chisnall            __node_alloc() = _VSTD::move(__c.__node_alloc());
6887a984708SDavid Chisnall        }
6897a984708SDavid Chisnall
6907a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
691aed8d94eSDimitry Andric    void __move_assign_alloc(__list_imp&, false_type)
6927a984708SDavid Chisnall        _NOEXCEPT
6937a984708SDavid Chisnall        {}
694aed8d94eSDimitry Andric
695aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
696aed8d94eSDimitry Andric    void __invalidate_all_iterators() {
697aed8d94eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
698aed8d94eSDimitry Andric      __get_db()->__invalidate_all(this);
699aed8d94eSDimitry Andric#endif
700aed8d94eSDimitry Andric    }
7017a984708SDavid Chisnall};
7027a984708SDavid Chisnall
7037a984708SDavid Chisnall// Unlink nodes [__f, __l]
7047a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7057c82a1ecSDimitry Andricinline
7067a984708SDavid Chisnallvoid
7079729cf09SDimitry Andric__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
7087a984708SDavid Chisnall    _NOEXCEPT
7097a984708SDavid Chisnall{
7104bab9fd9SDavid Chisnall    __f->__prev_->__next_ = __l->__next_;
7114bab9fd9SDavid Chisnall    __l->__next_->__prev_ = __f->__prev_;
7127a984708SDavid Chisnall}
7137a984708SDavid Chisnall
7147a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7157c82a1ecSDimitry Andricinline
7167a984708SDavid Chisnall__list_imp<_Tp, _Alloc>::__list_imp()
7177a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
7187a984708SDavid Chisnall    : __size_alloc_(0)
7197a984708SDavid Chisnall{
7207a984708SDavid Chisnall}
7217a984708SDavid Chisnall
7227a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7237c82a1ecSDimitry Andricinline
7247a984708SDavid Chisnall__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
7257a984708SDavid Chisnall    : __size_alloc_(0, __node_allocator(__a))
7267a984708SDavid Chisnall{
7277a984708SDavid Chisnall}
7287a984708SDavid Chisnall
7297a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7304ba319b5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a)
7314ba319b5SDimitry Andric    : __size_alloc_(0, __a) {}
7324ba319b5SDimitry Andric
7334ba319b5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7344ba319b5SDimitry Andrictemplate <class _Tp, class _Alloc>
7354ba319b5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
7364ba319b5SDimitry Andric    : __size_alloc_(0, std::move(__a)) {}
7374ba319b5SDimitry Andric#endif
7384ba319b5SDimitry Andric
7394ba319b5SDimitry Andrictemplate <class _Tp, class _Alloc>
7404ba319b5SDimitry Andric__list_imp<_Tp, _Alloc>::~__list_imp() {
7417a984708SDavid Chisnall  clear();
7427a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
7437a984708SDavid Chisnall    __get_db()->__erase_c(this);
7447a984708SDavid Chisnall#endif
7457a984708SDavid Chisnall}
7467a984708SDavid Chisnall
7477a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7487a984708SDavid Chisnallvoid
7497a984708SDavid Chisnall__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
7507a984708SDavid Chisnall{
7517a984708SDavid Chisnall    if (!empty())
7527a984708SDavid Chisnall    {
7537a984708SDavid Chisnall        __node_allocator& __na = __node_alloc();
7549729cf09SDimitry Andric        __link_pointer __f = __end_.__next_;
7559729cf09SDimitry Andric        __link_pointer __l = __end_as_link();
7564bab9fd9SDavid Chisnall        __unlink_nodes(__f, __l->__prev_);
7577a984708SDavid Chisnall        __sz() = 0;
7587a984708SDavid Chisnall        while (__f != __l)
7597a984708SDavid Chisnall        {
7609729cf09SDimitry Andric            __node_pointer __np = __f->__as_node();
7617a984708SDavid Chisnall            __f = __f->__next_;
7629729cf09SDimitry Andric            __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
7639729cf09SDimitry Andric            __node_alloc_traits::deallocate(__na, __np, 1);
7647a984708SDavid Chisnall        }
765aed8d94eSDimitry Andric        __invalidate_all_iterators();
7667a984708SDavid Chisnall    }
7677a984708SDavid Chisnall}
7687a984708SDavid Chisnall
7697a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
7707a984708SDavid Chisnallvoid
7717a984708SDavid Chisnall__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
772854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
773aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG
774854fa44bSDimitry Andric#else
775aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
776854fa44bSDimitry Andric                    __is_nothrow_swappable<allocator_type>::value)
777854fa44bSDimitry Andric#endif
7787a984708SDavid Chisnall{
7797a984708SDavid Chisnall    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
7807a984708SDavid Chisnall                   this->__node_alloc() == __c.__node_alloc(),
7817a984708SDavid Chisnall                   "list::swap: Either propagate_on_container_swap must be true"
7827a984708SDavid Chisnall                   " or the allocators must compare equal");
7837a984708SDavid Chisnall    using _VSTD::swap;
784854fa44bSDimitry Andric    __swap_allocator(__node_alloc(), __c.__node_alloc());
7857a984708SDavid Chisnall    swap(__sz(), __c.__sz());
7867a984708SDavid Chisnall    swap(__end_, __c.__end_);
7877a984708SDavid Chisnall    if (__sz() == 0)
7889729cf09SDimitry Andric        __end_.__next_ = __end_.__prev_ = __end_as_link();
7897a984708SDavid Chisnall    else
7909729cf09SDimitry Andric        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
7917a984708SDavid Chisnall    if (__c.__sz() == 0)
7929729cf09SDimitry Andric        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
7937a984708SDavid Chisnall    else
7949729cf09SDimitry Andric        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
795d72607e9SDimitry Andric
7967a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
7977a984708SDavid Chisnall    __libcpp_db* __db = __get_db();
7987a984708SDavid Chisnall    __c_node* __cn1 = __db->__find_c_and_lock(this);
7997a984708SDavid Chisnall    __c_node* __cn2 = __db->__find_c(&__c);
8007a984708SDavid Chisnall    std::swap(__cn1->beg_, __cn2->beg_);
8017a984708SDavid Chisnall    std::swap(__cn1->end_, __cn2->end_);
8027a984708SDavid Chisnall    std::swap(__cn1->cap_, __cn2->cap_);
8037a984708SDavid Chisnall    for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
8047a984708SDavid Chisnall    {
8057a984708SDavid Chisnall        --__p;
8067a984708SDavid Chisnall        const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
8079729cf09SDimitry Andric        if (__i->__ptr_ == __c.__end_as_link())
8087a984708SDavid Chisnall        {
8097a984708SDavid Chisnall            __cn2->__add(*__p);
8107a984708SDavid Chisnall            if (--__cn1->end_ != __p)
8117a984708SDavid Chisnall                memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
8127a984708SDavid Chisnall        }
8137a984708SDavid Chisnall        else
8147a984708SDavid Chisnall            (*__p)->__c_ = __cn1;
8157a984708SDavid Chisnall    }
8167a984708SDavid Chisnall    for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
8177a984708SDavid Chisnall    {
8187a984708SDavid Chisnall        --__p;
8197a984708SDavid Chisnall        const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
8209729cf09SDimitry Andric        if (__i->__ptr_ == __end_as_link())
8217a984708SDavid Chisnall        {
8227a984708SDavid Chisnall            __cn1->__add(*__p);
8237a984708SDavid Chisnall            if (--__cn2->end_ != __p)
8247a984708SDavid Chisnall                memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
8257a984708SDavid Chisnall        }
8267a984708SDavid Chisnall        else
8277a984708SDavid Chisnall            (*__p)->__c_ = __cn2;
8287a984708SDavid Chisnall    }
8297a984708SDavid Chisnall    __db->unlock();
8307a984708SDavid Chisnall#endif
8317a984708SDavid Chisnall}
8327a984708SDavid Chisnall
833854fa44bSDimitry Andrictemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/>
834aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS list
8357a984708SDavid Chisnall    : private __list_imp<_Tp, _Alloc>
8367a984708SDavid Chisnall{
8377a984708SDavid Chisnall    typedef __list_imp<_Tp, _Alloc> base;
8387a984708SDavid Chisnall    typedef typename base::__node              __node;
8397a984708SDavid Chisnall    typedef typename base::__node_allocator    __node_allocator;
8407a984708SDavid Chisnall    typedef typename base::__node_pointer      __node_pointer;
8417a984708SDavid Chisnall    typedef typename base::__node_alloc_traits __node_alloc_traits;
8424bab9fd9SDavid Chisnall    typedef typename base::__node_base         __node_base;
8434bab9fd9SDavid Chisnall    typedef typename base::__node_base_pointer __node_base_pointer;
8449729cf09SDimitry Andric    typedef typename base::__link_pointer __link_pointer;
8457a984708SDavid Chisnall
8467a984708SDavid Chisnallpublic:
8477a984708SDavid Chisnall    typedef _Tp                                      value_type;
8487a984708SDavid Chisnall    typedef _Alloc                                   allocator_type;
8497a984708SDavid Chisnall    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
8507a984708SDavid Chisnall                  "Invalid allocator::value_type");
8517a984708SDavid Chisnall    typedef value_type&                              reference;
8527a984708SDavid Chisnall    typedef const value_type&                        const_reference;
8537a984708SDavid Chisnall    typedef typename base::pointer                   pointer;
8547a984708SDavid Chisnall    typedef typename base::const_pointer             const_pointer;
8557a984708SDavid Chisnall    typedef typename base::size_type                 size_type;
8567a984708SDavid Chisnall    typedef typename base::difference_type           difference_type;
8577a984708SDavid Chisnall    typedef typename base::iterator                  iterator;
8587a984708SDavid Chisnall    typedef typename base::const_iterator            const_iterator;
8597a984708SDavid Chisnall    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
8607a984708SDavid Chisnall    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
8617a984708SDavid Chisnall
8627a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8637a984708SDavid Chisnall    list()
8647a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
8657a984708SDavid Chisnall    {
8667a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
8677a984708SDavid Chisnall        __get_db()->__insert_c(this);
8687a984708SDavid Chisnall#endif
8697a984708SDavid Chisnall    }
8707a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
8714f7ab58eSDimitry Andric    explicit list(const allocator_type& __a) : base(__a)
8727a984708SDavid Chisnall    {
8737a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
8747a984708SDavid Chisnall        __get_db()->__insert_c(this);
8757a984708SDavid Chisnall#endif
8767a984708SDavid Chisnall    }
8774f7ab58eSDimitry Andric    explicit list(size_type __n);
8784f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11
8794f7ab58eSDimitry Andric    explicit list(size_type __n, const allocator_type& __a);
8804f7ab58eSDimitry Andric#endif
8817a984708SDavid Chisnall    list(size_type __n, const value_type& __x);
8827a984708SDavid Chisnall    list(size_type __n, const value_type& __x, const allocator_type& __a);
8837a984708SDavid Chisnall    template <class _InpIter>
8847a984708SDavid Chisnall        list(_InpIter __f, _InpIter __l,
8857a984708SDavid Chisnall             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
8867a984708SDavid Chisnall    template <class _InpIter>
8877a984708SDavid Chisnall        list(_InpIter __f, _InpIter __l, const allocator_type& __a,
8887a984708SDavid Chisnall             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
8897a984708SDavid Chisnall
8907a984708SDavid Chisnall    list(const list& __c);
8917a984708SDavid Chisnall    list(const list& __c, const allocator_type& __a);
8927c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8937a984708SDavid Chisnall    list& operator=(const list& __c);
894540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8957a984708SDavid Chisnall    list(initializer_list<value_type> __il);
8967a984708SDavid Chisnall    list(initializer_list<value_type> __il, const allocator_type& __a);
897540d2a8bSDimitry Andric
8987c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8997a984708SDavid Chisnall    list(list&& __c)
9007a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
9017c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9027a984708SDavid Chisnall    list(list&& __c, const allocator_type& __a);
9037c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9047a984708SDavid Chisnall    list& operator=(list&& __c)
9057a984708SDavid Chisnall        _NOEXCEPT_(
9067a984708SDavid Chisnall            __node_alloc_traits::propagate_on_container_move_assignment::value &&
9077a984708SDavid Chisnall            is_nothrow_move_assignable<__node_allocator>::value);
908540d2a8bSDimitry Andric
9097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9107a984708SDavid Chisnall    list& operator=(initializer_list<value_type> __il)
9117a984708SDavid Chisnall        {assign(__il.begin(), __il.end()); return *this;}
912540d2a8bSDimitry Andric
913540d2a8bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
914540d2a8bSDimitry Andric    void assign(initializer_list<value_type> __il)
915540d2a8bSDimitry Andric        {assign(__il.begin(), __il.end());}
916540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
9177a984708SDavid Chisnall
9187a984708SDavid Chisnall    template <class _InpIter>
9197a984708SDavid Chisnall        void assign(_InpIter __f, _InpIter __l,
9207a984708SDavid Chisnall             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
9217a984708SDavid Chisnall    void assign(size_type __n, const value_type& __x);
9227a984708SDavid Chisnall
9237c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9247a984708SDavid Chisnall    allocator_type get_allocator() const _NOEXCEPT;
9257a984708SDavid Chisnall
9267a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9277a984708SDavid Chisnall    size_type size() const _NOEXCEPT     {return base::__sz();}
928b2c7081bSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
9297a984708SDavid Chisnall    bool empty() const _NOEXCEPT         {return base::empty();}
9307a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9317a984708SDavid Chisnall    size_type max_size() const _NOEXCEPT
932aed8d94eSDimitry Andric        {
933aed8d94eSDimitry Andric            return std::min<size_type>(
934aed8d94eSDimitry Andric                base::__node_alloc_max_size(),
935aed8d94eSDimitry Andric                numeric_limits<difference_type >::max());
936aed8d94eSDimitry Andric        }
9377a984708SDavid Chisnall
9387a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9397a984708SDavid Chisnall          iterator begin() _NOEXCEPT        {return base::begin();}
9407a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9417a984708SDavid Chisnall    const_iterator begin()  const _NOEXCEPT {return base::begin();}
9427a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9437a984708SDavid Chisnall          iterator end() _NOEXCEPT          {return base::end();}
9447a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9457a984708SDavid Chisnall    const_iterator end()    const _NOEXCEPT {return base::end();}
9467a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9477a984708SDavid Chisnall    const_iterator cbegin() const _NOEXCEPT {return base::begin();}
9487a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9497a984708SDavid Chisnall    const_iterator cend()   const _NOEXCEPT {return base::end();}
9507a984708SDavid Chisnall
9517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9527a984708SDavid Chisnall          reverse_iterator rbegin() _NOEXCEPT
9537a984708SDavid Chisnall            {return       reverse_iterator(end());}
9547a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9557a984708SDavid Chisnall    const_reverse_iterator rbegin()  const _NOEXCEPT
9567a984708SDavid Chisnall        {return const_reverse_iterator(end());}
9577a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9587a984708SDavid Chisnall          reverse_iterator rend() _NOEXCEPT
9597a984708SDavid Chisnall            {return       reverse_iterator(begin());}
9607a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9617a984708SDavid Chisnall    const_reverse_iterator rend()    const _NOEXCEPT
9627a984708SDavid Chisnall        {return const_reverse_iterator(begin());}
9637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9647a984708SDavid Chisnall    const_reverse_iterator crbegin() const _NOEXCEPT
9657a984708SDavid Chisnall        {return const_reverse_iterator(end());}
9667a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9677a984708SDavid Chisnall    const_reverse_iterator crend()   const _NOEXCEPT
9687a984708SDavid Chisnall        {return const_reverse_iterator(begin());}
9697a984708SDavid Chisnall
9707a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9717a984708SDavid Chisnall    reference front()
9727a984708SDavid Chisnall    {
9737a984708SDavid Chisnall        _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
9749729cf09SDimitry Andric        return base::__end_.__next_->__as_node()->__value_;
9757a984708SDavid Chisnall    }
9767a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9777a984708SDavid Chisnall    const_reference front() const
9787a984708SDavid Chisnall    {
9797a984708SDavid Chisnall        _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
9809729cf09SDimitry Andric        return base::__end_.__next_->__as_node()->__value_;
9817a984708SDavid Chisnall    }
9827a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9837a984708SDavid Chisnall    reference back()
9847a984708SDavid Chisnall    {
9857a984708SDavid Chisnall        _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
9869729cf09SDimitry Andric        return base::__end_.__prev_->__as_node()->__value_;
9877a984708SDavid Chisnall    }
9887a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
9897a984708SDavid Chisnall    const_reference back() const
9907a984708SDavid Chisnall    {
9917a984708SDavid Chisnall        _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
9929729cf09SDimitry Andric        return base::__end_.__prev_->__as_node()->__value_;
9937a984708SDavid Chisnall    }
9947a984708SDavid Chisnall
995540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9967a984708SDavid Chisnall    void push_front(value_type&& __x);
9977a984708SDavid Chisnall    void push_back(value_type&& __x);
998540d2a8bSDimitry Andric
9997a984708SDavid Chisnall    template <class... _Args>
100098221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1001aed8d94eSDimitry Andric       reference emplace_front(_Args&&... __args);
100298221d2eSDimitry Andric#else
100398221d2eSDimitry Andric       void      emplace_front(_Args&&... __args);
100498221d2eSDimitry Andric#endif
10057a984708SDavid Chisnall    template <class... _Args>
100698221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1007aed8d94eSDimitry Andric        reference emplace_back(_Args&&... __args);
100898221d2eSDimitry Andric#else
100998221d2eSDimitry Andric       void       emplace_back(_Args&&... __args);
101098221d2eSDimitry Andric#endif
10117a984708SDavid Chisnall    template <class... _Args>
10127a984708SDavid Chisnall        iterator emplace(const_iterator __p, _Args&&... __args);
1013540d2a8bSDimitry Andric
10147a984708SDavid Chisnall    iterator insert(const_iterator __p, value_type&& __x);
1015540d2a8bSDimitry Andric
1016540d2a8bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1017540d2a8bSDimitry Andric    iterator insert(const_iterator __p, initializer_list<value_type> __il)
1018540d2a8bSDimitry Andric        {return insert(__p, __il.begin(), __il.end());}
1019540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
10207a984708SDavid Chisnall
10217a984708SDavid Chisnall    void push_front(const value_type& __x);
10227a984708SDavid Chisnall    void push_back(const value_type& __x);
10237a984708SDavid Chisnall
1024d4419f6fSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1025d4419f6fSDimitry Andric    template <class _Arg>
1026d4419f6fSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1027d4419f6fSDimitry Andric    void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); }
1028d4419f6fSDimitry Andric#else
1029d4419f6fSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1030d4419f6fSDimitry Andric    void __emplace_back(value_type const& __arg) { push_back(__arg); }
1031d4419f6fSDimitry Andric#endif
1032d4419f6fSDimitry Andric
10337a984708SDavid Chisnall    iterator insert(const_iterator __p, const value_type& __x);
10347a984708SDavid Chisnall    iterator insert(const_iterator __p, size_type __n, const value_type& __x);
10357a984708SDavid Chisnall    template <class _InpIter>
10367a984708SDavid Chisnall        iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
10377a984708SDavid Chisnall             typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
10387a984708SDavid Chisnall
10397a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10407a984708SDavid Chisnall    void swap(list& __c)
1041854fa44bSDimitry Andric#if _LIBCPP_STD_VER >= 14
1042aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG
1043854fa44bSDimitry Andric#else
1044aed8d94eSDimitry Andric        _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
10457a984708SDavid Chisnall                   __is_nothrow_swappable<__node_allocator>::value)
1046854fa44bSDimitry Andric#endif
10477a984708SDavid Chisnall        {base::swap(__c);}
10487a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10497a984708SDavid Chisnall    void clear() _NOEXCEPT {base::clear();}
10507a984708SDavid Chisnall
10517a984708SDavid Chisnall    void pop_front();
10527a984708SDavid Chisnall    void pop_back();
10537a984708SDavid Chisnall
10547a984708SDavid Chisnall    iterator erase(const_iterator __p);
10557a984708SDavid Chisnall    iterator erase(const_iterator __f, const_iterator __l);
10567a984708SDavid Chisnall
10577a984708SDavid Chisnall    void resize(size_type __n);
10587a984708SDavid Chisnall    void resize(size_type __n, const value_type& __x);
10597a984708SDavid Chisnall
10607a984708SDavid Chisnall    void splice(const_iterator __p, list& __c);
1061540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10627a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10637a984708SDavid Chisnall    void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
10647a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10657a984708SDavid Chisnall    void splice(const_iterator __p, list&& __c, const_iterator __i)
10667a984708SDavid Chisnall        {splice(__p, __c, __i);}
10677a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10687a984708SDavid Chisnall    void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
10697a984708SDavid Chisnall        {splice(__p, __c, __f, __l);}
1070540d2a8bSDimitry Andric#endif
1071540d2a8bSDimitry Andric    void splice(const_iterator __p, list& __c, const_iterator __i);
1072540d2a8bSDimitry Andric    void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
10737a984708SDavid Chisnall
10747a984708SDavid Chisnall    void remove(const value_type& __x);
10757a984708SDavid Chisnall    template <class _Pred> void remove_if(_Pred __pred);
10767c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10777a984708SDavid Chisnall    void unique();
10787a984708SDavid Chisnall    template <class _BinaryPred>
10797a984708SDavid Chisnall        void unique(_BinaryPred __binary_pred);
10807c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10817a984708SDavid Chisnall    void merge(list& __c);
1082540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10837a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10847a984708SDavid Chisnall    void merge(list&& __c) {merge(__c);}
1085540d2a8bSDimitry Andric
10867a984708SDavid Chisnall    template <class _Comp>
10877a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
10887a984708SDavid Chisnall        void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
1089540d2a8bSDimitry Andric#endif
1090540d2a8bSDimitry Andric    template <class _Comp>
1091540d2a8bSDimitry Andric        void merge(list& __c, _Comp __comp);
1092540d2a8bSDimitry Andric
10937c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10947a984708SDavid Chisnall    void sort();
10957a984708SDavid Chisnall    template <class _Comp>
10967c82a1ecSDimitry Andric        _LIBCPP_INLINE_VISIBILITY
10977a984708SDavid Chisnall        void sort(_Comp __comp);
10987a984708SDavid Chisnall
10997a984708SDavid Chisnall    void reverse() _NOEXCEPT;
11007a984708SDavid Chisnall
11017a984708SDavid Chisnall    bool __invariants() const;
11027a984708SDavid Chisnall
1103b2c7081bSDimitry Andric    typedef __allocator_destructor<__node_allocator> __node_destructor;
1104b2c7081bSDimitry Andric    typedef unique_ptr<__node, __node_destructor> __hold_pointer;
1105b2c7081bSDimitry Andric
1106b2c7081bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1107b2c7081bSDimitry Andric    __hold_pointer __allocate_node(__node_allocator& __na) {
1108b2c7081bSDimitry Andric      __node_pointer __p = __node_alloc_traits::allocate(__na, 1);
1109b2c7081bSDimitry Andric      __p->__prev_ = nullptr;
1110b2c7081bSDimitry Andric      return __hold_pointer(__p, __node_destructor(__na, 1));
1111b2c7081bSDimitry Andric    }
1112b2c7081bSDimitry Andric
11137a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
11147a984708SDavid Chisnall
11157a984708SDavid Chisnall    bool __dereferenceable(const const_iterator* __i) const;
11167a984708SDavid Chisnall    bool __decrementable(const const_iterator* __i) const;
11177a984708SDavid Chisnall    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
11187a984708SDavid Chisnall    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
11197a984708SDavid Chisnall
11207a984708SDavid Chisnall#endif  // _LIBCPP_DEBUG_LEVEL >= 2
11217a984708SDavid Chisnall
11227a984708SDavid Chisnallprivate:
11237c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11249729cf09SDimitry Andric    static void __link_nodes  (__link_pointer __p, __link_pointer __f, __link_pointer __l);
11257c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11269729cf09SDimitry Andric    void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
11277c82a1ecSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11289729cf09SDimitry Andric    void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
11297a984708SDavid Chisnall    iterator __iterator(size_type __n);
11307a984708SDavid Chisnall    template <class _Comp>
11317a984708SDavid Chisnall        static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
11327a984708SDavid Chisnall
11337a984708SDavid Chisnall    void __move_assign(list& __c, true_type)
11347a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
11357a984708SDavid Chisnall    void __move_assign(list& __c, false_type);
11367a984708SDavid Chisnall};
11377a984708SDavid Chisnall
11384ba319b5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
11394ba319b5SDimitry Andrictemplate<class _InputIterator,
11404ba319b5SDimitry Andric         class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
11414ba319b5SDimitry Andric         class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
11424ba319b5SDimitry Andric         >
11434ba319b5SDimitry Andriclist(_InputIterator, _InputIterator)
11444ba319b5SDimitry Andric  -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
11454ba319b5SDimitry Andric
11464ba319b5SDimitry Andrictemplate<class _InputIterator,
11474ba319b5SDimitry Andric         class _Alloc,
11484ba319b5SDimitry Andric         class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
11494ba319b5SDimitry Andric         >
11504ba319b5SDimitry Andriclist(_InputIterator, _InputIterator, _Alloc)
11514ba319b5SDimitry Andric  -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
11524ba319b5SDimitry Andric#endif
11534ba319b5SDimitry Andric
11547a984708SDavid Chisnall// Link in nodes [__f, __l] just prior to __p
11557a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11567c82a1ecSDimitry Andricinline
11577a984708SDavid Chisnallvoid
11589729cf09SDimitry Andriclist<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
11597a984708SDavid Chisnall{
11604bab9fd9SDavid Chisnall    __p->__prev_->__next_ = __f;
11614bab9fd9SDavid Chisnall    __f->__prev_ = __p->__prev_;
11624bab9fd9SDavid Chisnall    __p->__prev_ = __l;
11634bab9fd9SDavid Chisnall    __l->__next_ = __p;
11647a984708SDavid Chisnall}
11657a984708SDavid Chisnall
1166d72607e9SDimitry Andric// Link in nodes [__f, __l] at the front of the list
1167d72607e9SDimitry Andrictemplate <class _Tp, class _Alloc>
11687c82a1ecSDimitry Andricinline
1169d72607e9SDimitry Andricvoid
11709729cf09SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
1171d72607e9SDimitry Andric{
11729729cf09SDimitry Andric    __f->__prev_ = base::__end_as_link();
1173d72607e9SDimitry Andric    __l->__next_ = base::__end_.__next_;
1174d72607e9SDimitry Andric    __l->__next_->__prev_ = __l;
1175d72607e9SDimitry Andric    base::__end_.__next_ = __f;
1176d72607e9SDimitry Andric}
1177d72607e9SDimitry Andric
1178*b5893f02SDimitry Andric// Link in nodes [__f, __l] at the back of the list
1179d72607e9SDimitry Andrictemplate <class _Tp, class _Alloc>
11807c82a1ecSDimitry Andricinline
1181d72607e9SDimitry Andricvoid
11829729cf09SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
1183d72607e9SDimitry Andric{
11849729cf09SDimitry Andric    __l->__next_ = base::__end_as_link();
1185d72607e9SDimitry Andric    __f->__prev_ = base::__end_.__prev_;
1186d72607e9SDimitry Andric    __f->__prev_->__next_ = __f;
1187d72607e9SDimitry Andric    base::__end_.__prev_ = __l;
1188d72607e9SDimitry Andric}
1189d72607e9SDimitry Andric
1190d72607e9SDimitry Andric
11917a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
11927c82a1ecSDimitry Andricinline
11937a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
11947a984708SDavid Chisnalllist<_Tp, _Alloc>::__iterator(size_type __n)
11957a984708SDavid Chisnall{
11967a984708SDavid Chisnall    return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
11977a984708SDavid Chisnall                                   : _VSTD::prev(end(), base::__sz() - __n);
11987a984708SDavid Chisnall}
11997a984708SDavid Chisnall
12007a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12017a984708SDavid Chisnalllist<_Tp, _Alloc>::list(size_type __n)
12027a984708SDavid Chisnall{
12037a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12047a984708SDavid Chisnall    __get_db()->__insert_c(this);
12057a984708SDavid Chisnall#endif
12067a984708SDavid Chisnall    for (; __n > 0; --__n)
1207540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12087a984708SDavid Chisnall        emplace_back();
12097a984708SDavid Chisnall#else
12107a984708SDavid Chisnall        push_back(value_type());
12117a984708SDavid Chisnall#endif
12127a984708SDavid Chisnall}
12137a984708SDavid Chisnall
12144f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11
12154f7ab58eSDimitry Andrictemplate <class _Tp, class _Alloc>
12164f7ab58eSDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
12174f7ab58eSDimitry Andric{
12184f7ab58eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
12194f7ab58eSDimitry Andric    __get_db()->__insert_c(this);
12204f7ab58eSDimitry Andric#endif
12214f7ab58eSDimitry Andric    for (; __n > 0; --__n)
12224f7ab58eSDimitry Andric        emplace_back();
12234f7ab58eSDimitry Andric}
12244f7ab58eSDimitry Andric#endif
12254f7ab58eSDimitry Andric
12267a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12277a984708SDavid Chisnalllist<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
12287a984708SDavid Chisnall{
12297a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12307a984708SDavid Chisnall    __get_db()->__insert_c(this);
12317a984708SDavid Chisnall#endif
12327a984708SDavid Chisnall    for (; __n > 0; --__n)
12337a984708SDavid Chisnall        push_back(__x);
12347a984708SDavid Chisnall}
12357a984708SDavid Chisnall
12367a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12377a984708SDavid Chisnalllist<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
12387a984708SDavid Chisnall    : base(__a)
12397a984708SDavid Chisnall{
12407a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12417a984708SDavid Chisnall    __get_db()->__insert_c(this);
12427a984708SDavid Chisnall#endif
12437a984708SDavid Chisnall    for (; __n > 0; --__n)
12447a984708SDavid Chisnall        push_back(__x);
12457a984708SDavid Chisnall}
12467a984708SDavid Chisnall
12477a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12487a984708SDavid Chisnalltemplate <class _InpIter>
12497a984708SDavid Chisnalllist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
12507a984708SDavid Chisnall                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
12517a984708SDavid Chisnall{
12527a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12537a984708SDavid Chisnall    __get_db()->__insert_c(this);
12547a984708SDavid Chisnall#endif
12557a984708SDavid Chisnall    for (; __f != __l; ++__f)
1256d4419f6fSDimitry Andric        __emplace_back(*__f);
12577a984708SDavid Chisnall}
12587a984708SDavid Chisnall
12597a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12607a984708SDavid Chisnalltemplate <class _InpIter>
12617a984708SDavid Chisnalllist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
12627a984708SDavid Chisnall                        typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
12637a984708SDavid Chisnall    : base(__a)
12647a984708SDavid Chisnall{
12657a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12667a984708SDavid Chisnall    __get_db()->__insert_c(this);
12677a984708SDavid Chisnall#endif
12687a984708SDavid Chisnall    for (; __f != __l; ++__f)
1269d4419f6fSDimitry Andric        __emplace_back(*__f);
12707a984708SDavid Chisnall}
12717a984708SDavid Chisnall
12727a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12737a984708SDavid Chisnalllist<_Tp, _Alloc>::list(const list& __c)
12744ba319b5SDimitry Andric    : base(__node_alloc_traits::select_on_container_copy_construction(
12754ba319b5SDimitry Andric          __c.__node_alloc())) {
12767a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12777a984708SDavid Chisnall    __get_db()->__insert_c(this);
12787a984708SDavid Chisnall#endif
12797a984708SDavid Chisnall    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12807a984708SDavid Chisnall        push_back(*__i);
12817a984708SDavid Chisnall}
12827a984708SDavid Chisnall
12837a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12847a984708SDavid Chisnalllist<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
12857a984708SDavid Chisnall    : base(__a)
12867a984708SDavid Chisnall{
12877a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
12887a984708SDavid Chisnall    __get_db()->__insert_c(this);
12897a984708SDavid Chisnall#endif
12907a984708SDavid Chisnall    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12917a984708SDavid Chisnall        push_back(*__i);
12927a984708SDavid Chisnall}
12937a984708SDavid Chisnall
1294540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12957a984708SDavid Chisnall
12967a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
12977a984708SDavid Chisnalllist<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
12987a984708SDavid Chisnall    : base(__a)
12997a984708SDavid Chisnall{
13007a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
13017a984708SDavid Chisnall    __get_db()->__insert_c(this);
13027a984708SDavid Chisnall#endif
13037a984708SDavid Chisnall    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
13047a984708SDavid Chisnall            __e = __il.end(); __i != __e; ++__i)
13057a984708SDavid Chisnall        push_back(*__i);
13067a984708SDavid Chisnall}
13077a984708SDavid Chisnall
13087a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13097a984708SDavid Chisnalllist<_Tp, _Alloc>::list(initializer_list<value_type> __il)
13107a984708SDavid Chisnall{
13117a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
13127a984708SDavid Chisnall    __get_db()->__insert_c(this);
13137a984708SDavid Chisnall#endif
13147a984708SDavid Chisnall    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
13157a984708SDavid Chisnall            __e = __il.end(); __i != __e; ++__i)
13167a984708SDavid Chisnall        push_back(*__i);
13177a984708SDavid Chisnall}
13187a984708SDavid Chisnall
13197a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13204ba319b5SDimitry Andricinline list<_Tp, _Alloc>::list(list&& __c)
13217a984708SDavid Chisnall    _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
13224ba319b5SDimitry Andric    : base(_VSTD::move(__c.__node_alloc())) {
13237a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
13247a984708SDavid Chisnall    __get_db()->__insert_c(this);
13257a984708SDavid Chisnall#endif
13267a984708SDavid Chisnall    splice(end(), __c);
13277a984708SDavid Chisnall}
13287a984708SDavid Chisnall
13297a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13307c82a1ecSDimitry Andricinline
13317a984708SDavid Chisnalllist<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
13327a984708SDavid Chisnall    : base(__a)
13337a984708SDavid Chisnall{
13347a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
13357a984708SDavid Chisnall    __get_db()->__insert_c(this);
13367a984708SDavid Chisnall#endif
13377a984708SDavid Chisnall    if (__a == __c.get_allocator())
13387a984708SDavid Chisnall        splice(end(), __c);
13397a984708SDavid Chisnall    else
13407a984708SDavid Chisnall    {
134194e3ee44SDavid Chisnall        typedef move_iterator<iterator> _Ip;
134294e3ee44SDavid Chisnall        assign(_Ip(__c.begin()), _Ip(__c.end()));
13437a984708SDavid Chisnall    }
13447a984708SDavid Chisnall}
13457a984708SDavid Chisnall
13467a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13477c82a1ecSDimitry Andricinline
13487a984708SDavid Chisnalllist<_Tp, _Alloc>&
13497a984708SDavid Chisnalllist<_Tp, _Alloc>::operator=(list&& __c)
13507a984708SDavid Chisnall        _NOEXCEPT_(
13517a984708SDavid Chisnall            __node_alloc_traits::propagate_on_container_move_assignment::value &&
13527a984708SDavid Chisnall            is_nothrow_move_assignable<__node_allocator>::value)
13537a984708SDavid Chisnall{
13547a984708SDavid Chisnall    __move_assign(__c, integral_constant<bool,
13557a984708SDavid Chisnall          __node_alloc_traits::propagate_on_container_move_assignment::value>());
13567a984708SDavid Chisnall    return *this;
13577a984708SDavid Chisnall}
13587a984708SDavid Chisnall
13597a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13607a984708SDavid Chisnallvoid
13617a984708SDavid Chisnalllist<_Tp, _Alloc>::__move_assign(list& __c, false_type)
13627a984708SDavid Chisnall{
13637a984708SDavid Chisnall    if (base::__node_alloc() != __c.__node_alloc())
13647a984708SDavid Chisnall    {
136594e3ee44SDavid Chisnall        typedef move_iterator<iterator> _Ip;
136694e3ee44SDavid Chisnall        assign(_Ip(__c.begin()), _Ip(__c.end()));
13677a984708SDavid Chisnall    }
13687a984708SDavid Chisnall    else
13697a984708SDavid Chisnall        __move_assign(__c, true_type());
13707a984708SDavid Chisnall}
13717a984708SDavid Chisnall
13727a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13737a984708SDavid Chisnallvoid
13747a984708SDavid Chisnalllist<_Tp, _Alloc>::__move_assign(list& __c, true_type)
13757a984708SDavid Chisnall        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
13767a984708SDavid Chisnall{
13777a984708SDavid Chisnall    clear();
13787a984708SDavid Chisnall    base::__move_assign_alloc(__c);
13797a984708SDavid Chisnall    splice(end(), __c);
13807a984708SDavid Chisnall}
13817a984708SDavid Chisnall
1382540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
1383540d2a8bSDimitry Andric
1384540d2a8bSDimitry Andrictemplate <class _Tp, class _Alloc>
1385540d2a8bSDimitry Andricinline
1386540d2a8bSDimitry Andriclist<_Tp, _Alloc>&
1387540d2a8bSDimitry Andriclist<_Tp, _Alloc>::operator=(const list& __c)
1388540d2a8bSDimitry Andric{
1389540d2a8bSDimitry Andric    if (this != &__c)
1390540d2a8bSDimitry Andric    {
1391540d2a8bSDimitry Andric        base::__copy_assign_alloc(__c);
1392540d2a8bSDimitry Andric        assign(__c.begin(), __c.end());
1393540d2a8bSDimitry Andric    }
1394540d2a8bSDimitry Andric    return *this;
1395540d2a8bSDimitry Andric}
13967a984708SDavid Chisnall
13977a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
13987a984708SDavid Chisnalltemplate <class _InpIter>
13997a984708SDavid Chisnallvoid
14007a984708SDavid Chisnalllist<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
14017a984708SDavid Chisnall                          typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
14027a984708SDavid Chisnall{
14037a984708SDavid Chisnall    iterator __i = begin();
14047a984708SDavid Chisnall    iterator __e = end();
14057a984708SDavid Chisnall    for (; __f != __l && __i != __e; ++__f, ++__i)
14067a984708SDavid Chisnall        *__i = *__f;
14077a984708SDavid Chisnall    if (__i == __e)
14087a984708SDavid Chisnall        insert(__e, __f, __l);
14097a984708SDavid Chisnall    else
14107a984708SDavid Chisnall        erase(__i, __e);
1411aed8d94eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1412aed8d94eSDimitry Andric      __get_db()->__invalidate_all(this);
1413aed8d94eSDimitry Andric#endif
14147a984708SDavid Chisnall}
14157a984708SDavid Chisnall
14167a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14177a984708SDavid Chisnallvoid
14187a984708SDavid Chisnalllist<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
14197a984708SDavid Chisnall{
14207a984708SDavid Chisnall    iterator __i = begin();
14217a984708SDavid Chisnall    iterator __e = end();
14227a984708SDavid Chisnall    for (; __n > 0 && __i != __e; --__n, ++__i)
14237a984708SDavid Chisnall        *__i = __x;
14247a984708SDavid Chisnall    if (__i == __e)
14257a984708SDavid Chisnall        insert(__e, __n, __x);
14267a984708SDavid Chisnall    else
14277a984708SDavid Chisnall        erase(__i, __e);
1428aed8d94eSDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
1429aed8d94eSDimitry Andric      __get_db()->__invalidate_all(this);
1430aed8d94eSDimitry Andric#endif
14317a984708SDavid Chisnall}
14327a984708SDavid Chisnall
14337a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14347c82a1ecSDimitry Andricinline
14357a984708SDavid Chisnall_Alloc
14367a984708SDavid Chisnalllist<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
14377a984708SDavid Chisnall{
14387a984708SDavid Chisnall    return allocator_type(base::__node_alloc());
14397a984708SDavid Chisnall}
14407a984708SDavid Chisnall
14417a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14427a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
14437a984708SDavid Chisnalllist<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
14447a984708SDavid Chisnall{
14457a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
14467a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
14477a984708SDavid Chisnall        "list::insert(iterator, x) called with an iterator not"
14487a984708SDavid Chisnall        " referring to this list");
14497a984708SDavid Chisnall#endif
14507a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1451b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
14527a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14539729cf09SDimitry Andric    __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
14547a984708SDavid Chisnall    ++base::__sz();
14551bf9f7c1SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
14569729cf09SDimitry Andric    return iterator(__hold.release()->__as_link(), this);
14571bf9f7c1SDimitry Andric#else
14589729cf09SDimitry Andric    return iterator(__hold.release()->__as_link());
14591bf9f7c1SDimitry Andric#endif
14607a984708SDavid Chisnall}
14617a984708SDavid Chisnall
14627a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
14637a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
14647a984708SDavid Chisnalllist<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
14657a984708SDavid Chisnall{
14667a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
14677a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
14687a984708SDavid Chisnall        "list::insert(iterator, n, x) called with an iterator not"
14697a984708SDavid Chisnall        " referring to this list");
14704bab9fd9SDavid Chisnall    iterator __r(__p.__ptr_, this);
14717a984708SDavid Chisnall#else
14724bab9fd9SDavid Chisnall    iterator __r(__p.__ptr_);
14737a984708SDavid Chisnall#endif
14747a984708SDavid Chisnall    if (__n > 0)
14757a984708SDavid Chisnall    {
14767a984708SDavid Chisnall        size_type __ds = 0;
14777a984708SDavid Chisnall        __node_allocator& __na = base::__node_alloc();
1478b2c7081bSDimitry Andric        __hold_pointer __hold = __allocate_node(__na);
14797a984708SDavid Chisnall        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14807a984708SDavid Chisnall        ++__ds;
14817a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
14829729cf09SDimitry Andric        __r = iterator(__hold->__as_link(), this);
14837a984708SDavid Chisnall#else
14849729cf09SDimitry Andric        __r = iterator(__hold->__as_link());
14857a984708SDavid Chisnall#endif
14867a984708SDavid Chisnall        __hold.release();
14877a984708SDavid Chisnall        iterator __e = __r;
14887a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
14897a984708SDavid Chisnall        try
14907a984708SDavid Chisnall        {
14917a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
14927a984708SDavid Chisnall            for (--__n; __n != 0; --__n, ++__e, ++__ds)
14937a984708SDavid Chisnall            {
14947a984708SDavid Chisnall                __hold.reset(__node_alloc_traits::allocate(__na, 1));
14957a984708SDavid Chisnall                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
14969729cf09SDimitry Andric                __e.__ptr_->__next_ = __hold->__as_link();
14977a984708SDavid Chisnall                __hold->__prev_ = __e.__ptr_;
14987a984708SDavid Chisnall                __hold.release();
14997a984708SDavid Chisnall            }
15007a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
15017a984708SDavid Chisnall        }
15027a984708SDavid Chisnall        catch (...)
15037a984708SDavid Chisnall        {
15047a984708SDavid Chisnall            while (true)
15057a984708SDavid Chisnall            {
15067a984708SDavid Chisnall                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
15079729cf09SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
15089729cf09SDimitry Andric                __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
15097a984708SDavid Chisnall                if (__prev == 0)
15107a984708SDavid Chisnall                    break;
15117a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
15127a984708SDavid Chisnall                __e = iterator(__prev, this);
15137a984708SDavid Chisnall#else
15147a984708SDavid Chisnall                __e = iterator(__prev);
15157a984708SDavid Chisnall#endif
15167a984708SDavid Chisnall            }
15177a984708SDavid Chisnall            throw;
15187a984708SDavid Chisnall        }
15197a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
15204bab9fd9SDavid Chisnall        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
15217a984708SDavid Chisnall        base::__sz() += __ds;
15227a984708SDavid Chisnall    }
15237a984708SDavid Chisnall    return __r;
15247a984708SDavid Chisnall}
15257a984708SDavid Chisnall
15267a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15277a984708SDavid Chisnalltemplate <class _InpIter>
15287a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
15297a984708SDavid Chisnalllist<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
15307a984708SDavid Chisnall             typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
15317a984708SDavid Chisnall{
15327a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
15337a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
15347a984708SDavid Chisnall        "list::insert(iterator, range) called with an iterator not"
15357a984708SDavid Chisnall        " referring to this list");
15364bab9fd9SDavid Chisnall    iterator __r(__p.__ptr_, this);
15377a984708SDavid Chisnall#else
15384bab9fd9SDavid Chisnall    iterator __r(__p.__ptr_);
15397a984708SDavid Chisnall#endif
15407a984708SDavid Chisnall    if (__f != __l)
15417a984708SDavid Chisnall    {
15427a984708SDavid Chisnall        size_type __ds = 0;
15437a984708SDavid Chisnall        __node_allocator& __na = base::__node_alloc();
1544b2c7081bSDimitry Andric        __hold_pointer __hold = __allocate_node(__na);
15457a984708SDavid Chisnall        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
15467a984708SDavid Chisnall        ++__ds;
15477a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
15489729cf09SDimitry Andric        __r = iterator(__hold.get()->__as_link(), this);
15497a984708SDavid Chisnall#else
15509729cf09SDimitry Andric        __r = iterator(__hold.get()->__as_link());
15517a984708SDavid Chisnall#endif
15527a984708SDavid Chisnall        __hold.release();
15537a984708SDavid Chisnall        iterator __e = __r;
15547a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
15557a984708SDavid Chisnall        try
15567a984708SDavid Chisnall        {
15577a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
1558854fa44bSDimitry Andric            for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
15597a984708SDavid Chisnall            {
15607a984708SDavid Chisnall                __hold.reset(__node_alloc_traits::allocate(__na, 1));
15617a984708SDavid Chisnall                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
15629729cf09SDimitry Andric                __e.__ptr_->__next_ = __hold.get()->__as_link();
15637a984708SDavid Chisnall                __hold->__prev_ = __e.__ptr_;
15647a984708SDavid Chisnall                __hold.release();
15657a984708SDavid Chisnall            }
15667a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
15677a984708SDavid Chisnall        }
15687a984708SDavid Chisnall        catch (...)
15697a984708SDavid Chisnall        {
15707a984708SDavid Chisnall            while (true)
15717a984708SDavid Chisnall            {
15727a984708SDavid Chisnall                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
15739729cf09SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
15749729cf09SDimitry Andric                __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
15757a984708SDavid Chisnall                if (__prev == 0)
15767a984708SDavid Chisnall                    break;
15777a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
15787a984708SDavid Chisnall                __e = iterator(__prev, this);
15797a984708SDavid Chisnall#else
15807a984708SDavid Chisnall                __e = iterator(__prev);
15817a984708SDavid Chisnall#endif
15827a984708SDavid Chisnall            }
15837a984708SDavid Chisnall            throw;
15847a984708SDavid Chisnall        }
15857a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
15864bab9fd9SDavid Chisnall        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
15877a984708SDavid Chisnall        base::__sz() += __ds;
15887a984708SDavid Chisnall    }
15897a984708SDavid Chisnall    return __r;
15907a984708SDavid Chisnall}
15917a984708SDavid Chisnall
15927a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
15937a984708SDavid Chisnallvoid
15947a984708SDavid Chisnalllist<_Tp, _Alloc>::push_front(const value_type& __x)
15957a984708SDavid Chisnall{
15967a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1597b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
15987a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
15999729cf09SDimitry Andric    __link_pointer __nl = __hold->__as_link();
16009729cf09SDimitry Andric    __link_nodes_at_front(__nl, __nl);
16017a984708SDavid Chisnall    ++base::__sz();
16027a984708SDavid Chisnall    __hold.release();
16037a984708SDavid Chisnall}
16047a984708SDavid Chisnall
16057a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16067a984708SDavid Chisnallvoid
16077a984708SDavid Chisnalllist<_Tp, _Alloc>::push_back(const value_type& __x)
16087a984708SDavid Chisnall{
16097a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1610b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16117a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
16129729cf09SDimitry Andric    __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
16137a984708SDavid Chisnall    ++base::__sz();
16147a984708SDavid Chisnall    __hold.release();
16157a984708SDavid Chisnall}
16167a984708SDavid Chisnall
1617540d2a8bSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16187a984708SDavid Chisnall
16197a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16207a984708SDavid Chisnallvoid
16217a984708SDavid Chisnalllist<_Tp, _Alloc>::push_front(value_type&& __x)
16227a984708SDavid Chisnall{
16237a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1624b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16257a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
16269729cf09SDimitry Andric    __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
16277a984708SDavid Chisnall    ++base::__sz();
16287a984708SDavid Chisnall    __hold.release();
16297a984708SDavid Chisnall}
16307a984708SDavid Chisnall
16317a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16327a984708SDavid Chisnallvoid
16337a984708SDavid Chisnalllist<_Tp, _Alloc>::push_back(value_type&& __x)
16347a984708SDavid Chisnall{
16357a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1636b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16377a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
16389729cf09SDimitry Andric    __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
16397a984708SDavid Chisnall    ++base::__sz();
16407a984708SDavid Chisnall    __hold.release();
16417a984708SDavid Chisnall}
16427a984708SDavid Chisnall
16437a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16447a984708SDavid Chisnalltemplate <class... _Args>
164598221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1646aed8d94eSDimitry Andrictypename list<_Tp, _Alloc>::reference
164798221d2eSDimitry Andric#else
164898221d2eSDimitry Andricvoid
164998221d2eSDimitry Andric#endif
16507a984708SDavid Chisnalllist<_Tp, _Alloc>::emplace_front(_Args&&... __args)
16517a984708SDavid Chisnall{
16527a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1653b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16547a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
16559729cf09SDimitry Andric    __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
16567a984708SDavid Chisnall    ++base::__sz();
165798221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1658aed8d94eSDimitry Andric    return __hold.release()->__value_;
165998221d2eSDimitry Andric#else
166098221d2eSDimitry Andric    __hold.release();
166198221d2eSDimitry Andric#endif
16627a984708SDavid Chisnall}
16637a984708SDavid Chisnall
16647a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16657a984708SDavid Chisnalltemplate <class... _Args>
166698221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1667aed8d94eSDimitry Andrictypename list<_Tp, _Alloc>::reference
166898221d2eSDimitry Andric#else
166998221d2eSDimitry Andricvoid
167098221d2eSDimitry Andric#endif
16717a984708SDavid Chisnalllist<_Tp, _Alloc>::emplace_back(_Args&&... __args)
16727a984708SDavid Chisnall{
16737a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1674b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16757a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
16769729cf09SDimitry Andric    __link_pointer __nl = __hold->__as_link();
16779729cf09SDimitry Andric    __link_nodes_at_back(__nl, __nl);
16787a984708SDavid Chisnall    ++base::__sz();
167998221d2eSDimitry Andric#if _LIBCPP_STD_VER > 14
1680aed8d94eSDimitry Andric    return __hold.release()->__value_;
168198221d2eSDimitry Andric#else
168298221d2eSDimitry Andric    __hold.release();
168398221d2eSDimitry Andric#endif
16847a984708SDavid Chisnall}
16857a984708SDavid Chisnall
16867a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
16877a984708SDavid Chisnalltemplate <class... _Args>
16887a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
16897a984708SDavid Chisnalllist<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
16907a984708SDavid Chisnall{
16911bf9f7c1SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2
16921bf9f7c1SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
16931bf9f7c1SDimitry Andric        "list::emplace(iterator, args...) called with an iterator not"
16941bf9f7c1SDimitry Andric        " referring to this list");
16951bf9f7c1SDimitry Andric#endif
16967a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1697b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
16987a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
16999729cf09SDimitry Andric    __link_pointer __nl = __hold.get()->__as_link();
17009729cf09SDimitry Andric    __link_nodes(__p.__ptr_, __nl, __nl);
17017a984708SDavid Chisnall    ++base::__sz();
17029729cf09SDimitry Andric    __hold.release();
17037a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17049729cf09SDimitry Andric    return iterator(__nl, this);
17057a984708SDavid Chisnall#else
17069729cf09SDimitry Andric    return iterator(__nl);
17077a984708SDavid Chisnall#endif
17087a984708SDavid Chisnall}
17097a984708SDavid Chisnall
17107a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17117a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
17127a984708SDavid Chisnalllist<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
17137a984708SDavid Chisnall{
17147a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17157a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
17167a984708SDavid Chisnall        "list::insert(iterator, x) called with an iterator not"
17177a984708SDavid Chisnall        " referring to this list");
17187a984708SDavid Chisnall#endif
17197a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
1720b2c7081bSDimitry Andric    __hold_pointer __hold = __allocate_node(__na);
17217a984708SDavid Chisnall    __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
17229729cf09SDimitry Andric    __link_pointer __nl = __hold->__as_link();
17239729cf09SDimitry Andric    __link_nodes(__p.__ptr_, __nl, __nl);
17247a984708SDavid Chisnall    ++base::__sz();
17259729cf09SDimitry Andric    __hold.release();
17267a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17279729cf09SDimitry Andric    return iterator(__nl, this);
17287a984708SDavid Chisnall#else
17299729cf09SDimitry Andric    return iterator(__nl);
17307a984708SDavid Chisnall#endif
17317a984708SDavid Chisnall}
17327a984708SDavid Chisnall
1733540d2a8bSDimitry Andric#endif  // _LIBCPP_CXX03_LANG
17347a984708SDavid Chisnall
17357a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17367a984708SDavid Chisnallvoid
17377a984708SDavid Chisnalllist<_Tp, _Alloc>::pop_front()
17387a984708SDavid Chisnall{
17397a984708SDavid Chisnall    _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
17407a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
17419729cf09SDimitry Andric    __link_pointer __n = base::__end_.__next_;
17427a984708SDavid Chisnall    base::__unlink_nodes(__n, __n);
17437a984708SDavid Chisnall    --base::__sz();
17447a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17457a984708SDavid Chisnall    __c_node* __c = __get_db()->__find_c_and_lock(this);
17467a984708SDavid Chisnall    for (__i_node** __p = __c->end_; __p != __c->beg_; )
17477a984708SDavid Chisnall    {
17487a984708SDavid Chisnall        --__p;
17497a984708SDavid Chisnall        iterator* __i = static_cast<iterator*>((*__p)->__i_);
17504bab9fd9SDavid Chisnall        if (__i->__ptr_ == __n)
17517a984708SDavid Chisnall        {
17527a984708SDavid Chisnall            (*__p)->__c_ = nullptr;
17537a984708SDavid Chisnall            if (--__c->end_ != __p)
17547a984708SDavid Chisnall                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
17557a984708SDavid Chisnall        }
17567a984708SDavid Chisnall    }
17577a984708SDavid Chisnall    __get_db()->unlock();
17587a984708SDavid Chisnall#endif
17599729cf09SDimitry Andric    __node_pointer __np = __n->__as_node();
17609729cf09SDimitry Andric    __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
17619729cf09SDimitry Andric    __node_alloc_traits::deallocate(__na, __np, 1);
17627a984708SDavid Chisnall}
17637a984708SDavid Chisnall
17647a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17657a984708SDavid Chisnallvoid
17667a984708SDavid Chisnalllist<_Tp, _Alloc>::pop_back()
17677a984708SDavid Chisnall{
17684bab9fd9SDavid Chisnall    _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
17697a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
17709729cf09SDimitry Andric    __link_pointer __n = base::__end_.__prev_;
17717a984708SDavid Chisnall    base::__unlink_nodes(__n, __n);
17727a984708SDavid Chisnall    --base::__sz();
17737a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17747a984708SDavid Chisnall    __c_node* __c = __get_db()->__find_c_and_lock(this);
17757a984708SDavid Chisnall    for (__i_node** __p = __c->end_; __p != __c->beg_; )
17767a984708SDavid Chisnall    {
17777a984708SDavid Chisnall        --__p;
17787a984708SDavid Chisnall        iterator* __i = static_cast<iterator*>((*__p)->__i_);
17794bab9fd9SDavid Chisnall        if (__i->__ptr_ == __n)
17807a984708SDavid Chisnall        {
17817a984708SDavid Chisnall            (*__p)->__c_ = nullptr;
17827a984708SDavid Chisnall            if (--__c->end_ != __p)
17837a984708SDavid Chisnall                memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
17847a984708SDavid Chisnall        }
17857a984708SDavid Chisnall    }
17867a984708SDavid Chisnall    __get_db()->unlock();
17877a984708SDavid Chisnall#endif
17889729cf09SDimitry Andric    __node_pointer __np = __n->__as_node();
17899729cf09SDimitry Andric    __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
17909729cf09SDimitry Andric    __node_alloc_traits::deallocate(__na, __np, 1);
17917a984708SDavid Chisnall}
17927a984708SDavid Chisnall
17937a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
17947a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
17957a984708SDavid Chisnalllist<_Tp, _Alloc>::erase(const_iterator __p)
17967a984708SDavid Chisnall{
17977a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
17987a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
17997a984708SDavid Chisnall        "list::erase(iterator) called with an iterator not"
18007a984708SDavid Chisnall        " referring to this list");
18017a984708SDavid Chisnall#endif
18021bf9f7c1SDimitry Andric    _LIBCPP_ASSERT(__p != end(),
18031bf9f7c1SDimitry Andric        "list::erase(iterator) called with a non-dereferenceable iterator");
18047a984708SDavid Chisnall    __node_allocator& __na = base::__node_alloc();
18059729cf09SDimitry Andric    __link_pointer __n = __p.__ptr_;
18069729cf09SDimitry Andric    __link_pointer __r = __n->__next_;
18077a984708SDavid Chisnall    base::__unlink_nodes(__n, __n);
18087a984708SDavid Chisnall    --base::__sz();
18097a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18107a984708SDavid Chisnall    __c_node* __c = __get_db()->__find_c_and_lock(this);
1811aed8d94eSDimitry Andric    for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
18127a984708SDavid Chisnall    {
1813aed8d94eSDimitry Andric        --__ip;
1814aed8d94eSDimitry Andric        iterator* __i = static_cast<iterator*>((*__ip)->__i_);
18154bab9fd9SDavid Chisnall        if (__i->__ptr_ == __n)
18167a984708SDavid Chisnall        {
1817aed8d94eSDimitry Andric            (*__ip)->__c_ = nullptr;
1818aed8d94eSDimitry Andric            if (--__c->end_ != __ip)
1819aed8d94eSDimitry Andric                memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
18207a984708SDavid Chisnall        }
18217a984708SDavid Chisnall    }
18227a984708SDavid Chisnall    __get_db()->unlock();
18237a984708SDavid Chisnall#endif
18249729cf09SDimitry Andric    __node_pointer __np = __n->__as_node();
18259729cf09SDimitry Andric    __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
18269729cf09SDimitry Andric    __node_alloc_traits::deallocate(__na, __np, 1);
18277a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18287a984708SDavid Chisnall    return iterator(__r, this);
18297a984708SDavid Chisnall#else
18307a984708SDavid Chisnall    return iterator(__r);
18317a984708SDavid Chisnall#endif
18327a984708SDavid Chisnall}
18337a984708SDavid Chisnall
18347a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
18357a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
18367a984708SDavid Chisnalllist<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
18377a984708SDavid Chisnall{
18387a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18397a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
18407a984708SDavid Chisnall        "list::erase(iterator, iterator) called with an iterator not"
18417a984708SDavid Chisnall        " referring to this list");
1842aed8d94eSDimitry Andric   _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1843aed8d94eSDimitry Andric        "list::erase(iterator, iterator) called with an iterator not"
1844aed8d94eSDimitry Andric        " referring to this list");
18457a984708SDavid Chisnall#endif
18467a984708SDavid Chisnall    if (__f != __l)
18477a984708SDavid Chisnall    {
18487a984708SDavid Chisnall        __node_allocator& __na = base::__node_alloc();
18494bab9fd9SDavid Chisnall        base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
18507a984708SDavid Chisnall        while (__f != __l)
18517a984708SDavid Chisnall        {
18529729cf09SDimitry Andric            __link_pointer __n = __f.__ptr_;
18537a984708SDavid Chisnall            ++__f;
18547a984708SDavid Chisnall            --base::__sz();
18557a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18567a984708SDavid Chisnall            __c_node* __c = __get_db()->__find_c_and_lock(this);
18577a984708SDavid Chisnall            for (__i_node** __p = __c->end_; __p != __c->beg_; )
18587a984708SDavid Chisnall            {
18597a984708SDavid Chisnall                --__p;
18607a984708SDavid Chisnall                iterator* __i = static_cast<iterator*>((*__p)->__i_);
18614bab9fd9SDavid Chisnall                if (__i->__ptr_ == __n)
18627a984708SDavid Chisnall                {
18637a984708SDavid Chisnall                    (*__p)->__c_ = nullptr;
18647a984708SDavid Chisnall                    if (--__c->end_ != __p)
18657a984708SDavid Chisnall                        memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
18667a984708SDavid Chisnall                }
18677a984708SDavid Chisnall            }
18687a984708SDavid Chisnall            __get_db()->unlock();
18697a984708SDavid Chisnall#endif
18709729cf09SDimitry Andric            __node_pointer __np = __n->__as_node();
18719729cf09SDimitry Andric            __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
18729729cf09SDimitry Andric            __node_alloc_traits::deallocate(__na, __np, 1);
18737a984708SDavid Chisnall        }
18747a984708SDavid Chisnall    }
18757a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18764bab9fd9SDavid Chisnall    return iterator(__l.__ptr_, this);
18777a984708SDavid Chisnall#else
18784bab9fd9SDavid Chisnall    return iterator(__l.__ptr_);
18797a984708SDavid Chisnall#endif
18807a984708SDavid Chisnall}
18817a984708SDavid Chisnall
18827a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
18837a984708SDavid Chisnallvoid
18847a984708SDavid Chisnalllist<_Tp, _Alloc>::resize(size_type __n)
18857a984708SDavid Chisnall{
18867a984708SDavid Chisnall    if (__n < base::__sz())
18877a984708SDavid Chisnall        erase(__iterator(__n), end());
18887a984708SDavid Chisnall    else if (__n > base::__sz())
18897a984708SDavid Chisnall    {
18907a984708SDavid Chisnall        __n -= base::__sz();
18917a984708SDavid Chisnall        size_type __ds = 0;
18927a984708SDavid Chisnall        __node_allocator& __na = base::__node_alloc();
1893b2c7081bSDimitry Andric        __hold_pointer __hold = __allocate_node(__na);
18947a984708SDavid Chisnall        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
18957a984708SDavid Chisnall        ++__ds;
18967a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
18979729cf09SDimitry Andric        iterator __r = iterator(__hold.release()->__as_link(), this);
18987a984708SDavid Chisnall#else
18999729cf09SDimitry Andric        iterator __r = iterator(__hold.release()->__as_link());
19007a984708SDavid Chisnall#endif
19017a984708SDavid Chisnall        iterator __e = __r;
19027a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
19037a984708SDavid Chisnall        try
19047a984708SDavid Chisnall        {
19057a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
19067a984708SDavid Chisnall            for (--__n; __n != 0; --__n, ++__e, ++__ds)
19077a984708SDavid Chisnall            {
19087a984708SDavid Chisnall                __hold.reset(__node_alloc_traits::allocate(__na, 1));
19097a984708SDavid Chisnall                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
19109729cf09SDimitry Andric                __e.__ptr_->__next_ = __hold.get()->__as_link();
19117a984708SDavid Chisnall                __hold->__prev_ = __e.__ptr_;
19127a984708SDavid Chisnall                __hold.release();
19137a984708SDavid Chisnall            }
19147a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
19157a984708SDavid Chisnall        }
19167a984708SDavid Chisnall        catch (...)
19177a984708SDavid Chisnall        {
19187a984708SDavid Chisnall            while (true)
19197a984708SDavid Chisnall            {
19207a984708SDavid Chisnall                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
19219729cf09SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
19229729cf09SDimitry Andric                __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
19237a984708SDavid Chisnall                if (__prev == 0)
19247a984708SDavid Chisnall                    break;
19257a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
19267a984708SDavid Chisnall                __e = iterator(__prev, this);
19277a984708SDavid Chisnall#else
19287a984708SDavid Chisnall                __e = iterator(__prev);
19297a984708SDavid Chisnall#endif
19307a984708SDavid Chisnall            }
19317a984708SDavid Chisnall            throw;
19327a984708SDavid Chisnall        }
19337a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
1934d72607e9SDimitry Andric        __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
19357a984708SDavid Chisnall        base::__sz() += __ds;
19367a984708SDavid Chisnall    }
19377a984708SDavid Chisnall}
19387a984708SDavid Chisnall
19397a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
19407a984708SDavid Chisnallvoid
19417a984708SDavid Chisnalllist<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
19427a984708SDavid Chisnall{
19437a984708SDavid Chisnall    if (__n < base::__sz())
19447a984708SDavid Chisnall        erase(__iterator(__n), end());
19457a984708SDavid Chisnall    else if (__n > base::__sz())
19467a984708SDavid Chisnall    {
19477a984708SDavid Chisnall        __n -= base::__sz();
19487a984708SDavid Chisnall        size_type __ds = 0;
19497a984708SDavid Chisnall        __node_allocator& __na = base::__node_alloc();
1950b2c7081bSDimitry Andric        __hold_pointer __hold = __allocate_node(__na);
19517a984708SDavid Chisnall        __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
19527a984708SDavid Chisnall        ++__ds;
19539729cf09SDimitry Andric        __link_pointer __nl = __hold.release()->__as_link();
19547a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
19559729cf09SDimitry Andric        iterator __r = iterator(__nl, this);
19567a984708SDavid Chisnall#else
19579729cf09SDimitry Andric        iterator __r = iterator(__nl);
19587a984708SDavid Chisnall#endif
19597a984708SDavid Chisnall        iterator __e = __r;
19607a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
19617a984708SDavid Chisnall        try
19627a984708SDavid Chisnall        {
19637a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
19647a984708SDavid Chisnall            for (--__n; __n != 0; --__n, ++__e, ++__ds)
19657a984708SDavid Chisnall            {
19667a984708SDavid Chisnall                __hold.reset(__node_alloc_traits::allocate(__na, 1));
19677a984708SDavid Chisnall                __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
19689729cf09SDimitry Andric                __e.__ptr_->__next_ = __hold.get()->__as_link();
19697a984708SDavid Chisnall                __hold->__prev_ = __e.__ptr_;
19707a984708SDavid Chisnall                __hold.release();
19717a984708SDavid Chisnall            }
19727a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
19737a984708SDavid Chisnall        }
19747a984708SDavid Chisnall        catch (...)
19757a984708SDavid Chisnall        {
19767a984708SDavid Chisnall            while (true)
19777a984708SDavid Chisnall            {
19787a984708SDavid Chisnall                __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
19799729cf09SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
19809729cf09SDimitry Andric                __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
19817a984708SDavid Chisnall                if (__prev == 0)
19827a984708SDavid Chisnall                    break;
19837a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
19847a984708SDavid Chisnall                __e = iterator(__prev, this);
19857a984708SDavid Chisnall#else
19867a984708SDavid Chisnall                __e = iterator(__prev);
19877a984708SDavid Chisnall#endif
19887a984708SDavid Chisnall            }
19897a984708SDavid Chisnall            throw;
19907a984708SDavid Chisnall        }
19917a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
19929729cf09SDimitry Andric        __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
19937a984708SDavid Chisnall        base::__sz() += __ds;
19947a984708SDavid Chisnall    }
19957a984708SDavid Chisnall}
19967a984708SDavid Chisnall
19977a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
19987a984708SDavid Chisnallvoid
19997a984708SDavid Chisnalllist<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
20007a984708SDavid Chisnall{
20017a984708SDavid Chisnall    _LIBCPP_ASSERT(this != &__c,
20027a984708SDavid Chisnall                   "list::splice(iterator, list) called with this == &list");
20037a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
20047a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
20057a984708SDavid Chisnall        "list::splice(iterator, list) called with an iterator not"
20067a984708SDavid Chisnall        " referring to this list");
20077a984708SDavid Chisnall#endif
20087a984708SDavid Chisnall    if (!__c.empty())
20097a984708SDavid Chisnall    {
20109729cf09SDimitry Andric        __link_pointer __f = __c.__end_.__next_;
20119729cf09SDimitry Andric        __link_pointer __l = __c.__end_.__prev_;
20127a984708SDavid Chisnall        base::__unlink_nodes(__f, __l);
20134bab9fd9SDavid Chisnall        __link_nodes(__p.__ptr_, __f, __l);
20147a984708SDavid Chisnall        base::__sz() += __c.__sz();
20157a984708SDavid Chisnall        __c.__sz() = 0;
20167a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
20177a984708SDavid Chisnall        __libcpp_db* __db = __get_db();
20187a984708SDavid Chisnall        __c_node* __cn1 = __db->__find_c_and_lock(this);
20197a984708SDavid Chisnall        __c_node* __cn2 = __db->__find_c(&__c);
2020aed8d94eSDimitry Andric        for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
20217a984708SDavid Chisnall        {
2022aed8d94eSDimitry Andric            --__ip;
2023aed8d94eSDimitry Andric            iterator* __i = static_cast<iterator*>((*__ip)->__i_);
20249729cf09SDimitry Andric            if (__i->__ptr_ != __c.__end_as_link())
20257a984708SDavid Chisnall            {
2026aed8d94eSDimitry Andric                __cn1->__add(*__ip);
2027aed8d94eSDimitry Andric                (*__ip)->__c_ = __cn1;
2028aed8d94eSDimitry Andric                if (--__cn2->end_ != __ip)
2029aed8d94eSDimitry Andric                    memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
20307a984708SDavid Chisnall            }
20317a984708SDavid Chisnall        }
20327a984708SDavid Chisnall        __db->unlock();
20337a984708SDavid Chisnall#endif
20347a984708SDavid Chisnall    }
20357a984708SDavid Chisnall}
20367a984708SDavid Chisnall
20377a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
20387a984708SDavid Chisnallvoid
20397a984708SDavid Chisnalllist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
20407a984708SDavid Chisnall{
20417a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
20427a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
20437a984708SDavid Chisnall        "list::splice(iterator, list, iterator) called with first iterator not"
20447a984708SDavid Chisnall        " referring to this list");
20457a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
20467a984708SDavid Chisnall        "list::splice(iterator, list, iterator) called with second iterator not"
20477a984708SDavid Chisnall        " referring to list argument");
20487a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
20497a984708SDavid Chisnall        "list::splice(iterator, list, iterator) called with second iterator not"
20507a984708SDavid Chisnall        " derefereceable");
20517a984708SDavid Chisnall#endif
20527a984708SDavid Chisnall    if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
20537a984708SDavid Chisnall    {
20549729cf09SDimitry Andric        __link_pointer __f = __i.__ptr_;
20557a984708SDavid Chisnall        base::__unlink_nodes(__f, __f);
20564bab9fd9SDavid Chisnall        __link_nodes(__p.__ptr_, __f, __f);
20577a984708SDavid Chisnall        --__c.__sz();
20587a984708SDavid Chisnall        ++base::__sz();
20597a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
20607a984708SDavid Chisnall        __libcpp_db* __db = __get_db();
20617a984708SDavid Chisnall        __c_node* __cn1 = __db->__find_c_and_lock(this);
20627a984708SDavid Chisnall        __c_node* __cn2 = __db->__find_c(&__c);
2063aed8d94eSDimitry Andric        for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
20647a984708SDavid Chisnall        {
2065aed8d94eSDimitry Andric            --__ip;
2066aed8d94eSDimitry Andric            iterator* __j = static_cast<iterator*>((*__ip)->__i_);
20674bab9fd9SDavid Chisnall            if (__j->__ptr_ == __f)
20687a984708SDavid Chisnall            {
2069aed8d94eSDimitry Andric                __cn1->__add(*__ip);
2070aed8d94eSDimitry Andric                (*__ip)->__c_ = __cn1;
2071aed8d94eSDimitry Andric                if (--__cn2->end_ != __ip)
2072aed8d94eSDimitry Andric                    memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
20737a984708SDavid Chisnall            }
20747a984708SDavid Chisnall        }
20757a984708SDavid Chisnall        __db->unlock();
20767a984708SDavid Chisnall#endif
20777a984708SDavid Chisnall    }
20787a984708SDavid Chisnall}
20797a984708SDavid Chisnall
20807a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
20817a984708SDavid Chisnallvoid
20827a984708SDavid Chisnalllist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
20837a984708SDavid Chisnall{
20847a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
20857a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
20867a984708SDavid Chisnall        "list::splice(iterator, list, iterator, iterator) called with first iterator not"
20877a984708SDavid Chisnall        " referring to this list");
20887a984708SDavid Chisnall    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
20897a984708SDavid Chisnall        "list::splice(iterator, list, iterator, iterator) called with second iterator not"
20907a984708SDavid Chisnall        " referring to list argument");
20917a984708SDavid Chisnall    if (this == &__c)
20927a984708SDavid Chisnall    {
20937a984708SDavid Chisnall        for (const_iterator __i = __f; __i != __l; ++__i)
20947a984708SDavid Chisnall            _LIBCPP_ASSERT(__i != __p,
20957a984708SDavid Chisnall                           "list::splice(iterator, list, iterator, iterator)"
20967a984708SDavid Chisnall                           " called with the first iterator within the range"
20977a984708SDavid Chisnall                           " of the second and third iterators");
20987a984708SDavid Chisnall    }
20997a984708SDavid Chisnall#endif
21007a984708SDavid Chisnall    if (__f != __l)
21017a984708SDavid Chisnall    {
21029729cf09SDimitry Andric        __link_pointer __first = __f.__ptr_;
21037a984708SDavid Chisnall        --__l;
21049729cf09SDimitry Andric        __link_pointer __last = __l.__ptr_;
21056ccc06f6SDimitry Andric        if (this != &__c)
21066ccc06f6SDimitry Andric        {
21076ccc06f6SDimitry Andric            size_type __s = _VSTD::distance(__f, __l) + 1;
21086ccc06f6SDimitry Andric            __c.__sz() -= __s;
21096ccc06f6SDimitry Andric            base::__sz() += __s;
21106ccc06f6SDimitry Andric        }
21117a984708SDavid Chisnall        base::__unlink_nodes(__first, __last);
21124bab9fd9SDavid Chisnall        __link_nodes(__p.__ptr_, __first, __last);
21137a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
21147a984708SDavid Chisnall        __libcpp_db* __db = __get_db();
21157a984708SDavid Chisnall        __c_node* __cn1 = __db->__find_c_and_lock(this);
21167a984708SDavid Chisnall        __c_node* __cn2 = __db->__find_c(&__c);
2117aed8d94eSDimitry Andric        for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
21187a984708SDavid Chisnall        {
2119aed8d94eSDimitry Andric            --__ip;
2120aed8d94eSDimitry Andric            iterator* __j = static_cast<iterator*>((*__ip)->__i_);
21219729cf09SDimitry Andric            for (__link_pointer __k = __f.__ptr_;
21227a984708SDavid Chisnall                                          __k != __l.__ptr_; __k = __k->__next_)
21237a984708SDavid Chisnall            {
21247a984708SDavid Chisnall                if (__j->__ptr_ == __k)
21257a984708SDavid Chisnall                {
2126aed8d94eSDimitry Andric                    __cn1->__add(*__ip);
2127aed8d94eSDimitry Andric                    (*__ip)->__c_ = __cn1;
2128aed8d94eSDimitry Andric                    if (--__cn2->end_ != __ip)
2129aed8d94eSDimitry Andric                        memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
21307a984708SDavid Chisnall                }
21317a984708SDavid Chisnall            }
21327a984708SDavid Chisnall        }
21337a984708SDavid Chisnall        __db->unlock();
21347a984708SDavid Chisnall#endif
21357a984708SDavid Chisnall    }
21367a984708SDavid Chisnall}
21377a984708SDavid Chisnall
21387a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
21397a984708SDavid Chisnallvoid
21407a984708SDavid Chisnalllist<_Tp, _Alloc>::remove(const value_type& __x)
21417a984708SDavid Chisnall{
2142aed8d94eSDimitry Andric    list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
2143d72607e9SDimitry Andric    for (const_iterator __i = begin(), __e = end(); __i != __e;)
21447a984708SDavid Chisnall    {
21457a984708SDavid Chisnall        if (*__i == __x)
21467a984708SDavid Chisnall        {
2147d72607e9SDimitry Andric            const_iterator __j = _VSTD::next(__i);
21487a984708SDavid Chisnall            for (; __j != __e && *__j == __x; ++__j)
21497a984708SDavid Chisnall                ;
2150d72607e9SDimitry Andric            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2151d72607e9SDimitry Andric            __i = __j;
2152f48026fcSDimitry Andric            if (__i != __e)
2153d72607e9SDimitry Andric                ++__i;
21547a984708SDavid Chisnall        }
21557a984708SDavid Chisnall        else
21567a984708SDavid Chisnall            ++__i;
21577a984708SDavid Chisnall    }
21587a984708SDavid Chisnall}
21597a984708SDavid Chisnall
21607a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
21617a984708SDavid Chisnalltemplate <class _Pred>
21627a984708SDavid Chisnallvoid
21637a984708SDavid Chisnalllist<_Tp, _Alloc>::remove_if(_Pred __pred)
21647a984708SDavid Chisnall{
21657a984708SDavid Chisnall    for (iterator __i = begin(), __e = end(); __i != __e;)
21667a984708SDavid Chisnall    {
21677a984708SDavid Chisnall        if (__pred(*__i))
21687a984708SDavid Chisnall        {
21697a984708SDavid Chisnall            iterator __j = _VSTD::next(__i);
21707a984708SDavid Chisnall            for (; __j != __e && __pred(*__j); ++__j)
21717a984708SDavid Chisnall                ;
21727a984708SDavid Chisnall            __i = erase(__i, __j);
2173f48026fcSDimitry Andric            if (__i != __e)
2174d72607e9SDimitry Andric                ++__i;
21757a984708SDavid Chisnall        }
21767a984708SDavid Chisnall        else
21777a984708SDavid Chisnall            ++__i;
21787a984708SDavid Chisnall    }
21797a984708SDavid Chisnall}
21807a984708SDavid Chisnall
21817a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
21827c82a1ecSDimitry Andricinline
21837a984708SDavid Chisnallvoid
21847a984708SDavid Chisnalllist<_Tp, _Alloc>::unique()
21857a984708SDavid Chisnall{
21867a984708SDavid Chisnall    unique(__equal_to<value_type>());
21877a984708SDavid Chisnall}
21887a984708SDavid Chisnall
21897a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
21907a984708SDavid Chisnalltemplate <class _BinaryPred>
21917a984708SDavid Chisnallvoid
21927a984708SDavid Chisnalllist<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
21937a984708SDavid Chisnall{
21947a984708SDavid Chisnall    for (iterator __i = begin(), __e = end(); __i != __e;)
21957a984708SDavid Chisnall    {
21967a984708SDavid Chisnall        iterator __j = _VSTD::next(__i);
21977a984708SDavid Chisnall        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
21987a984708SDavid Chisnall            ;
21997a984708SDavid Chisnall        if (++__i != __j)
22007a984708SDavid Chisnall            __i = erase(__i, __j);
22017a984708SDavid Chisnall    }
22027a984708SDavid Chisnall}
22037a984708SDavid Chisnall
22047a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
22057c82a1ecSDimitry Andricinline
22067a984708SDavid Chisnallvoid
22077a984708SDavid Chisnalllist<_Tp, _Alloc>::merge(list& __c)
22087a984708SDavid Chisnall{
22097a984708SDavid Chisnall    merge(__c, __less<value_type>());
22107a984708SDavid Chisnall}
22117a984708SDavid Chisnall
22127a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
22137a984708SDavid Chisnalltemplate <class _Comp>
22147a984708SDavid Chisnallvoid
22157a984708SDavid Chisnalllist<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
22167a984708SDavid Chisnall{
2217*b5893f02SDimitry Andric    if (this != _VSTD::addressof(__c))
22187a984708SDavid Chisnall    {
22197a984708SDavid Chisnall        iterator __f1 = begin();
22207a984708SDavid Chisnall        iterator __e1 = end();
22217a984708SDavid Chisnall        iterator __f2 = __c.begin();
22227a984708SDavid Chisnall        iterator __e2 = __c.end();
22237a984708SDavid Chisnall        while (__f1 != __e1 && __f2 != __e2)
22247a984708SDavid Chisnall        {
22257a984708SDavid Chisnall            if (__comp(*__f2, *__f1))
22267a984708SDavid Chisnall            {
22277a984708SDavid Chisnall                size_type __ds = 1;
22287a984708SDavid Chisnall                iterator __m2 = _VSTD::next(__f2);
22297a984708SDavid Chisnall                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
22307a984708SDavid Chisnall                    ;
22317a984708SDavid Chisnall                base::__sz() += __ds;
22327a984708SDavid Chisnall                __c.__sz() -= __ds;
22339729cf09SDimitry Andric                __link_pointer __f = __f2.__ptr_;
22349729cf09SDimitry Andric                __link_pointer __l = __m2.__ptr_->__prev_;
22357a984708SDavid Chisnall                __f2 = __m2;
22367a984708SDavid Chisnall                base::__unlink_nodes(__f, __l);
22377a984708SDavid Chisnall                __m2 = _VSTD::next(__f1);
22384bab9fd9SDavid Chisnall                __link_nodes(__f1.__ptr_, __f, __l);
22397a984708SDavid Chisnall                __f1 = __m2;
22407a984708SDavid Chisnall            }
22417a984708SDavid Chisnall            else
22427a984708SDavid Chisnall                ++__f1;
22437a984708SDavid Chisnall        }
22447a984708SDavid Chisnall        splice(__e1, __c);
22457a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
22467a984708SDavid Chisnall        __libcpp_db* __db = __get_db();
22477a984708SDavid Chisnall        __c_node* __cn1 = __db->__find_c_and_lock(this);
22487a984708SDavid Chisnall        __c_node* __cn2 = __db->__find_c(&__c);
22497a984708SDavid Chisnall        for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
22507a984708SDavid Chisnall        {
22517a984708SDavid Chisnall            --__p;
22527a984708SDavid Chisnall            iterator* __i = static_cast<iterator*>((*__p)->__i_);
22539729cf09SDimitry Andric            if (__i->__ptr_ != __c.__end_as_link())
22547a984708SDavid Chisnall            {
22557a984708SDavid Chisnall                __cn1->__add(*__p);
22567a984708SDavid Chisnall                (*__p)->__c_ = __cn1;
22577a984708SDavid Chisnall                if (--__cn2->end_ != __p)
22587a984708SDavid Chisnall                    memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
22597a984708SDavid Chisnall            }
22607a984708SDavid Chisnall        }
22617a984708SDavid Chisnall        __db->unlock();
22627a984708SDavid Chisnall#endif
22637a984708SDavid Chisnall    }
22647a984708SDavid Chisnall}
22657a984708SDavid Chisnall
22667a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
22677c82a1ecSDimitry Andricinline
22687a984708SDavid Chisnallvoid
22697a984708SDavid Chisnalllist<_Tp, _Alloc>::sort()
22707a984708SDavid Chisnall{
22717a984708SDavid Chisnall    sort(__less<value_type>());
22727a984708SDavid Chisnall}
22737a984708SDavid Chisnall
22747a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
22757a984708SDavid Chisnalltemplate <class _Comp>
22767c82a1ecSDimitry Andricinline
22777a984708SDavid Chisnallvoid
22787a984708SDavid Chisnalllist<_Tp, _Alloc>::sort(_Comp __comp)
22797a984708SDavid Chisnall{
22807a984708SDavid Chisnall    __sort(begin(), end(), base::__sz(), __comp);
22817a984708SDavid Chisnall}
22827a984708SDavid Chisnall
22837a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
22847a984708SDavid Chisnalltemplate <class _Comp>
22857a984708SDavid Chisnalltypename list<_Tp, _Alloc>::iterator
22867a984708SDavid Chisnalllist<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
22877a984708SDavid Chisnall{
22887a984708SDavid Chisnall    switch (__n)
22897a984708SDavid Chisnall    {
22907a984708SDavid Chisnall    case 0:
22917a984708SDavid Chisnall    case 1:
22927a984708SDavid Chisnall        return __f1;
22937a984708SDavid Chisnall    case 2:
22947a984708SDavid Chisnall        if (__comp(*--__e2, *__f1))
22957a984708SDavid Chisnall        {
22969729cf09SDimitry Andric            __link_pointer __f = __e2.__ptr_;
22977a984708SDavid Chisnall            base::__unlink_nodes(__f, __f);
22984bab9fd9SDavid Chisnall            __link_nodes(__f1.__ptr_, __f, __f);
22997a984708SDavid Chisnall            return __e2;
23007a984708SDavid Chisnall        }
23017a984708SDavid Chisnall        return __f1;
23027a984708SDavid Chisnall    }
23037a984708SDavid Chisnall    size_type __n2 = __n / 2;
23047a984708SDavid Chisnall    iterator __e1 = _VSTD::next(__f1, __n2);
23057a984708SDavid Chisnall    iterator  __r = __f1 = __sort(__f1, __e1, __n2, __comp);
23067a984708SDavid Chisnall    iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
23077a984708SDavid Chisnall    if (__comp(*__f2, *__f1))
23087a984708SDavid Chisnall    {
23097a984708SDavid Chisnall        iterator __m2 = _VSTD::next(__f2);
23107a984708SDavid Chisnall        for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
23117a984708SDavid Chisnall            ;
23129729cf09SDimitry Andric        __link_pointer __f = __f2.__ptr_;
23139729cf09SDimitry Andric        __link_pointer __l = __m2.__ptr_->__prev_;
23147a984708SDavid Chisnall        __r = __f2;
23157a984708SDavid Chisnall        __e1 = __f2 = __m2;
23167a984708SDavid Chisnall        base::__unlink_nodes(__f, __l);
23177a984708SDavid Chisnall        __m2 = _VSTD::next(__f1);
23184bab9fd9SDavid Chisnall        __link_nodes(__f1.__ptr_, __f, __l);
23197a984708SDavid Chisnall        __f1 = __m2;
23207a984708SDavid Chisnall    }
23217a984708SDavid Chisnall    else
23227a984708SDavid Chisnall        ++__f1;
23237a984708SDavid Chisnall    while (__f1 != __e1 && __f2 != __e2)
23247a984708SDavid Chisnall    {
23257a984708SDavid Chisnall        if (__comp(*__f2, *__f1))
23267a984708SDavid Chisnall        {
23277a984708SDavid Chisnall            iterator __m2 = _VSTD::next(__f2);
23287a984708SDavid Chisnall            for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
23297a984708SDavid Chisnall                ;
23309729cf09SDimitry Andric            __link_pointer __f = __f2.__ptr_;
23319729cf09SDimitry Andric            __link_pointer __l = __m2.__ptr_->__prev_;
23327a984708SDavid Chisnall            if (__e1 == __f2)
23337a984708SDavid Chisnall                __e1 = __m2;
23347a984708SDavid Chisnall            __f2 = __m2;
23357a984708SDavid Chisnall            base::__unlink_nodes(__f, __l);
23367a984708SDavid Chisnall            __m2 = _VSTD::next(__f1);
23374bab9fd9SDavid Chisnall            __link_nodes(__f1.__ptr_, __f, __l);
23387a984708SDavid Chisnall            __f1 = __m2;
23397a984708SDavid Chisnall        }
23407a984708SDavid Chisnall        else
23417a984708SDavid Chisnall            ++__f1;
23427a984708SDavid Chisnall    }
23437a984708SDavid Chisnall    return __r;
23447a984708SDavid Chisnall}
23457a984708SDavid Chisnall
23467a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23477a984708SDavid Chisnallvoid
23487a984708SDavid Chisnalllist<_Tp, _Alloc>::reverse() _NOEXCEPT
23497a984708SDavid Chisnall{
23507a984708SDavid Chisnall    if (base::__sz() > 1)
23517a984708SDavid Chisnall    {
23527a984708SDavid Chisnall        iterator __e = end();
23537a984708SDavid Chisnall        for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
23547a984708SDavid Chisnall        {
23557a984708SDavid Chisnall            _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
23567a984708SDavid Chisnall            __i.__ptr_ = __i.__ptr_->__prev_;
23577a984708SDavid Chisnall        }
23587a984708SDavid Chisnall        _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
23597a984708SDavid Chisnall    }
23607a984708SDavid Chisnall}
23617a984708SDavid Chisnall
23627a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23637a984708SDavid Chisnallbool
23647a984708SDavid Chisnalllist<_Tp, _Alloc>::__invariants() const
23657a984708SDavid Chisnall{
23667a984708SDavid Chisnall    return size() == _VSTD::distance(begin(), end());
23677a984708SDavid Chisnall}
23687a984708SDavid Chisnall
23697a984708SDavid Chisnall#if _LIBCPP_DEBUG_LEVEL >= 2
23707a984708SDavid Chisnall
23717a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23727a984708SDavid Chisnallbool
23737a984708SDavid Chisnalllist<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
23747a984708SDavid Chisnall{
23759729cf09SDimitry Andric    return __i->__ptr_ != this->__end_as_link();
23767a984708SDavid Chisnall}
23777a984708SDavid Chisnall
23787a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23797a984708SDavid Chisnallbool
23807a984708SDavid Chisnalllist<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
23817a984708SDavid Chisnall{
23827a984708SDavid Chisnall    return !empty() &&  __i->__ptr_ != base::__end_.__next_;
23837a984708SDavid Chisnall}
23847a984708SDavid Chisnall
23857a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23867a984708SDavid Chisnallbool
2387aed8d94eSDimitry Andriclist<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
23887a984708SDavid Chisnall{
23897a984708SDavid Chisnall    return false;
23907a984708SDavid Chisnall}
23917a984708SDavid Chisnall
23927a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
23937a984708SDavid Chisnallbool
2394aed8d94eSDimitry Andriclist<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
23957a984708SDavid Chisnall{
23967a984708SDavid Chisnall    return false;
23977a984708SDavid Chisnall}
23987a984708SDavid Chisnall
23997a984708SDavid Chisnall#endif  // _LIBCPP_DEBUG_LEVEL >= 2
24007a984708SDavid Chisnall
24017a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24027a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24037a984708SDavid Chisnallbool
24047a984708SDavid Chisnalloperator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24057a984708SDavid Chisnall{
24067a984708SDavid Chisnall    return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
24077a984708SDavid Chisnall}
24087a984708SDavid Chisnall
24097a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24107a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24117a984708SDavid Chisnallbool
24127a984708SDavid Chisnalloperator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24137a984708SDavid Chisnall{
24147a984708SDavid Chisnall    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
24157a984708SDavid Chisnall}
24167a984708SDavid Chisnall
24177a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24187a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24197a984708SDavid Chisnallbool
24207a984708SDavid Chisnalloperator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24217a984708SDavid Chisnall{
24227a984708SDavid Chisnall    return !(__x == __y);
24237a984708SDavid Chisnall}
24247a984708SDavid Chisnall
24257a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24267a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24277a984708SDavid Chisnallbool
24287a984708SDavid Chisnalloperator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24297a984708SDavid Chisnall{
24307a984708SDavid Chisnall    return __y < __x;
24317a984708SDavid Chisnall}
24327a984708SDavid Chisnall
24337a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24347a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24357a984708SDavid Chisnallbool
24367a984708SDavid Chisnalloperator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24377a984708SDavid Chisnall{
24387a984708SDavid Chisnall    return !(__x < __y);
24397a984708SDavid Chisnall}
24407a984708SDavid Chisnall
24417a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24427a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24437a984708SDavid Chisnallbool
24447a984708SDavid Chisnalloperator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
24457a984708SDavid Chisnall{
24467a984708SDavid Chisnall    return !(__y < __x);
24477a984708SDavid Chisnall}
24487a984708SDavid Chisnall
24497a984708SDavid Chisnalltemplate <class _Tp, class _Alloc>
24507a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
24517a984708SDavid Chisnallvoid
24527a984708SDavid Chisnallswap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
24537a984708SDavid Chisnall    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
24547a984708SDavid Chisnall{
24557a984708SDavid Chisnall    __x.swap(__y);
24567a984708SDavid Chisnall}
24577a984708SDavid Chisnall
2458*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17
2459*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
2460*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2461*b5893f02SDimitry Andricvoid erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred)
2462*b5893f02SDimitry Andric{ __c.remove_if(__pred); }
2463*b5893f02SDimitry Andric
2464*b5893f02SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
2465*b5893f02SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2466*b5893f02SDimitry Andricvoid erase(list<_Tp, _Allocator>& __c, const _Up& __v)
2467*b5893f02SDimitry Andric{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
2468*b5893f02SDimitry Andric#endif
2469*b5893f02SDimitry Andric
24707a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
24717a984708SDavid Chisnall
2472f9448bf3SDimitry Andric_LIBCPP_POP_MACROS
2473f9448bf3SDimitry Andric
24747a984708SDavid Chisnall#endif  // _LIBCPP_LIST
2475