10b57cec5SDimitry Andric// -*- C++ -*- 2*349cc55cSDimitry 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); 490b57cec5SDimitry Andric list(const list& x); 500b57cec5SDimitry Andric list(const list&, const allocator_type& a); 510b57cec5SDimitry Andric list(list&& x) 520b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 530b57cec5SDimitry Andric list(list&&, const allocator_type& a); 540b57cec5SDimitry Andric list(initializer_list<value_type>); 550b57cec5SDimitry Andric list(initializer_list<value_type>, const allocator_type& a); 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric ~list(); 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric list& operator=(const list& x); 600b57cec5SDimitry Andric list& operator=(list&& x) 610b57cec5SDimitry Andric noexcept( 620b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value && 630b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value); 640b57cec5SDimitry Andric list& operator=(initializer_list<value_type>); 650b57cec5SDimitry Andric template <class Iter> 660b57cec5SDimitry Andric void assign(Iter first, Iter last); 670b57cec5SDimitry Andric void assign(size_type n, const value_type& t); 680b57cec5SDimitry Andric void assign(initializer_list<value_type>); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 710b57cec5SDimitry Andric 720b57cec5SDimitry Andric iterator begin() noexcept; 730b57cec5SDimitry Andric const_iterator begin() const noexcept; 740b57cec5SDimitry Andric iterator end() noexcept; 750b57cec5SDimitry Andric const_iterator end() const noexcept; 760b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 770b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 780b57cec5SDimitry Andric reverse_iterator rend() noexcept; 790b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 800b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 810b57cec5SDimitry Andric const_iterator cend() const noexcept; 820b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 830b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric reference front(); 860b57cec5SDimitry Andric const_reference front() const; 870b57cec5SDimitry Andric reference back(); 880b57cec5SDimitry Andric const_reference back() const; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric bool empty() const noexcept; 910b57cec5SDimitry Andric size_type size() const noexcept; 920b57cec5SDimitry Andric size_type max_size() const noexcept; 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric template <class... Args> 950b57cec5SDimitry Andric reference emplace_front(Args&&... args); // reference in C++17 960b57cec5SDimitry Andric void pop_front(); 970b57cec5SDimitry Andric template <class... Args> 980b57cec5SDimitry Andric reference emplace_back(Args&&... args); // reference in C++17 990b57cec5SDimitry Andric void pop_back(); 1000b57cec5SDimitry Andric void push_front(const value_type& x); 1010b57cec5SDimitry Andric void push_front(value_type&& x); 1020b57cec5SDimitry Andric void push_back(const value_type& x); 1030b57cec5SDimitry Andric void push_back(value_type&& x); 1040b57cec5SDimitry Andric template <class... Args> 1050b57cec5SDimitry Andric iterator emplace(const_iterator position, Args&&... args); 1060b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 1070b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& x); 1080b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 1090b57cec5SDimitry Andric template <class Iter> 1100b57cec5SDimitry Andric iterator insert(const_iterator position, Iter first, Iter last); 1110b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric iterator erase(const_iterator position); 1140b57cec5SDimitry Andric iterator erase(const_iterator position, const_iterator last); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric void resize(size_type sz); 1170b57cec5SDimitry Andric void resize(size_type sz, const value_type& c); 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andric void swap(list&) 1200b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 1210b57cec5SDimitry Andric void clear() noexcept; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric void splice(const_iterator position, list& x); 1240b57cec5SDimitry Andric void splice(const_iterator position, list&& x); 1250b57cec5SDimitry Andric void splice(const_iterator position, list& x, const_iterator i); 1260b57cec5SDimitry Andric void splice(const_iterator position, list&& x, const_iterator i); 1270b57cec5SDimitry Andric void splice(const_iterator position, list& x, const_iterator first, 1280b57cec5SDimitry Andric const_iterator last); 1290b57cec5SDimitry Andric void splice(const_iterator position, list&& x, const_iterator first, 1300b57cec5SDimitry Andric const_iterator last); 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric size_type remove(const value_type& value); // void before C++20 1330b57cec5SDimitry Andric template <class Pred> 1340b57cec5SDimitry Andric size_type remove_if(Pred pred); // void before C++20 1350b57cec5SDimitry Andric size_type unique(); // void before C++20 1360b57cec5SDimitry Andric template <class BinaryPredicate> 1370b57cec5SDimitry Andric size_type unique(BinaryPredicate binary_pred); // void before C++20 1380b57cec5SDimitry Andric void merge(list& x); 1390b57cec5SDimitry Andric void merge(list&& x); 1400b57cec5SDimitry Andric template <class Compare> 1410b57cec5SDimitry Andric void merge(list& x, Compare comp); 1420b57cec5SDimitry Andric template <class Compare> 1430b57cec5SDimitry Andric void merge(list&& x, Compare comp); 1440b57cec5SDimitry Andric void sort(); 1450b57cec5SDimitry Andric template <class Compare> 1460b57cec5SDimitry Andric void sort(Compare comp); 1470b57cec5SDimitry Andric void reverse() noexcept; 1480b57cec5SDimitry Andric}; 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 1520b57cec5SDimitry Andric list(InputIterator, InputIterator, Allocator = Allocator()) 1530b57cec5SDimitry Andric -> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andrictemplate <class T, class Alloc> 1560b57cec5SDimitry Andric bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y); 1570b57cec5SDimitry Andrictemplate <class T, class Alloc> 1580b57cec5SDimitry Andric bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); 1590b57cec5SDimitry Andrictemplate <class T, class Alloc> 1600b57cec5SDimitry Andric bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); 1610b57cec5SDimitry Andrictemplate <class T, class Alloc> 1620b57cec5SDimitry Andric bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); 1630b57cec5SDimitry Andrictemplate <class T, class Alloc> 1640b57cec5SDimitry Andric bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); 1650b57cec5SDimitry Andrictemplate <class T, class Alloc> 1660b57cec5SDimitry Andric bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andrictemplate <class T, class Alloc> 1690b57cec5SDimitry Andric void swap(list<T,Alloc>& x, list<T,Alloc>& y) 1700b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 1710b57cec5SDimitry Andric 1720b57cec5SDimitry Andrictemplate <class T, class Allocator, class U> 1735ffd83dbSDimitry Andric typename list<T, Allocator>::size_type 1745ffd83dbSDimitry Andric erase(list<T, Allocator>& c, const U& value); // C++20 1750b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 1765ffd83dbSDimitry Andric typename list<T, Allocator>::size_type 1775ffd83dbSDimitry Andric erase_if(list<T, Allocator>& c, Predicate pred); // C++20 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andric} // std 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric*/ 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andric#include <__config> 184fe6060f1SDimitry Andric#include <__debug> 185fe6060f1SDimitry Andric#include <__utility/forward.h> 186fe6060f1SDimitry Andric#include <algorithm> 1870b57cec5SDimitry Andric#include <initializer_list> 1880b57cec5SDimitry Andric#include <iterator> 189fe6060f1SDimitry Andric#include <limits> 190fe6060f1SDimitry Andric#include <memory> 1910b57cec5SDimitry Andric#include <type_traits> 1920b57cec5SDimitry Andric#include <version> 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1950b57cec5SDimitry Andric#pragma GCC system_header 1960b57cec5SDimitry Andric#endif 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 1990b57cec5SDimitry Andric#include <__undef_macros> 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> struct __list_node; 2050b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> struct __list_node_base; 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> 2080b57cec5SDimitry Andricstruct __list_node_pointer_traits { 2090b57cec5SDimitry Andric typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type 2100b57cec5SDimitry Andric __node_pointer; 2110b57cec5SDimitry Andric typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type 2120b57cec5SDimitry Andric __base_pointer; 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB) 2150b57cec5SDimitry Andric typedef __base_pointer __link_pointer; 2160b57cec5SDimitry Andric#else 2170b57cec5SDimitry Andric typedef typename conditional< 2180b57cec5SDimitry Andric is_pointer<_VoidPtr>::value, 2190b57cec5SDimitry Andric __base_pointer, 2200b57cec5SDimitry Andric __node_pointer 2210b57cec5SDimitry Andric >::type __link_pointer; 2220b57cec5SDimitry Andric#endif 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andric typedef typename conditional< 2250b57cec5SDimitry Andric is_same<__link_pointer, __node_pointer>::value, 2260b57cec5SDimitry Andric __base_pointer, 2270b57cec5SDimitry Andric __node_pointer 2280b57cec5SDimitry Andric >::type __non_link_pointer; 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric static _LIBCPP_INLINE_VISIBILITY 2310b57cec5SDimitry Andric __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) { 2320b57cec5SDimitry Andric return __p; 2330b57cec5SDimitry Andric } 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric static _LIBCPP_INLINE_VISIBILITY 2360b57cec5SDimitry Andric __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) { 2370b57cec5SDimitry Andric return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p)); 2380b57cec5SDimitry Andric } 2390b57cec5SDimitry Andric 2400b57cec5SDimitry Andric}; 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> 2430b57cec5SDimitry Andricstruct __list_node_base 2440b57cec5SDimitry Andric{ 2450b57cec5SDimitry Andric typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; 2460b57cec5SDimitry Andric typedef typename _NodeTraits::__node_pointer __node_pointer; 2470b57cec5SDimitry Andric typedef typename _NodeTraits::__base_pointer __base_pointer; 2480b57cec5SDimitry Andric typedef typename _NodeTraits::__link_pointer __link_pointer; 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric __link_pointer __prev_; 2510b57cec5SDimitry Andric __link_pointer __next_; 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2540b57cec5SDimitry Andric __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())), 2550b57cec5SDimitry Andric __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {} 2560b57cec5SDimitry Andric 2570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2580b57cec5SDimitry Andric __base_pointer __self() { 2590b57cec5SDimitry Andric return pointer_traits<__base_pointer>::pointer_to(*this); 2600b57cec5SDimitry Andric } 2610b57cec5SDimitry Andric 2620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2630b57cec5SDimitry Andric __node_pointer __as_node() { 2640b57cec5SDimitry Andric return static_cast<__node_pointer>(__self()); 2650b57cec5SDimitry Andric } 2660b57cec5SDimitry Andric}; 2670b57cec5SDimitry Andric 2680b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> 269fe6060f1SDimitry Andricstruct _LIBCPP_STANDALONE_DEBUG __list_node 2700b57cec5SDimitry Andric : public __list_node_base<_Tp, _VoidPtr> 2710b57cec5SDimitry Andric{ 2720b57cec5SDimitry Andric _Tp __value_; 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric typedef __list_node_base<_Tp, _VoidPtr> __base; 2750b57cec5SDimitry Andric typedef typename __base::__link_pointer __link_pointer; 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2780b57cec5SDimitry Andric __link_pointer __as_link() { 2790b57cec5SDimitry Andric return static_cast<__link_pointer>(__base::__self()); 2800b57cec5SDimitry Andric } 2810b57cec5SDimitry Andric}; 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list; 2840b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> class __list_imp; 2850b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> 2880b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_iterator 2890b57cec5SDimitry Andric{ 2900b57cec5SDimitry Andric typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; 2910b57cec5SDimitry Andric typedef typename _NodeTraits::__link_pointer __link_pointer; 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andric __link_pointer __ptr_; 2940b57cec5SDimitry Andric 295e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 2970b57cec5SDimitry Andric explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT 2980b57cec5SDimitry Andric : __ptr_(__p) 2990b57cec5SDimitry Andric { 3000b57cec5SDimitry Andric __get_db()->__insert_ic(this, __c); 3010b57cec5SDimitry Andric } 3020b57cec5SDimitry Andric#else 3030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3040b57cec5SDimitry Andric explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} 3050b57cec5SDimitry Andric#endif 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric 3080b57cec5SDimitry Andric 3090b57cec5SDimitry Andric template<class, class> friend class list; 3100b57cec5SDimitry Andric template<class, class> friend class __list_imp; 3110b57cec5SDimitry Andric template<class, class> friend class __list_const_iterator; 3120b57cec5SDimitry Andricpublic: 3130b57cec5SDimitry Andric typedef bidirectional_iterator_tag iterator_category; 3140b57cec5SDimitry Andric typedef _Tp value_type; 3150b57cec5SDimitry Andric typedef value_type& reference; 3160b57cec5SDimitry Andric typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer; 3170b57cec5SDimitry Andric typedef typename pointer_traits<pointer>::difference_type difference_type; 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3200b57cec5SDimitry Andric __list_iterator() _NOEXCEPT : __ptr_(nullptr) 3210b57cec5SDimitry Andric { 322e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3230b57cec5SDimitry Andric __get_db()->__insert_i(this); 3240b57cec5SDimitry Andric#endif 3250b57cec5SDimitry Andric } 3260b57cec5SDimitry Andric 327e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3300b57cec5SDimitry Andric __list_iterator(const __list_iterator& __p) 3310b57cec5SDimitry Andric : __ptr_(__p.__ptr_) 3320b57cec5SDimitry Andric { 333*349cc55cSDimitry Andric __get_db()->__iterator_copy(this, _VSTD::addressof(__p)); 3340b57cec5SDimitry Andric } 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3370b57cec5SDimitry Andric ~__list_iterator() 3380b57cec5SDimitry Andric { 3390b57cec5SDimitry Andric __get_db()->__erase_i(this); 3400b57cec5SDimitry Andric } 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3430b57cec5SDimitry Andric __list_iterator& operator=(const __list_iterator& __p) 3440b57cec5SDimitry Andric { 345*349cc55cSDimitry Andric if (this != _VSTD::addressof(__p)) 3460b57cec5SDimitry Andric { 347*349cc55cSDimitry Andric __get_db()->__iterator_copy(this, _VSTD::addressof(__p)); 3480b57cec5SDimitry Andric __ptr_ = __p.__ptr_; 3490b57cec5SDimitry Andric } 3500b57cec5SDimitry Andric return *this; 3510b57cec5SDimitry Andric } 3520b57cec5SDimitry Andric 353e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2 3540b57cec5SDimitry Andric 3550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3560b57cec5SDimitry Andric reference operator*() const 3570b57cec5SDimitry Andric { 358e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3590b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 3600b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable list::iterator"); 3610b57cec5SDimitry Andric#endif 3620b57cec5SDimitry Andric return __ptr_->__as_node()->__value_; 3630b57cec5SDimitry Andric } 3640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3650b57cec5SDimitry Andric pointer operator->() const 3660b57cec5SDimitry Andric { 367e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3680b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 3690b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable list::iterator"); 3700b57cec5SDimitry Andric#endif 3710b57cec5SDimitry Andric return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); 3720b57cec5SDimitry Andric } 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3750b57cec5SDimitry Andric __list_iterator& operator++() 3760b57cec5SDimitry Andric { 377e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3780b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 379fe6060f1SDimitry Andric "Attempted to increment a non-incrementable list::iterator"); 3800b57cec5SDimitry Andric#endif 3810b57cec5SDimitry Andric __ptr_ = __ptr_->__next_; 3820b57cec5SDimitry Andric return *this; 3830b57cec5SDimitry Andric } 3840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3850b57cec5SDimitry Andric __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3880b57cec5SDimitry Andric __list_iterator& operator--() 3890b57cec5SDimitry Andric { 390e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 3910b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 392fe6060f1SDimitry Andric "Attempted to decrement a non-decrementable list::iterator"); 3930b57cec5SDimitry Andric#endif 3940b57cec5SDimitry Andric __ptr_ = __ptr_->__prev_; 3950b57cec5SDimitry Andric return *this; 3960b57cec5SDimitry Andric } 3970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3980b57cec5SDimitry Andric __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4010b57cec5SDimitry Andric bool operator==(const __list_iterator& __x, const __list_iterator& __y) 4020b57cec5SDimitry Andric { 4030b57cec5SDimitry Andric return __x.__ptr_ == __y.__ptr_; 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 4060b57cec5SDimitry Andric bool operator!=(const __list_iterator& __x, const __list_iterator& __y) 4070b57cec5SDimitry Andric {return !(__x == __y);} 4080b57cec5SDimitry Andric}; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andrictemplate <class _Tp, class _VoidPtr> 4110b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS __list_const_iterator 4120b57cec5SDimitry Andric{ 4130b57cec5SDimitry Andric typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; 4140b57cec5SDimitry Andric typedef typename _NodeTraits::__link_pointer __link_pointer; 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andric __link_pointer __ptr_; 4170b57cec5SDimitry Andric 418e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 4190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4200b57cec5SDimitry Andric explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT 4210b57cec5SDimitry Andric : __ptr_(__p) 4220b57cec5SDimitry Andric { 4230b57cec5SDimitry Andric __get_db()->__insert_ic(this, __c); 4240b57cec5SDimitry Andric } 4250b57cec5SDimitry Andric#else 4260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4270b57cec5SDimitry Andric explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} 4280b57cec5SDimitry Andric#endif 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric template<class, class> friend class list; 4310b57cec5SDimitry Andric template<class, class> friend class __list_imp; 4320b57cec5SDimitry Andricpublic: 4330b57cec5SDimitry Andric typedef bidirectional_iterator_tag iterator_category; 4340b57cec5SDimitry Andric typedef _Tp value_type; 4350b57cec5SDimitry Andric typedef const value_type& reference; 4360b57cec5SDimitry Andric typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer; 4370b57cec5SDimitry Andric typedef typename pointer_traits<pointer>::difference_type difference_type; 4380b57cec5SDimitry Andric 4390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4400b57cec5SDimitry Andric __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) 4410b57cec5SDimitry Andric { 442e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 4430b57cec5SDimitry Andric __get_db()->__insert_i(this); 4440b57cec5SDimitry Andric#endif 4450b57cec5SDimitry Andric } 4460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4470b57cec5SDimitry Andric __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT 4480b57cec5SDimitry Andric : __ptr_(__p.__ptr_) 4490b57cec5SDimitry Andric { 450e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 451*349cc55cSDimitry Andric __get_db()->__iterator_copy(this, _VSTD::addressof(__p)); 4520b57cec5SDimitry Andric#endif 4530b57cec5SDimitry Andric } 4540b57cec5SDimitry Andric 455e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4580b57cec5SDimitry Andric __list_const_iterator(const __list_const_iterator& __p) 4590b57cec5SDimitry Andric : __ptr_(__p.__ptr_) 4600b57cec5SDimitry Andric { 461*349cc55cSDimitry Andric __get_db()->__iterator_copy(this, _VSTD::addressof(__p)); 4620b57cec5SDimitry Andric } 4630b57cec5SDimitry Andric 4640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4650b57cec5SDimitry Andric ~__list_const_iterator() 4660b57cec5SDimitry Andric { 4670b57cec5SDimitry Andric __get_db()->__erase_i(this); 4680b57cec5SDimitry Andric } 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4710b57cec5SDimitry Andric __list_const_iterator& operator=(const __list_const_iterator& __p) 4720b57cec5SDimitry Andric { 473*349cc55cSDimitry Andric if (this != _VSTD::addressof(__p)) 4740b57cec5SDimitry Andric { 475*349cc55cSDimitry Andric __get_db()->__iterator_copy(this, _VSTD::addressof(__p)); 4760b57cec5SDimitry Andric __ptr_ = __p.__ptr_; 4770b57cec5SDimitry Andric } 4780b57cec5SDimitry Andric return *this; 4790b57cec5SDimitry Andric } 4800b57cec5SDimitry Andric 481e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2 4820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4830b57cec5SDimitry Andric reference operator*() const 4840b57cec5SDimitry Andric { 485e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 4860b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 4870b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable list::const_iterator"); 4880b57cec5SDimitry Andric#endif 4890b57cec5SDimitry Andric return __ptr_->__as_node()->__value_; 4900b57cec5SDimitry Andric } 4910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4920b57cec5SDimitry Andric pointer operator->() const 4930b57cec5SDimitry Andric { 494e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 4950b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 4960b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable list::const_iterator"); 4970b57cec5SDimitry Andric#endif 4980b57cec5SDimitry Andric return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); 4990b57cec5SDimitry Andric } 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5020b57cec5SDimitry Andric __list_const_iterator& operator++() 5030b57cec5SDimitry Andric { 504e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 5050b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 506fe6060f1SDimitry Andric "Attempted to increment a non-incrementable list::const_iterator"); 5070b57cec5SDimitry Andric#endif 5080b57cec5SDimitry Andric __ptr_ = __ptr_->__next_; 5090b57cec5SDimitry Andric return *this; 5100b57cec5SDimitry Andric } 5110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5120b57cec5SDimitry Andric __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} 5130b57cec5SDimitry Andric 5140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5150b57cec5SDimitry Andric __list_const_iterator& operator--() 5160b57cec5SDimitry Andric { 517e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 5180b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 519fe6060f1SDimitry Andric "Attempted to decrement a non-decrementable list::const_iterator"); 5200b57cec5SDimitry Andric#endif 5210b57cec5SDimitry Andric __ptr_ = __ptr_->__prev_; 5220b57cec5SDimitry Andric return *this; 5230b57cec5SDimitry Andric } 5240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5250b57cec5SDimitry Andric __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} 5260b57cec5SDimitry Andric 5270b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5280b57cec5SDimitry Andric bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) 5290b57cec5SDimitry Andric { 5300b57cec5SDimitry Andric return __x.__ptr_ == __y.__ptr_; 5310b57cec5SDimitry Andric } 5320b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 5330b57cec5SDimitry Andric bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) 5340b57cec5SDimitry Andric {return !(__x == __y);} 5350b57cec5SDimitry Andric}; 5360b57cec5SDimitry Andric 5370b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 5380b57cec5SDimitry Andricclass __list_imp 5390b57cec5SDimitry Andric{ 5400b57cec5SDimitry Andric __list_imp(const __list_imp&); 5410b57cec5SDimitry Andric __list_imp& operator=(const __list_imp&); 5420b57cec5SDimitry Andricpublic: 5430b57cec5SDimitry Andric typedef _Alloc allocator_type; 5440b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 5450b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 5460b57cec5SDimitry Andricprotected: 5470b57cec5SDimitry Andric typedef _Tp value_type; 5480b57cec5SDimitry Andric typedef typename __alloc_traits::void_pointer __void_pointer; 5490b57cec5SDimitry Andric typedef __list_iterator<value_type, __void_pointer> iterator; 5500b57cec5SDimitry Andric typedef __list_const_iterator<value_type, __void_pointer> const_iterator; 5510b57cec5SDimitry Andric typedef __list_node_base<value_type, __void_pointer> __node_base; 5520b57cec5SDimitry Andric typedef __list_node<value_type, __void_pointer> __node; 5530b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; 5540b57cec5SDimitry Andric typedef allocator_traits<__node_allocator> __node_alloc_traits; 5550b57cec5SDimitry Andric typedef typename __node_alloc_traits::pointer __node_pointer; 5560b57cec5SDimitry Andric typedef typename __node_alloc_traits::pointer __node_const_pointer; 5570b57cec5SDimitry Andric typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits; 5580b57cec5SDimitry Andric typedef typename __node_pointer_traits::__link_pointer __link_pointer; 5590b57cec5SDimitry Andric typedef __link_pointer __link_const_pointer; 5600b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 5610b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 5620b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 5630b57cec5SDimitry Andric 5640b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; 5650b57cec5SDimitry Andric typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; 5660b57cec5SDimitry Andric static_assert((!is_same<allocator_type, __node_allocator>::value), 5670b57cec5SDimitry Andric "internal allocator type must differ from user-specified " 5680b57cec5SDimitry Andric "type; otherwise overload resolution breaks"); 5690b57cec5SDimitry Andric 5700b57cec5SDimitry Andric __node_base __end_; 5710b57cec5SDimitry Andric __compressed_pair<size_type, __node_allocator> __size_alloc_; 5720b57cec5SDimitry Andric 5730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5740b57cec5SDimitry Andric __link_pointer __end_as_link() const _NOEXCEPT { 5750b57cec5SDimitry Andric return __node_pointer_traits::__unsafe_link_pointer_cast( 5760b57cec5SDimitry Andric const_cast<__node_base&>(__end_).__self()); 5770b57cec5SDimitry Andric } 5780b57cec5SDimitry Andric 5790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5800b57cec5SDimitry Andric size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} 5810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5820b57cec5SDimitry Andric const size_type& __sz() const _NOEXCEPT 5830b57cec5SDimitry Andric {return __size_alloc_.first();} 5840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5850b57cec5SDimitry Andric __node_allocator& __node_alloc() _NOEXCEPT 5860b57cec5SDimitry Andric {return __size_alloc_.second();} 5870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5880b57cec5SDimitry Andric const __node_allocator& __node_alloc() const _NOEXCEPT 5890b57cec5SDimitry Andric {return __size_alloc_.second();} 5900b57cec5SDimitry Andric 5910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5920b57cec5SDimitry Andric size_type __node_alloc_max_size() const _NOEXCEPT { 5930b57cec5SDimitry Andric return __node_alloc_traits::max_size(__node_alloc()); 5940b57cec5SDimitry Andric } 5950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5960b57cec5SDimitry Andric static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; 5970b57cec5SDimitry Andric 5980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5990b57cec5SDimitry Andric __list_imp() 6000b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); 6010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6020b57cec5SDimitry Andric __list_imp(const allocator_type& __a); 6030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6040b57cec5SDimitry Andric __list_imp(const __node_allocator& __a); 6050b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6060b57cec5SDimitry Andric __list_imp(__node_allocator&& __a) _NOEXCEPT; 6070b57cec5SDimitry Andric#endif 6080b57cec5SDimitry Andric ~__list_imp(); 6090b57cec5SDimitry Andric void clear() _NOEXCEPT; 6100b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6110b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return __sz() == 0;} 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6140b57cec5SDimitry Andric iterator begin() _NOEXCEPT 6150b57cec5SDimitry Andric { 616e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 6170b57cec5SDimitry Andric return iterator(__end_.__next_, this); 6180b57cec5SDimitry Andric#else 6190b57cec5SDimitry Andric return iterator(__end_.__next_); 6200b57cec5SDimitry Andric#endif 6210b57cec5SDimitry Andric } 6220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6230b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 6240b57cec5SDimitry Andric { 625e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 6260b57cec5SDimitry Andric return const_iterator(__end_.__next_, this); 6270b57cec5SDimitry Andric#else 6280b57cec5SDimitry Andric return const_iterator(__end_.__next_); 6290b57cec5SDimitry Andric#endif 6300b57cec5SDimitry Andric } 6310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6320b57cec5SDimitry Andric iterator end() _NOEXCEPT 6330b57cec5SDimitry Andric { 634e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 6350b57cec5SDimitry Andric return iterator(__end_as_link(), this); 6360b57cec5SDimitry Andric#else 6370b57cec5SDimitry Andric return iterator(__end_as_link()); 6380b57cec5SDimitry Andric#endif 6390b57cec5SDimitry Andric } 6400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6410b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 6420b57cec5SDimitry Andric { 643e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 6440b57cec5SDimitry Andric return const_iterator(__end_as_link(), this); 6450b57cec5SDimitry Andric#else 6460b57cec5SDimitry Andric return const_iterator(__end_as_link()); 6470b57cec5SDimitry Andric#endif 6480b57cec5SDimitry Andric } 6490b57cec5SDimitry Andric 6500b57cec5SDimitry Andric void swap(__list_imp& __c) 6510b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 6520b57cec5SDimitry Andric _NOEXCEPT; 6530b57cec5SDimitry Andric#else 6540b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 6550b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 6560b57cec5SDimitry Andric#endif 6570b57cec5SDimitry Andric 6580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6590b57cec5SDimitry Andric void __copy_assign_alloc(const __list_imp& __c) 6600b57cec5SDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 6610b57cec5SDimitry Andric __node_alloc_traits::propagate_on_container_copy_assignment::value>());} 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6640b57cec5SDimitry Andric void __move_assign_alloc(__list_imp& __c) 6650b57cec5SDimitry Andric _NOEXCEPT_( 6660b57cec5SDimitry Andric !__node_alloc_traits::propagate_on_container_move_assignment::value || 6670b57cec5SDimitry Andric is_nothrow_move_assignable<__node_allocator>::value) 6680b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 6690b57cec5SDimitry Andric __node_alloc_traits::propagate_on_container_move_assignment::value>());} 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andricprivate: 6720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6730b57cec5SDimitry Andric void __copy_assign_alloc(const __list_imp& __c, true_type) 6740b57cec5SDimitry Andric { 6750b57cec5SDimitry Andric if (__node_alloc() != __c.__node_alloc()) 6760b57cec5SDimitry Andric clear(); 6770b57cec5SDimitry Andric __node_alloc() = __c.__node_alloc(); 6780b57cec5SDimitry Andric } 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6810b57cec5SDimitry Andric void __copy_assign_alloc(const __list_imp&, false_type) 6820b57cec5SDimitry Andric {} 6830b57cec5SDimitry Andric 6840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6850b57cec5SDimitry Andric void __move_assign_alloc(__list_imp& __c, true_type) 6860b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) 6870b57cec5SDimitry Andric { 6880b57cec5SDimitry Andric __node_alloc() = _VSTD::move(__c.__node_alloc()); 6890b57cec5SDimitry Andric } 6900b57cec5SDimitry Andric 6910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6920b57cec5SDimitry Andric void __move_assign_alloc(__list_imp&, false_type) 6930b57cec5SDimitry Andric _NOEXCEPT 6940b57cec5SDimitry Andric {} 6950b57cec5SDimitry Andric 6960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6970b57cec5SDimitry Andric void __invalidate_all_iterators() { 698e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 6990b57cec5SDimitry Andric __get_db()->__invalidate_all(this); 7000b57cec5SDimitry Andric#endif 7010b57cec5SDimitry Andric } 7020b57cec5SDimitry Andric}; 7030b57cec5SDimitry Andric 7040b57cec5SDimitry Andric// Unlink nodes [__f, __l] 7050b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7060b57cec5SDimitry Andricinline 7070b57cec5SDimitry Andricvoid 7080b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l) 7090b57cec5SDimitry Andric _NOEXCEPT 7100b57cec5SDimitry Andric{ 7110b57cec5SDimitry Andric __f->__prev_->__next_ = __l->__next_; 7120b57cec5SDimitry Andric __l->__next_->__prev_ = __f->__prev_; 7130b57cec5SDimitry Andric} 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7160b57cec5SDimitry Andricinline 7170b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__list_imp() 7180b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) 719480093f4SDimitry Andric : __size_alloc_(0, __default_init_tag()) 7200b57cec5SDimitry Andric{ 7210b57cec5SDimitry Andric} 7220b57cec5SDimitry Andric 7230b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7240b57cec5SDimitry Andricinline 7250b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) 7260b57cec5SDimitry Andric : __size_alloc_(0, __node_allocator(__a)) 7270b57cec5SDimitry Andric{ 7280b57cec5SDimitry Andric} 7290b57cec5SDimitry Andric 7300b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7310b57cec5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) 7320b57cec5SDimitry Andric : __size_alloc_(0, __a) {} 7330b57cec5SDimitry Andric 7340b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7350b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7360b57cec5SDimitry Andricinline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT 737e8d8bef9SDimitry Andric : __size_alloc_(0, _VSTD::move(__a)) {} 7380b57cec5SDimitry Andric#endif 7390b57cec5SDimitry Andric 7400b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7410b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::~__list_imp() { 7420b57cec5SDimitry Andric clear(); 743e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 7440b57cec5SDimitry Andric __get_db()->__erase_c(this); 7450b57cec5SDimitry Andric#endif 7460b57cec5SDimitry Andric} 7470b57cec5SDimitry Andric 7480b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7490b57cec5SDimitry Andricvoid 7500b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT 7510b57cec5SDimitry Andric{ 7520b57cec5SDimitry Andric if (!empty()) 7530b57cec5SDimitry Andric { 7540b57cec5SDimitry Andric __node_allocator& __na = __node_alloc(); 7550b57cec5SDimitry Andric __link_pointer __f = __end_.__next_; 7560b57cec5SDimitry Andric __link_pointer __l = __end_as_link(); 7570b57cec5SDimitry Andric __unlink_nodes(__f, __l->__prev_); 7580b57cec5SDimitry Andric __sz() = 0; 7590b57cec5SDimitry Andric while (__f != __l) 7600b57cec5SDimitry Andric { 7610b57cec5SDimitry Andric __node_pointer __np = __f->__as_node(); 7620b57cec5SDimitry Andric __f = __f->__next_; 7630b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); 7640b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __np, 1); 7650b57cec5SDimitry Andric } 7660b57cec5SDimitry Andric __invalidate_all_iterators(); 7670b57cec5SDimitry Andric } 7680b57cec5SDimitry Andric} 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 7710b57cec5SDimitry Andricvoid 7720b57cec5SDimitry Andric__list_imp<_Tp, _Alloc>::swap(__list_imp& __c) 7730b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 7740b57cec5SDimitry Andric _NOEXCEPT 7750b57cec5SDimitry Andric#else 7760b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 7770b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 7780b57cec5SDimitry Andric#endif 7790b57cec5SDimitry Andric{ 7800b57cec5SDimitry Andric _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 7810b57cec5SDimitry Andric this->__node_alloc() == __c.__node_alloc(), 7820b57cec5SDimitry Andric "list::swap: Either propagate_on_container_swap must be true" 7830b57cec5SDimitry Andric " or the allocators must compare equal"); 7840b57cec5SDimitry Andric using _VSTD::swap; 785e8d8bef9SDimitry Andric _VSTD::__swap_allocator(__node_alloc(), __c.__node_alloc()); 7860b57cec5SDimitry Andric swap(__sz(), __c.__sz()); 7870b57cec5SDimitry Andric swap(__end_, __c.__end_); 7880b57cec5SDimitry Andric if (__sz() == 0) 7890b57cec5SDimitry Andric __end_.__next_ = __end_.__prev_ = __end_as_link(); 7900b57cec5SDimitry Andric else 7910b57cec5SDimitry Andric __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link(); 7920b57cec5SDimitry Andric if (__c.__sz() == 0) 7930b57cec5SDimitry Andric __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link(); 7940b57cec5SDimitry Andric else 7950b57cec5SDimitry Andric __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link(); 7960b57cec5SDimitry Andric 797e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 7980b57cec5SDimitry Andric __libcpp_db* __db = __get_db(); 7990b57cec5SDimitry Andric __c_node* __cn1 = __db->__find_c_and_lock(this); 800*349cc55cSDimitry Andric __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); 801e8d8bef9SDimitry Andric _VSTD::swap(__cn1->beg_, __cn2->beg_); 802e8d8bef9SDimitry Andric _VSTD::swap(__cn1->end_, __cn2->end_); 803e8d8bef9SDimitry Andric _VSTD::swap(__cn1->cap_, __cn2->cap_); 8040b57cec5SDimitry Andric for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) 8050b57cec5SDimitry Andric { 8060b57cec5SDimitry Andric --__p; 8070b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 8080b57cec5SDimitry Andric if (__i->__ptr_ == __c.__end_as_link()) 8090b57cec5SDimitry Andric { 8100b57cec5SDimitry Andric __cn2->__add(*__p); 8110b57cec5SDimitry Andric if (--__cn1->end_ != __p) 812e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); 8130b57cec5SDimitry Andric } 8140b57cec5SDimitry Andric else 8150b57cec5SDimitry Andric (*__p)->__c_ = __cn1; 8160b57cec5SDimitry Andric } 8170b57cec5SDimitry Andric for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 8180b57cec5SDimitry Andric { 8190b57cec5SDimitry Andric --__p; 8200b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 8210b57cec5SDimitry Andric if (__i->__ptr_ == __end_as_link()) 8220b57cec5SDimitry Andric { 8230b57cec5SDimitry Andric __cn1->__add(*__p); 8240b57cec5SDimitry Andric if (--__cn2->end_ != __p) 825e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 8260b57cec5SDimitry Andric } 8270b57cec5SDimitry Andric else 8280b57cec5SDimitry Andric (*__p)->__c_ = __cn2; 8290b57cec5SDimitry Andric } 8300b57cec5SDimitry Andric __db->unlock(); 8310b57cec5SDimitry Andric#endif 8320b57cec5SDimitry Andric} 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc /*= allocator<_Tp>*/> 8350b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS list 8360b57cec5SDimitry Andric : private __list_imp<_Tp, _Alloc> 8370b57cec5SDimitry Andric{ 8380b57cec5SDimitry Andric typedef __list_imp<_Tp, _Alloc> base; 8390b57cec5SDimitry Andric typedef typename base::__node __node; 8400b57cec5SDimitry Andric typedef typename base::__node_allocator __node_allocator; 8410b57cec5SDimitry Andric typedef typename base::__node_pointer __node_pointer; 8420b57cec5SDimitry Andric typedef typename base::__node_alloc_traits __node_alloc_traits; 8430b57cec5SDimitry Andric typedef typename base::__node_base __node_base; 8440b57cec5SDimitry Andric typedef typename base::__node_base_pointer __node_base_pointer; 8450b57cec5SDimitry Andric typedef typename base::__link_pointer __link_pointer; 8460b57cec5SDimitry Andric 8470b57cec5SDimitry Andricpublic: 8480b57cec5SDimitry Andric typedef _Tp value_type; 8490b57cec5SDimitry Andric typedef _Alloc allocator_type; 8500b57cec5SDimitry Andric static_assert((is_same<value_type, typename allocator_type::value_type>::value), 8510b57cec5SDimitry Andric "Invalid allocator::value_type"); 8520b57cec5SDimitry Andric typedef value_type& reference; 8530b57cec5SDimitry Andric typedef const value_type& const_reference; 8540b57cec5SDimitry Andric typedef typename base::pointer pointer; 8550b57cec5SDimitry Andric typedef typename base::const_pointer const_pointer; 856*349cc55cSDimitry Andric typedef typename __allocator_traits<allocator_type>::size_type size_type; 8570b57cec5SDimitry Andric typedef typename base::difference_type difference_type; 8580b57cec5SDimitry Andric typedef typename base::iterator iterator; 8590b57cec5SDimitry Andric typedef typename base::const_iterator const_iterator; 8600b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 8610b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 8620b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 8630b57cec5SDimitry Andric typedef size_type __remove_return_type; 8640b57cec5SDimitry Andric#else 8650b57cec5SDimitry Andric typedef void __remove_return_type; 8660b57cec5SDimitry Andric#endif 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8690b57cec5SDimitry Andric list() 8700b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) 8710b57cec5SDimitry Andric { 872e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 8730b57cec5SDimitry Andric __get_db()->__insert_c(this); 8740b57cec5SDimitry Andric#endif 8750b57cec5SDimitry Andric } 8760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8770b57cec5SDimitry Andric explicit list(const allocator_type& __a) : base(__a) 8780b57cec5SDimitry Andric { 879e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 8800b57cec5SDimitry Andric __get_db()->__insert_c(this); 8810b57cec5SDimitry Andric#endif 8820b57cec5SDimitry Andric } 8830b57cec5SDimitry Andric explicit list(size_type __n); 8840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8850b57cec5SDimitry Andric explicit list(size_type __n, const allocator_type& __a); 8860b57cec5SDimitry Andric#endif 8870b57cec5SDimitry Andric list(size_type __n, const value_type& __x); 8880b57cec5SDimitry Andric list(size_type __n, const value_type& __x, const allocator_type& __a); 8890b57cec5SDimitry Andric template <class _InpIter> 8900b57cec5SDimitry Andric list(_InpIter __f, _InpIter __l, 891480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0); 8920b57cec5SDimitry Andric template <class _InpIter> 8930b57cec5SDimitry Andric list(_InpIter __f, _InpIter __l, const allocator_type& __a, 894480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0); 8950b57cec5SDimitry Andric 8960b57cec5SDimitry Andric list(const list& __c); 897fe6060f1SDimitry Andric list(const list& __c, const __identity_t<allocator_type>& __a); 8980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8990b57cec5SDimitry Andric list& operator=(const list& __c); 9000b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 9010b57cec5SDimitry Andric list(initializer_list<value_type> __il); 9020b57cec5SDimitry Andric list(initializer_list<value_type> __il, const allocator_type& __a); 9030b57cec5SDimitry Andric 9040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9050b57cec5SDimitry Andric list(list&& __c) 9060b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); 9070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 908fe6060f1SDimitry Andric list(list&& __c, const __identity_t<allocator_type>& __a); 9090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9100b57cec5SDimitry Andric list& operator=(list&& __c) 9110b57cec5SDimitry Andric _NOEXCEPT_( 9120b57cec5SDimitry Andric __node_alloc_traits::propagate_on_container_move_assignment::value && 9130b57cec5SDimitry Andric is_nothrow_move_assignable<__node_allocator>::value); 9140b57cec5SDimitry Andric 9150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9160b57cec5SDimitry Andric list& operator=(initializer_list<value_type> __il) 9170b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 9180b57cec5SDimitry Andric 9190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9200b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 9210b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 9220b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 9230b57cec5SDimitry Andric 9240b57cec5SDimitry Andric template <class _InpIter> 9250b57cec5SDimitry Andric void assign(_InpIter __f, _InpIter __l, 926480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0); 9270b57cec5SDimitry Andric void assign(size_type __n, const value_type& __x); 9280b57cec5SDimitry Andric 9290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9300b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT; 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9330b57cec5SDimitry Andric size_type size() const _NOEXCEPT {return base::__sz();} 9340b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 9350b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return base::empty();} 9360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9370b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT 9380b57cec5SDimitry Andric { 939e8d8bef9SDimitry Andric return _VSTD::min<size_type>( 9400b57cec5SDimitry Andric base::__node_alloc_max_size(), 9410b57cec5SDimitry Andric numeric_limits<difference_type >::max()); 9420b57cec5SDimitry Andric } 9430b57cec5SDimitry Andric 9440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9450b57cec5SDimitry Andric iterator begin() _NOEXCEPT {return base::begin();} 9460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9470b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT {return base::begin();} 9480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9490b57cec5SDimitry Andric iterator end() _NOEXCEPT {return base::end();} 9500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9510b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT {return base::end();} 9520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9530b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT {return base::begin();} 9540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9550b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT {return base::end();} 9560b57cec5SDimitry Andric 9570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9580b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 9590b57cec5SDimitry Andric {return reverse_iterator(end());} 9600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9610b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 9620b57cec5SDimitry Andric {return const_reverse_iterator(end());} 9630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9640b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 9650b57cec5SDimitry Andric {return reverse_iterator(begin());} 9660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9670b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 9680b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 9690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9700b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 9710b57cec5SDimitry Andric {return const_reverse_iterator(end());} 9720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9730b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 9740b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 9750b57cec5SDimitry Andric 9760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9770b57cec5SDimitry Andric reference front() 9780b57cec5SDimitry Andric { 9790b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); 9800b57cec5SDimitry Andric return base::__end_.__next_->__as_node()->__value_; 9810b57cec5SDimitry Andric } 9820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9830b57cec5SDimitry Andric const_reference front() const 9840b57cec5SDimitry Andric { 9850b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); 9860b57cec5SDimitry Andric return base::__end_.__next_->__as_node()->__value_; 9870b57cec5SDimitry Andric } 9880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9890b57cec5SDimitry Andric reference back() 9900b57cec5SDimitry Andric { 9910b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); 9920b57cec5SDimitry Andric return base::__end_.__prev_->__as_node()->__value_; 9930b57cec5SDimitry Andric } 9940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 9950b57cec5SDimitry Andric const_reference back() const 9960b57cec5SDimitry Andric { 9970b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); 9980b57cec5SDimitry Andric return base::__end_.__prev_->__as_node()->__value_; 9990b57cec5SDimitry Andric } 10000b57cec5SDimitry Andric 10010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10020b57cec5SDimitry Andric void push_front(value_type&& __x); 10030b57cec5SDimitry Andric void push_back(value_type&& __x); 10040b57cec5SDimitry Andric 10050b57cec5SDimitry Andric template <class... _Args> 10060b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 10070b57cec5SDimitry Andric reference emplace_front(_Args&&... __args); 10080b57cec5SDimitry Andric#else 10090b57cec5SDimitry Andric void emplace_front(_Args&&... __args); 10100b57cec5SDimitry Andric#endif 10110b57cec5SDimitry Andric template <class... _Args> 10120b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 10130b57cec5SDimitry Andric reference emplace_back(_Args&&... __args); 10140b57cec5SDimitry Andric#else 10150b57cec5SDimitry Andric void emplace_back(_Args&&... __args); 10160b57cec5SDimitry Andric#endif 10170b57cec5SDimitry Andric template <class... _Args> 10180b57cec5SDimitry Andric iterator emplace(const_iterator __p, _Args&&... __args); 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andric iterator insert(const_iterator __p, value_type&& __x); 10210b57cec5SDimitry Andric 10220b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10230b57cec5SDimitry Andric iterator insert(const_iterator __p, initializer_list<value_type> __il) 10240b57cec5SDimitry Andric {return insert(__p, __il.begin(), __il.end());} 10250b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 10260b57cec5SDimitry Andric 10270b57cec5SDimitry Andric void push_front(const value_type& __x); 10280b57cec5SDimitry Andric void push_back(const value_type& __x); 10290b57cec5SDimitry Andric 10300b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10310b57cec5SDimitry Andric template <class _Arg> 10320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10330b57cec5SDimitry Andric void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); } 10340b57cec5SDimitry Andric#else 10350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10360b57cec5SDimitry Andric void __emplace_back(value_type const& __arg) { push_back(__arg); } 10370b57cec5SDimitry Andric#endif 10380b57cec5SDimitry Andric 10390b57cec5SDimitry Andric iterator insert(const_iterator __p, const value_type& __x); 10400b57cec5SDimitry Andric iterator insert(const_iterator __p, size_type __n, const value_type& __x); 10410b57cec5SDimitry Andric template <class _InpIter> 10420b57cec5SDimitry Andric iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, 1043480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type* = 0); 10440b57cec5SDimitry Andric 10450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10460b57cec5SDimitry Andric void swap(list& __c) 10470b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 10480b57cec5SDimitry Andric _NOEXCEPT 10490b57cec5SDimitry Andric#else 10500b57cec5SDimitry Andric _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || 10510b57cec5SDimitry Andric __is_nothrow_swappable<__node_allocator>::value) 10520b57cec5SDimitry Andric#endif 10530b57cec5SDimitry Andric {base::swap(__c);} 10540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10550b57cec5SDimitry Andric void clear() _NOEXCEPT {base::clear();} 10560b57cec5SDimitry Andric 10570b57cec5SDimitry Andric void pop_front(); 10580b57cec5SDimitry Andric void pop_back(); 10590b57cec5SDimitry Andric 10600b57cec5SDimitry Andric iterator erase(const_iterator __p); 10610b57cec5SDimitry Andric iterator erase(const_iterator __f, const_iterator __l); 10620b57cec5SDimitry Andric 10630b57cec5SDimitry Andric void resize(size_type __n); 10640b57cec5SDimitry Andric void resize(size_type __n, const value_type& __x); 10650b57cec5SDimitry Andric 10660b57cec5SDimitry Andric void splice(const_iterator __p, list& __c); 10670b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10690b57cec5SDimitry Andric void splice(const_iterator __p, list&& __c) {splice(__p, __c);} 10700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10710b57cec5SDimitry Andric void splice(const_iterator __p, list&& __c, const_iterator __i) 10720b57cec5SDimitry Andric {splice(__p, __c, __i);} 10730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10740b57cec5SDimitry Andric void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) 10750b57cec5SDimitry Andric {splice(__p, __c, __f, __l);} 10760b57cec5SDimitry Andric#endif 10770b57cec5SDimitry Andric void splice(const_iterator __p, list& __c, const_iterator __i); 10780b57cec5SDimitry Andric void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); 10790b57cec5SDimitry Andric 10800b57cec5SDimitry Andric __remove_return_type remove(const value_type& __x); 10810b57cec5SDimitry Andric template <class _Pred> __remove_return_type remove_if(_Pred __pred); 10820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10830b57cec5SDimitry Andric __remove_return_type unique() { return unique(__equal_to<value_type>()); } 10840b57cec5SDimitry Andric template <class _BinaryPred> 10850b57cec5SDimitry Andric __remove_return_type unique(_BinaryPred __binary_pred); 10860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10870b57cec5SDimitry Andric void merge(list& __c); 10880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10900b57cec5SDimitry Andric void merge(list&& __c) {merge(__c);} 10910b57cec5SDimitry Andric 10920b57cec5SDimitry Andric template <class _Comp> 10930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 10940b57cec5SDimitry Andric void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} 10950b57cec5SDimitry Andric#endif 10960b57cec5SDimitry Andric template <class _Comp> 10970b57cec5SDimitry Andric void merge(list& __c, _Comp __comp); 10980b57cec5SDimitry Andric 10990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11000b57cec5SDimitry Andric void sort(); 11010b57cec5SDimitry Andric template <class _Comp> 11020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11030b57cec5SDimitry Andric void sort(_Comp __comp); 11040b57cec5SDimitry Andric 11050b57cec5SDimitry Andric void reverse() _NOEXCEPT; 11060b57cec5SDimitry Andric 11070b57cec5SDimitry Andric bool __invariants() const; 11080b57cec5SDimitry Andric 11090b57cec5SDimitry Andric typedef __allocator_destructor<__node_allocator> __node_destructor; 11100b57cec5SDimitry Andric typedef unique_ptr<__node, __node_destructor> __hold_pointer; 11110b57cec5SDimitry Andric 11120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11130b57cec5SDimitry Andric __hold_pointer __allocate_node(__node_allocator& __na) { 11140b57cec5SDimitry Andric __node_pointer __p = __node_alloc_traits::allocate(__na, 1); 11150b57cec5SDimitry Andric __p->__prev_ = nullptr; 11160b57cec5SDimitry Andric return __hold_pointer(__p, __node_destructor(__na, 1)); 11170b57cec5SDimitry Andric } 11180b57cec5SDimitry Andric 1119e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 11200b57cec5SDimitry Andric 11210b57cec5SDimitry Andric bool __dereferenceable(const const_iterator* __i) const; 11220b57cec5SDimitry Andric bool __decrementable(const const_iterator* __i) const; 11230b57cec5SDimitry Andric bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 11240b57cec5SDimitry Andric bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 11250b57cec5SDimitry Andric 1126e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2 11270b57cec5SDimitry Andric 11280b57cec5SDimitry Andricprivate: 11290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11300b57cec5SDimitry Andric static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l); 11310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11320b57cec5SDimitry Andric void __link_nodes_at_front(__link_pointer __f, __link_pointer __l); 11330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11340b57cec5SDimitry Andric void __link_nodes_at_back (__link_pointer __f, __link_pointer __l); 11350b57cec5SDimitry Andric iterator __iterator(size_type __n); 11360b57cec5SDimitry Andric template <class _Comp> 11370b57cec5SDimitry Andric static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); 11380b57cec5SDimitry Andric 11390b57cec5SDimitry Andric void __move_assign(list& __c, true_type) 11400b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); 11410b57cec5SDimitry Andric void __move_assign(list& __c, false_type); 11420b57cec5SDimitry Andric}; 11430b57cec5SDimitry Andric 1144*349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 11450b57cec5SDimitry Andrictemplate<class _InputIterator, 1146fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 1147*349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1148*349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 11490b57cec5SDimitry Andric > 11500b57cec5SDimitry Andriclist(_InputIterator, _InputIterator) 1151fe6060f1SDimitry Andric -> list<__iter_value_type<_InputIterator>, _Alloc>; 11520b57cec5SDimitry Andric 11530b57cec5SDimitry Andrictemplate<class _InputIterator, 11540b57cec5SDimitry Andric class _Alloc, 1155*349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1156*349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 11570b57cec5SDimitry Andric > 11580b57cec5SDimitry Andriclist(_InputIterator, _InputIterator, _Alloc) 1159fe6060f1SDimitry Andric -> list<__iter_value_type<_InputIterator>, _Alloc>; 11600b57cec5SDimitry Andric#endif 11610b57cec5SDimitry Andric 11620b57cec5SDimitry Andric// Link in nodes [__f, __l] just prior to __p 11630b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 11640b57cec5SDimitry Andricinline 11650b57cec5SDimitry Andricvoid 11660b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l) 11670b57cec5SDimitry Andric{ 11680b57cec5SDimitry Andric __p->__prev_->__next_ = __f; 11690b57cec5SDimitry Andric __f->__prev_ = __p->__prev_; 11700b57cec5SDimitry Andric __p->__prev_ = __l; 11710b57cec5SDimitry Andric __l->__next_ = __p; 11720b57cec5SDimitry Andric} 11730b57cec5SDimitry Andric 11740b57cec5SDimitry Andric// Link in nodes [__f, __l] at the front of the list 11750b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 11760b57cec5SDimitry Andricinline 11770b57cec5SDimitry Andricvoid 11780b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l) 11790b57cec5SDimitry Andric{ 11800b57cec5SDimitry Andric __f->__prev_ = base::__end_as_link(); 11810b57cec5SDimitry Andric __l->__next_ = base::__end_.__next_; 11820b57cec5SDimitry Andric __l->__next_->__prev_ = __l; 11830b57cec5SDimitry Andric base::__end_.__next_ = __f; 11840b57cec5SDimitry Andric} 11850b57cec5SDimitry Andric 11860b57cec5SDimitry Andric// Link in nodes [__f, __l] at the back of the list 11870b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 11880b57cec5SDimitry Andricinline 11890b57cec5SDimitry Andricvoid 11900b57cec5SDimitry Andriclist<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l) 11910b57cec5SDimitry Andric{ 11920b57cec5SDimitry Andric __l->__next_ = base::__end_as_link(); 11930b57cec5SDimitry Andric __f->__prev_ = base::__end_.__prev_; 11940b57cec5SDimitry Andric __f->__prev_->__next_ = __f; 11950b57cec5SDimitry Andric base::__end_.__prev_ = __l; 11960b57cec5SDimitry Andric} 11970b57cec5SDimitry Andric 11980b57cec5SDimitry Andric 11990b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12000b57cec5SDimitry Andricinline 12010b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 12020b57cec5SDimitry Andriclist<_Tp, _Alloc>::__iterator(size_type __n) 12030b57cec5SDimitry Andric{ 12040b57cec5SDimitry Andric return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) 12050b57cec5SDimitry Andric : _VSTD::prev(end(), base::__sz() - __n); 12060b57cec5SDimitry Andric} 12070b57cec5SDimitry Andric 12080b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12090b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n) 12100b57cec5SDimitry Andric{ 1211e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12120b57cec5SDimitry Andric __get_db()->__insert_c(this); 12130b57cec5SDimitry Andric#endif 12140b57cec5SDimitry Andric for (; __n > 0; --__n) 12150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12160b57cec5SDimitry Andric emplace_back(); 12170b57cec5SDimitry Andric#else 12180b57cec5SDimitry Andric push_back(value_type()); 12190b57cec5SDimitry Andric#endif 12200b57cec5SDimitry Andric} 12210b57cec5SDimitry Andric 12220b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 12230b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12240b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) 12250b57cec5SDimitry Andric{ 1226e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12270b57cec5SDimitry Andric __get_db()->__insert_c(this); 12280b57cec5SDimitry Andric#endif 12290b57cec5SDimitry Andric for (; __n > 0; --__n) 12300b57cec5SDimitry Andric emplace_back(); 12310b57cec5SDimitry Andric} 12320b57cec5SDimitry Andric#endif 12330b57cec5SDimitry Andric 12340b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12350b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const value_type& __x) 12360b57cec5SDimitry Andric{ 1237e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12380b57cec5SDimitry Andric __get_db()->__insert_c(this); 12390b57cec5SDimitry Andric#endif 12400b57cec5SDimitry Andric for (; __n > 0; --__n) 12410b57cec5SDimitry Andric push_back(__x); 12420b57cec5SDimitry Andric} 12430b57cec5SDimitry Andric 12440b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12450b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) 12460b57cec5SDimitry Andric : base(__a) 12470b57cec5SDimitry Andric{ 1248e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12490b57cec5SDimitry Andric __get_db()->__insert_c(this); 12500b57cec5SDimitry Andric#endif 12510b57cec5SDimitry Andric for (; __n > 0; --__n) 12520b57cec5SDimitry Andric push_back(__x); 12530b57cec5SDimitry Andric} 12540b57cec5SDimitry Andric 12550b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12560b57cec5SDimitry Andrictemplate <class _InpIter> 12570b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, 1258480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*) 12590b57cec5SDimitry Andric{ 1260e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12610b57cec5SDimitry Andric __get_db()->__insert_c(this); 12620b57cec5SDimitry Andric#endif 12630b57cec5SDimitry Andric for (; __f != __l; ++__f) 12640b57cec5SDimitry Andric __emplace_back(*__f); 12650b57cec5SDimitry Andric} 12660b57cec5SDimitry Andric 12670b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12680b57cec5SDimitry Andrictemplate <class _InpIter> 12690b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, 1270480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*) 12710b57cec5SDimitry Andric : base(__a) 12720b57cec5SDimitry Andric{ 1273e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12740b57cec5SDimitry Andric __get_db()->__insert_c(this); 12750b57cec5SDimitry Andric#endif 12760b57cec5SDimitry Andric for (; __f != __l; ++__f) 12770b57cec5SDimitry Andric __emplace_back(*__f); 12780b57cec5SDimitry Andric} 12790b57cec5SDimitry Andric 12800b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 12810b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(const list& __c) 12820b57cec5SDimitry Andric : base(__node_alloc_traits::select_on_container_copy_construction( 12830b57cec5SDimitry Andric __c.__node_alloc())) { 1284e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12850b57cec5SDimitry Andric __get_db()->__insert_c(this); 12860b57cec5SDimitry Andric#endif 12870b57cec5SDimitry Andric for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) 12880b57cec5SDimitry Andric push_back(*__i); 12890b57cec5SDimitry Andric} 12900b57cec5SDimitry Andric 12910b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 1292fe6060f1SDimitry Andriclist<_Tp, _Alloc>::list(const list& __c, const __identity_t<allocator_type>& __a) 12930b57cec5SDimitry Andric : base(__a) 12940b57cec5SDimitry Andric{ 1295e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 12960b57cec5SDimitry Andric __get_db()->__insert_c(this); 12970b57cec5SDimitry Andric#endif 12980b57cec5SDimitry Andric for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) 12990b57cec5SDimitry Andric push_back(*__i); 13000b57cec5SDimitry Andric} 13010b57cec5SDimitry Andric 13020b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 13030b57cec5SDimitry Andric 13040b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13050b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) 13060b57cec5SDimitry Andric : base(__a) 13070b57cec5SDimitry Andric{ 1308e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 13090b57cec5SDimitry Andric __get_db()->__insert_c(this); 13100b57cec5SDimitry Andric#endif 13110b57cec5SDimitry Andric for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), 13120b57cec5SDimitry Andric __e = __il.end(); __i != __e; ++__i) 13130b57cec5SDimitry Andric push_back(*__i); 13140b57cec5SDimitry Andric} 13150b57cec5SDimitry Andric 13160b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13170b57cec5SDimitry Andriclist<_Tp, _Alloc>::list(initializer_list<value_type> __il) 13180b57cec5SDimitry Andric{ 1319e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 13200b57cec5SDimitry Andric __get_db()->__insert_c(this); 13210b57cec5SDimitry Andric#endif 13220b57cec5SDimitry Andric for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), 13230b57cec5SDimitry Andric __e = __il.end(); __i != __e; ++__i) 13240b57cec5SDimitry Andric push_back(*__i); 13250b57cec5SDimitry Andric} 13260b57cec5SDimitry Andric 13270b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13280b57cec5SDimitry Andricinline list<_Tp, _Alloc>::list(list&& __c) 13290b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) 13300b57cec5SDimitry Andric : base(_VSTD::move(__c.__node_alloc())) { 1331e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 13320b57cec5SDimitry Andric __get_db()->__insert_c(this); 13330b57cec5SDimitry Andric#endif 13340b57cec5SDimitry Andric splice(end(), __c); 13350b57cec5SDimitry Andric} 13360b57cec5SDimitry Andric 13370b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13380b57cec5SDimitry Andricinline 1339fe6060f1SDimitry Andriclist<_Tp, _Alloc>::list(list&& __c, const __identity_t<allocator_type>& __a) 13400b57cec5SDimitry Andric : base(__a) 13410b57cec5SDimitry Andric{ 1342e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 13430b57cec5SDimitry Andric __get_db()->__insert_c(this); 13440b57cec5SDimitry Andric#endif 13450b57cec5SDimitry Andric if (__a == __c.get_allocator()) 13460b57cec5SDimitry Andric splice(end(), __c); 13470b57cec5SDimitry Andric else 13480b57cec5SDimitry Andric { 13490b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13500b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 13510b57cec5SDimitry Andric } 13520b57cec5SDimitry Andric} 13530b57cec5SDimitry Andric 13540b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13550b57cec5SDimitry Andricinline 13560b57cec5SDimitry Andriclist<_Tp, _Alloc>& 13570b57cec5SDimitry Andriclist<_Tp, _Alloc>::operator=(list&& __c) 13580b57cec5SDimitry Andric _NOEXCEPT_( 13590b57cec5SDimitry Andric __node_alloc_traits::propagate_on_container_move_assignment::value && 13600b57cec5SDimitry Andric is_nothrow_move_assignable<__node_allocator>::value) 13610b57cec5SDimitry Andric{ 13620b57cec5SDimitry Andric __move_assign(__c, integral_constant<bool, 13630b57cec5SDimitry Andric __node_alloc_traits::propagate_on_container_move_assignment::value>()); 13640b57cec5SDimitry Andric return *this; 13650b57cec5SDimitry Andric} 13660b57cec5SDimitry Andric 13670b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13680b57cec5SDimitry Andricvoid 13690b57cec5SDimitry Andriclist<_Tp, _Alloc>::__move_assign(list& __c, false_type) 13700b57cec5SDimitry Andric{ 13710b57cec5SDimitry Andric if (base::__node_alloc() != __c.__node_alloc()) 13720b57cec5SDimitry Andric { 13730b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13740b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 13750b57cec5SDimitry Andric } 13760b57cec5SDimitry Andric else 13770b57cec5SDimitry Andric __move_assign(__c, true_type()); 13780b57cec5SDimitry Andric} 13790b57cec5SDimitry Andric 13800b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13810b57cec5SDimitry Andricvoid 13820b57cec5SDimitry Andriclist<_Tp, _Alloc>::__move_assign(list& __c, true_type) 13830b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) 13840b57cec5SDimitry Andric{ 13850b57cec5SDimitry Andric clear(); 13860b57cec5SDimitry Andric base::__move_assign_alloc(__c); 13870b57cec5SDimitry Andric splice(end(), __c); 13880b57cec5SDimitry Andric} 13890b57cec5SDimitry Andric 13900b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 13910b57cec5SDimitry Andric 13920b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 13930b57cec5SDimitry Andricinline 13940b57cec5SDimitry Andriclist<_Tp, _Alloc>& 13950b57cec5SDimitry Andriclist<_Tp, _Alloc>::operator=(const list& __c) 13960b57cec5SDimitry Andric{ 1397*349cc55cSDimitry Andric if (this != _VSTD::addressof(__c)) 13980b57cec5SDimitry Andric { 13990b57cec5SDimitry Andric base::__copy_assign_alloc(__c); 14000b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 14010b57cec5SDimitry Andric } 14020b57cec5SDimitry Andric return *this; 14030b57cec5SDimitry Andric} 14040b57cec5SDimitry Andric 14050b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 14060b57cec5SDimitry Andrictemplate <class _InpIter> 14070b57cec5SDimitry Andricvoid 14080b57cec5SDimitry Andriclist<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, 1409480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*) 14100b57cec5SDimitry Andric{ 14110b57cec5SDimitry Andric iterator __i = begin(); 14120b57cec5SDimitry Andric iterator __e = end(); 1413*349cc55cSDimitry Andric for (; __f != __l && __i != __e; ++__f, (void) ++__i) 14140b57cec5SDimitry Andric *__i = *__f; 14150b57cec5SDimitry Andric if (__i == __e) 14160b57cec5SDimitry Andric insert(__e, __f, __l); 14170b57cec5SDimitry Andric else 14180b57cec5SDimitry Andric erase(__i, __e); 1419e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 14200b57cec5SDimitry Andric __get_db()->__invalidate_all(this); 14210b57cec5SDimitry Andric#endif 14220b57cec5SDimitry Andric} 14230b57cec5SDimitry Andric 14240b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 14250b57cec5SDimitry Andricvoid 14260b57cec5SDimitry Andriclist<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) 14270b57cec5SDimitry Andric{ 14280b57cec5SDimitry Andric iterator __i = begin(); 14290b57cec5SDimitry Andric iterator __e = end(); 1430*349cc55cSDimitry Andric for (; __n > 0 && __i != __e; --__n, (void) ++__i) 14310b57cec5SDimitry Andric *__i = __x; 14320b57cec5SDimitry Andric if (__i == __e) 14330b57cec5SDimitry Andric insert(__e, __n, __x); 14340b57cec5SDimitry Andric else 14350b57cec5SDimitry Andric erase(__i, __e); 1436e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 14370b57cec5SDimitry Andric __get_db()->__invalidate_all(this); 14380b57cec5SDimitry Andric#endif 14390b57cec5SDimitry Andric} 14400b57cec5SDimitry Andric 14410b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 14420b57cec5SDimitry Andricinline 14430b57cec5SDimitry Andric_Alloc 14440b57cec5SDimitry Andriclist<_Tp, _Alloc>::get_allocator() const _NOEXCEPT 14450b57cec5SDimitry Andric{ 14460b57cec5SDimitry Andric return allocator_type(base::__node_alloc()); 14470b57cec5SDimitry Andric} 14480b57cec5SDimitry Andric 14490b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 14500b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 14510b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) 14520b57cec5SDimitry Andric{ 1453e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1454*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 14550b57cec5SDimitry Andric "list::insert(iterator, x) called with an iterator not" 14560b57cec5SDimitry Andric " referring to this list"); 14570b57cec5SDimitry Andric#endif 14580b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 14590b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 14600b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 14610b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); 14620b57cec5SDimitry Andric ++base::__sz(); 1463e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 14640b57cec5SDimitry Andric return iterator(__hold.release()->__as_link(), this); 14650b57cec5SDimitry Andric#else 14660b57cec5SDimitry Andric return iterator(__hold.release()->__as_link()); 14670b57cec5SDimitry Andric#endif 14680b57cec5SDimitry Andric} 14690b57cec5SDimitry Andric 14700b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 14710b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 14720b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) 14730b57cec5SDimitry Andric{ 1474e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1475*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 14760b57cec5SDimitry Andric "list::insert(iterator, n, x) called with an iterator not" 14770b57cec5SDimitry Andric " referring to this list"); 14780b57cec5SDimitry Andric iterator __r(__p.__ptr_, this); 14790b57cec5SDimitry Andric#else 14800b57cec5SDimitry Andric iterator __r(__p.__ptr_); 14810b57cec5SDimitry Andric#endif 14820b57cec5SDimitry Andric if (__n > 0) 14830b57cec5SDimitry Andric { 14840b57cec5SDimitry Andric size_type __ds = 0; 14850b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 14860b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 14870b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 14880b57cec5SDimitry Andric ++__ds; 1489e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 14900b57cec5SDimitry Andric __r = iterator(__hold->__as_link(), this); 14910b57cec5SDimitry Andric#else 14920b57cec5SDimitry Andric __r = iterator(__hold->__as_link()); 14930b57cec5SDimitry Andric#endif 14940b57cec5SDimitry Andric __hold.release(); 14950b57cec5SDimitry Andric iterator __e = __r; 14960b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 14970b57cec5SDimitry Andric try 14980b57cec5SDimitry Andric { 14990b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 1500*349cc55cSDimitry Andric for (--__n; __n != 0; --__n, (void) ++__e, ++__ds) 15010b57cec5SDimitry Andric { 15020b57cec5SDimitry Andric __hold.reset(__node_alloc_traits::allocate(__na, 1)); 15030b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 15040b57cec5SDimitry Andric __e.__ptr_->__next_ = __hold->__as_link(); 15050b57cec5SDimitry Andric __hold->__prev_ = __e.__ptr_; 15060b57cec5SDimitry Andric __hold.release(); 15070b57cec5SDimitry Andric } 15080b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 15090b57cec5SDimitry Andric } 15100b57cec5SDimitry Andric catch (...) 15110b57cec5SDimitry Andric { 15120b57cec5SDimitry Andric while (true) 15130b57cec5SDimitry Andric { 15140b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 15150b57cec5SDimitry Andric __link_pointer __prev = __e.__ptr_->__prev_; 15160b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); 15170b57cec5SDimitry Andric if (__prev == 0) 15180b57cec5SDimitry Andric break; 1519e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 15200b57cec5SDimitry Andric __e = iterator(__prev, this); 15210b57cec5SDimitry Andric#else 15220b57cec5SDimitry Andric __e = iterator(__prev); 15230b57cec5SDimitry Andric#endif 15240b57cec5SDimitry Andric } 15250b57cec5SDimitry Andric throw; 15260b57cec5SDimitry Andric } 15270b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 15280b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); 15290b57cec5SDimitry Andric base::__sz() += __ds; 15300b57cec5SDimitry Andric } 15310b57cec5SDimitry Andric return __r; 15320b57cec5SDimitry Andric} 15330b57cec5SDimitry Andric 15340b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 15350b57cec5SDimitry Andrictemplate <class _InpIter> 15360b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 15370b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, 1538480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*) 15390b57cec5SDimitry Andric{ 1540e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1541*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 15420b57cec5SDimitry Andric "list::insert(iterator, range) called with an iterator not" 15430b57cec5SDimitry Andric " referring to this list"); 15440b57cec5SDimitry Andric iterator __r(__p.__ptr_, this); 15450b57cec5SDimitry Andric#else 15460b57cec5SDimitry Andric iterator __r(__p.__ptr_); 15470b57cec5SDimitry Andric#endif 15480b57cec5SDimitry Andric if (__f != __l) 15490b57cec5SDimitry Andric { 15500b57cec5SDimitry Andric size_type __ds = 0; 15510b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 15520b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 15530b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); 15540b57cec5SDimitry Andric ++__ds; 1555e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 15560b57cec5SDimitry Andric __r = iterator(__hold.get()->__as_link(), this); 15570b57cec5SDimitry Andric#else 15580b57cec5SDimitry Andric __r = iterator(__hold.get()->__as_link()); 15590b57cec5SDimitry Andric#endif 15600b57cec5SDimitry Andric __hold.release(); 15610b57cec5SDimitry Andric iterator __e = __r; 15620b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 15630b57cec5SDimitry Andric try 15640b57cec5SDimitry Andric { 15650b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 1566*349cc55cSDimitry Andric for (++__f; __f != __l; ++__f, (void) ++__e, ++__ds) 15670b57cec5SDimitry Andric { 15680b57cec5SDimitry Andric __hold.reset(__node_alloc_traits::allocate(__na, 1)); 15690b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); 15700b57cec5SDimitry Andric __e.__ptr_->__next_ = __hold.get()->__as_link(); 15710b57cec5SDimitry Andric __hold->__prev_ = __e.__ptr_; 15720b57cec5SDimitry Andric __hold.release(); 15730b57cec5SDimitry Andric } 15740b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 15750b57cec5SDimitry Andric } 15760b57cec5SDimitry Andric catch (...) 15770b57cec5SDimitry Andric { 15780b57cec5SDimitry Andric while (true) 15790b57cec5SDimitry Andric { 15800b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 15810b57cec5SDimitry Andric __link_pointer __prev = __e.__ptr_->__prev_; 15820b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); 15830b57cec5SDimitry Andric if (__prev == 0) 15840b57cec5SDimitry Andric break; 1585e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 15860b57cec5SDimitry Andric __e = iterator(__prev, this); 15870b57cec5SDimitry Andric#else 15880b57cec5SDimitry Andric __e = iterator(__prev); 15890b57cec5SDimitry Andric#endif 15900b57cec5SDimitry Andric } 15910b57cec5SDimitry Andric throw; 15920b57cec5SDimitry Andric } 15930b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 15940b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); 15950b57cec5SDimitry Andric base::__sz() += __ds; 15960b57cec5SDimitry Andric } 15970b57cec5SDimitry Andric return __r; 15980b57cec5SDimitry Andric} 15990b57cec5SDimitry Andric 16000b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16010b57cec5SDimitry Andricvoid 16020b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_front(const value_type& __x) 16030b57cec5SDimitry Andric{ 16040b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16050b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16060b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 16070b57cec5SDimitry Andric __link_pointer __nl = __hold->__as_link(); 16080b57cec5SDimitry Andric __link_nodes_at_front(__nl, __nl); 16090b57cec5SDimitry Andric ++base::__sz(); 16100b57cec5SDimitry Andric __hold.release(); 16110b57cec5SDimitry Andric} 16120b57cec5SDimitry Andric 16130b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16140b57cec5SDimitry Andricvoid 16150b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_back(const value_type& __x) 16160b57cec5SDimitry Andric{ 16170b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16180b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16190b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 16200b57cec5SDimitry Andric __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); 16210b57cec5SDimitry Andric ++base::__sz(); 16220b57cec5SDimitry Andric __hold.release(); 16230b57cec5SDimitry Andric} 16240b57cec5SDimitry Andric 16250b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16260b57cec5SDimitry Andric 16270b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16280b57cec5SDimitry Andricvoid 16290b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_front(value_type&& __x) 16300b57cec5SDimitry Andric{ 16310b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16320b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16330b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 16340b57cec5SDimitry Andric __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); 16350b57cec5SDimitry Andric ++base::__sz(); 16360b57cec5SDimitry Andric __hold.release(); 16370b57cec5SDimitry Andric} 16380b57cec5SDimitry Andric 16390b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16400b57cec5SDimitry Andricvoid 16410b57cec5SDimitry Andriclist<_Tp, _Alloc>::push_back(value_type&& __x) 16420b57cec5SDimitry Andric{ 16430b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16440b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16450b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 16460b57cec5SDimitry Andric __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); 16470b57cec5SDimitry Andric ++base::__sz(); 16480b57cec5SDimitry Andric __hold.release(); 16490b57cec5SDimitry Andric} 16500b57cec5SDimitry Andric 16510b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16520b57cec5SDimitry Andrictemplate <class... _Args> 16530b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16540b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::reference 16550b57cec5SDimitry Andric#else 16560b57cec5SDimitry Andricvoid 16570b57cec5SDimitry Andric#endif 16580b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace_front(_Args&&... __args) 16590b57cec5SDimitry Andric{ 16600b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16610b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16620b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 16630b57cec5SDimitry Andric __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); 16640b57cec5SDimitry Andric ++base::__sz(); 16650b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16660b57cec5SDimitry Andric return __hold.release()->__value_; 16670b57cec5SDimitry Andric#else 16680b57cec5SDimitry Andric __hold.release(); 16690b57cec5SDimitry Andric#endif 16700b57cec5SDimitry Andric} 16710b57cec5SDimitry Andric 16720b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16730b57cec5SDimitry Andrictemplate <class... _Args> 16740b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16750b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::reference 16760b57cec5SDimitry Andric#else 16770b57cec5SDimitry Andricvoid 16780b57cec5SDimitry Andric#endif 16790b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace_back(_Args&&... __args) 16800b57cec5SDimitry Andric{ 16810b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 16820b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 16830b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 16840b57cec5SDimitry Andric __link_pointer __nl = __hold->__as_link(); 16850b57cec5SDimitry Andric __link_nodes_at_back(__nl, __nl); 16860b57cec5SDimitry Andric ++base::__sz(); 16870b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16880b57cec5SDimitry Andric return __hold.release()->__value_; 16890b57cec5SDimitry Andric#else 16900b57cec5SDimitry Andric __hold.release(); 16910b57cec5SDimitry Andric#endif 16920b57cec5SDimitry Andric} 16930b57cec5SDimitry Andric 16940b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 16950b57cec5SDimitry Andrictemplate <class... _Args> 16960b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 16970b57cec5SDimitry Andriclist<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) 16980b57cec5SDimitry Andric{ 1699e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1700*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 17010b57cec5SDimitry Andric "list::emplace(iterator, args...) called with an iterator not" 17020b57cec5SDimitry Andric " referring to this list"); 17030b57cec5SDimitry Andric#endif 17040b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 17050b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 17060b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 17070b57cec5SDimitry Andric __link_pointer __nl = __hold.get()->__as_link(); 17080b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __nl, __nl); 17090b57cec5SDimitry Andric ++base::__sz(); 17100b57cec5SDimitry Andric __hold.release(); 1711e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 17120b57cec5SDimitry Andric return iterator(__nl, this); 17130b57cec5SDimitry Andric#else 17140b57cec5SDimitry Andric return iterator(__nl); 17150b57cec5SDimitry Andric#endif 17160b57cec5SDimitry Andric} 17170b57cec5SDimitry Andric 17180b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 17190b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 17200b57cec5SDimitry Andriclist<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) 17210b57cec5SDimitry Andric{ 1722e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1723*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 17240b57cec5SDimitry Andric "list::insert(iterator, x) called with an iterator not" 17250b57cec5SDimitry Andric " referring to this list"); 17260b57cec5SDimitry Andric#endif 17270b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 17280b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 17290b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 17300b57cec5SDimitry Andric __link_pointer __nl = __hold->__as_link(); 17310b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __nl, __nl); 17320b57cec5SDimitry Andric ++base::__sz(); 17330b57cec5SDimitry Andric __hold.release(); 1734e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 17350b57cec5SDimitry Andric return iterator(__nl, this); 17360b57cec5SDimitry Andric#else 17370b57cec5SDimitry Andric return iterator(__nl); 17380b57cec5SDimitry Andric#endif 17390b57cec5SDimitry Andric} 17400b57cec5SDimitry Andric 17410b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 17420b57cec5SDimitry Andric 17430b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 17440b57cec5SDimitry Andricvoid 17450b57cec5SDimitry Andriclist<_Tp, _Alloc>::pop_front() 17460b57cec5SDimitry Andric{ 17470b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); 17480b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 17490b57cec5SDimitry Andric __link_pointer __n = base::__end_.__next_; 17500b57cec5SDimitry Andric base::__unlink_nodes(__n, __n); 17510b57cec5SDimitry Andric --base::__sz(); 1752e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 17530b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 17540b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) 17550b57cec5SDimitry Andric { 17560b57cec5SDimitry Andric --__p; 17570b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__p)->__i_); 17580b57cec5SDimitry Andric if (__i->__ptr_ == __n) 17590b57cec5SDimitry Andric { 17600b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 17610b57cec5SDimitry Andric if (--__c->end_ != __p) 1762e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 17630b57cec5SDimitry Andric } 17640b57cec5SDimitry Andric } 17650b57cec5SDimitry Andric __get_db()->unlock(); 17660b57cec5SDimitry Andric#endif 17670b57cec5SDimitry Andric __node_pointer __np = __n->__as_node(); 17680b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); 17690b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __np, 1); 17700b57cec5SDimitry Andric} 17710b57cec5SDimitry Andric 17720b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 17730b57cec5SDimitry Andricvoid 17740b57cec5SDimitry Andriclist<_Tp, _Alloc>::pop_back() 17750b57cec5SDimitry Andric{ 1776fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "list::pop_back() called on an empty list"); 17770b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 17780b57cec5SDimitry Andric __link_pointer __n = base::__end_.__prev_; 17790b57cec5SDimitry Andric base::__unlink_nodes(__n, __n); 17800b57cec5SDimitry Andric --base::__sz(); 1781e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 17820b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 17830b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) 17840b57cec5SDimitry Andric { 17850b57cec5SDimitry Andric --__p; 17860b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__p)->__i_); 17870b57cec5SDimitry Andric if (__i->__ptr_ == __n) 17880b57cec5SDimitry Andric { 17890b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 17900b57cec5SDimitry Andric if (--__c->end_ != __p) 1791e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 17920b57cec5SDimitry Andric } 17930b57cec5SDimitry Andric } 17940b57cec5SDimitry Andric __get_db()->unlock(); 17950b57cec5SDimitry Andric#endif 17960b57cec5SDimitry Andric __node_pointer __np = __n->__as_node(); 17970b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); 17980b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __np, 1); 17990b57cec5SDimitry Andric} 18000b57cec5SDimitry Andric 18010b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 18020b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 18030b57cec5SDimitry Andriclist<_Tp, _Alloc>::erase(const_iterator __p) 18040b57cec5SDimitry Andric{ 1805e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1806*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 18070b57cec5SDimitry Andric "list::erase(iterator) called with an iterator not" 18080b57cec5SDimitry Andric " referring to this list"); 18090b57cec5SDimitry Andric#endif 18100b57cec5SDimitry Andric _LIBCPP_ASSERT(__p != end(), 18110b57cec5SDimitry Andric "list::erase(iterator) called with a non-dereferenceable iterator"); 18120b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 18130b57cec5SDimitry Andric __link_pointer __n = __p.__ptr_; 18140b57cec5SDimitry Andric __link_pointer __r = __n->__next_; 18150b57cec5SDimitry Andric base::__unlink_nodes(__n, __n); 18160b57cec5SDimitry Andric --base::__sz(); 1817e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 18180b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 18190b57cec5SDimitry Andric for (__i_node** __ip = __c->end_; __ip != __c->beg_; ) 18200b57cec5SDimitry Andric { 18210b57cec5SDimitry Andric --__ip; 18220b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__ip)->__i_); 18230b57cec5SDimitry Andric if (__i->__ptr_ == __n) 18240b57cec5SDimitry Andric { 18250b57cec5SDimitry Andric (*__ip)->__c_ = nullptr; 18260b57cec5SDimitry Andric if (--__c->end_ != __ip) 1827e8d8bef9SDimitry Andric _VSTD::memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*)); 18280b57cec5SDimitry Andric } 18290b57cec5SDimitry Andric } 18300b57cec5SDimitry Andric __get_db()->unlock(); 18310b57cec5SDimitry Andric#endif 18320b57cec5SDimitry Andric __node_pointer __np = __n->__as_node(); 18330b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); 18340b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __np, 1); 1835e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 18360b57cec5SDimitry Andric return iterator(__r, this); 18370b57cec5SDimitry Andric#else 18380b57cec5SDimitry Andric return iterator(__r); 18390b57cec5SDimitry Andric#endif 18400b57cec5SDimitry Andric} 18410b57cec5SDimitry Andric 18420b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 18430b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 18440b57cec5SDimitry Andriclist<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) 18450b57cec5SDimitry Andric{ 1846e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 1847*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == this, 18480b57cec5SDimitry Andric "list::erase(iterator, iterator) called with an iterator not" 18490b57cec5SDimitry Andric " referring to this list"); 1850*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == this, 18510b57cec5SDimitry Andric "list::erase(iterator, iterator) called with an iterator not" 18520b57cec5SDimitry Andric " referring to this list"); 18530b57cec5SDimitry Andric#endif 18540b57cec5SDimitry Andric if (__f != __l) 18550b57cec5SDimitry Andric { 18560b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 18570b57cec5SDimitry Andric base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); 18580b57cec5SDimitry Andric while (__f != __l) 18590b57cec5SDimitry Andric { 18600b57cec5SDimitry Andric __link_pointer __n = __f.__ptr_; 18610b57cec5SDimitry Andric ++__f; 18620b57cec5SDimitry Andric --base::__sz(); 1863e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 18640b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 18650b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) 18660b57cec5SDimitry Andric { 18670b57cec5SDimitry Andric --__p; 18680b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__p)->__i_); 18690b57cec5SDimitry Andric if (__i->__ptr_ == __n) 18700b57cec5SDimitry Andric { 18710b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 18720b57cec5SDimitry Andric if (--__c->end_ != __p) 1873e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 18740b57cec5SDimitry Andric } 18750b57cec5SDimitry Andric } 18760b57cec5SDimitry Andric __get_db()->unlock(); 18770b57cec5SDimitry Andric#endif 18780b57cec5SDimitry Andric __node_pointer __np = __n->__as_node(); 18790b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); 18800b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __np, 1); 18810b57cec5SDimitry Andric } 18820b57cec5SDimitry Andric } 1883e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 18840b57cec5SDimitry Andric return iterator(__l.__ptr_, this); 18850b57cec5SDimitry Andric#else 18860b57cec5SDimitry Andric return iterator(__l.__ptr_); 18870b57cec5SDimitry Andric#endif 18880b57cec5SDimitry Andric} 18890b57cec5SDimitry Andric 18900b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 18910b57cec5SDimitry Andricvoid 18920b57cec5SDimitry Andriclist<_Tp, _Alloc>::resize(size_type __n) 18930b57cec5SDimitry Andric{ 18940b57cec5SDimitry Andric if (__n < base::__sz()) 18950b57cec5SDimitry Andric erase(__iterator(__n), end()); 18960b57cec5SDimitry Andric else if (__n > base::__sz()) 18970b57cec5SDimitry Andric { 18980b57cec5SDimitry Andric __n -= base::__sz(); 18990b57cec5SDimitry Andric size_type __ds = 0; 19000b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 19010b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 19020b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); 19030b57cec5SDimitry Andric ++__ds; 1904e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 19050b57cec5SDimitry Andric iterator __r = iterator(__hold.release()->__as_link(), this); 19060b57cec5SDimitry Andric#else 19070b57cec5SDimitry Andric iterator __r = iterator(__hold.release()->__as_link()); 19080b57cec5SDimitry Andric#endif 19090b57cec5SDimitry Andric iterator __e = __r; 19100b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19110b57cec5SDimitry Andric try 19120b57cec5SDimitry Andric { 19130b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 1914*349cc55cSDimitry Andric for (--__n; __n != 0; --__n, (void) ++__e, ++__ds) 19150b57cec5SDimitry Andric { 19160b57cec5SDimitry Andric __hold.reset(__node_alloc_traits::allocate(__na, 1)); 19170b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); 19180b57cec5SDimitry Andric __e.__ptr_->__next_ = __hold.get()->__as_link(); 19190b57cec5SDimitry Andric __hold->__prev_ = __e.__ptr_; 19200b57cec5SDimitry Andric __hold.release(); 19210b57cec5SDimitry Andric } 19220b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19230b57cec5SDimitry Andric } 19240b57cec5SDimitry Andric catch (...) 19250b57cec5SDimitry Andric { 19260b57cec5SDimitry Andric while (true) 19270b57cec5SDimitry Andric { 19280b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 19290b57cec5SDimitry Andric __link_pointer __prev = __e.__ptr_->__prev_; 19300b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); 19310b57cec5SDimitry Andric if (__prev == 0) 19320b57cec5SDimitry Andric break; 1933e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 19340b57cec5SDimitry Andric __e = iterator(__prev, this); 19350b57cec5SDimitry Andric#else 19360b57cec5SDimitry Andric __e = iterator(__prev); 19370b57cec5SDimitry Andric#endif 19380b57cec5SDimitry Andric } 19390b57cec5SDimitry Andric throw; 19400b57cec5SDimitry Andric } 19410b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 19420b57cec5SDimitry Andric __link_nodes_at_back(__r.__ptr_, __e.__ptr_); 19430b57cec5SDimitry Andric base::__sz() += __ds; 19440b57cec5SDimitry Andric } 19450b57cec5SDimitry Andric} 19460b57cec5SDimitry Andric 19470b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 19480b57cec5SDimitry Andricvoid 19490b57cec5SDimitry Andriclist<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) 19500b57cec5SDimitry Andric{ 19510b57cec5SDimitry Andric if (__n < base::__sz()) 19520b57cec5SDimitry Andric erase(__iterator(__n), end()); 19530b57cec5SDimitry Andric else if (__n > base::__sz()) 19540b57cec5SDimitry Andric { 19550b57cec5SDimitry Andric __n -= base::__sz(); 19560b57cec5SDimitry Andric size_type __ds = 0; 19570b57cec5SDimitry Andric __node_allocator& __na = base::__node_alloc(); 19580b57cec5SDimitry Andric __hold_pointer __hold = __allocate_node(__na); 19590b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 19600b57cec5SDimitry Andric ++__ds; 19610b57cec5SDimitry Andric __link_pointer __nl = __hold.release()->__as_link(); 1962e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 19630b57cec5SDimitry Andric iterator __r = iterator(__nl, this); 19640b57cec5SDimitry Andric#else 19650b57cec5SDimitry Andric iterator __r = iterator(__nl); 19660b57cec5SDimitry Andric#endif 19670b57cec5SDimitry Andric iterator __e = __r; 19680b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19690b57cec5SDimitry Andric try 19700b57cec5SDimitry Andric { 19710b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 1972*349cc55cSDimitry Andric for (--__n; __n != 0; --__n, (void) ++__e, ++__ds) 19730b57cec5SDimitry Andric { 19740b57cec5SDimitry Andric __hold.reset(__node_alloc_traits::allocate(__na, 1)); 19750b57cec5SDimitry Andric __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 19760b57cec5SDimitry Andric __e.__ptr_->__next_ = __hold.get()->__as_link(); 19770b57cec5SDimitry Andric __hold->__prev_ = __e.__ptr_; 19780b57cec5SDimitry Andric __hold.release(); 19790b57cec5SDimitry Andric } 19800b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19810b57cec5SDimitry Andric } 19820b57cec5SDimitry Andric catch (...) 19830b57cec5SDimitry Andric { 19840b57cec5SDimitry Andric while (true) 19850b57cec5SDimitry Andric { 19860b57cec5SDimitry Andric __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 19870b57cec5SDimitry Andric __link_pointer __prev = __e.__ptr_->__prev_; 19880b57cec5SDimitry Andric __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); 19890b57cec5SDimitry Andric if (__prev == 0) 19900b57cec5SDimitry Andric break; 1991e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 19920b57cec5SDimitry Andric __e = iterator(__prev, this); 19930b57cec5SDimitry Andric#else 19940b57cec5SDimitry Andric __e = iterator(__prev); 19950b57cec5SDimitry Andric#endif 19960b57cec5SDimitry Andric } 19970b57cec5SDimitry Andric throw; 19980b57cec5SDimitry Andric } 19990b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 20000b57cec5SDimitry Andric __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_); 20010b57cec5SDimitry Andric base::__sz() += __ds; 20020b57cec5SDimitry Andric } 20030b57cec5SDimitry Andric} 20040b57cec5SDimitry Andric 20050b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 20060b57cec5SDimitry Andricvoid 20070b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c) 20080b57cec5SDimitry Andric{ 2009*349cc55cSDimitry Andric _LIBCPP_ASSERT(this != _VSTD::addressof(__c), 20100b57cec5SDimitry Andric "list::splice(iterator, list) called with this == &list"); 2011e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2012*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 20130b57cec5SDimitry Andric "list::splice(iterator, list) called with an iterator not" 20140b57cec5SDimitry Andric " referring to this list"); 20150b57cec5SDimitry Andric#endif 20160b57cec5SDimitry Andric if (!__c.empty()) 20170b57cec5SDimitry Andric { 20180b57cec5SDimitry Andric __link_pointer __f = __c.__end_.__next_; 20190b57cec5SDimitry Andric __link_pointer __l = __c.__end_.__prev_; 20200b57cec5SDimitry Andric base::__unlink_nodes(__f, __l); 20210b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __f, __l); 20220b57cec5SDimitry Andric base::__sz() += __c.__sz(); 20230b57cec5SDimitry Andric __c.__sz() = 0; 2024e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2025*349cc55cSDimitry Andric if (_VSTD::addressof(__c) != this) { 20260b57cec5SDimitry Andric __libcpp_db* __db = __get_db(); 20270b57cec5SDimitry Andric __c_node* __cn1 = __db->__find_c_and_lock(this); 2028*349cc55cSDimitry Andric __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); 20290b57cec5SDimitry Andric for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) 20300b57cec5SDimitry Andric { 20310b57cec5SDimitry Andric --__ip; 20320b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__ip)->__i_); 20330b57cec5SDimitry Andric if (__i->__ptr_ != __c.__end_as_link()) 20340b57cec5SDimitry Andric { 20350b57cec5SDimitry Andric __cn1->__add(*__ip); 20360b57cec5SDimitry Andric (*__ip)->__c_ = __cn1; 20370b57cec5SDimitry Andric if (--__cn2->end_ != __ip) 2038e8d8bef9SDimitry Andric _VSTD::memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); 20390b57cec5SDimitry Andric } 20400b57cec5SDimitry Andric } 20410b57cec5SDimitry Andric __db->unlock(); 20420b57cec5SDimitry Andric } 20430b57cec5SDimitry Andric#endif 20440b57cec5SDimitry Andric } 20450b57cec5SDimitry Andric} 20460b57cec5SDimitry Andric 20470b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 20480b57cec5SDimitry Andricvoid 20490b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) 20500b57cec5SDimitry Andric{ 2051e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2052*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 2053fe6060f1SDimitry Andric "list::splice(iterator, list, iterator) called with the first iterator" 2054fe6060f1SDimitry Andric " not referring to this list"); 2055*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__i)) == _VSTD::addressof(__c), 2056fe6060f1SDimitry Andric "list::splice(iterator, list, iterator) called with the second iterator" 2057fe6060f1SDimitry Andric " not referring to the list argument"); 2058*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(_VSTD::addressof(__i)), 2059fe6060f1SDimitry Andric "list::splice(iterator, list, iterator) called with the second iterator" 2060fe6060f1SDimitry Andric " not dereferenceable"); 20610b57cec5SDimitry Andric#endif 20620b57cec5SDimitry Andric if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) 20630b57cec5SDimitry Andric { 20640b57cec5SDimitry Andric __link_pointer __f = __i.__ptr_; 20650b57cec5SDimitry Andric base::__unlink_nodes(__f, __f); 20660b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __f, __f); 20670b57cec5SDimitry Andric --__c.__sz(); 20680b57cec5SDimitry Andric ++base::__sz(); 2069e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2070*349cc55cSDimitry Andric if (_VSTD::addressof(__c) != this) { 20710b57cec5SDimitry Andric __libcpp_db* __db = __get_db(); 20720b57cec5SDimitry Andric __c_node* __cn1 = __db->__find_c_and_lock(this); 2073*349cc55cSDimitry Andric __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); 20740b57cec5SDimitry Andric for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) 20750b57cec5SDimitry Andric { 20760b57cec5SDimitry Andric --__ip; 20770b57cec5SDimitry Andric iterator* __j = static_cast<iterator*>((*__ip)->__i_); 20780b57cec5SDimitry Andric if (__j->__ptr_ == __f) 20790b57cec5SDimitry Andric { 20800b57cec5SDimitry Andric __cn1->__add(*__ip); 20810b57cec5SDimitry Andric (*__ip)->__c_ = __cn1; 20820b57cec5SDimitry Andric if (--__cn2->end_ != __ip) 2083e8d8bef9SDimitry Andric _VSTD::memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); 20840b57cec5SDimitry Andric } 20850b57cec5SDimitry Andric } 20860b57cec5SDimitry Andric __db->unlock(); 20870b57cec5SDimitry Andric } 20880b57cec5SDimitry Andric#endif 20890b57cec5SDimitry Andric } 20900b57cec5SDimitry Andric} 20910b57cec5SDimitry Andric 20920b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 20930b57cec5SDimitry Andricvoid 20940b57cec5SDimitry Andriclist<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) 20950b57cec5SDimitry Andric{ 2096e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2097*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this, 20980b57cec5SDimitry Andric "list::splice(iterator, list, iterator, iterator) called with first iterator not" 20990b57cec5SDimitry Andric " referring to this list"); 2100*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == _VSTD::addressof(__c), 21010b57cec5SDimitry Andric "list::splice(iterator, list, iterator, iterator) called with second iterator not" 2102fe6060f1SDimitry Andric " referring to the list argument"); 2103*349cc55cSDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == _VSTD::addressof(__c), 2104fe6060f1SDimitry Andric "list::splice(iterator, list, iterator, iterator) called with third iterator not" 2105fe6060f1SDimitry Andric " referring to the list argument"); 2106*349cc55cSDimitry Andric if (this == _VSTD::addressof(__c)) 21070b57cec5SDimitry Andric { 21080b57cec5SDimitry Andric for (const_iterator __i = __f; __i != __l; ++__i) 21090b57cec5SDimitry Andric _LIBCPP_ASSERT(__i != __p, 21100b57cec5SDimitry Andric "list::splice(iterator, list, iterator, iterator)" 21110b57cec5SDimitry Andric " called with the first iterator within the range" 21120b57cec5SDimitry Andric " of the second and third iterators"); 21130b57cec5SDimitry Andric } 21140b57cec5SDimitry Andric#endif 21150b57cec5SDimitry Andric if (__f != __l) 21160b57cec5SDimitry Andric { 21170b57cec5SDimitry Andric __link_pointer __first = __f.__ptr_; 21180b57cec5SDimitry Andric --__l; 21190b57cec5SDimitry Andric __link_pointer __last = __l.__ptr_; 2120*349cc55cSDimitry Andric if (this != _VSTD::addressof(__c)) 21210b57cec5SDimitry Andric { 21220b57cec5SDimitry Andric size_type __s = _VSTD::distance(__f, __l) + 1; 21230b57cec5SDimitry Andric __c.__sz() -= __s; 21240b57cec5SDimitry Andric base::__sz() += __s; 21250b57cec5SDimitry Andric } 21260b57cec5SDimitry Andric base::__unlink_nodes(__first, __last); 21270b57cec5SDimitry Andric __link_nodes(__p.__ptr_, __first, __last); 2128e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 2129*349cc55cSDimitry Andric if (_VSTD::addressof(__c) != this) { 21300b57cec5SDimitry Andric __libcpp_db* __db = __get_db(); 21310b57cec5SDimitry Andric __c_node* __cn1 = __db->__find_c_and_lock(this); 2132*349cc55cSDimitry Andric __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); 21330b57cec5SDimitry Andric for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) 21340b57cec5SDimitry Andric { 21350b57cec5SDimitry Andric --__ip; 21360b57cec5SDimitry Andric iterator* __j = static_cast<iterator*>((*__ip)->__i_); 21370b57cec5SDimitry Andric for (__link_pointer __k = __f.__ptr_; 21380b57cec5SDimitry Andric __k != __l.__ptr_; __k = __k->__next_) 21390b57cec5SDimitry Andric { 21400b57cec5SDimitry Andric if (__j->__ptr_ == __k) 21410b57cec5SDimitry Andric { 21420b57cec5SDimitry Andric __cn1->__add(*__ip); 21430b57cec5SDimitry Andric (*__ip)->__c_ = __cn1; 21440b57cec5SDimitry Andric if (--__cn2->end_ != __ip) 2145e8d8bef9SDimitry Andric _VSTD::memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); 21460b57cec5SDimitry Andric } 21470b57cec5SDimitry Andric } 21480b57cec5SDimitry Andric } 21490b57cec5SDimitry Andric __db->unlock(); 21500b57cec5SDimitry Andric } 21510b57cec5SDimitry Andric#endif 21520b57cec5SDimitry Andric } 21530b57cec5SDimitry Andric} 21540b57cec5SDimitry Andric 21550b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 21560b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type 21570b57cec5SDimitry Andriclist<_Tp, _Alloc>::remove(const value_type& __x) 21580b57cec5SDimitry Andric{ 21590b57cec5SDimitry Andric list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing 21600b57cec5SDimitry Andric for (const_iterator __i = begin(), __e = end(); __i != __e;) 21610b57cec5SDimitry Andric { 21620b57cec5SDimitry Andric if (*__i == __x) 21630b57cec5SDimitry Andric { 21640b57cec5SDimitry Andric const_iterator __j = _VSTD::next(__i); 21650b57cec5SDimitry Andric for (; __j != __e && *__j == __x; ++__j) 21660b57cec5SDimitry Andric ; 21670b57cec5SDimitry Andric __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); 21680b57cec5SDimitry Andric __i = __j; 21690b57cec5SDimitry Andric if (__i != __e) 21700b57cec5SDimitry Andric ++__i; 21710b57cec5SDimitry Andric } 21720b57cec5SDimitry Andric else 21730b57cec5SDimitry Andric ++__i; 21740b57cec5SDimitry Andric } 21750b57cec5SDimitry Andric 21760b57cec5SDimitry Andric return (__remove_return_type) __deleted_nodes.size(); 21770b57cec5SDimitry Andric} 21780b57cec5SDimitry Andric 21790b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 21800b57cec5SDimitry Andrictemplate <class _Pred> 21810b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type 21820b57cec5SDimitry Andriclist<_Tp, _Alloc>::remove_if(_Pred __pred) 21830b57cec5SDimitry Andric{ 21840b57cec5SDimitry Andric list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing 21850b57cec5SDimitry Andric for (iterator __i = begin(), __e = end(); __i != __e;) 21860b57cec5SDimitry Andric { 21870b57cec5SDimitry Andric if (__pred(*__i)) 21880b57cec5SDimitry Andric { 21890b57cec5SDimitry Andric iterator __j = _VSTD::next(__i); 21900b57cec5SDimitry Andric for (; __j != __e && __pred(*__j); ++__j) 21910b57cec5SDimitry Andric ; 21920b57cec5SDimitry Andric __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); 21930b57cec5SDimitry Andric __i = __j; 21940b57cec5SDimitry Andric if (__i != __e) 21950b57cec5SDimitry Andric ++__i; 21960b57cec5SDimitry Andric } 21970b57cec5SDimitry Andric else 21980b57cec5SDimitry Andric ++__i; 21990b57cec5SDimitry Andric } 22000b57cec5SDimitry Andric 22010b57cec5SDimitry Andric return (__remove_return_type) __deleted_nodes.size(); 22020b57cec5SDimitry Andric} 22030b57cec5SDimitry Andric 22040b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 22050b57cec5SDimitry Andrictemplate <class _BinaryPred> 22060b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::__remove_return_type 22070b57cec5SDimitry Andriclist<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) 22080b57cec5SDimitry Andric{ 22090b57cec5SDimitry Andric list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing 22100b57cec5SDimitry Andric for (iterator __i = begin(), __e = end(); __i != __e;) 22110b57cec5SDimitry Andric { 22120b57cec5SDimitry Andric iterator __j = _VSTD::next(__i); 22130b57cec5SDimitry Andric for (; __j != __e && __binary_pred(*__i, *__j); ++__j) 22140b57cec5SDimitry Andric ; 22150b57cec5SDimitry Andric if (++__i != __j) { 22160b57cec5SDimitry Andric __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); 22170b57cec5SDimitry Andric __i = __j; 22180b57cec5SDimitry Andric } 22190b57cec5SDimitry Andric } 22200b57cec5SDimitry Andric 22210b57cec5SDimitry Andric return (__remove_return_type) __deleted_nodes.size(); 22220b57cec5SDimitry Andric} 22230b57cec5SDimitry Andric 22240b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 22250b57cec5SDimitry Andricinline 22260b57cec5SDimitry Andricvoid 22270b57cec5SDimitry Andriclist<_Tp, _Alloc>::merge(list& __c) 22280b57cec5SDimitry Andric{ 22290b57cec5SDimitry Andric merge(__c, __less<value_type>()); 22300b57cec5SDimitry Andric} 22310b57cec5SDimitry Andric 22320b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 22330b57cec5SDimitry Andrictemplate <class _Comp> 22340b57cec5SDimitry Andricvoid 22350b57cec5SDimitry Andriclist<_Tp, _Alloc>::merge(list& __c, _Comp __comp) 22360b57cec5SDimitry Andric{ 22370b57cec5SDimitry Andric if (this != _VSTD::addressof(__c)) 22380b57cec5SDimitry Andric { 22390b57cec5SDimitry Andric iterator __f1 = begin(); 22400b57cec5SDimitry Andric iterator __e1 = end(); 22410b57cec5SDimitry Andric iterator __f2 = __c.begin(); 22420b57cec5SDimitry Andric iterator __e2 = __c.end(); 22430b57cec5SDimitry Andric while (__f1 != __e1 && __f2 != __e2) 22440b57cec5SDimitry Andric { 22450b57cec5SDimitry Andric if (__comp(*__f2, *__f1)) 22460b57cec5SDimitry Andric { 22470b57cec5SDimitry Andric size_type __ds = 1; 22480b57cec5SDimitry Andric iterator __m2 = _VSTD::next(__f2); 2249*349cc55cSDimitry Andric for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void) ++__ds) 22500b57cec5SDimitry Andric ; 22510b57cec5SDimitry Andric base::__sz() += __ds; 22520b57cec5SDimitry Andric __c.__sz() -= __ds; 22530b57cec5SDimitry Andric __link_pointer __f = __f2.__ptr_; 22540b57cec5SDimitry Andric __link_pointer __l = __m2.__ptr_->__prev_; 22550b57cec5SDimitry Andric __f2 = __m2; 22560b57cec5SDimitry Andric base::__unlink_nodes(__f, __l); 22570b57cec5SDimitry Andric __m2 = _VSTD::next(__f1); 22580b57cec5SDimitry Andric __link_nodes(__f1.__ptr_, __f, __l); 22590b57cec5SDimitry Andric __f1 = __m2; 22600b57cec5SDimitry Andric } 22610b57cec5SDimitry Andric else 22620b57cec5SDimitry Andric ++__f1; 22630b57cec5SDimitry Andric } 22640b57cec5SDimitry Andric splice(__e1, __c); 2265e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 22660b57cec5SDimitry Andric __libcpp_db* __db = __get_db(); 22670b57cec5SDimitry Andric __c_node* __cn1 = __db->__find_c_and_lock(this); 2268*349cc55cSDimitry Andric __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); 22690b57cec5SDimitry Andric for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 22700b57cec5SDimitry Andric { 22710b57cec5SDimitry Andric --__p; 22720b57cec5SDimitry Andric iterator* __i = static_cast<iterator*>((*__p)->__i_); 22730b57cec5SDimitry Andric if (__i->__ptr_ != __c.__end_as_link()) 22740b57cec5SDimitry Andric { 22750b57cec5SDimitry Andric __cn1->__add(*__p); 22760b57cec5SDimitry Andric (*__p)->__c_ = __cn1; 22770b57cec5SDimitry Andric if (--__cn2->end_ != __p) 2278e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 22790b57cec5SDimitry Andric } 22800b57cec5SDimitry Andric } 22810b57cec5SDimitry Andric __db->unlock(); 22820b57cec5SDimitry Andric#endif 22830b57cec5SDimitry Andric } 22840b57cec5SDimitry Andric} 22850b57cec5SDimitry Andric 22860b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 22870b57cec5SDimitry Andricinline 22880b57cec5SDimitry Andricvoid 22890b57cec5SDimitry Andriclist<_Tp, _Alloc>::sort() 22900b57cec5SDimitry Andric{ 22910b57cec5SDimitry Andric sort(__less<value_type>()); 22920b57cec5SDimitry Andric} 22930b57cec5SDimitry Andric 22940b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 22950b57cec5SDimitry Andrictemplate <class _Comp> 22960b57cec5SDimitry Andricinline 22970b57cec5SDimitry Andricvoid 22980b57cec5SDimitry Andriclist<_Tp, _Alloc>::sort(_Comp __comp) 22990b57cec5SDimitry Andric{ 23000b57cec5SDimitry Andric __sort(begin(), end(), base::__sz(), __comp); 23010b57cec5SDimitry Andric} 23020b57cec5SDimitry Andric 23030b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 23040b57cec5SDimitry Andrictemplate <class _Comp> 23050b57cec5SDimitry Andrictypename list<_Tp, _Alloc>::iterator 23060b57cec5SDimitry Andriclist<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) 23070b57cec5SDimitry Andric{ 23080b57cec5SDimitry Andric switch (__n) 23090b57cec5SDimitry Andric { 23100b57cec5SDimitry Andric case 0: 23110b57cec5SDimitry Andric case 1: 23120b57cec5SDimitry Andric return __f1; 23130b57cec5SDimitry Andric case 2: 23140b57cec5SDimitry Andric if (__comp(*--__e2, *__f1)) 23150b57cec5SDimitry Andric { 23160b57cec5SDimitry Andric __link_pointer __f = __e2.__ptr_; 23170b57cec5SDimitry Andric base::__unlink_nodes(__f, __f); 23180b57cec5SDimitry Andric __link_nodes(__f1.__ptr_, __f, __f); 23190b57cec5SDimitry Andric return __e2; 23200b57cec5SDimitry Andric } 23210b57cec5SDimitry Andric return __f1; 23220b57cec5SDimitry Andric } 23230b57cec5SDimitry Andric size_type __n2 = __n / 2; 23240b57cec5SDimitry Andric iterator __e1 = _VSTD::next(__f1, __n2); 23250b57cec5SDimitry Andric iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); 23260b57cec5SDimitry Andric iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); 23270b57cec5SDimitry Andric if (__comp(*__f2, *__f1)) 23280b57cec5SDimitry Andric { 23290b57cec5SDimitry Andric iterator __m2 = _VSTD::next(__f2); 23300b57cec5SDimitry Andric for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) 23310b57cec5SDimitry Andric ; 23320b57cec5SDimitry Andric __link_pointer __f = __f2.__ptr_; 23330b57cec5SDimitry Andric __link_pointer __l = __m2.__ptr_->__prev_; 23340b57cec5SDimitry Andric __r = __f2; 23350b57cec5SDimitry Andric __e1 = __f2 = __m2; 23360b57cec5SDimitry Andric base::__unlink_nodes(__f, __l); 23370b57cec5SDimitry Andric __m2 = _VSTD::next(__f1); 23380b57cec5SDimitry Andric __link_nodes(__f1.__ptr_, __f, __l); 23390b57cec5SDimitry Andric __f1 = __m2; 23400b57cec5SDimitry Andric } 23410b57cec5SDimitry Andric else 23420b57cec5SDimitry Andric ++__f1; 23430b57cec5SDimitry Andric while (__f1 != __e1 && __f2 != __e2) 23440b57cec5SDimitry Andric { 23450b57cec5SDimitry Andric if (__comp(*__f2, *__f1)) 23460b57cec5SDimitry Andric { 23470b57cec5SDimitry Andric iterator __m2 = _VSTD::next(__f2); 23480b57cec5SDimitry Andric for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) 23490b57cec5SDimitry Andric ; 23500b57cec5SDimitry Andric __link_pointer __f = __f2.__ptr_; 23510b57cec5SDimitry Andric __link_pointer __l = __m2.__ptr_->__prev_; 23520b57cec5SDimitry Andric if (__e1 == __f2) 23530b57cec5SDimitry Andric __e1 = __m2; 23540b57cec5SDimitry Andric __f2 = __m2; 23550b57cec5SDimitry Andric base::__unlink_nodes(__f, __l); 23560b57cec5SDimitry Andric __m2 = _VSTD::next(__f1); 23570b57cec5SDimitry Andric __link_nodes(__f1.__ptr_, __f, __l); 23580b57cec5SDimitry Andric __f1 = __m2; 23590b57cec5SDimitry Andric } 23600b57cec5SDimitry Andric else 23610b57cec5SDimitry Andric ++__f1; 23620b57cec5SDimitry Andric } 23630b57cec5SDimitry Andric return __r; 23640b57cec5SDimitry Andric} 23650b57cec5SDimitry Andric 23660b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 23670b57cec5SDimitry Andricvoid 23680b57cec5SDimitry Andriclist<_Tp, _Alloc>::reverse() _NOEXCEPT 23690b57cec5SDimitry Andric{ 23700b57cec5SDimitry Andric if (base::__sz() > 1) 23710b57cec5SDimitry Andric { 23720b57cec5SDimitry Andric iterator __e = end(); 23730b57cec5SDimitry Andric for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) 23740b57cec5SDimitry Andric { 23750b57cec5SDimitry Andric _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); 23760b57cec5SDimitry Andric __i.__ptr_ = __i.__ptr_->__prev_; 23770b57cec5SDimitry Andric } 23780b57cec5SDimitry Andric _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); 23790b57cec5SDimitry Andric } 23800b57cec5SDimitry Andric} 23810b57cec5SDimitry Andric 23820b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 23830b57cec5SDimitry Andricbool 23840b57cec5SDimitry Andriclist<_Tp, _Alloc>::__invariants() const 23850b57cec5SDimitry Andric{ 23860b57cec5SDimitry Andric return size() == _VSTD::distance(begin(), end()); 23870b57cec5SDimitry Andric} 23880b57cec5SDimitry Andric 2389e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2 23900b57cec5SDimitry Andric 23910b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 23920b57cec5SDimitry Andricbool 23930b57cec5SDimitry Andriclist<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const 23940b57cec5SDimitry Andric{ 23950b57cec5SDimitry Andric return __i->__ptr_ != this->__end_as_link(); 23960b57cec5SDimitry Andric} 23970b57cec5SDimitry Andric 23980b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 23990b57cec5SDimitry Andricbool 24000b57cec5SDimitry Andriclist<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const 24010b57cec5SDimitry Andric{ 24020b57cec5SDimitry Andric return !empty() && __i->__ptr_ != base::__end_.__next_; 24030b57cec5SDimitry Andric} 24040b57cec5SDimitry Andric 24050b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24060b57cec5SDimitry Andricbool 24070b57cec5SDimitry Andriclist<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const 24080b57cec5SDimitry Andric{ 24090b57cec5SDimitry Andric return false; 24100b57cec5SDimitry Andric} 24110b57cec5SDimitry Andric 24120b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24130b57cec5SDimitry Andricbool 24140b57cec5SDimitry Andriclist<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const 24150b57cec5SDimitry Andric{ 24160b57cec5SDimitry Andric return false; 24170b57cec5SDimitry Andric} 24180b57cec5SDimitry Andric 2419e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2 24200b57cec5SDimitry Andric 24210b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24230b57cec5SDimitry Andricbool 24240b57cec5SDimitry Andricoperator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24250b57cec5SDimitry Andric{ 24260b57cec5SDimitry Andric return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 24270b57cec5SDimitry Andric} 24280b57cec5SDimitry Andric 24290b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24310b57cec5SDimitry Andricbool 24320b57cec5SDimitry Andricoperator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24330b57cec5SDimitry Andric{ 24340b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 24350b57cec5SDimitry Andric} 24360b57cec5SDimitry Andric 24370b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24390b57cec5SDimitry Andricbool 24400b57cec5SDimitry Andricoperator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24410b57cec5SDimitry Andric{ 24420b57cec5SDimitry Andric return !(__x == __y); 24430b57cec5SDimitry Andric} 24440b57cec5SDimitry Andric 24450b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24470b57cec5SDimitry Andricbool 24480b57cec5SDimitry Andricoperator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24490b57cec5SDimitry Andric{ 24500b57cec5SDimitry Andric return __y < __x; 24510b57cec5SDimitry Andric} 24520b57cec5SDimitry Andric 24530b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24550b57cec5SDimitry Andricbool 24560b57cec5SDimitry Andricoperator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24570b57cec5SDimitry Andric{ 24580b57cec5SDimitry Andric return !(__x < __y); 24590b57cec5SDimitry Andric} 24600b57cec5SDimitry Andric 24610b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24630b57cec5SDimitry Andricbool 24640b57cec5SDimitry Andricoperator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 24650b57cec5SDimitry Andric{ 24660b57cec5SDimitry Andric return !(__y < __x); 24670b57cec5SDimitry Andric} 24680b57cec5SDimitry Andric 24690b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 24700b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 24710b57cec5SDimitry Andricvoid 24720b57cec5SDimitry Andricswap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) 24730b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 24740b57cec5SDimitry Andric{ 24750b57cec5SDimitry Andric __x.swap(__y); 24760b57cec5SDimitry Andric} 24770b57cec5SDimitry Andric 24780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 24790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 24805ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename list<_Tp, _Allocator>::size_type 24815ffd83dbSDimitry Andricerase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) { 24825ffd83dbSDimitry Andric return __c.remove_if(__pred); 24835ffd83dbSDimitry Andric} 24840b57cec5SDimitry Andric 24850b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 24865ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename list<_Tp, _Allocator>::size_type 24875ffd83dbSDimitry Andricerase(list<_Tp, _Allocator>& __c, const _Up& __v) { 24885ffd83dbSDimitry Andric return _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); 24895ffd83dbSDimitry Andric} 24900b57cec5SDimitry Andric#endif 24910b57cec5SDimitry Andric 24920b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 24930b57cec5SDimitry Andric 24940b57cec5SDimitry Andric_LIBCPP_POP_MACROS 24950b57cec5SDimitry Andric 24960b57cec5SDimitry Andric#endif // _LIBCPP_LIST 2497