xref: /freebsd/contrib/llvm-project/libcxx/include/list (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_LIST
110b57cec5SDimitry Andric#define _LIBCPP_LIST
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    list synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class T, class Alloc = allocator<T> >
200b57cec5SDimitry Andricclass list
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricpublic:
230b57cec5SDimitry Andric
240b57cec5SDimitry Andric    // types:
250b57cec5SDimitry Andric    typedef T value_type;
260b57cec5SDimitry Andric    typedef Alloc allocator_type;
270b57cec5SDimitry Andric    typedef typename allocator_type::reference reference;
280b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
290b57cec5SDimitry Andric    typedef typename allocator_type::pointer pointer;
300b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer const_pointer;
310b57cec5SDimitry Andric    typedef implementation-defined iterator;
320b57cec5SDimitry Andric    typedef implementation-defined const_iterator;
330b57cec5SDimitry Andric    typedef implementation-defined size_type;
340b57cec5SDimitry Andric    typedef implementation-defined difference_type;
350b57cec5SDimitry Andric    typedef reverse_iterator<iterator> reverse_iterator;
360b57cec5SDimitry Andric    typedef reverse_iterator<const_iterator> const_reverse_iterator;
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric    list()
390b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
400b57cec5SDimitry Andric    explicit list(const allocator_type& a);
410b57cec5SDimitry Andric    explicit list(size_type n);
420b57cec5SDimitry Andric    explicit list(size_type n, const allocator_type& a); // C++14
430b57cec5SDimitry Andric    list(size_type n, const value_type& value);
440b57cec5SDimitry Andric    list(size_type n, const value_type& value, const allocator_type& a);
450b57cec5SDimitry Andric    template <class Iter>
460b57cec5SDimitry Andric        list(Iter first, Iter last);
470b57cec5SDimitry Andric    template <class Iter>
480b57cec5SDimitry Andric        list(Iter first, Iter last, const allocator_type& a);
4906c3fb27SDimitry Andric    template<container-compatible-range<T> R>
5006c3fb27SDimitry Andric      list(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
510b57cec5SDimitry Andric    list(const list& x);
520b57cec5SDimitry Andric    list(const list&, const allocator_type& a);
530b57cec5SDimitry Andric    list(list&& x)
540b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
550b57cec5SDimitry Andric    list(list&&, const allocator_type& a);
560b57cec5SDimitry Andric    list(initializer_list<value_type>);
570b57cec5SDimitry Andric    list(initializer_list<value_type>, const allocator_type& a);
580b57cec5SDimitry Andric
590b57cec5SDimitry Andric    ~list();
600b57cec5SDimitry Andric
610b57cec5SDimitry Andric    list& operator=(const list& x);
620b57cec5SDimitry Andric    list& operator=(list&& x)
630b57cec5SDimitry Andric        noexcept(
640b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value &&
650b57cec5SDimitry Andric             is_nothrow_move_assignable<allocator_type>::value);
660b57cec5SDimitry Andric    list& operator=(initializer_list<value_type>);
670b57cec5SDimitry Andric    template <class Iter>
680b57cec5SDimitry Andric        void assign(Iter first, Iter last);
6906c3fb27SDimitry Andric    template<container-compatible-range<T> R>
7006c3fb27SDimitry Andric      void assign_range(R&& rg); // C++23
710b57cec5SDimitry Andric    void assign(size_type n, const value_type& t);
720b57cec5SDimitry Andric    void assign(initializer_list<value_type>);
730b57cec5SDimitry Andric
740b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
750b57cec5SDimitry Andric
760b57cec5SDimitry Andric    iterator begin() noexcept;
770b57cec5SDimitry Andric    const_iterator begin() const noexcept;
780b57cec5SDimitry Andric    iterator end() noexcept;
790b57cec5SDimitry Andric    const_iterator end() const noexcept;
800b57cec5SDimitry Andric    reverse_iterator rbegin() noexcept;
810b57cec5SDimitry Andric    const_reverse_iterator rbegin() const noexcept;
820b57cec5SDimitry Andric    reverse_iterator rend() noexcept;
830b57cec5SDimitry Andric    const_reverse_iterator rend() const noexcept;
840b57cec5SDimitry Andric    const_iterator cbegin() const noexcept;
850b57cec5SDimitry Andric    const_iterator cend() const noexcept;
860b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
870b57cec5SDimitry Andric    const_reverse_iterator crend() const noexcept;
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric    reference front();
900b57cec5SDimitry Andric    const_reference front() const;
910b57cec5SDimitry Andric    reference back();
920b57cec5SDimitry Andric    const_reference back() const;
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric    bool empty() const noexcept;
950b57cec5SDimitry Andric    size_type size() const noexcept;
960b57cec5SDimitry Andric    size_type max_size() const noexcept;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric    template <class... Args>
990b57cec5SDimitry Andric        reference emplace_front(Args&&... args); // reference in C++17
1000b57cec5SDimitry Andric    void pop_front();
1010b57cec5SDimitry Andric    template <class... Args>
1020b57cec5SDimitry Andric        reference emplace_back(Args&&... args);  // reference in C++17
1030b57cec5SDimitry Andric    void pop_back();
1040b57cec5SDimitry Andric    void push_front(const value_type& x);
1050b57cec5SDimitry Andric    void push_front(value_type&& x);
10606c3fb27SDimitry Andric    template<container-compatible-range<T> R>
10706c3fb27SDimitry Andric      void prepend_range(R&& rg); // C++23
1080b57cec5SDimitry Andric    void push_back(const value_type& x);
1090b57cec5SDimitry Andric    void push_back(value_type&& x);
11006c3fb27SDimitry Andric    template<container-compatible-range<T> R>
11106c3fb27SDimitry Andric      void append_range(R&& rg); // C++23
1120b57cec5SDimitry Andric    template <class... Args>
1130b57cec5SDimitry Andric        iterator emplace(const_iterator position, Args&&... args);
1140b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& x);
1150b57cec5SDimitry Andric    iterator insert(const_iterator position, value_type&& x);
1160b57cec5SDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
1170b57cec5SDimitry Andric    template <class Iter>
1180b57cec5SDimitry Andric        iterator insert(const_iterator position, Iter first, Iter last);
11906c3fb27SDimitry Andric    template<container-compatible-range<T> R>
12006c3fb27SDimitry Andric      iterator insert_range(const_iterator position, R&& rg); // C++23
1210b57cec5SDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric    iterator erase(const_iterator position);
1240b57cec5SDimitry Andric    iterator erase(const_iterator position, const_iterator last);
1250b57cec5SDimitry Andric
1260b57cec5SDimitry Andric    void resize(size_type sz);
1270b57cec5SDimitry Andric    void resize(size_type sz, const value_type& c);
1280b57cec5SDimitry Andric
1290b57cec5SDimitry Andric    void swap(list&)
1300b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1310b57cec5SDimitry Andric    void clear() noexcept;
1320b57cec5SDimitry Andric
1330b57cec5SDimitry Andric    void splice(const_iterator position, list& x);
1340b57cec5SDimitry Andric    void splice(const_iterator position, list&& x);
1350b57cec5SDimitry Andric    void splice(const_iterator position, list& x, const_iterator i);
1360b57cec5SDimitry Andric    void splice(const_iterator position, list&& x, const_iterator i);
1370b57cec5SDimitry Andric    void splice(const_iterator position, list& x, const_iterator first,
1380b57cec5SDimitry Andric                                                  const_iterator last);
1390b57cec5SDimitry Andric    void splice(const_iterator position, list&& x, const_iterator first,
1400b57cec5SDimitry Andric                                                  const_iterator last);
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andric    size_type remove(const value_type& value);       // void before C++20
1430b57cec5SDimitry Andric    template <class Pred>
1440b57cec5SDimitry Andric      size_type remove_if(Pred pred);                // void before C++20
1450b57cec5SDimitry Andric    size_type unique();                              // void before C++20
1460b57cec5SDimitry Andric    template <class BinaryPredicate>
1470b57cec5SDimitry Andric      size_type unique(BinaryPredicate binary_pred); // void before C++20
1480b57cec5SDimitry Andric    void merge(list& x);
1490b57cec5SDimitry Andric    void merge(list&& x);
1500b57cec5SDimitry Andric    template <class Compare>
1510b57cec5SDimitry Andric        void merge(list& x, Compare comp);
1520b57cec5SDimitry Andric    template <class Compare>
1530b57cec5SDimitry Andric        void merge(list&& x, Compare comp);
1540b57cec5SDimitry Andric    void sort();
1550b57cec5SDimitry Andric    template <class Compare>
1560b57cec5SDimitry Andric        void sort(Compare comp);
1570b57cec5SDimitry Andric    void reverse() noexcept;
1580b57cec5SDimitry Andric};
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1620b57cec5SDimitry Andric    list(InputIterator, InputIterator, Allocator = Allocator())
1630b57cec5SDimitry Andric    -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;  // C++17
1640b57cec5SDimitry Andric
16506c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
16606c3fb27SDimitry Andric  list(from_range_t, R&&, Allocator = Allocator())
16706c3fb27SDimitry Andric    -> list<ranges::range_value_t<R>, Allocator>; // C++23
16806c3fb27SDimitry Andric
1690b57cec5SDimitry Andrictemplate <class T, class Alloc>
1700b57cec5SDimitry Andric    bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
1710b57cec5SDimitry Andrictemplate <class T, class Alloc>
17206c3fb27SDimitry Andric    bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);     // removed in C++20
1730b57cec5SDimitry Andrictemplate <class T, class Alloc>
17406c3fb27SDimitry Andric    bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);     // removed in C++20
1750b57cec5SDimitry Andrictemplate <class T, class Alloc>
17606c3fb27SDimitry Andric    bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);     // removed in C++20
1770b57cec5SDimitry Andrictemplate <class T, class Alloc>
17806c3fb27SDimitry Andric    bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);     // removed in C++20
1790b57cec5SDimitry Andrictemplate <class T, class Alloc>
18006c3fb27SDimitry Andric    bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);     // removed in C++20
18106c3fb27SDimitry Andrictemplate<class T, class Allocator>
18206c3fb27SDimitry Andric  synth-three-way-result<T> operator<=>(const list<T, Allocator>& x,
18306c3fb27SDimitry Andric                                        const list<T, Allocator>& y);    // since C++20
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andrictemplate <class T, class Alloc>
1860b57cec5SDimitry Andric    void swap(list<T,Alloc>& x, list<T,Alloc>& y)
1870b57cec5SDimitry Andric         noexcept(noexcept(x.swap(y)));
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andrictemplate <class T, class Allocator, class U>
1905ffd83dbSDimitry Andric    typename list<T, Allocator>::size_type
19106c3fb27SDimitry Andric    erase(list<T, Allocator>& c, const U& value);       // since C++20
1920b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate>
1935ffd83dbSDimitry Andric    typename list<T, Allocator>::size_type
19406c3fb27SDimitry Andric    erase_if(list<T, Allocator>& c, Predicate pred);    // since C++20
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric}  // std
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric*/
1990b57cec5SDimitry Andric
20081ad6265SDimitry Andric#include <__algorithm/comp.h>
20181ad6265SDimitry Andric#include <__algorithm/equal.h>
20281ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
20306c3fb27SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h>
20481ad6265SDimitry Andric#include <__algorithm/min.h>
20581ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
20606c3fb27SDimitry Andric#include <__availability>
2070b57cec5SDimitry Andric#include <__config>
20881ad6265SDimitry Andric#include <__format/enable_insertable.h>
20981ad6265SDimitry Andric#include <__iterator/distance.h>
21081ad6265SDimitry Andric#include <__iterator/iterator_traits.h>
21181ad6265SDimitry Andric#include <__iterator/move_iterator.h>
21281ad6265SDimitry Andric#include <__iterator/next.h>
21381ad6265SDimitry Andric#include <__iterator/prev.h>
21481ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
215bdd1243dSDimitry Andric#include <__memory/addressof.h>
216*5f757f3fSDimitry Andric#include <__memory/allocation_guard.h>
217bdd1243dSDimitry Andric#include <__memory/allocator.h>
218bdd1243dSDimitry Andric#include <__memory/allocator_traits.h>
219bdd1243dSDimitry Andric#include <__memory/compressed_pair.h>
220*5f757f3fSDimitry Andric#include <__memory/construct_at.h>
221bdd1243dSDimitry Andric#include <__memory/pointer_traits.h>
222972a253aSDimitry Andric#include <__memory/swap_allocator.h>
223bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h>
22406c3fb27SDimitry Andric#include <__ranges/access.h>
22506c3fb27SDimitry Andric#include <__ranges/concepts.h>
22606c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h>
22706c3fb27SDimitry Andric#include <__ranges/from_range.h>
22806c3fb27SDimitry Andric#include <__type_traits/conditional.h>
229bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h>
23006c3fb27SDimitry Andric#include <__type_traits/is_nothrow_default_constructible.h>
23106c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h>
23206c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_constructible.h>
23306c3fb27SDimitry Andric#include <__type_traits/is_pointer.h>
23406c3fb27SDimitry Andric#include <__type_traits/is_same.h>
23506c3fb27SDimitry Andric#include <__type_traits/type_identity.h>
236fe6060f1SDimitry Andric#include <__utility/forward.h>
23781ad6265SDimitry Andric#include <__utility/move.h>
23881ad6265SDimitry Andric#include <__utility/swap.h>
239bdd1243dSDimitry Andric#include <cstring>
240fe6060f1SDimitry Andric#include <limits>
241*5f757f3fSDimitry Andric#include <new> // __launder
2420b57cec5SDimitry Andric#include <version>
2430b57cec5SDimitry Andric
24481ad6265SDimitry Andric// standard-mandated includes
24581ad6265SDimitry Andric
24681ad6265SDimitry Andric// [iterator.range]
24781ad6265SDimitry Andric#include <__iterator/access.h>
24881ad6265SDimitry Andric#include <__iterator/data.h>
24981ad6265SDimitry Andric#include <__iterator/empty.h>
25081ad6265SDimitry Andric#include <__iterator/reverse_access.h>
25181ad6265SDimitry Andric#include <__iterator/size.h>
25281ad6265SDimitry Andric
25381ad6265SDimitry Andric// [list.syn]
25481ad6265SDimitry Andric#include <compare>
25581ad6265SDimitry Andric#include <initializer_list>
25681ad6265SDimitry Andric
2570b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2580b57cec5SDimitry Andric#  pragma GCC system_header
2590b57cec5SDimitry Andric#endif
2600b57cec5SDimitry Andric
2610b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
2620b57cec5SDimitry Andric#include <__undef_macros>
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andric
2650b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2660b57cec5SDimitry Andric
2670b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> struct __list_node;
2680b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> struct __list_node_base;
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr>
2710b57cec5SDimitry Andricstruct __list_node_pointer_traits {
272bdd1243dSDimitry Andric  typedef __rebind_pointer_t<_VoidPtr, __list_node<_Tp, _VoidPtr> >
2730b57cec5SDimitry Andric        __node_pointer;
274bdd1243dSDimitry Andric  typedef __rebind_pointer_t<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >
2750b57cec5SDimitry Andric        __base_pointer;
2760b57cec5SDimitry Andric
2770b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
2780b57cec5SDimitry Andric  typedef __base_pointer __link_pointer;
2790b57cec5SDimitry Andric#else
280bdd1243dSDimitry Andric  typedef __conditional_t<is_pointer<_VoidPtr>::value, __base_pointer, __node_pointer> __link_pointer;
2810b57cec5SDimitry Andric#endif
2820b57cec5SDimitry Andric
283bdd1243dSDimitry Andric  typedef __conditional_t<is_same<__link_pointer, __node_pointer>::value, __base_pointer, __node_pointer>
284bdd1243dSDimitry Andric      __non_link_pointer;
2850b57cec5SDimitry Andric
286*5f757f3fSDimitry Andric  static _LIBCPP_HIDE_FROM_ABI
2870b57cec5SDimitry Andric  __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
2880b57cec5SDimitry Andric      return __p;
2890b57cec5SDimitry Andric  }
2900b57cec5SDimitry Andric
291*5f757f3fSDimitry Andric  static _LIBCPP_HIDE_FROM_ABI
2920b57cec5SDimitry Andric  __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
2930b57cec5SDimitry Andric      return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
2940b57cec5SDimitry Andric  }
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andric};
2970b57cec5SDimitry Andric
2980b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr>
2990b57cec5SDimitry Andricstruct __list_node_base
3000b57cec5SDimitry Andric{
3010b57cec5SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
3020b57cec5SDimitry Andric    typedef typename _NodeTraits::__node_pointer __node_pointer;
3030b57cec5SDimitry Andric    typedef typename _NodeTraits::__base_pointer __base_pointer;
3040b57cec5SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andric    __link_pointer __prev_;
3070b57cec5SDimitry Andric    __link_pointer __next_;
3080b57cec5SDimitry Andric
309*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3100b57cec5SDimitry Andric    __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
3110b57cec5SDimitry Andric                         __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
3120b57cec5SDimitry Andric
313*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__link_pointer __prev, __link_pointer __next)
314*5f757f3fSDimitry Andric        : __prev_(__prev), __next_(__next) {}
315*5f757f3fSDimitry Andric
316*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3170b57cec5SDimitry Andric    __base_pointer __self() {
3180b57cec5SDimitry Andric        return pointer_traits<__base_pointer>::pointer_to(*this);
3190b57cec5SDimitry Andric    }
3200b57cec5SDimitry Andric
321*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3220b57cec5SDimitry Andric    __node_pointer __as_node() {
3230b57cec5SDimitry Andric        return static_cast<__node_pointer>(__self());
3240b57cec5SDimitry Andric    }
3250b57cec5SDimitry Andric};
3260b57cec5SDimitry Andric
3270b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr>
328*5f757f3fSDimitry Andricstruct __list_node
3290b57cec5SDimitry Andric    : public __list_node_base<_Tp, _VoidPtr>
3300b57cec5SDimitry Andric{
331*5f757f3fSDimitry Andric    // We allow starting the lifetime of nodes without initializing the value held by the node,
332*5f757f3fSDimitry Andric    // since that is handled by the list itself in order to be allocator-aware.
333*5f757f3fSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
334*5f757f3fSDimitry Andricprivate:
335*5f757f3fSDimitry Andric    union {
3360b57cec5SDimitry Andric        _Tp __value_;
337*5f757f3fSDimitry Andric    };
338*5f757f3fSDimitry Andric
339*5f757f3fSDimitry Andricpublic:
340*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
341*5f757f3fSDimitry Andric#else
342*5f757f3fSDimitry Andricprivate:
343*5f757f3fSDimitry Andric    _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
344*5f757f3fSDimitry Andric
345*5f757f3fSDimitry Andricpublic:
346*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() {
347*5f757f3fSDimitry Andric        return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_));
348*5f757f3fSDimitry Andric    }
349*5f757f3fSDimitry Andric#endif
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andric    typedef __list_node_base<_Tp, _VoidPtr> __base;
3520b57cec5SDimitry Andric    typedef typename __base::__link_pointer __link_pointer;
3530b57cec5SDimitry Andric
354*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI explicit __list_node(__link_pointer __prev, __link_pointer __next) : __base(__prev, __next) {}
355*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
356*5f757f3fSDimitry Andric
357*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3580b57cec5SDimitry Andric    __link_pointer __as_link() {
3590b57cec5SDimitry Andric        return static_cast<__link_pointer>(__base::__self());
3600b57cec5SDimitry Andric    }
3610b57cec5SDimitry Andric};
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
3640b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> class __list_imp;
3650b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
3660b57cec5SDimitry Andric
3670b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr>
3680b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_iterator
3690b57cec5SDimitry Andric{
3700b57cec5SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
3710b57cec5SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
3720b57cec5SDimitry Andric
3730b57cec5SDimitry Andric    __link_pointer __ptr_;
3740b57cec5SDimitry Andric
375*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
37606c3fb27SDimitry Andric    explicit __list_iterator(__link_pointer __p) _NOEXCEPT
3770b57cec5SDimitry Andric        : __ptr_(__p)
3780b57cec5SDimitry Andric    {
37981ad6265SDimitry Andric    }
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andric    template<class, class> friend class list;
3820b57cec5SDimitry Andric    template<class, class> friend class __list_imp;
3830b57cec5SDimitry Andric    template<class, class> friend class __list_const_iterator;
3840b57cec5SDimitry Andricpublic:
3850b57cec5SDimitry Andric    typedef bidirectional_iterator_tag       iterator_category;
3860b57cec5SDimitry Andric    typedef _Tp                              value_type;
3870b57cec5SDimitry Andric    typedef value_type&                      reference;
388bdd1243dSDimitry Andric    typedef __rebind_pointer_t<_VoidPtr, value_type> pointer;
3890b57cec5SDimitry Andric    typedef typename pointer_traits<pointer>::difference_type difference_type;
3900b57cec5SDimitry Andric
391*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3920b57cec5SDimitry Andric    __list_iterator() _NOEXCEPT : __ptr_(nullptr)
3930b57cec5SDimitry Andric    {
3940b57cec5SDimitry Andric    }
3950b57cec5SDimitry Andric
396*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3970b57cec5SDimitry Andric    reference operator*() const
3980b57cec5SDimitry Andric    {
399*5f757f3fSDimitry Andric        return __ptr_->__as_node()->__get_value();
4000b57cec5SDimitry Andric    }
401*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4020b57cec5SDimitry Andric    pointer operator->() const
4030b57cec5SDimitry Andric    {
404*5f757f3fSDimitry Andric        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
4050b57cec5SDimitry Andric    }
4060b57cec5SDimitry Andric
407*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4080b57cec5SDimitry Andric    __list_iterator& operator++()
4090b57cec5SDimitry Andric    {
4100b57cec5SDimitry Andric        __ptr_ = __ptr_->__next_;
4110b57cec5SDimitry Andric        return *this;
4120b57cec5SDimitry Andric    }
413*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4140b57cec5SDimitry Andric    __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
4150b57cec5SDimitry Andric
416*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4170b57cec5SDimitry Andric    __list_iterator& operator--()
4180b57cec5SDimitry Andric    {
4190b57cec5SDimitry Andric        __ptr_ = __ptr_->__prev_;
4200b57cec5SDimitry Andric        return *this;
4210b57cec5SDimitry Andric    }
422*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4230b57cec5SDimitry Andric    __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
4240b57cec5SDimitry Andric
425*5f757f3fSDimitry Andric    friend _LIBCPP_HIDE_FROM_ABI
4260b57cec5SDimitry Andric    bool operator==(const __list_iterator& __x, const __list_iterator& __y)
4270b57cec5SDimitry Andric    {
4280b57cec5SDimitry Andric        return __x.__ptr_ == __y.__ptr_;
4290b57cec5SDimitry Andric    }
430*5f757f3fSDimitry Andric    friend _LIBCPP_HIDE_FROM_ABI
4310b57cec5SDimitry Andric     bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
4320b57cec5SDimitry Andric        {return !(__x == __y);}
4330b57cec5SDimitry Andric};
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr>
4360b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_const_iterator
4370b57cec5SDimitry Andric{
4380b57cec5SDimitry Andric    typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
4390b57cec5SDimitry Andric    typedef typename _NodeTraits::__link_pointer __link_pointer;
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andric    __link_pointer __ptr_;
4420b57cec5SDimitry Andric
443*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
44406c3fb27SDimitry Andric    explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT
4450b57cec5SDimitry Andric        : __ptr_(__p)
4460b57cec5SDimitry Andric    {
44781ad6265SDimitry Andric    }
4480b57cec5SDimitry Andric
4490b57cec5SDimitry Andric    template<class, class> friend class list;
4500b57cec5SDimitry Andric    template<class, class> friend class __list_imp;
4510b57cec5SDimitry Andricpublic:
4520b57cec5SDimitry Andric    typedef bidirectional_iterator_tag       iterator_category;
4530b57cec5SDimitry Andric    typedef _Tp                              value_type;
4540b57cec5SDimitry Andric    typedef const value_type&                reference;
455bdd1243dSDimitry Andric    typedef __rebind_pointer_t<_VoidPtr, const value_type> pointer;
4560b57cec5SDimitry Andric    typedef typename pointer_traits<pointer>::difference_type difference_type;
4570b57cec5SDimitry Andric
458*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4590b57cec5SDimitry Andric    __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
4600b57cec5SDimitry Andric    {
4610b57cec5SDimitry Andric    }
462*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4630b57cec5SDimitry Andric    __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
4640b57cec5SDimitry Andric        : __ptr_(__p.__ptr_)
4650b57cec5SDimitry Andric    {
4660b57cec5SDimitry Andric    }
4670b57cec5SDimitry Andric
468*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4690b57cec5SDimitry Andric    reference operator*() const
4700b57cec5SDimitry Andric    {
471*5f757f3fSDimitry Andric        return __ptr_->__as_node()->__get_value();
4720b57cec5SDimitry Andric    }
473*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4740b57cec5SDimitry Andric    pointer operator->() const
4750b57cec5SDimitry Andric    {
476*5f757f3fSDimitry Andric        return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
4770b57cec5SDimitry Andric    }
4780b57cec5SDimitry Andric
479*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4800b57cec5SDimitry Andric    __list_const_iterator& operator++()
4810b57cec5SDimitry Andric    {
4820b57cec5SDimitry Andric        __ptr_ = __ptr_->__next_;
4830b57cec5SDimitry Andric        return *this;
4840b57cec5SDimitry Andric    }
485*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4860b57cec5SDimitry Andric    __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
4870b57cec5SDimitry Andric
488*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4890b57cec5SDimitry Andric    __list_const_iterator& operator--()
4900b57cec5SDimitry Andric    {
4910b57cec5SDimitry Andric        __ptr_ = __ptr_->__prev_;
4920b57cec5SDimitry Andric        return *this;
4930b57cec5SDimitry Andric    }
494*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
4950b57cec5SDimitry Andric    __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
4960b57cec5SDimitry Andric
497*5f757f3fSDimitry Andric    friend _LIBCPP_HIDE_FROM_ABI
4980b57cec5SDimitry Andric    bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
4990b57cec5SDimitry Andric    {
5000b57cec5SDimitry Andric        return __x.__ptr_ == __y.__ptr_;
5010b57cec5SDimitry Andric    }
502*5f757f3fSDimitry Andric    friend _LIBCPP_HIDE_FROM_ABI
5030b57cec5SDimitry Andric    bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
5040b57cec5SDimitry Andric        {return !(__x == __y);}
5050b57cec5SDimitry Andric};
5060b57cec5SDimitry Andric
5070b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
5080b57cec5SDimitry Andricclass __list_imp
5090b57cec5SDimitry Andric{
5100b57cec5SDimitry Andric    __list_imp(const __list_imp&);
5110b57cec5SDimitry Andric    __list_imp& operator=(const __list_imp&);
5120b57cec5SDimitry Andricpublic:
5130b57cec5SDimitry Andric    typedef _Alloc                                                  allocator_type;
5140b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>                        __alloc_traits;
5150b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type                      size_type;
5160b57cec5SDimitry Andricprotected:
5170b57cec5SDimitry Andric    typedef _Tp                                                     value_type;
5180b57cec5SDimitry Andric    typedef typename __alloc_traits::void_pointer                   __void_pointer;
5190b57cec5SDimitry Andric    typedef __list_iterator<value_type, __void_pointer>             iterator;
5200b57cec5SDimitry Andric    typedef __list_const_iterator<value_type, __void_pointer>       const_iterator;
5210b57cec5SDimitry Andric    typedef __list_node_base<value_type, __void_pointer>            __node_base;
522*5f757f3fSDimitry Andric    typedef __list_node<value_type, __void_pointer>                 __node_type;
523*5f757f3fSDimitry Andric    typedef __rebind_alloc<__alloc_traits, __node_type>             __node_allocator;
5240b57cec5SDimitry Andric    typedef allocator_traits<__node_allocator>                       __node_alloc_traits;
5250b57cec5SDimitry Andric    typedef typename __node_alloc_traits::pointer                    __node_pointer;
5260b57cec5SDimitry Andric    typedef typename __node_alloc_traits::pointer                    __node_const_pointer;
5270b57cec5SDimitry Andric    typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
5280b57cec5SDimitry Andric    typedef typename __node_pointer_traits::__link_pointer __link_pointer;
5290b57cec5SDimitry Andric    typedef __link_pointer __link_const_pointer;
5300b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer                         pointer;
5310b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer                   const_pointer;
5320b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type                 difference_type;
5330b57cec5SDimitry Andric
534bdd1243dSDimitry Andric    typedef __rebind_alloc<__alloc_traits, __node_base>               __node_base_allocator;
5350b57cec5SDimitry Andric    typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
5360b57cec5SDimitry Andric    static_assert((!is_same<allocator_type, __node_allocator>::value),
5370b57cec5SDimitry Andric                  "internal allocator type must differ from user-specified "
5380b57cec5SDimitry Andric                  "type; otherwise overload resolution breaks");
5390b57cec5SDimitry Andric
5400b57cec5SDimitry Andric    __node_base __end_;
5410b57cec5SDimitry Andric    __compressed_pair<size_type, __node_allocator> __size_alloc_;
5420b57cec5SDimitry Andric
543*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5440b57cec5SDimitry Andric    __link_pointer __end_as_link() const _NOEXCEPT {
5450b57cec5SDimitry Andric        return __node_pointer_traits::__unsafe_link_pointer_cast(
5460b57cec5SDimitry Andric                const_cast<__node_base&>(__end_).__self());
5470b57cec5SDimitry Andric    }
5480b57cec5SDimitry Andric
549*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5500b57cec5SDimitry Andric          size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
551*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5520b57cec5SDimitry Andric    const size_type& __sz() const _NOEXCEPT
5530b57cec5SDimitry Andric        {return __size_alloc_.first();}
554*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5550b57cec5SDimitry Andric          __node_allocator& __node_alloc() _NOEXCEPT
5560b57cec5SDimitry Andric          {return __size_alloc_.second();}
557*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5580b57cec5SDimitry Andric    const __node_allocator& __node_alloc() const _NOEXCEPT
5590b57cec5SDimitry Andric        {return __size_alloc_.second();}
5600b57cec5SDimitry Andric
561*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5620b57cec5SDimitry Andric    size_type __node_alloc_max_size() const _NOEXCEPT {
5630b57cec5SDimitry Andric        return __node_alloc_traits::max_size(__node_alloc());
5640b57cec5SDimitry Andric    }
565*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5660b57cec5SDimitry Andric    static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
5670b57cec5SDimitry Andric
568*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5690b57cec5SDimitry Andric    __list_imp()
5700b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
571*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5720b57cec5SDimitry Andric    __list_imp(const allocator_type& __a);
573*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5740b57cec5SDimitry Andric    __list_imp(const __node_allocator& __a);
5750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
57606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
5770b57cec5SDimitry Andric#endif
57806c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI ~__list_imp();
57906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
580*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5810b57cec5SDimitry Andric    bool empty() const _NOEXCEPT {return __sz() == 0;}
5820b57cec5SDimitry Andric
583*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5840b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
5850b57cec5SDimitry Andric    {
58606c3fb27SDimitry Andric        return iterator(__end_.__next_);
5870b57cec5SDimitry Andric    }
588*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5890b57cec5SDimitry Andric    const_iterator begin() const  _NOEXCEPT
5900b57cec5SDimitry Andric    {
59106c3fb27SDimitry Andric        return const_iterator(__end_.__next_);
5920b57cec5SDimitry Andric    }
593*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5940b57cec5SDimitry Andric    iterator end() _NOEXCEPT
5950b57cec5SDimitry Andric    {
59606c3fb27SDimitry Andric        return iterator(__end_as_link());
5970b57cec5SDimitry Andric    }
598*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
5990b57cec5SDimitry Andric    const_iterator end() const _NOEXCEPT
6000b57cec5SDimitry Andric    {
60106c3fb27SDimitry Andric        return const_iterator(__end_as_link());
6020b57cec5SDimitry Andric    }
6030b57cec5SDimitry Andric
60406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
6050b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
6060b57cec5SDimitry Andric        _NOEXCEPT;
6070b57cec5SDimitry Andric#else
6080b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
6090b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
6100b57cec5SDimitry Andric#endif
6110b57cec5SDimitry Andric
612*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6130b57cec5SDimitry Andric    void __copy_assign_alloc(const __list_imp& __c)
6140b57cec5SDimitry Andric        {__copy_assign_alloc(__c, integral_constant<bool,
6150b57cec5SDimitry Andric                      __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
6160b57cec5SDimitry Andric
617*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6180b57cec5SDimitry Andric    void __move_assign_alloc(__list_imp& __c)
6190b57cec5SDimitry Andric        _NOEXCEPT_(
6200b57cec5SDimitry Andric            !__node_alloc_traits::propagate_on_container_move_assignment::value ||
6210b57cec5SDimitry Andric            is_nothrow_move_assignable<__node_allocator>::value)
6220b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
6230b57cec5SDimitry Andric                      __node_alloc_traits::propagate_on_container_move_assignment::value>());}
6240b57cec5SDimitry Andric
625*5f757f3fSDimitry Andric    template <class ..._Args>
626*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__link_pointer __prev, __link_pointer __next, _Args&& ...__args) {
627*5f757f3fSDimitry Andric        __node_allocator& __alloc = __node_alloc();
628*5f757f3fSDimitry Andric        __allocation_guard<__node_allocator> __guard(__alloc, 1);
629*5f757f3fSDimitry Andric        // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
630*5f757f3fSDimitry Andric        // held inside the node, since we need to use the allocator's construct() method for that.
631*5f757f3fSDimitry Andric        //
632*5f757f3fSDimitry Andric        // We don't use the allocator's construct() method to construct the node itself since the
633*5f757f3fSDimitry Andric        // Cpp17FooInsertable named requirements don't require the allocator's construct() method
634*5f757f3fSDimitry Andric        // to work on anything other than the value_type.
635*5f757f3fSDimitry Andric        std::__construct_at(std::addressof(*__guard.__get()), __prev, __next);
636*5f757f3fSDimitry Andric
637*5f757f3fSDimitry Andric        // Now construct the value_type using the allocator's construct() method.
638*5f757f3fSDimitry Andric        __node_alloc_traits::construct(__alloc, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
639*5f757f3fSDimitry Andric        return __guard.__release_ptr();
640*5f757f3fSDimitry Andric    }
641*5f757f3fSDimitry Andric
642*5f757f3fSDimitry Andric    template <class ..._Args>
643*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
644*5f757f3fSDimitry Andric        // For the same reason as above, we use the allocator's destroy() method for the value_type,
645*5f757f3fSDimitry Andric        // but not for the node itself.
646*5f757f3fSDimitry Andric        __node_allocator& __alloc = __node_alloc();
647*5f757f3fSDimitry Andric        __node_alloc_traits::destroy(__alloc, std::addressof(__node->__get_value()));
648*5f757f3fSDimitry Andric        std::__destroy_at(std::addressof(*__node));
649*5f757f3fSDimitry Andric        __node_alloc_traits::deallocate(__alloc, __node, 1);
650*5f757f3fSDimitry Andric    }
651*5f757f3fSDimitry Andric
6520b57cec5SDimitry Andricprivate:
653*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6540b57cec5SDimitry Andric    void __copy_assign_alloc(const __list_imp& __c, true_type)
6550b57cec5SDimitry Andric        {
6560b57cec5SDimitry Andric            if (__node_alloc() != __c.__node_alloc())
6570b57cec5SDimitry Andric                clear();
6580b57cec5SDimitry Andric            __node_alloc() = __c.__node_alloc();
6590b57cec5SDimitry Andric        }
6600b57cec5SDimitry Andric
661*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6620b57cec5SDimitry Andric    void __copy_assign_alloc(const __list_imp&, false_type)
6630b57cec5SDimitry Andric        {}
6640b57cec5SDimitry Andric
665*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6660b57cec5SDimitry Andric    void __move_assign_alloc(__list_imp& __c, true_type)
6670b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
6680b57cec5SDimitry Andric        {
669*5f757f3fSDimitry Andric            __node_alloc() = std::move(__c.__node_alloc());
6700b57cec5SDimitry Andric        }
6710b57cec5SDimitry Andric
672*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
6730b57cec5SDimitry Andric    void __move_assign_alloc(__list_imp&, false_type)
6740b57cec5SDimitry Andric        _NOEXCEPT
6750b57cec5SDimitry Andric        {}
6760b57cec5SDimitry Andric};
6770b57cec5SDimitry Andric
6780b57cec5SDimitry Andric// Unlink nodes [__f, __l]
6790b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
6800b57cec5SDimitry Andricinline
6810b57cec5SDimitry Andricvoid
6820b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
6830b57cec5SDimitry Andric    _NOEXCEPT
6840b57cec5SDimitry Andric{
6850b57cec5SDimitry Andric    __f->__prev_->__next_ = __l->__next_;
6860b57cec5SDimitry Andric    __l->__next_->__prev_ = __f->__prev_;
6870b57cec5SDimitry Andric}
6880b57cec5SDimitry Andric
6890b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
6900b57cec5SDimitry Andricinline
6910b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__list_imp()
6920b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
693480093f4SDimitry Andric    : __size_alloc_(0, __default_init_tag())
6940b57cec5SDimitry Andric{
6950b57cec5SDimitry Andric}
6960b57cec5SDimitry Andric
6970b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
6980b57cec5SDimitry Andricinline
6990b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
7000b57cec5SDimitry Andric    : __size_alloc_(0, __node_allocator(__a))
7010b57cec5SDimitry Andric{
7020b57cec5SDimitry Andric}
7030b57cec5SDimitry Andric
7040b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
7050b57cec5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a)
7060b57cec5SDimitry Andric    : __size_alloc_(0, __a) {}
7070b57cec5SDimitry Andric
7080b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7090b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
7100b57cec5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
711*5f757f3fSDimitry Andric    : __size_alloc_(0, std::move(__a)) {}
7120b57cec5SDimitry Andric#endif
7130b57cec5SDimitry Andric
7140b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
7150b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::~__list_imp() {
7160b57cec5SDimitry Andric  clear();
7170b57cec5SDimitry Andric}
7180b57cec5SDimitry Andric
7190b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
7200b57cec5SDimitry Andricvoid
7210b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
7220b57cec5SDimitry Andric{
7230b57cec5SDimitry Andric    if (!empty())
7240b57cec5SDimitry Andric    {
7250b57cec5SDimitry Andric        __link_pointer __f = __end_.__next_;
7260b57cec5SDimitry Andric        __link_pointer __l = __end_as_link();
7270b57cec5SDimitry Andric        __unlink_nodes(__f, __l->__prev_);
7280b57cec5SDimitry Andric        __sz() = 0;
7290b57cec5SDimitry Andric        while (__f != __l)
7300b57cec5SDimitry Andric        {
7310b57cec5SDimitry Andric            __node_pointer __np = __f->__as_node();
7320b57cec5SDimitry Andric            __f = __f->__next_;
733*5f757f3fSDimitry Andric            __delete_node(__np);
7340b57cec5SDimitry Andric        }
7350b57cec5SDimitry Andric    }
7360b57cec5SDimitry Andric}
7370b57cec5SDimitry Andric
7380b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
7390b57cec5SDimitry Andricvoid
7400b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
7410b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
7420b57cec5SDimitry Andric        _NOEXCEPT
7430b57cec5SDimitry Andric#else
7440b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
7450b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value)
7460b57cec5SDimitry Andric#endif
7470b57cec5SDimitry Andric{
74806c3fb27SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__alloc_traits::propagate_on_container_swap::value ||
7490b57cec5SDimitry Andric                                        this->__node_alloc() == __c.__node_alloc(),
7500b57cec5SDimitry Andric                                        "list::swap: Either propagate_on_container_swap must be true"
7510b57cec5SDimitry Andric                                        " or the allocators must compare equal");
752*5f757f3fSDimitry Andric    using std::swap;
753*5f757f3fSDimitry Andric    std::__swap_allocator(__node_alloc(), __c.__node_alloc());
7540b57cec5SDimitry Andric    swap(__sz(), __c.__sz());
7550b57cec5SDimitry Andric    swap(__end_, __c.__end_);
7560b57cec5SDimitry Andric    if (__sz() == 0)
7570b57cec5SDimitry Andric        __end_.__next_ = __end_.__prev_ = __end_as_link();
7580b57cec5SDimitry Andric    else
7590b57cec5SDimitry Andric        __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
7600b57cec5SDimitry Andric    if (__c.__sz() == 0)
7610b57cec5SDimitry Andric        __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
7620b57cec5SDimitry Andric    else
7630b57cec5SDimitry Andric        __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
7640b57cec5SDimitry Andric}
7650b57cec5SDimitry Andric
7660b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/>
7670b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS list
7680b57cec5SDimitry Andric    : private __list_imp<_Tp, _Alloc>
7690b57cec5SDimitry Andric{
7700b57cec5SDimitry Andric    typedef __list_imp<_Tp, _Alloc> base;
771*5f757f3fSDimitry Andric    typedef typename base::__node_type         __node_type;
7720b57cec5SDimitry Andric    typedef typename base::__node_allocator    __node_allocator;
7730b57cec5SDimitry Andric    typedef typename base::__node_pointer      __node_pointer;
7740b57cec5SDimitry Andric    typedef typename base::__node_alloc_traits __node_alloc_traits;
7750b57cec5SDimitry Andric    typedef typename base::__node_base         __node_base;
7760b57cec5SDimitry Andric    typedef typename base::__node_base_pointer __node_base_pointer;
7770b57cec5SDimitry Andric    typedef typename base::__link_pointer __link_pointer;
7780b57cec5SDimitry Andric
7790b57cec5SDimitry Andricpublic:
7800b57cec5SDimitry Andric    typedef _Tp                                            value_type;
7810b57cec5SDimitry Andric    typedef _Alloc                                         allocator_type;
7820b57cec5SDimitry Andric    static_assert((is_same<value_type, typename allocator_type::value_type>::value),
78306c3fb27SDimitry Andric                  "Allocator::value_type must be same type as value_type");
7840b57cec5SDimitry Andric    typedef value_type&                                    reference;
7850b57cec5SDimitry Andric    typedef const value_type&                              const_reference;
7860b57cec5SDimitry Andric    typedef typename base::pointer                         pointer;
7870b57cec5SDimitry Andric    typedef typename base::const_pointer                   const_pointer;
7884824e7fdSDimitry Andric    typedef typename base::size_type                       size_type;
7890b57cec5SDimitry Andric    typedef typename base::difference_type                 difference_type;
7900b57cec5SDimitry Andric    typedef typename base::iterator                        iterator;
7910b57cec5SDimitry Andric    typedef typename base::const_iterator                  const_iterator;
792*5f757f3fSDimitry Andric    typedef std::reverse_iterator<iterator>              reverse_iterator;
793*5f757f3fSDimitry Andric    typedef std::reverse_iterator<const_iterator>        const_reverse_iterator;
79406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
7950b57cec5SDimitry Andric    typedef size_type                                      __remove_return_type;
7960b57cec5SDimitry Andric#else
7970b57cec5SDimitry Andric    typedef void                                           __remove_return_type;
7980b57cec5SDimitry Andric#endif
7990b57cec5SDimitry Andric
800bdd1243dSDimitry Andric    static_assert(is_same<allocator_type, __rebind_alloc<allocator_traits<allocator_type>, value_type> >::value,
801bdd1243dSDimitry Andric                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
802bdd1243dSDimitry Andric                  "original allocator");
803bdd1243dSDimitry Andric
804*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8050b57cec5SDimitry Andric    list()
8060b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
8070b57cec5SDimitry Andric    {
8080b57cec5SDimitry Andric    }
809*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8100b57cec5SDimitry Andric    explicit list(const allocator_type& __a) : base(__a)
8110b57cec5SDimitry Andric    {
8120b57cec5SDimitry Andric    }
81306c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
81406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
81506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
8160b57cec5SDimitry Andric#endif
81706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
8184824e7fdSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Alloc>::value> >
81906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : base(__a)
8204824e7fdSDimitry Andric    {
8214824e7fdSDimitry Andric        for (; __n > 0; --__n)
8224824e7fdSDimitry Andric            push_back(__x);
8234824e7fdSDimitry Andric    }
8244824e7fdSDimitry Andric
8250b57cec5SDimitry Andric    template <class _InpIter>
82606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l,
82706c3fb27SDimitry Andric             __enable_if_t<__has_input_iterator_category<_InpIter>::value>* = 0);
8280b57cec5SDimitry Andric    template <class _InpIter>
82906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a,
83006c3fb27SDimitry Andric             __enable_if_t<__has_input_iterator_category<_InpIter>::value>* = 0);
8310b57cec5SDimitry Andric
83206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
83306c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
83406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range,
83506c3fb27SDimitry Andric        const allocator_type& __a = allocator_type()) : base(__a) {
83606c3fb27SDimitry Andric      prepend_range(std::forward<_Range>(__range));
83706c3fb27SDimitry Andric    }
83806c3fb27SDimitry Andric#endif
83906c3fb27SDimitry Andric
84006c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(const list& __c);
84106c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(const list& __c, const __type_identity_t<allocator_type>& __a);
842*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8430b57cec5SDimitry Andric    list& operator=(const list& __c);
8440b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
84506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
84606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il, const allocator_type& __a);
8470b57cec5SDimitry Andric
848*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8490b57cec5SDimitry Andric    list(list&& __c)
8500b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
851*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
85281ad6265SDimitry Andric    list(list&& __c, const __type_identity_t<allocator_type>& __a);
853*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8540b57cec5SDimitry Andric    list& operator=(list&& __c)
8550b57cec5SDimitry Andric        _NOEXCEPT_(
8560b57cec5SDimitry Andric            __node_alloc_traits::propagate_on_container_move_assignment::value &&
8570b57cec5SDimitry Andric            is_nothrow_move_assignable<__node_allocator>::value);
8580b57cec5SDimitry Andric
859*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8600b57cec5SDimitry Andric    list& operator=(initializer_list<value_type> __il)
8610b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
8620b57cec5SDimitry Andric
863*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8640b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
8650b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
8660b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8670b57cec5SDimitry Andric
8680b57cec5SDimitry Andric    template <class _InpIter>
86906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l,
87006c3fb27SDimitry Andric                    __enable_if_t<__has_input_iterator_category<_InpIter>::value>* = 0);
87106c3fb27SDimitry Andric
87206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
87306c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
87406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
87506c3fb27SDimitry Andric    void assign_range(_Range&& __range) {
87606c3fb27SDimitry Andric      __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
87706c3fb27SDimitry Andric    }
87806c3fb27SDimitry Andric#endif
87906c3fb27SDimitry Andric
88006c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
8810b57cec5SDimitry Andric
882*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8830b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT;
8840b57cec5SDimitry Andric
885*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8860b57cec5SDimitry Andric    size_type size() const _NOEXCEPT     {return base::__sz();}
887*5f757f3fSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI
8880b57cec5SDimitry Andric    bool empty() const _NOEXCEPT         {return base::empty();}
889*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8900b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT
8910b57cec5SDimitry Andric        {
892*5f757f3fSDimitry Andric            return std::min<size_type>(
8930b57cec5SDimitry Andric                base::__node_alloc_max_size(),
8940b57cec5SDimitry Andric                numeric_limits<difference_type >::max());
8950b57cec5SDimitry Andric        }
8960b57cec5SDimitry Andric
897*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
8980b57cec5SDimitry Andric          iterator begin() _NOEXCEPT        {return base::begin();}
899*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9000b57cec5SDimitry Andric    const_iterator begin()  const _NOEXCEPT {return base::begin();}
901*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9020b57cec5SDimitry Andric          iterator end() _NOEXCEPT          {return base::end();}
903*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9040b57cec5SDimitry Andric    const_iterator end()    const _NOEXCEPT {return base::end();}
905*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9060b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {return base::begin();}
907*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9080b57cec5SDimitry Andric    const_iterator cend()   const _NOEXCEPT {return base::end();}
9090b57cec5SDimitry Andric
910*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9110b57cec5SDimitry Andric          reverse_iterator rbegin() _NOEXCEPT
9120b57cec5SDimitry Andric            {return       reverse_iterator(end());}
913*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9140b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const _NOEXCEPT
9150b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
916*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9170b57cec5SDimitry Andric          reverse_iterator rend() _NOEXCEPT
9180b57cec5SDimitry Andric            {return       reverse_iterator(begin());}
919*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9200b57cec5SDimitry Andric    const_reverse_iterator rend()    const _NOEXCEPT
9210b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
922*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9230b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
9240b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
925*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9260b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
9270b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
9280b57cec5SDimitry Andric
929*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9300b57cec5SDimitry Andric    reference front()
9310b57cec5SDimitry Andric    {
93206c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
933*5f757f3fSDimitry Andric        return base::__end_.__next_->__as_node()->__get_value();
9340b57cec5SDimitry Andric    }
935*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9360b57cec5SDimitry Andric    const_reference front() const
9370b57cec5SDimitry Andric    {
93806c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
939*5f757f3fSDimitry Andric        return base::__end_.__next_->__as_node()->__get_value();
9400b57cec5SDimitry Andric    }
941*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9420b57cec5SDimitry Andric    reference back()
9430b57cec5SDimitry Andric    {
94406c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
945*5f757f3fSDimitry Andric        return base::__end_.__prev_->__as_node()->__get_value();
9460b57cec5SDimitry Andric    }
947*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9480b57cec5SDimitry Andric    const_reference back() const
9490b57cec5SDimitry Andric    {
95006c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
951*5f757f3fSDimitry Andric        return base::__end_.__prev_->__as_node()->__get_value();
9520b57cec5SDimitry Andric    }
9530b57cec5SDimitry Andric
9540b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
95506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
95606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
95706c3fb27SDimitry Andric
95806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
95906c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
96006c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
96106c3fb27SDimitry Andric    void prepend_range(_Range&& __range) {
96206c3fb27SDimitry Andric      insert_range(begin(), std::forward<_Range>(__range));
96306c3fb27SDimitry Andric    }
96406c3fb27SDimitry Andric
96506c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
96606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
96706c3fb27SDimitry Andric    void append_range(_Range&& __range) {
96806c3fb27SDimitry Andric      insert_range(end(), std::forward<_Range>(__range));
96906c3fb27SDimitry Andric    }
97006c3fb27SDimitry Andric#endif
9710b57cec5SDimitry Andric
9720b57cec5SDimitry Andric    template <class... _Args>
97306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
97406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
9750b57cec5SDimitry Andric#else
97606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void      emplace_front(_Args&&... __args);
9770b57cec5SDimitry Andric#endif
9780b57cec5SDimitry Andric    template <class... _Args>
97906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
98006c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
9810b57cec5SDimitry Andric#else
98206c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void       emplace_back(_Args&&... __args);
9830b57cec5SDimitry Andric#endif
9840b57cec5SDimitry Andric    template <class... _Args>
98506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
9860b57cec5SDimitry Andric
98706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x);
9880b57cec5SDimitry Andric
989*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9900b57cec5SDimitry Andric    iterator insert(const_iterator __p, initializer_list<value_type> __il)
9910b57cec5SDimitry Andric        {return insert(__p, __il.begin(), __il.end());}
9920b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
9930b57cec5SDimitry Andric
99406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
99506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
9960b57cec5SDimitry Andric
9970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
9980b57cec5SDimitry Andric    template <class _Arg>
999*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
1000*5f757f3fSDimitry Andric    void __emplace_back(_Arg&& __arg) { emplace_back(std::forward<_Arg>(__arg)); }
10010b57cec5SDimitry Andric#else
1002*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10030b57cec5SDimitry Andric    void __emplace_back(value_type const& __arg) { push_back(__arg); }
10040b57cec5SDimitry Andric#endif
10050b57cec5SDimitry Andric
100606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
100706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __x);
10080b57cec5SDimitry Andric    template <class _InpIter>
100906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
101006c3fb27SDimitry Andric                        __enable_if_t<__has_input_iterator_category<_InpIter>::value>* = 0);
101106c3fb27SDimitry Andric
101206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
101306c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
101406c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
101506c3fb27SDimitry Andric    iterator insert_range(const_iterator __position, _Range&& __range) {
101606c3fb27SDimitry Andric      return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
101706c3fb27SDimitry Andric    }
101806c3fb27SDimitry Andric#endif
10190b57cec5SDimitry Andric
1020*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10210b57cec5SDimitry Andric    void swap(list& __c)
10220b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
10230b57cec5SDimitry Andric        _NOEXCEPT
10240b57cec5SDimitry Andric#else
10250b57cec5SDimitry Andric        _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
10260b57cec5SDimitry Andric                   __is_nothrow_swappable<__node_allocator>::value)
10270b57cec5SDimitry Andric#endif
10280b57cec5SDimitry Andric        {base::swap(__c);}
1029*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10300b57cec5SDimitry Andric    void clear() _NOEXCEPT {base::clear();}
10310b57cec5SDimitry Andric
103206c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void pop_front();
103306c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void pop_back();
10340b57cec5SDimitry Andric
103506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
103606c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
10370b57cec5SDimitry Andric
103806c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
103906c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
10400b57cec5SDimitry Andric
104106c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
10420b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1043*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10440b57cec5SDimitry Andric    void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1045*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10460b57cec5SDimitry Andric    void splice(const_iterator __p, list&& __c, const_iterator __i)
10470b57cec5SDimitry Andric        {splice(__p, __c, __i);}
1048*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10490b57cec5SDimitry Andric    void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
10500b57cec5SDimitry Andric        {splice(__p, __c, __f, __l);}
10510b57cec5SDimitry Andric#endif
105206c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
105306c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
10540b57cec5SDimitry Andric
105506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __x);
105606c3fb27SDimitry Andric    template <class _Pred>
105706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Pred __pred);
1058*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
1059bdd1243dSDimitry Andric    __remove_return_type unique() { return unique(__equal_to()); }
10600b57cec5SDimitry Andric    template <class _BinaryPred>
106106c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
1062*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10630b57cec5SDimitry Andric    void merge(list& __c);
10640b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1065*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10660b57cec5SDimitry Andric    void merge(list&& __c) {merge(__c);}
10670b57cec5SDimitry Andric
10680b57cec5SDimitry Andric    template <class _Comp>
1069*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10700b57cec5SDimitry Andric        void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
10710b57cec5SDimitry Andric#endif
10720b57cec5SDimitry Andric    template <class _Comp>
107306c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
10740b57cec5SDimitry Andric
1075*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10760b57cec5SDimitry Andric    void sort();
10770b57cec5SDimitry Andric    template <class _Comp>
1078*5f757f3fSDimitry Andric        _LIBCPP_HIDE_FROM_ABI
10790b57cec5SDimitry Andric        void sort(_Comp __comp);
10800b57cec5SDimitry Andric
108106c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
10820b57cec5SDimitry Andric
108306c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andricprivate:
108606c3fb27SDimitry Andric    template <class _Iterator, class _Sentinel>
108706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
108806c3fb27SDimitry Andric    void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
108906c3fb27SDimitry Andric
109006c3fb27SDimitry Andric    template <class _Iterator, class _Sentinel>
109106c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
109206c3fb27SDimitry Andric    iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
109306c3fb27SDimitry Andric
1094*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10950b57cec5SDimitry Andric    static void __link_nodes  (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1096*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10970b57cec5SDimitry Andric    void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1098*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
10990b57cec5SDimitry Andric    void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
110006c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
110106c3fb27SDimitry Andric    // TODO: Make this _LIBCPP_HIDE_FROM_ABI
11020b57cec5SDimitry Andric    template <class _Comp>
110306c3fb27SDimitry Andric    _LIBCPP_HIDDEN static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
11040b57cec5SDimitry Andric
110506c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, true_type)
11060b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
110706c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
11080b57cec5SDimitry Andric};
11090b57cec5SDimitry Andric
1110349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
11110b57cec5SDimitry Andrictemplate<class _InputIterator,
1112fe6060f1SDimitry Andric         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
111306c3fb27SDimitry Andric         class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1114349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
11150b57cec5SDimitry Andric         >
11160b57cec5SDimitry Andriclist(_InputIterator, _InputIterator)
1117fe6060f1SDimitry Andric  -> list<__iter_value_type<_InputIterator>, _Alloc>;
11180b57cec5SDimitry Andric
11190b57cec5SDimitry Andrictemplate<class _InputIterator,
11200b57cec5SDimitry Andric         class _Alloc,
112106c3fb27SDimitry Andric         class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1122349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
11230b57cec5SDimitry Andric         >
11240b57cec5SDimitry Andriclist(_InputIterator, _InputIterator, _Alloc)
1125fe6060f1SDimitry Andric  -> list<__iter_value_type<_InputIterator>, _Alloc>;
11260b57cec5SDimitry Andric#endif
11270b57cec5SDimitry Andric
112806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
112906c3fb27SDimitry Andrictemplate <ranges::input_range _Range,
113006c3fb27SDimitry Andric          class _Alloc = allocator<ranges::range_value_t<_Range>>,
113106c3fb27SDimitry Andric          class = enable_if_t<__is_allocator<_Alloc>::value>
113206c3fb27SDimitry Andric          >
113306c3fb27SDimitry Andriclist(from_range_t, _Range&&, _Alloc = _Alloc())
113406c3fb27SDimitry Andric  -> list<ranges::range_value_t<_Range>, _Alloc>;
113506c3fb27SDimitry Andric#endif
113606c3fb27SDimitry Andric
11370b57cec5SDimitry Andric// Link in nodes [__f, __l] just prior to __p
11380b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11390b57cec5SDimitry Andricinline
11400b57cec5SDimitry Andricvoid
11410b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
11420b57cec5SDimitry Andric{
11430b57cec5SDimitry Andric    __p->__prev_->__next_ = __f;
11440b57cec5SDimitry Andric    __f->__prev_ = __p->__prev_;
11450b57cec5SDimitry Andric    __p->__prev_ = __l;
11460b57cec5SDimitry Andric    __l->__next_ = __p;
11470b57cec5SDimitry Andric}
11480b57cec5SDimitry Andric
11490b57cec5SDimitry Andric// Link in nodes [__f, __l] at the front of the list
11500b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11510b57cec5SDimitry Andricinline
11520b57cec5SDimitry Andricvoid
11530b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
11540b57cec5SDimitry Andric{
11550b57cec5SDimitry Andric    __f->__prev_ = base::__end_as_link();
11560b57cec5SDimitry Andric    __l->__next_ = base::__end_.__next_;
11570b57cec5SDimitry Andric    __l->__next_->__prev_ = __l;
11580b57cec5SDimitry Andric    base::__end_.__next_ = __f;
11590b57cec5SDimitry Andric}
11600b57cec5SDimitry Andric
11610b57cec5SDimitry Andric// Link in nodes [__f, __l] at the back of the list
11620b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11630b57cec5SDimitry Andricinline
11640b57cec5SDimitry Andricvoid
11650b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
11660b57cec5SDimitry Andric{
11670b57cec5SDimitry Andric    __l->__next_ = base::__end_as_link();
11680b57cec5SDimitry Andric    __f->__prev_ = base::__end_.__prev_;
11690b57cec5SDimitry Andric    __f->__prev_->__next_ = __f;
11700b57cec5SDimitry Andric    base::__end_.__prev_ = __l;
11710b57cec5SDimitry Andric}
11720b57cec5SDimitry Andric
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11750b57cec5SDimitry Andricinline
11760b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
11770b57cec5SDimitry Andriclist<_Tp, _Alloc>::__iterator(size_type __n)
11780b57cec5SDimitry Andric{
1179*5f757f3fSDimitry Andric    return __n <= base::__sz() / 2 ? std::next(begin(), __n)
1180*5f757f3fSDimitry Andric                                   : std::prev(end(), base::__sz() - __n);
11810b57cec5SDimitry Andric}
11820b57cec5SDimitry Andric
11830b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11840b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n)
11850b57cec5SDimitry Andric{
11860b57cec5SDimitry Andric    for (; __n > 0; --__n)
11870b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
11880b57cec5SDimitry Andric        emplace_back();
11890b57cec5SDimitry Andric#else
11900b57cec5SDimitry Andric        push_back(value_type());
11910b57cec5SDimitry Andric#endif
11920b57cec5SDimitry Andric}
11930b57cec5SDimitry Andric
119406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
11950b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
11960b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
11970b57cec5SDimitry Andric{
11980b57cec5SDimitry Andric    for (; __n > 0; --__n)
11990b57cec5SDimitry Andric        emplace_back();
12000b57cec5SDimitry Andric}
12010b57cec5SDimitry Andric#endif
12020b57cec5SDimitry Andric
12030b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12040b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
12050b57cec5SDimitry Andric{
12060b57cec5SDimitry Andric    for (; __n > 0; --__n)
12070b57cec5SDimitry Andric        push_back(__x);
12080b57cec5SDimitry Andric}
12090b57cec5SDimitry Andric
12100b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12110b57cec5SDimitry Andrictemplate <class _InpIter>
12120b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
121306c3fb27SDimitry Andric                        __enable_if_t<__has_input_iterator_category<_InpIter>::value>*)
12140b57cec5SDimitry Andric{
12150b57cec5SDimitry Andric    for (; __f != __l; ++__f)
12160b57cec5SDimitry Andric        __emplace_back(*__f);
12170b57cec5SDimitry Andric}
12180b57cec5SDimitry Andric
12190b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12200b57cec5SDimitry Andrictemplate <class _InpIter>
12210b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
122206c3fb27SDimitry Andric                        __enable_if_t<__has_input_iterator_category<_InpIter>::value>*)
12230b57cec5SDimitry Andric    : base(__a)
12240b57cec5SDimitry Andric{
12250b57cec5SDimitry Andric    for (; __f != __l; ++__f)
12260b57cec5SDimitry Andric        __emplace_back(*__f);
12270b57cec5SDimitry Andric}
12280b57cec5SDimitry Andric
12290b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12300b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(const list& __c)
12310b57cec5SDimitry Andric    : base(__node_alloc_traits::select_on_container_copy_construction(
12320b57cec5SDimitry Andric          __c.__node_alloc())) {
12330b57cec5SDimitry Andric    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12340b57cec5SDimitry Andric        push_back(*__i);
12350b57cec5SDimitry Andric}
12360b57cec5SDimitry Andric
12370b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
123881ad6265SDimitry Andriclist<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a)
12390b57cec5SDimitry Andric    : base(__a)
12400b57cec5SDimitry Andric{
12410b57cec5SDimitry Andric    for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
12420b57cec5SDimitry Andric        push_back(*__i);
12430b57cec5SDimitry Andric}
12440b57cec5SDimitry Andric
12450b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12460b57cec5SDimitry Andric
12470b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12480b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
12490b57cec5SDimitry Andric    : base(__a)
12500b57cec5SDimitry Andric{
12510b57cec5SDimitry Andric    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
12520b57cec5SDimitry Andric            __e = __il.end(); __i != __e; ++__i)
12530b57cec5SDimitry Andric        push_back(*__i);
12540b57cec5SDimitry Andric}
12550b57cec5SDimitry Andric
12560b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12570b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(initializer_list<value_type> __il)
12580b57cec5SDimitry Andric{
12590b57cec5SDimitry Andric    for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
12600b57cec5SDimitry Andric            __e = __il.end(); __i != __e; ++__i)
12610b57cec5SDimitry Andric        push_back(*__i);
12620b57cec5SDimitry Andric}
12630b57cec5SDimitry Andric
12640b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12650b57cec5SDimitry Andricinline list<_Tp, _Alloc>::list(list&& __c)
12660b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1267*5f757f3fSDimitry Andric        : base(std::move(__c.__node_alloc())) {
12680b57cec5SDimitry Andric    splice(end(), __c);
12690b57cec5SDimitry Andric}
12700b57cec5SDimitry Andric
12710b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12720b57cec5SDimitry Andricinline
127381ad6265SDimitry Andriclist<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a)
12740b57cec5SDimitry Andric    : base(__a)
12750b57cec5SDimitry Andric{
12760b57cec5SDimitry Andric    if (__a == __c.get_allocator())
12770b57cec5SDimitry Andric        splice(end(), __c);
12780b57cec5SDimitry Andric    else
12790b57cec5SDimitry Andric    {
12800b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
12810b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
12820b57cec5SDimitry Andric    }
12830b57cec5SDimitry Andric}
12840b57cec5SDimitry Andric
12850b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12860b57cec5SDimitry Andricinline
12870b57cec5SDimitry Andriclist<_Tp, _Alloc>&
12880b57cec5SDimitry Andriclist<_Tp, _Alloc>::operator=(list&& __c)
12890b57cec5SDimitry Andric        _NOEXCEPT_(
12900b57cec5SDimitry Andric            __node_alloc_traits::propagate_on_container_move_assignment::value &&
12910b57cec5SDimitry Andric            is_nothrow_move_assignable<__node_allocator>::value)
12920b57cec5SDimitry Andric{
12930b57cec5SDimitry Andric    __move_assign(__c, integral_constant<bool,
12940b57cec5SDimitry Andric          __node_alloc_traits::propagate_on_container_move_assignment::value>());
12950b57cec5SDimitry Andric    return *this;
12960b57cec5SDimitry Andric}
12970b57cec5SDimitry Andric
12980b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
12990b57cec5SDimitry Andricvoid
13000b57cec5SDimitry Andriclist<_Tp, _Alloc>::__move_assign(list& __c, false_type)
13010b57cec5SDimitry Andric{
13020b57cec5SDimitry Andric    if (base::__node_alloc() != __c.__node_alloc())
13030b57cec5SDimitry Andric    {
13040b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
13050b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
13060b57cec5SDimitry Andric    }
13070b57cec5SDimitry Andric    else
13080b57cec5SDimitry Andric        __move_assign(__c, true_type());
13090b57cec5SDimitry Andric}
13100b57cec5SDimitry Andric
13110b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13120b57cec5SDimitry Andricvoid
13130b57cec5SDimitry Andriclist<_Tp, _Alloc>::__move_assign(list& __c, true_type)
13140b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
13150b57cec5SDimitry Andric{
13160b57cec5SDimitry Andric    clear();
13170b57cec5SDimitry Andric    base::__move_assign_alloc(__c);
13180b57cec5SDimitry Andric    splice(end(), __c);
13190b57cec5SDimitry Andric}
13200b57cec5SDimitry Andric
13210b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
13220b57cec5SDimitry Andric
13230b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13240b57cec5SDimitry Andricinline
13250b57cec5SDimitry Andriclist<_Tp, _Alloc>&
13260b57cec5SDimitry Andriclist<_Tp, _Alloc>::operator=(const list& __c)
13270b57cec5SDimitry Andric{
1328*5f757f3fSDimitry Andric    if (this != std::addressof(__c))
13290b57cec5SDimitry Andric    {
13300b57cec5SDimitry Andric        base::__copy_assign_alloc(__c);
13310b57cec5SDimitry Andric        assign(__c.begin(), __c.end());
13320b57cec5SDimitry Andric    }
13330b57cec5SDimitry Andric    return *this;
13340b57cec5SDimitry Andric}
13350b57cec5SDimitry Andric
13360b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13370b57cec5SDimitry Andrictemplate <class _InpIter>
13380b57cec5SDimitry Andricvoid
13390b57cec5SDimitry Andriclist<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
134006c3fb27SDimitry Andric                          __enable_if_t<__has_input_iterator_category<_InpIter>::value>*)
13410b57cec5SDimitry Andric{
134206c3fb27SDimitry Andric  __assign_with_sentinel(__f, __l);
134306c3fb27SDimitry Andric}
134406c3fb27SDimitry Andric
134506c3fb27SDimitry Andrictemplate <class _Tp, class _Alloc>
134606c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
134706c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI
134806c3fb27SDimitry Andricvoid list<_Tp, _Alloc>::__assign_with_sentinel(_Iterator __f, _Sentinel __l) {
13490b57cec5SDimitry Andric    iterator __i = begin();
13500b57cec5SDimitry Andric    iterator __e = end();
1351349cc55cSDimitry Andric    for (; __f != __l && __i != __e; ++__f, (void) ++__i)
13520b57cec5SDimitry Andric        *__i = *__f;
13530b57cec5SDimitry Andric    if (__i == __e)
135406c3fb27SDimitry Andric        __insert_with_sentinel(__e, std::move(__f), std::move(__l));
13550b57cec5SDimitry Andric    else
13560b57cec5SDimitry Andric        erase(__i, __e);
13570b57cec5SDimitry Andric}
13580b57cec5SDimitry Andric
13590b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13600b57cec5SDimitry Andricvoid
13610b57cec5SDimitry Andriclist<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
13620b57cec5SDimitry Andric{
13630b57cec5SDimitry Andric    iterator __i = begin();
13640b57cec5SDimitry Andric    iterator __e = end();
1365349cc55cSDimitry Andric    for (; __n > 0 && __i != __e; --__n, (void) ++__i)
13660b57cec5SDimitry Andric        *__i = __x;
13670b57cec5SDimitry Andric    if (__i == __e)
13680b57cec5SDimitry Andric        insert(__e, __n, __x);
13690b57cec5SDimitry Andric    else
13700b57cec5SDimitry Andric        erase(__i, __e);
13710b57cec5SDimitry Andric}
13720b57cec5SDimitry Andric
13730b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13740b57cec5SDimitry Andricinline
13750b57cec5SDimitry Andric_Alloc
13760b57cec5SDimitry Andriclist<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
13770b57cec5SDimitry Andric{
13780b57cec5SDimitry Andric    return allocator_type(base::__node_alloc());
13790b57cec5SDimitry Andric}
13800b57cec5SDimitry Andric
13810b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13820b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
13830b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
13840b57cec5SDimitry Andric{
1385*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, __x);
1386*5f757f3fSDimitry Andric    __link_nodes(__p.__ptr_, __node->__as_link(), __node->__as_link());
13870b57cec5SDimitry Andric    ++base::__sz();
1388*5f757f3fSDimitry Andric    return iterator(__node->__as_link());
13890b57cec5SDimitry Andric}
13900b57cec5SDimitry Andric
13910b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
13920b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
13930b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
13940b57cec5SDimitry Andric{
139506c3fb27SDimitry Andric    iterator __r(__p.__ptr_);
13960b57cec5SDimitry Andric    if (__n > 0)
13970b57cec5SDimitry Andric    {
13980b57cec5SDimitry Andric        size_type __ds = 0;
1399*5f757f3fSDimitry Andric        __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, __x);
14000b57cec5SDimitry Andric        ++__ds;
1401*5f757f3fSDimitry Andric        __r = iterator(__node->__as_link());
14020b57cec5SDimitry Andric        iterator __e = __r;
140306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
14040b57cec5SDimitry Andric        try
14050b57cec5SDimitry Andric        {
140606c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1407349cc55cSDimitry Andric            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
14080b57cec5SDimitry Andric            {
1409*5f757f3fSDimitry Andric                __e.__ptr_->__next_ = this->__create_node(/* prev = */__e.__ptr_, /* next = */nullptr, __x)->__as_link();
14100b57cec5SDimitry Andric            }
141106c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
14120b57cec5SDimitry Andric        }
14130b57cec5SDimitry Andric        catch (...)
14140b57cec5SDimitry Andric        {
14150b57cec5SDimitry Andric            while (true)
14160b57cec5SDimitry Andric            {
14170b57cec5SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
1418*5f757f3fSDimitry Andric                __node_pointer __current = __e.__ptr_->__as_node();
1419*5f757f3fSDimitry Andric                this->__delete_node(__current);
14200b57cec5SDimitry Andric                if (__prev == 0)
14210b57cec5SDimitry Andric                    break;
142206c3fb27SDimitry Andric                __e = iterator(__prev);
14230b57cec5SDimitry Andric            }
14240b57cec5SDimitry Andric            throw;
14250b57cec5SDimitry Andric        }
142606c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
14270b57cec5SDimitry Andric        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
14280b57cec5SDimitry Andric        base::__sz() += __ds;
14290b57cec5SDimitry Andric    }
14300b57cec5SDimitry Andric    return __r;
14310b57cec5SDimitry Andric}
14320b57cec5SDimitry Andric
14330b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
14340b57cec5SDimitry Andrictemplate <class _InpIter>
14350b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
14360b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
143706c3fb27SDimitry Andric                          __enable_if_t<__has_input_iterator_category<_InpIter>::value>*)
14380b57cec5SDimitry Andric{
143906c3fb27SDimitry Andric    return __insert_with_sentinel(__p, __f, __l);
144006c3fb27SDimitry Andric}
144106c3fb27SDimitry Andric
144206c3fb27SDimitry Andrictemplate <class _Tp, class _Alloc>
144306c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
144406c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI
144506c3fb27SDimitry Andrictypename list<_Tp, _Alloc>::iterator
144606c3fb27SDimitry Andriclist<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l) {
144706c3fb27SDimitry Andric    iterator __r(__p.__ptr_);
14480b57cec5SDimitry Andric    if (__f != __l)
14490b57cec5SDimitry Andric    {
14500b57cec5SDimitry Andric        size_type __ds = 0;
1451*5f757f3fSDimitry Andric        __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, *__f);
14520b57cec5SDimitry Andric        ++__ds;
1453*5f757f3fSDimitry Andric        __r = iterator(__node->__as_link());
14540b57cec5SDimitry Andric        iterator __e = __r;
145506c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
14560b57cec5SDimitry Andric        try
14570b57cec5SDimitry Andric        {
145806c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1459349cc55cSDimitry Andric            for (++__f; __f != __l; ++__f, (void) ++__e, ++__ds)
14600b57cec5SDimitry Andric            {
1461*5f757f3fSDimitry Andric                __e.__ptr_->__next_ = this->__create_node(/* prev = */__e.__ptr_, /* next = */nullptr, *__f)->__as_link();
14620b57cec5SDimitry Andric            }
146306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
14640b57cec5SDimitry Andric        }
14650b57cec5SDimitry Andric        catch (...)
14660b57cec5SDimitry Andric        {
14670b57cec5SDimitry Andric            while (true)
14680b57cec5SDimitry Andric            {
14690b57cec5SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
1470*5f757f3fSDimitry Andric                __node_pointer __current = __e.__ptr_->__as_node();
1471*5f757f3fSDimitry Andric                this->__delete_node(__current);
14720b57cec5SDimitry Andric                if (__prev == 0)
14730b57cec5SDimitry Andric                    break;
147406c3fb27SDimitry Andric                __e = iterator(__prev);
14750b57cec5SDimitry Andric            }
14760b57cec5SDimitry Andric            throw;
14770b57cec5SDimitry Andric        }
147806c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
14790b57cec5SDimitry Andric        __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
14800b57cec5SDimitry Andric        base::__sz() += __ds;
14810b57cec5SDimitry Andric    }
14820b57cec5SDimitry Andric    return __r;
14830b57cec5SDimitry Andric}
14840b57cec5SDimitry Andric
14850b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
14860b57cec5SDimitry Andricvoid
14870b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_front(const value_type& __x)
14880b57cec5SDimitry Andric{
1489*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, __x);
1490*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
14910b57cec5SDimitry Andric    __link_nodes_at_front(__nl, __nl);
14920b57cec5SDimitry Andric    ++base::__sz();
14930b57cec5SDimitry Andric}
14940b57cec5SDimitry Andric
14950b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
14960b57cec5SDimitry Andricvoid
14970b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_back(const value_type& __x)
14980b57cec5SDimitry Andric{
1499*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, __x);
1500*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
1501*5f757f3fSDimitry Andric    __link_nodes_at_back(__nl, __nl);
15020b57cec5SDimitry Andric    ++base::__sz();
15030b57cec5SDimitry Andric}
15040b57cec5SDimitry Andric
15050b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
15060b57cec5SDimitry Andric
15070b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15080b57cec5SDimitry Andricvoid
15090b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_front(value_type&& __x)
15100b57cec5SDimitry Andric{
1511*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::move(__x));
1512*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
1513*5f757f3fSDimitry Andric    __link_nodes_at_front(__nl, __nl);
15140b57cec5SDimitry Andric    ++base::__sz();
15150b57cec5SDimitry Andric}
15160b57cec5SDimitry Andric
15170b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15180b57cec5SDimitry Andricvoid
15190b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_back(value_type&& __x)
15200b57cec5SDimitry Andric{
1521*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::move(__x));
1522*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
1523*5f757f3fSDimitry Andric    __link_nodes_at_back(__nl, __nl);
15240b57cec5SDimitry Andric    ++base::__sz();
15250b57cec5SDimitry Andric}
15260b57cec5SDimitry Andric
15270b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15280b57cec5SDimitry Andrictemplate <class... _Args>
152906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
15300b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::reference
15310b57cec5SDimitry Andric#else
15320b57cec5SDimitry Andricvoid
15330b57cec5SDimitry Andric#endif
15340b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace_front(_Args&&... __args)
15350b57cec5SDimitry Andric{
1536*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::forward<_Args>(__args)...);
1537*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
1538*5f757f3fSDimitry Andric    __link_nodes_at_front(__nl, __nl);
15390b57cec5SDimitry Andric    ++base::__sz();
154006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
1541*5f757f3fSDimitry Andric    return __node->__get_value();
15420b57cec5SDimitry Andric#endif
15430b57cec5SDimitry Andric}
15440b57cec5SDimitry Andric
15450b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15460b57cec5SDimitry Andrictemplate <class... _Args>
154706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
15480b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::reference
15490b57cec5SDimitry Andric#else
15500b57cec5SDimitry Andricvoid
15510b57cec5SDimitry Andric#endif
15520b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace_back(_Args&&... __args)
15530b57cec5SDimitry Andric{
1554*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::forward<_Args>(__args)...);
1555*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
15560b57cec5SDimitry Andric    __link_nodes_at_back(__nl, __nl);
15570b57cec5SDimitry Andric    ++base::__sz();
155806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
1559*5f757f3fSDimitry Andric    return __node->__get_value();
15600b57cec5SDimitry Andric#endif
15610b57cec5SDimitry Andric}
15620b57cec5SDimitry Andric
15630b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15640b57cec5SDimitry Andrictemplate <class... _Args>
15650b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
15660b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
15670b57cec5SDimitry Andric{
1568*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::forward<_Args>(__args)...);
1569*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
15700b57cec5SDimitry Andric    __link_nodes(__p.__ptr_, __nl, __nl);
15710b57cec5SDimitry Andric    ++base::__sz();
157206c3fb27SDimitry Andric    return iterator(__nl);
15730b57cec5SDimitry Andric}
15740b57cec5SDimitry Andric
15750b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15760b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
15770b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
15780b57cec5SDimitry Andric{
1579*5f757f3fSDimitry Andric    __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, std::move(__x));
1580*5f757f3fSDimitry Andric    __link_pointer __nl = __node->__as_link();
15810b57cec5SDimitry Andric    __link_nodes(__p.__ptr_, __nl, __nl);
15820b57cec5SDimitry Andric    ++base::__sz();
158306c3fb27SDimitry Andric    return iterator(__nl);
15840b57cec5SDimitry Andric}
15850b57cec5SDimitry Andric
15860b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
15870b57cec5SDimitry Andric
15880b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
15890b57cec5SDimitry Andricvoid
15900b57cec5SDimitry Andriclist<_Tp, _Alloc>::pop_front()
15910b57cec5SDimitry Andric{
159206c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_front() called with empty list");
15930b57cec5SDimitry Andric    __link_pointer __n = base::__end_.__next_;
15940b57cec5SDimitry Andric    base::__unlink_nodes(__n, __n);
15950b57cec5SDimitry Andric    --base::__sz();
1596*5f757f3fSDimitry Andric    this->__delete_node(__n->__as_node());
15970b57cec5SDimitry Andric}
15980b57cec5SDimitry Andric
15990b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
16000b57cec5SDimitry Andricvoid
16010b57cec5SDimitry Andriclist<_Tp, _Alloc>::pop_back()
16020b57cec5SDimitry Andric{
160306c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_back() called on an empty list");
16040b57cec5SDimitry Andric    __link_pointer __n = base::__end_.__prev_;
16050b57cec5SDimitry Andric    base::__unlink_nodes(__n, __n);
16060b57cec5SDimitry Andric    --base::__sz();
1607*5f757f3fSDimitry Andric    this->__delete_node(__n->__as_node());
16080b57cec5SDimitry Andric}
16090b57cec5SDimitry Andric
16100b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
16110b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
16120b57cec5SDimitry Andriclist<_Tp, _Alloc>::erase(const_iterator __p)
16130b57cec5SDimitry Andric{
161406c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p != end(),
16150b57cec5SDimitry Andric        "list::erase(iterator) called with a non-dereferenceable iterator");
16160b57cec5SDimitry Andric    __link_pointer __n = __p.__ptr_;
16170b57cec5SDimitry Andric    __link_pointer __r = __n->__next_;
16180b57cec5SDimitry Andric    base::__unlink_nodes(__n, __n);
16190b57cec5SDimitry Andric    --base::__sz();
1620*5f757f3fSDimitry Andric    this->__delete_node(__n->__as_node());
162106c3fb27SDimitry Andric    return iterator(__r);
16220b57cec5SDimitry Andric}
16230b57cec5SDimitry Andric
16240b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
16250b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
16260b57cec5SDimitry Andriclist<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
16270b57cec5SDimitry Andric{
16280b57cec5SDimitry Andric    if (__f != __l)
16290b57cec5SDimitry Andric    {
16300b57cec5SDimitry Andric        base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
16310b57cec5SDimitry Andric        while (__f != __l)
16320b57cec5SDimitry Andric        {
16330b57cec5SDimitry Andric            __link_pointer __n = __f.__ptr_;
16340b57cec5SDimitry Andric            ++__f;
16350b57cec5SDimitry Andric            --base::__sz();
1636*5f757f3fSDimitry Andric            this->__delete_node(__n->__as_node());
16370b57cec5SDimitry Andric        }
16380b57cec5SDimitry Andric    }
163906c3fb27SDimitry Andric    return iterator(__l.__ptr_);
16400b57cec5SDimitry Andric}
16410b57cec5SDimitry Andric
16420b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
16430b57cec5SDimitry Andricvoid
16440b57cec5SDimitry Andriclist<_Tp, _Alloc>::resize(size_type __n)
16450b57cec5SDimitry Andric{
16460b57cec5SDimitry Andric    if (__n < base::__sz())
16470b57cec5SDimitry Andric        erase(__iterator(__n), end());
16480b57cec5SDimitry Andric    else if (__n > base::__sz())
16490b57cec5SDimitry Andric    {
16500b57cec5SDimitry Andric        __n -= base::__sz();
16510b57cec5SDimitry Andric        size_type __ds = 0;
1652*5f757f3fSDimitry Andric        __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr);
16530b57cec5SDimitry Andric        ++__ds;
1654*5f757f3fSDimitry Andric        iterator __r = iterator(__node->__as_link());
16550b57cec5SDimitry Andric        iterator __e = __r;
165606c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
16570b57cec5SDimitry Andric        try
16580b57cec5SDimitry Andric        {
165906c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1660349cc55cSDimitry Andric            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
16610b57cec5SDimitry Andric            {
1662*5f757f3fSDimitry Andric                __e.__ptr_->__next_ = this->__create_node(/* prev = */__e.__ptr_, /* next = */nullptr)->__as_link();
16630b57cec5SDimitry Andric            }
166406c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
16650b57cec5SDimitry Andric        }
16660b57cec5SDimitry Andric        catch (...)
16670b57cec5SDimitry Andric        {
16680b57cec5SDimitry Andric            while (true)
16690b57cec5SDimitry Andric            {
16700b57cec5SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
1671*5f757f3fSDimitry Andric                __node_pointer __current = __e.__ptr_->__as_node();
1672*5f757f3fSDimitry Andric                this->__delete_node(__current);
16730b57cec5SDimitry Andric                if (__prev == 0)
16740b57cec5SDimitry Andric                    break;
167506c3fb27SDimitry Andric                __e = iterator(__prev);
16760b57cec5SDimitry Andric            }
16770b57cec5SDimitry Andric            throw;
16780b57cec5SDimitry Andric        }
167906c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
16800b57cec5SDimitry Andric        __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
16810b57cec5SDimitry Andric        base::__sz() += __ds;
16820b57cec5SDimitry Andric    }
16830b57cec5SDimitry Andric}
16840b57cec5SDimitry Andric
16850b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
16860b57cec5SDimitry Andricvoid
16870b57cec5SDimitry Andriclist<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
16880b57cec5SDimitry Andric{
16890b57cec5SDimitry Andric    if (__n < base::__sz())
16900b57cec5SDimitry Andric        erase(__iterator(__n), end());
16910b57cec5SDimitry Andric    else if (__n > base::__sz())
16920b57cec5SDimitry Andric    {
16930b57cec5SDimitry Andric        __n -= base::__sz();
16940b57cec5SDimitry Andric        size_type __ds = 0;
1695*5f757f3fSDimitry Andric        __node_pointer __node = this->__create_node(/* prev = */nullptr, /* next = */nullptr, __x);
16960b57cec5SDimitry Andric        ++__ds;
1697*5f757f3fSDimitry Andric        __link_pointer __nl = __node->__as_link();
169806c3fb27SDimitry Andric        iterator __r = iterator(__nl);
16990b57cec5SDimitry Andric        iterator __e = __r;
170006c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
17010b57cec5SDimitry Andric        try
17020b57cec5SDimitry Andric        {
170306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1704349cc55cSDimitry Andric            for (--__n; __n != 0; --__n, (void) ++__e, ++__ds)
17050b57cec5SDimitry Andric            {
1706*5f757f3fSDimitry Andric                __e.__ptr_->__next_ = this->__create_node(/* prev = */__e.__ptr_, /* next = */nullptr, __x)->__as_link();
17070b57cec5SDimitry Andric            }
170806c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
17090b57cec5SDimitry Andric        }
17100b57cec5SDimitry Andric        catch (...)
17110b57cec5SDimitry Andric        {
17120b57cec5SDimitry Andric            while (true)
17130b57cec5SDimitry Andric            {
17140b57cec5SDimitry Andric                __link_pointer __prev = __e.__ptr_->__prev_;
1715*5f757f3fSDimitry Andric                __node_pointer __current = __e.__ptr_->__as_node();
1716*5f757f3fSDimitry Andric                this->__delete_node(__current);
17170b57cec5SDimitry Andric                if (__prev == 0)
17180b57cec5SDimitry Andric                    break;
171906c3fb27SDimitry Andric                __e = iterator(__prev);
17200b57cec5SDimitry Andric            }
17210b57cec5SDimitry Andric            throw;
17220b57cec5SDimitry Andric        }
172306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
17240b57cec5SDimitry Andric        __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
17250b57cec5SDimitry Andric        base::__sz() += __ds;
17260b57cec5SDimitry Andric    }
17270b57cec5SDimitry Andric}
17280b57cec5SDimitry Andric
17290b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
17300b57cec5SDimitry Andricvoid
17310b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
17320b57cec5SDimitry Andric{
1733*5f757f3fSDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(this != std::addressof(__c),
17340b57cec5SDimitry Andric                                     "list::splice(iterator, list) called with this == &list");
17350b57cec5SDimitry Andric    if (!__c.empty())
17360b57cec5SDimitry Andric    {
17370b57cec5SDimitry Andric        __link_pointer __f = __c.__end_.__next_;
17380b57cec5SDimitry Andric        __link_pointer __l = __c.__end_.__prev_;
17390b57cec5SDimitry Andric        base::__unlink_nodes(__f, __l);
17400b57cec5SDimitry Andric        __link_nodes(__p.__ptr_, __f, __l);
17410b57cec5SDimitry Andric        base::__sz() += __c.__sz();
17420b57cec5SDimitry Andric        __c.__sz() = 0;
17430b57cec5SDimitry Andric    }
17440b57cec5SDimitry Andric}
17450b57cec5SDimitry Andric
17460b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
17470b57cec5SDimitry Andricvoid
17480b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
17490b57cec5SDimitry Andric{
17500b57cec5SDimitry Andric    if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
17510b57cec5SDimitry Andric    {
17520b57cec5SDimitry Andric        __link_pointer __f = __i.__ptr_;
17530b57cec5SDimitry Andric        base::__unlink_nodes(__f, __f);
17540b57cec5SDimitry Andric        __link_nodes(__p.__ptr_, __f, __f);
17550b57cec5SDimitry Andric        --__c.__sz();
17560b57cec5SDimitry Andric        ++base::__sz();
17570b57cec5SDimitry Andric    }
17580b57cec5SDimitry Andric}
17590b57cec5SDimitry Andric
17600b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
17610b57cec5SDimitry Andricvoid
17620b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
17630b57cec5SDimitry Andric{
17640b57cec5SDimitry Andric    if (__f != __l)
17650b57cec5SDimitry Andric    {
17660b57cec5SDimitry Andric        __link_pointer __first = __f.__ptr_;
17670b57cec5SDimitry Andric        --__l;
17680b57cec5SDimitry Andric        __link_pointer __last = __l.__ptr_;
1769*5f757f3fSDimitry Andric        if (this != std::addressof(__c))
17700b57cec5SDimitry Andric        {
1771*5f757f3fSDimitry Andric            size_type __s = std::distance(__f, __l) + 1;
17720b57cec5SDimitry Andric            __c.__sz() -= __s;
17730b57cec5SDimitry Andric            base::__sz() += __s;
17740b57cec5SDimitry Andric        }
17750b57cec5SDimitry Andric        base::__unlink_nodes(__first, __last);
17760b57cec5SDimitry Andric        __link_nodes(__p.__ptr_, __first, __last);
17770b57cec5SDimitry Andric    }
17780b57cec5SDimitry Andric}
17790b57cec5SDimitry Andric
17800b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
17810b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type
17820b57cec5SDimitry Andriclist<_Tp, _Alloc>::remove(const value_type& __x)
17830b57cec5SDimitry Andric{
17840b57cec5SDimitry Andric    list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
17850b57cec5SDimitry Andric    for (const_iterator __i = begin(), __e = end(); __i != __e;)
17860b57cec5SDimitry Andric    {
17870b57cec5SDimitry Andric        if (*__i == __x)
17880b57cec5SDimitry Andric        {
1789*5f757f3fSDimitry Andric            const_iterator __j = std::next(__i);
17900b57cec5SDimitry Andric            for (; __j != __e && *__j == __x; ++__j)
17910b57cec5SDimitry Andric                ;
17920b57cec5SDimitry Andric            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
17930b57cec5SDimitry Andric            __i = __j;
17940b57cec5SDimitry Andric            if (__i != __e)
17950b57cec5SDimitry Andric                ++__i;
17960b57cec5SDimitry Andric        }
17970b57cec5SDimitry Andric        else
17980b57cec5SDimitry Andric            ++__i;
17990b57cec5SDimitry Andric    }
18000b57cec5SDimitry Andric
18010b57cec5SDimitry Andric    return (__remove_return_type) __deleted_nodes.size();
18020b57cec5SDimitry Andric}
18030b57cec5SDimitry Andric
18040b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
18050b57cec5SDimitry Andrictemplate <class _Pred>
18060b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type
18070b57cec5SDimitry Andriclist<_Tp, _Alloc>::remove_if(_Pred __pred)
18080b57cec5SDimitry Andric{
18090b57cec5SDimitry Andric    list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
18100b57cec5SDimitry Andric    for (iterator __i = begin(), __e = end(); __i != __e;)
18110b57cec5SDimitry Andric    {
18120b57cec5SDimitry Andric        if (__pred(*__i))
18130b57cec5SDimitry Andric        {
1814*5f757f3fSDimitry Andric            iterator __j = std::next(__i);
18150b57cec5SDimitry Andric            for (; __j != __e && __pred(*__j); ++__j)
18160b57cec5SDimitry Andric                ;
18170b57cec5SDimitry Andric            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
18180b57cec5SDimitry Andric            __i = __j;
18190b57cec5SDimitry Andric            if (__i != __e)
18200b57cec5SDimitry Andric                ++__i;
18210b57cec5SDimitry Andric        }
18220b57cec5SDimitry Andric        else
18230b57cec5SDimitry Andric            ++__i;
18240b57cec5SDimitry Andric    }
18250b57cec5SDimitry Andric
18260b57cec5SDimitry Andric    return (__remove_return_type) __deleted_nodes.size();
18270b57cec5SDimitry Andric}
18280b57cec5SDimitry Andric
18290b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
18300b57cec5SDimitry Andrictemplate <class _BinaryPred>
18310b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type
18320b57cec5SDimitry Andriclist<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
18330b57cec5SDimitry Andric{
18340b57cec5SDimitry Andric    list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
18350b57cec5SDimitry Andric    for (iterator __i = begin(), __e = end(); __i != __e;)
18360b57cec5SDimitry Andric    {
1837*5f757f3fSDimitry Andric        iterator __j = std::next(__i);
18380b57cec5SDimitry Andric        for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
18390b57cec5SDimitry Andric            ;
18400b57cec5SDimitry Andric        if (++__i != __j) {
18410b57cec5SDimitry Andric            __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
18420b57cec5SDimitry Andric            __i = __j;
18430b57cec5SDimitry Andric            }
18440b57cec5SDimitry Andric    }
18450b57cec5SDimitry Andric
18460b57cec5SDimitry Andric    return (__remove_return_type) __deleted_nodes.size();
18470b57cec5SDimitry Andric}
18480b57cec5SDimitry Andric
18490b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
18500b57cec5SDimitry Andricinline
18510b57cec5SDimitry Andricvoid
18520b57cec5SDimitry Andriclist<_Tp, _Alloc>::merge(list& __c)
18530b57cec5SDimitry Andric{
185406c3fb27SDimitry Andric    merge(__c, __less<>());
18550b57cec5SDimitry Andric}
18560b57cec5SDimitry Andric
18570b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
18580b57cec5SDimitry Andrictemplate <class _Comp>
18590b57cec5SDimitry Andricvoid
18600b57cec5SDimitry Andriclist<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
18610b57cec5SDimitry Andric{
1862*5f757f3fSDimitry Andric    if (this != std::addressof(__c))
18630b57cec5SDimitry Andric    {
18640b57cec5SDimitry Andric        iterator __f1 = begin();
18650b57cec5SDimitry Andric        iterator __e1 = end();
18660b57cec5SDimitry Andric        iterator __f2 = __c.begin();
18670b57cec5SDimitry Andric        iterator __e2 = __c.end();
18680b57cec5SDimitry Andric        while (__f1 != __e1 && __f2 != __e2)
18690b57cec5SDimitry Andric        {
18700b57cec5SDimitry Andric            if (__comp(*__f2, *__f1))
18710b57cec5SDimitry Andric            {
18720b57cec5SDimitry Andric                size_type __ds = 1;
1873*5f757f3fSDimitry Andric                iterator __m2 = std::next(__f2);
1874349cc55cSDimitry Andric                for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void) ++__ds)
18750b57cec5SDimitry Andric                    ;
18760b57cec5SDimitry Andric                base::__sz() += __ds;
18770b57cec5SDimitry Andric                __c.__sz() -= __ds;
18780b57cec5SDimitry Andric                __link_pointer __f = __f2.__ptr_;
18790b57cec5SDimitry Andric                __link_pointer __l = __m2.__ptr_->__prev_;
18800b57cec5SDimitry Andric                __f2 = __m2;
18810b57cec5SDimitry Andric                base::__unlink_nodes(__f, __l);
1882*5f757f3fSDimitry Andric                __m2 = std::next(__f1);
18830b57cec5SDimitry Andric                __link_nodes(__f1.__ptr_, __f, __l);
18840b57cec5SDimitry Andric                __f1 = __m2;
18850b57cec5SDimitry Andric            }
18860b57cec5SDimitry Andric            else
18870b57cec5SDimitry Andric                ++__f1;
18880b57cec5SDimitry Andric        }
18890b57cec5SDimitry Andric        splice(__e1, __c);
18900b57cec5SDimitry Andric    }
18910b57cec5SDimitry Andric}
18920b57cec5SDimitry Andric
18930b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
18940b57cec5SDimitry Andricinline
18950b57cec5SDimitry Andricvoid
18960b57cec5SDimitry Andriclist<_Tp, _Alloc>::sort()
18970b57cec5SDimitry Andric{
189806c3fb27SDimitry Andric    sort(__less<>());
18990b57cec5SDimitry Andric}
19000b57cec5SDimitry Andric
19010b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
19020b57cec5SDimitry Andrictemplate <class _Comp>
19030b57cec5SDimitry Andricinline
19040b57cec5SDimitry Andricvoid
19050b57cec5SDimitry Andriclist<_Tp, _Alloc>::sort(_Comp __comp)
19060b57cec5SDimitry Andric{
19070b57cec5SDimitry Andric    __sort(begin(), end(), base::__sz(), __comp);
19080b57cec5SDimitry Andric}
19090b57cec5SDimitry Andric
19100b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
19110b57cec5SDimitry Andrictemplate <class _Comp>
19120b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator
19130b57cec5SDimitry Andriclist<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
19140b57cec5SDimitry Andric{
19150b57cec5SDimitry Andric    switch (__n)
19160b57cec5SDimitry Andric    {
19170b57cec5SDimitry Andric    case 0:
19180b57cec5SDimitry Andric    case 1:
19190b57cec5SDimitry Andric        return __f1;
19200b57cec5SDimitry Andric    case 2:
19210b57cec5SDimitry Andric        if (__comp(*--__e2, *__f1))
19220b57cec5SDimitry Andric        {
19230b57cec5SDimitry Andric            __link_pointer __f = __e2.__ptr_;
19240b57cec5SDimitry Andric            base::__unlink_nodes(__f, __f);
19250b57cec5SDimitry Andric            __link_nodes(__f1.__ptr_, __f, __f);
19260b57cec5SDimitry Andric            return __e2;
19270b57cec5SDimitry Andric        }
19280b57cec5SDimitry Andric        return __f1;
19290b57cec5SDimitry Andric    }
19300b57cec5SDimitry Andric    size_type __n2 = __n / 2;
1931*5f757f3fSDimitry Andric    iterator __e1 = std::next(__f1, __n2);
19320b57cec5SDimitry Andric    iterator  __r = __f1 = __sort(__f1, __e1, __n2, __comp);
19330b57cec5SDimitry Andric    iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
19340b57cec5SDimitry Andric    if (__comp(*__f2, *__f1))
19350b57cec5SDimitry Andric    {
1936*5f757f3fSDimitry Andric        iterator __m2 = std::next(__f2);
19370b57cec5SDimitry Andric        for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
19380b57cec5SDimitry Andric            ;
19390b57cec5SDimitry Andric        __link_pointer __f = __f2.__ptr_;
19400b57cec5SDimitry Andric        __link_pointer __l = __m2.__ptr_->__prev_;
19410b57cec5SDimitry Andric        __r = __f2;
19420b57cec5SDimitry Andric        __e1 = __f2 = __m2;
19430b57cec5SDimitry Andric        base::__unlink_nodes(__f, __l);
1944*5f757f3fSDimitry Andric        __m2 = std::next(__f1);
19450b57cec5SDimitry Andric        __link_nodes(__f1.__ptr_, __f, __l);
19460b57cec5SDimitry Andric        __f1 = __m2;
19470b57cec5SDimitry Andric    }
19480b57cec5SDimitry Andric    else
19490b57cec5SDimitry Andric        ++__f1;
19500b57cec5SDimitry Andric    while (__f1 != __e1 && __f2 != __e2)
19510b57cec5SDimitry Andric    {
19520b57cec5SDimitry Andric        if (__comp(*__f2, *__f1))
19530b57cec5SDimitry Andric        {
1954*5f757f3fSDimitry Andric            iterator __m2 = std::next(__f2);
19550b57cec5SDimitry Andric            for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
19560b57cec5SDimitry Andric                ;
19570b57cec5SDimitry Andric            __link_pointer __f = __f2.__ptr_;
19580b57cec5SDimitry Andric            __link_pointer __l = __m2.__ptr_->__prev_;
19590b57cec5SDimitry Andric            if (__e1 == __f2)
19600b57cec5SDimitry Andric                __e1 = __m2;
19610b57cec5SDimitry Andric            __f2 = __m2;
19620b57cec5SDimitry Andric            base::__unlink_nodes(__f, __l);
1963*5f757f3fSDimitry Andric            __m2 = std::next(__f1);
19640b57cec5SDimitry Andric            __link_nodes(__f1.__ptr_, __f, __l);
19650b57cec5SDimitry Andric            __f1 = __m2;
19660b57cec5SDimitry Andric        }
19670b57cec5SDimitry Andric        else
19680b57cec5SDimitry Andric            ++__f1;
19690b57cec5SDimitry Andric    }
19700b57cec5SDimitry Andric    return __r;
19710b57cec5SDimitry Andric}
19720b57cec5SDimitry Andric
19730b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
19740b57cec5SDimitry Andricvoid
19750b57cec5SDimitry Andriclist<_Tp, _Alloc>::reverse() _NOEXCEPT
19760b57cec5SDimitry Andric{
19770b57cec5SDimitry Andric    if (base::__sz() > 1)
19780b57cec5SDimitry Andric    {
19790b57cec5SDimitry Andric        iterator __e = end();
19800b57cec5SDimitry Andric        for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
19810b57cec5SDimitry Andric        {
1982*5f757f3fSDimitry Andric            std::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
19830b57cec5SDimitry Andric            __i.__ptr_ = __i.__ptr_->__prev_;
19840b57cec5SDimitry Andric        }
1985*5f757f3fSDimitry Andric        std::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
19860b57cec5SDimitry Andric    }
19870b57cec5SDimitry Andric}
19880b57cec5SDimitry Andric
19890b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
19900b57cec5SDimitry Andricbool
19910b57cec5SDimitry Andriclist<_Tp, _Alloc>::__invariants() const
19920b57cec5SDimitry Andric{
1993*5f757f3fSDimitry Andric    return size() == std::distance(begin(), end());
19940b57cec5SDimitry Andric}
19950b57cec5SDimitry Andric
19960b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
1997*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
19980b57cec5SDimitry Andricbool
19990b57cec5SDimitry Andricoperator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20000b57cec5SDimitry Andric{
2001*5f757f3fSDimitry Andric    return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
20020b57cec5SDimitry Andric}
20030b57cec5SDimitry Andric
200406c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
200506c3fb27SDimitry Andric
20060b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2007*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20080b57cec5SDimitry Andricbool
20090b57cec5SDimitry Andricoperator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20100b57cec5SDimitry Andric{
2011*5f757f3fSDimitry Andric    return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
20120b57cec5SDimitry Andric}
20130b57cec5SDimitry Andric
20140b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2015*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20160b57cec5SDimitry Andricbool
20170b57cec5SDimitry Andricoperator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20180b57cec5SDimitry Andric{
20190b57cec5SDimitry Andric    return !(__x == __y);
20200b57cec5SDimitry Andric}
20210b57cec5SDimitry Andric
20220b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2023*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20240b57cec5SDimitry Andricbool
20250b57cec5SDimitry Andricoperator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20260b57cec5SDimitry Andric{
20270b57cec5SDimitry Andric    return __y < __x;
20280b57cec5SDimitry Andric}
20290b57cec5SDimitry Andric
20300b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2031*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20320b57cec5SDimitry Andricbool
20330b57cec5SDimitry Andricoperator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20340b57cec5SDimitry Andric{
20350b57cec5SDimitry Andric    return !(__x < __y);
20360b57cec5SDimitry Andric}
20370b57cec5SDimitry Andric
20380b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2039*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20400b57cec5SDimitry Andricbool
20410b57cec5SDimitry Andricoperator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
20420b57cec5SDimitry Andric{
20430b57cec5SDimitry Andric    return !(__y < __x);
20440b57cec5SDimitry Andric}
20450b57cec5SDimitry Andric
204606c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
204706c3fb27SDimitry Andric
204806c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
204906c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
205006c3fb27SDimitry Andricoperator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) {
205106c3fb27SDimitry Andric    return std::lexicographical_compare_three_way(
205206c3fb27SDimitry Andric        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
205306c3fb27SDimitry Andric}
205406c3fb27SDimitry Andric
205506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
205606c3fb27SDimitry Andric
20570b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc>
2058*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
20590b57cec5SDimitry Andricvoid
20600b57cec5SDimitry Andricswap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
20610b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
20620b57cec5SDimitry Andric{
20630b57cec5SDimitry Andric    __x.swap(__y);
20640b57cec5SDimitry Andric}
20650b57cec5SDimitry Andric
206606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
20670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
2068*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
20695ffd83dbSDimitry Andricerase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
20705ffd83dbSDimitry Andric  return __c.remove_if(__pred);
20715ffd83dbSDimitry Andric}
20720b57cec5SDimitry Andric
20730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
2074*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
20755ffd83dbSDimitry Andricerase(list<_Tp, _Allocator>& __c, const _Up& __v) {
2076*5f757f3fSDimitry Andric  return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
20775ffd83dbSDimitry Andric}
207881ad6265SDimitry Andric
207981ad6265SDimitry Andrictemplate <>
208081ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::list<char>> = true;
208181ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
208281ad6265SDimitry Andrictemplate <>
208381ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
20840b57cec5SDimitry Andric#endif
20850b57cec5SDimitry Andric
208606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
208781ad6265SDimitry Andric
20880b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
20890b57cec5SDimitry Andric
209006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
2091bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2092bdd1243dSDimitry Andricnamespace pmr {
2093bdd1243dSDimitry Andrictemplate <class _ValueT>
209406c3fb27SDimitry Andricusing list _LIBCPP_AVAILABILITY_PMR = std::list<_ValueT, polymorphic_allocator<_ValueT>>;
2095bdd1243dSDimitry Andric} // namespace pmr
2096bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
2097bdd1243dSDimitry Andric#endif
2098bdd1243dSDimitry Andric
20990b57cec5SDimitry Andric_LIBCPP_POP_MACROS
21000b57cec5SDimitry Andric
2101bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2102bdd1243dSDimitry Andric#  include <algorithm>
2103bdd1243dSDimitry Andric#  include <atomic>
2104bdd1243dSDimitry Andric#  include <concepts>
2105*5f757f3fSDimitry Andric#  include <cstdint>
210606c3fb27SDimitry Andric#  include <cstdlib>
2107bdd1243dSDimitry Andric#  include <functional>
2108bdd1243dSDimitry Andric#  include <iosfwd>
2109bdd1243dSDimitry Andric#  include <iterator>
2110*5f757f3fSDimitry Andric#  include <stdexcept>
211106c3fb27SDimitry Andric#  include <type_traits>
2112bdd1243dSDimitry Andric#  include <typeinfo>
2113bdd1243dSDimitry Andric#endif
2114bdd1243dSDimitry Andric
21150b57cec5SDimitry Andric#endif // _LIBCPP_LIST
2116