xref: /aosp_15_r20/external/libcxx/include/memory (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker//===-------------------------- memory ------------------------------------===//
3*58b9f456SAndroid Build Coastguard Worker//
4*58b9f456SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker//
6*58b9f456SAndroid Build Coastguard Worker// This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker// Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker//
9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker
11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_MEMORY
12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_MEMORY
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker/*
15*58b9f456SAndroid Build Coastguard Worker    memory synopsis
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Workernamespace std
18*58b9f456SAndroid Build Coastguard Worker{
19*58b9f456SAndroid Build Coastguard Worker
20*58b9f456SAndroid Build Coastguard Workerstruct allocator_arg_t { };
21*58b9f456SAndroid Build Coastguard Workerinline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
22*58b9f456SAndroid Build Coastguard Worker
23*58b9f456SAndroid Build Coastguard Workertemplate <class T, class Alloc> struct uses_allocator;
24*58b9f456SAndroid Build Coastguard Worker
25*58b9f456SAndroid Build Coastguard Workertemplate <class Ptr>
26*58b9f456SAndroid Build Coastguard Workerstruct pointer_traits
27*58b9f456SAndroid Build Coastguard Worker{
28*58b9f456SAndroid Build Coastguard Worker    typedef Ptr pointer;
29*58b9f456SAndroid Build Coastguard Worker    typedef <details> element_type;
30*58b9f456SAndroid Build Coastguard Worker    typedef <details> difference_type;
31*58b9f456SAndroid Build Coastguard Worker
32*58b9f456SAndroid Build Coastguard Worker    template <class U> using rebind = <details>;
33*58b9f456SAndroid Build Coastguard Worker
34*58b9f456SAndroid Build Coastguard Worker    static pointer pointer_to(<details>);
35*58b9f456SAndroid Build Coastguard Worker};
36*58b9f456SAndroid Build Coastguard Worker
37*58b9f456SAndroid Build Coastguard Workertemplate <class T>
38*58b9f456SAndroid Build Coastguard Workerstruct pointer_traits<T*>
39*58b9f456SAndroid Build Coastguard Worker{
40*58b9f456SAndroid Build Coastguard Worker    typedef T* pointer;
41*58b9f456SAndroid Build Coastguard Worker    typedef T element_type;
42*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t difference_type;
43*58b9f456SAndroid Build Coastguard Worker
44*58b9f456SAndroid Build Coastguard Worker    template <class U> using rebind = U*;
45*58b9f456SAndroid Build Coastguard Worker
46*58b9f456SAndroid Build Coastguard Worker    static pointer pointer_to(<details>) noexcept; // constexpr in C++20
47*58b9f456SAndroid Build Coastguard Worker};
48*58b9f456SAndroid Build Coastguard Worker
49*58b9f456SAndroid Build Coastguard Workertemplate <class T> constexpr T* to_address(T* p) noexcept; // C++20
50*58b9f456SAndroid Build Coastguard Workertemplate <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
51*58b9f456SAndroid Build Coastguard Worker
52*58b9f456SAndroid Build Coastguard Workertemplate <class Alloc>
53*58b9f456SAndroid Build Coastguard Workerstruct allocator_traits
54*58b9f456SAndroid Build Coastguard Worker{
55*58b9f456SAndroid Build Coastguard Worker    typedef Alloc                        allocator_type;
56*58b9f456SAndroid Build Coastguard Worker    typedef typename allocator_type::value_type
57*58b9f456SAndroid Build Coastguard Worker                                         value_type;
58*58b9f456SAndroid Build Coastguard Worker
59*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::pointer | value_type* pointer;
60*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::const_pointer
61*58b9f456SAndroid Build Coastguard Worker          | pointer_traits<pointer>::rebind<const value_type>
62*58b9f456SAndroid Build Coastguard Worker                                         const_pointer;
63*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::void_pointer
64*58b9f456SAndroid Build Coastguard Worker          | pointer_traits<pointer>::rebind<void>
65*58b9f456SAndroid Build Coastguard Worker                                         void_pointer;
66*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::const_void_pointer
67*58b9f456SAndroid Build Coastguard Worker          | pointer_traits<pointer>::rebind<const void>
68*58b9f456SAndroid Build Coastguard Worker                                         const_void_pointer;
69*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::difference_type
70*58b9f456SAndroid Build Coastguard Worker          | pointer_traits<pointer>::difference_type
71*58b9f456SAndroid Build Coastguard Worker                                         difference_type;
72*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::size_type
73*58b9f456SAndroid Build Coastguard Worker          | make_unsigned<difference_type>::type
74*58b9f456SAndroid Build Coastguard Worker                                         size_type;
75*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::propagate_on_container_copy_assignment
76*58b9f456SAndroid Build Coastguard Worker          | false_type                   propagate_on_container_copy_assignment;
77*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::propagate_on_container_move_assignment
78*58b9f456SAndroid Build Coastguard Worker          | false_type                   propagate_on_container_move_assignment;
79*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::propagate_on_container_swap
80*58b9f456SAndroid Build Coastguard Worker          | false_type                   propagate_on_container_swap;
81*58b9f456SAndroid Build Coastguard Worker    typedef Alloc::is_always_equal
82*58b9f456SAndroid Build Coastguard Worker          | is_empty                     is_always_equal;
83*58b9f456SAndroid Build Coastguard Worker
84*58b9f456SAndroid Build Coastguard Worker    template <class T> using rebind_alloc  = Alloc::rebind<U>::other | Alloc<T, Args...>;
85*58b9f456SAndroid Build Coastguard Worker    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
86*58b9f456SAndroid Build Coastguard Worker
87*58b9f456SAndroid Build Coastguard Worker    static pointer allocate(allocator_type& a, size_type n);                          // [[nodiscard]] in C++20
88*58b9f456SAndroid Build Coastguard Worker    static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
89*58b9f456SAndroid Build Coastguard Worker
90*58b9f456SAndroid Build Coastguard Worker    static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
91*58b9f456SAndroid Build Coastguard Worker
92*58b9f456SAndroid Build Coastguard Worker    template <class T, class... Args>
93*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type& a, T* p, Args&&... args);
94*58b9f456SAndroid Build Coastguard Worker
95*58b9f456SAndroid Build Coastguard Worker    template <class T>
96*58b9f456SAndroid Build Coastguard Worker        static void destroy(allocator_type& a, T* p);
97*58b9f456SAndroid Build Coastguard Worker
98*58b9f456SAndroid Build Coastguard Worker    static size_type max_size(const allocator_type& a); // noexcept in C++14
99*58b9f456SAndroid Build Coastguard Worker
100*58b9f456SAndroid Build Coastguard Worker    static allocator_type
101*58b9f456SAndroid Build Coastguard Worker        select_on_container_copy_construction(const allocator_type& a);
102*58b9f456SAndroid Build Coastguard Worker};
103*58b9f456SAndroid Build Coastguard Worker
104*58b9f456SAndroid Build Coastguard Workertemplate <>
105*58b9f456SAndroid Build Coastguard Workerclass allocator<void>
106*58b9f456SAndroid Build Coastguard Worker{
107*58b9f456SAndroid Build Coastguard Workerpublic:
108*58b9f456SAndroid Build Coastguard Worker    typedef void*                                 pointer;
109*58b9f456SAndroid Build Coastguard Worker    typedef const void*                           const_pointer;
110*58b9f456SAndroid Build Coastguard Worker    typedef void                                  value_type;
111*58b9f456SAndroid Build Coastguard Worker
112*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef allocator<_Up> other;};
113*58b9f456SAndroid Build Coastguard Worker};
114*58b9f456SAndroid Build Coastguard Worker
115*58b9f456SAndroid Build Coastguard Workertemplate <class T>
116*58b9f456SAndroid Build Coastguard Workerclass allocator
117*58b9f456SAndroid Build Coastguard Worker{
118*58b9f456SAndroid Build Coastguard Workerpublic:
119*58b9f456SAndroid Build Coastguard Worker    typedef size_t                                size_type;
120*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t                             difference_type;
121*58b9f456SAndroid Build Coastguard Worker    typedef T*                                    pointer;
122*58b9f456SAndroid Build Coastguard Worker    typedef const T*                              const_pointer;
123*58b9f456SAndroid Build Coastguard Worker    typedef typename add_lvalue_reference<T>::type       reference;
124*58b9f456SAndroid Build Coastguard Worker    typedef typename add_lvalue_reference<const T>::type const_reference;
125*58b9f456SAndroid Build Coastguard Worker    typedef T                                     value_type;
126*58b9f456SAndroid Build Coastguard Worker
127*58b9f456SAndroid Build Coastguard Worker    template <class U> struct rebind {typedef allocator<U> other;};
128*58b9f456SAndroid Build Coastguard Worker
129*58b9f456SAndroid Build Coastguard Worker    constexpr allocator() noexcept;                      // constexpr in C++20
130*58b9f456SAndroid Build Coastguard Worker    constexpr allocator(const allocator&) noexcept;      // constexpr in C++20
131*58b9f456SAndroid Build Coastguard Worker    template <class U>
132*58b9f456SAndroid Build Coastguard Worker      constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
133*58b9f456SAndroid Build Coastguard Worker    ~allocator();
134*58b9f456SAndroid Build Coastguard Worker    pointer address(reference x) const noexcept;
135*58b9f456SAndroid Build Coastguard Worker    const_pointer address(const_reference x) const noexcept;
136*58b9f456SAndroid Build Coastguard Worker    pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
137*58b9f456SAndroid Build Coastguard Worker    void deallocate(pointer p, size_type n) noexcept;
138*58b9f456SAndroid Build Coastguard Worker    size_type max_size() const noexcept;
139*58b9f456SAndroid Build Coastguard Worker    template<class U, class... Args>
140*58b9f456SAndroid Build Coastguard Worker        void construct(U* p, Args&&... args);
141*58b9f456SAndroid Build Coastguard Worker    template <class U>
142*58b9f456SAndroid Build Coastguard Worker        void destroy(U* p);
143*58b9f456SAndroid Build Coastguard Worker};
144*58b9f456SAndroid Build Coastguard Worker
145*58b9f456SAndroid Build Coastguard Workertemplate <class T, class U>
146*58b9f456SAndroid Build Coastguard Workerbool operator==(const allocator<T>&, const allocator<U>&) noexcept;
147*58b9f456SAndroid Build Coastguard Worker
148*58b9f456SAndroid Build Coastguard Workertemplate <class T, class U>
149*58b9f456SAndroid Build Coastguard Workerbool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
150*58b9f456SAndroid Build Coastguard Worker
151*58b9f456SAndroid Build Coastguard Workertemplate <class OutputIterator, class T>
152*58b9f456SAndroid Build Coastguard Workerclass raw_storage_iterator
153*58b9f456SAndroid Build Coastguard Worker    : public iterator<output_iterator_tag,
154*58b9f456SAndroid Build Coastguard Worker                      T,                               // purposefully not C++03
155*58b9f456SAndroid Build Coastguard Worker                      ptrdiff_t,                       // purposefully not C++03
156*58b9f456SAndroid Build Coastguard Worker                      T*,                              // purposefully not C++03
157*58b9f456SAndroid Build Coastguard Worker                      raw_storage_iterator&>           // purposefully not C++03
158*58b9f456SAndroid Build Coastguard Worker{
159*58b9f456SAndroid Build Coastguard Workerpublic:
160*58b9f456SAndroid Build Coastguard Worker    explicit raw_storage_iterator(OutputIterator x);
161*58b9f456SAndroid Build Coastguard Worker    raw_storage_iterator& operator*();
162*58b9f456SAndroid Build Coastguard Worker    raw_storage_iterator& operator=(const T& element);
163*58b9f456SAndroid Build Coastguard Worker    raw_storage_iterator& operator++();
164*58b9f456SAndroid Build Coastguard Worker    raw_storage_iterator  operator++(int);
165*58b9f456SAndroid Build Coastguard Worker};
166*58b9f456SAndroid Build Coastguard Worker
167*58b9f456SAndroid Build Coastguard Workertemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
168*58b9f456SAndroid Build Coastguard Workertemplate <class T> void               return_temporary_buffer(T* p) noexcept;
169*58b9f456SAndroid Build Coastguard Worker
170*58b9f456SAndroid Build Coastguard Workertemplate <class T> T* addressof(T& r) noexcept;
171*58b9f456SAndroid Build Coastguard Workertemplate <class T> T* addressof(const T&& r) noexcept = delete;
172*58b9f456SAndroid Build Coastguard Worker
173*58b9f456SAndroid Build Coastguard Workertemplate <class InputIterator, class ForwardIterator>
174*58b9f456SAndroid Build Coastguard WorkerForwardIterator
175*58b9f456SAndroid Build Coastguard Workeruninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
176*58b9f456SAndroid Build Coastguard Worker
177*58b9f456SAndroid Build Coastguard Workertemplate <class InputIterator, class Size, class ForwardIterator>
178*58b9f456SAndroid Build Coastguard WorkerForwardIterator
179*58b9f456SAndroid Build Coastguard Workeruninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
180*58b9f456SAndroid Build Coastguard Worker
181*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator, class T>
182*58b9f456SAndroid Build Coastguard Workervoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
183*58b9f456SAndroid Build Coastguard Worker
184*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator, class Size, class T>
185*58b9f456SAndroid Build Coastguard WorkerForwardIterator
186*58b9f456SAndroid Build Coastguard Workeruninitialized_fill_n(ForwardIterator first, Size n, const T& x);
187*58b9f456SAndroid Build Coastguard Worker
188*58b9f456SAndroid Build Coastguard Workertemplate <class T>
189*58b9f456SAndroid Build Coastguard Workervoid destroy_at(T* location);
190*58b9f456SAndroid Build Coastguard Worker
191*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator>
192*58b9f456SAndroid Build Coastguard Worker void destroy(ForwardIterator first, ForwardIterator last);
193*58b9f456SAndroid Build Coastguard Worker
194*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator, class Size>
195*58b9f456SAndroid Build Coastguard Worker ForwardIterator destroy_n(ForwardIterator first, Size n);
196*58b9f456SAndroid Build Coastguard Worker
197*58b9f456SAndroid Build Coastguard Workertemplate <class InputIterator, class ForwardIterator>
198*58b9f456SAndroid Build Coastguard Worker ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
199*58b9f456SAndroid Build Coastguard Worker
200*58b9f456SAndroid Build Coastguard Workertemplate <class InputIterator, class Size, class ForwardIterator>
201*58b9f456SAndroid Build Coastguard Worker pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
202*58b9f456SAndroid Build Coastguard Worker
203*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator>
204*58b9f456SAndroid Build Coastguard Worker void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
205*58b9f456SAndroid Build Coastguard Worker
206*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator, class Size>
207*58b9f456SAndroid Build Coastguard Worker ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
208*58b9f456SAndroid Build Coastguard Worker
209*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator>
210*58b9f456SAndroid Build Coastguard Worker void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
211*58b9f456SAndroid Build Coastguard Worker
212*58b9f456SAndroid Build Coastguard Workertemplate <class ForwardIterator, class Size>
213*58b9f456SAndroid Build Coastguard Worker ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
214*58b9f456SAndroid Build Coastguard Worker
215*58b9f456SAndroid Build Coastguard Workertemplate <class Y> struct auto_ptr_ref {};      // deprecated in C++11, removed in C++17
216*58b9f456SAndroid Build Coastguard Worker
217*58b9f456SAndroid Build Coastguard Workertemplate<class X>
218*58b9f456SAndroid Build Coastguard Workerclass auto_ptr                                  // deprecated in C++11, removed in C++17
219*58b9f456SAndroid Build Coastguard Worker{
220*58b9f456SAndroid Build Coastguard Workerpublic:
221*58b9f456SAndroid Build Coastguard Worker    typedef X element_type;
222*58b9f456SAndroid Build Coastguard Worker
223*58b9f456SAndroid Build Coastguard Worker    explicit auto_ptr(X* p =0) throw();
224*58b9f456SAndroid Build Coastguard Worker    auto_ptr(auto_ptr&) throw();
225*58b9f456SAndroid Build Coastguard Worker    template<class Y> auto_ptr(auto_ptr<Y>&) throw();
226*58b9f456SAndroid Build Coastguard Worker    auto_ptr& operator=(auto_ptr&) throw();
227*58b9f456SAndroid Build Coastguard Worker    template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
228*58b9f456SAndroid Build Coastguard Worker    auto_ptr& operator=(auto_ptr_ref<X> r) throw();
229*58b9f456SAndroid Build Coastguard Worker    ~auto_ptr() throw();
230*58b9f456SAndroid Build Coastguard Worker
231*58b9f456SAndroid Build Coastguard Worker    typename add_lvalue_reference<X>::type operator*() const throw();
232*58b9f456SAndroid Build Coastguard Worker    X* operator->() const throw();
233*58b9f456SAndroid Build Coastguard Worker    X* get() const throw();
234*58b9f456SAndroid Build Coastguard Worker    X* release() throw();
235*58b9f456SAndroid Build Coastguard Worker    void reset(X* p =0) throw();
236*58b9f456SAndroid Build Coastguard Worker
237*58b9f456SAndroid Build Coastguard Worker    auto_ptr(auto_ptr_ref<X>) throw();
238*58b9f456SAndroid Build Coastguard Worker    template<class Y> operator auto_ptr_ref<Y>() throw();
239*58b9f456SAndroid Build Coastguard Worker    template<class Y> operator auto_ptr<Y>() throw();
240*58b9f456SAndroid Build Coastguard Worker};
241*58b9f456SAndroid Build Coastguard Worker
242*58b9f456SAndroid Build Coastguard Workertemplate <class T>
243*58b9f456SAndroid Build Coastguard Workerstruct default_delete
244*58b9f456SAndroid Build Coastguard Worker{
245*58b9f456SAndroid Build Coastguard Worker    constexpr default_delete() noexcept = default;
246*58b9f456SAndroid Build Coastguard Worker    template <class U> default_delete(const default_delete<U>&) noexcept;
247*58b9f456SAndroid Build Coastguard Worker
248*58b9f456SAndroid Build Coastguard Worker    void operator()(T*) const noexcept;
249*58b9f456SAndroid Build Coastguard Worker};
250*58b9f456SAndroid Build Coastguard Worker
251*58b9f456SAndroid Build Coastguard Workertemplate <class T>
252*58b9f456SAndroid Build Coastguard Workerstruct default_delete<T[]>
253*58b9f456SAndroid Build Coastguard Worker{
254*58b9f456SAndroid Build Coastguard Worker    constexpr default_delete() noexcept = default;
255*58b9f456SAndroid Build Coastguard Worker    void operator()(T*) const noexcept;
256*58b9f456SAndroid Build Coastguard Worker    template <class U> void operator()(U*) const = delete;
257*58b9f456SAndroid Build Coastguard Worker};
258*58b9f456SAndroid Build Coastguard Worker
259*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D = default_delete<T>>
260*58b9f456SAndroid Build Coastguard Workerclass unique_ptr
261*58b9f456SAndroid Build Coastguard Worker{
262*58b9f456SAndroid Build Coastguard Workerpublic:
263*58b9f456SAndroid Build Coastguard Worker    typedef see below pointer;
264*58b9f456SAndroid Build Coastguard Worker    typedef T element_type;
265*58b9f456SAndroid Build Coastguard Worker    typedef D deleter_type;
266*58b9f456SAndroid Build Coastguard Worker
267*58b9f456SAndroid Build Coastguard Worker    // constructors
268*58b9f456SAndroid Build Coastguard Worker    constexpr unique_ptr() noexcept;
269*58b9f456SAndroid Build Coastguard Worker    explicit unique_ptr(pointer p) noexcept;
270*58b9f456SAndroid Build Coastguard Worker    unique_ptr(pointer p, see below d1) noexcept;
271*58b9f456SAndroid Build Coastguard Worker    unique_ptr(pointer p, see below d2) noexcept;
272*58b9f456SAndroid Build Coastguard Worker    unique_ptr(unique_ptr&& u) noexcept;
273*58b9f456SAndroid Build Coastguard Worker    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
274*58b9f456SAndroid Build Coastguard Worker    template <class U, class E>
275*58b9f456SAndroid Build Coastguard Worker        unique_ptr(unique_ptr<U, E>&& u) noexcept;
276*58b9f456SAndroid Build Coastguard Worker    template <class U>
277*58b9f456SAndroid Build Coastguard Worker        unique_ptr(auto_ptr<U>&& u) noexcept;       // removed in C++17
278*58b9f456SAndroid Build Coastguard Worker
279*58b9f456SAndroid Build Coastguard Worker    // destructor
280*58b9f456SAndroid Build Coastguard Worker    ~unique_ptr();
281*58b9f456SAndroid Build Coastguard Worker
282*58b9f456SAndroid Build Coastguard Worker    // assignment
283*58b9f456SAndroid Build Coastguard Worker    unique_ptr& operator=(unique_ptr&& u) noexcept;
284*58b9f456SAndroid Build Coastguard Worker    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
285*58b9f456SAndroid Build Coastguard Worker    unique_ptr& operator=(nullptr_t) noexcept;
286*58b9f456SAndroid Build Coastguard Worker
287*58b9f456SAndroid Build Coastguard Worker    // observers
288*58b9f456SAndroid Build Coastguard Worker    typename add_lvalue_reference<T>::type operator*() const;
289*58b9f456SAndroid Build Coastguard Worker    pointer operator->() const noexcept;
290*58b9f456SAndroid Build Coastguard Worker    pointer get() const noexcept;
291*58b9f456SAndroid Build Coastguard Worker    deleter_type& get_deleter() noexcept;
292*58b9f456SAndroid Build Coastguard Worker    const deleter_type& get_deleter() const noexcept;
293*58b9f456SAndroid Build Coastguard Worker    explicit operator bool() const noexcept;
294*58b9f456SAndroid Build Coastguard Worker
295*58b9f456SAndroid Build Coastguard Worker    // modifiers
296*58b9f456SAndroid Build Coastguard Worker    pointer release() noexcept;
297*58b9f456SAndroid Build Coastguard Worker    void reset(pointer p = pointer()) noexcept;
298*58b9f456SAndroid Build Coastguard Worker    void swap(unique_ptr& u) noexcept;
299*58b9f456SAndroid Build Coastguard Worker};
300*58b9f456SAndroid Build Coastguard Worker
301*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
302*58b9f456SAndroid Build Coastguard Workerclass unique_ptr<T[], D>
303*58b9f456SAndroid Build Coastguard Worker{
304*58b9f456SAndroid Build Coastguard Workerpublic:
305*58b9f456SAndroid Build Coastguard Worker    typedef implementation-defined pointer;
306*58b9f456SAndroid Build Coastguard Worker    typedef T element_type;
307*58b9f456SAndroid Build Coastguard Worker    typedef D deleter_type;
308*58b9f456SAndroid Build Coastguard Worker
309*58b9f456SAndroid Build Coastguard Worker    // constructors
310*58b9f456SAndroid Build Coastguard Worker    constexpr unique_ptr() noexcept;
311*58b9f456SAndroid Build Coastguard Worker    explicit unique_ptr(pointer p) noexcept;
312*58b9f456SAndroid Build Coastguard Worker    unique_ptr(pointer p, see below d) noexcept;
313*58b9f456SAndroid Build Coastguard Worker    unique_ptr(pointer p, see below d) noexcept;
314*58b9f456SAndroid Build Coastguard Worker    unique_ptr(unique_ptr&& u) noexcept;
315*58b9f456SAndroid Build Coastguard Worker    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
316*58b9f456SAndroid Build Coastguard Worker
317*58b9f456SAndroid Build Coastguard Worker    // destructor
318*58b9f456SAndroid Build Coastguard Worker    ~unique_ptr();
319*58b9f456SAndroid Build Coastguard Worker
320*58b9f456SAndroid Build Coastguard Worker    // assignment
321*58b9f456SAndroid Build Coastguard Worker    unique_ptr& operator=(unique_ptr&& u) noexcept;
322*58b9f456SAndroid Build Coastguard Worker    unique_ptr& operator=(nullptr_t) noexcept;
323*58b9f456SAndroid Build Coastguard Worker
324*58b9f456SAndroid Build Coastguard Worker    // observers
325*58b9f456SAndroid Build Coastguard Worker    T& operator[](size_t i) const;
326*58b9f456SAndroid Build Coastguard Worker    pointer get() const noexcept;
327*58b9f456SAndroid Build Coastguard Worker    deleter_type& get_deleter() noexcept;
328*58b9f456SAndroid Build Coastguard Worker    const deleter_type& get_deleter() const noexcept;
329*58b9f456SAndroid Build Coastguard Worker    explicit operator bool() const noexcept;
330*58b9f456SAndroid Build Coastguard Worker
331*58b9f456SAndroid Build Coastguard Worker    // modifiers
332*58b9f456SAndroid Build Coastguard Worker    pointer release() noexcept;
333*58b9f456SAndroid Build Coastguard Worker    void reset(pointer p = pointer()) noexcept;
334*58b9f456SAndroid Build Coastguard Worker    void reset(nullptr_t) noexcept;
335*58b9f456SAndroid Build Coastguard Worker    template <class U> void reset(U) = delete;
336*58b9f456SAndroid Build Coastguard Worker    void swap(unique_ptr& u) noexcept;
337*58b9f456SAndroid Build Coastguard Worker};
338*58b9f456SAndroid Build Coastguard Worker
339*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
340*58b9f456SAndroid Build Coastguard Worker    void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
341*58b9f456SAndroid Build Coastguard Worker
342*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
343*58b9f456SAndroid Build Coastguard Worker    bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
344*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
345*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
346*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
347*58b9f456SAndroid Build Coastguard Worker    bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
348*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
349*58b9f456SAndroid Build Coastguard Worker    bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
350*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
351*58b9f456SAndroid Build Coastguard Worker    bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
352*58b9f456SAndroid Build Coastguard Workertemplate <class T1, class D1, class T2, class D2>
353*58b9f456SAndroid Build Coastguard Worker    bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
354*58b9f456SAndroid Build Coastguard Worker
355*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
356*58b9f456SAndroid Build Coastguard Worker    bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
357*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
358*58b9f456SAndroid Build Coastguard Worker    bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
359*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
360*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
361*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
362*58b9f456SAndroid Build Coastguard Worker    bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
363*58b9f456SAndroid Build Coastguard Worker
364*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
365*58b9f456SAndroid Build Coastguard Worker    bool operator<(const unique_ptr<T, D>& x, nullptr_t);
366*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
367*58b9f456SAndroid Build Coastguard Worker    bool operator<(nullptr_t, const unique_ptr<T, D>& y);
368*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
369*58b9f456SAndroid Build Coastguard Worker    bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
370*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
371*58b9f456SAndroid Build Coastguard Worker    bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
372*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
373*58b9f456SAndroid Build Coastguard Worker    bool operator>(const unique_ptr<T, D>& x, nullptr_t);
374*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
375*58b9f456SAndroid Build Coastguard Worker    bool operator>(nullptr_t, const unique_ptr<T, D>& y);
376*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
377*58b9f456SAndroid Build Coastguard Worker    bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
378*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D>
379*58b9f456SAndroid Build Coastguard Worker    bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
380*58b9f456SAndroid Build Coastguard Worker
381*58b9f456SAndroid Build Coastguard Workerclass bad_weak_ptr
382*58b9f456SAndroid Build Coastguard Worker    : public std::exception
383*58b9f456SAndroid Build Coastguard Worker{
384*58b9f456SAndroid Build Coastguard Worker    bad_weak_ptr() noexcept;
385*58b9f456SAndroid Build Coastguard Worker};
386*58b9f456SAndroid Build Coastguard Worker
387*58b9f456SAndroid Build Coastguard Workertemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);     // C++14
388*58b9f456SAndroid Build Coastguard Workertemplate<class T>                unique_ptr<T> make_unique(size_t n);           // C++14
389*58b9f456SAndroid Build Coastguard Workertemplate<class T, class... Args> unspecified   make_unique(Args&&...) = delete; // C++14, T == U[N]
390*58b9f456SAndroid Build Coastguard Worker
391*58b9f456SAndroid Build Coastguard Workertemplate<class E, class T, class Y, class D>
392*58b9f456SAndroid Build Coastguard Worker    basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
393*58b9f456SAndroid Build Coastguard Worker
394*58b9f456SAndroid Build Coastguard Workertemplate<class T>
395*58b9f456SAndroid Build Coastguard Workerclass shared_ptr
396*58b9f456SAndroid Build Coastguard Worker{
397*58b9f456SAndroid Build Coastguard Workerpublic:
398*58b9f456SAndroid Build Coastguard Worker    typedef T element_type;
399*58b9f456SAndroid Build Coastguard Worker    typedef weak_ptr<T> weak_type; // C++17
400*58b9f456SAndroid Build Coastguard Worker
401*58b9f456SAndroid Build Coastguard Worker    // constructors:
402*58b9f456SAndroid Build Coastguard Worker    constexpr shared_ptr() noexcept;
403*58b9f456SAndroid Build Coastguard Worker    template<class Y> explicit shared_ptr(Y* p);
404*58b9f456SAndroid Build Coastguard Worker    template<class Y, class D> shared_ptr(Y* p, D d);
405*58b9f456SAndroid Build Coastguard Worker    template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
406*58b9f456SAndroid Build Coastguard Worker    template <class D> shared_ptr(nullptr_t p, D d);
407*58b9f456SAndroid Build Coastguard Worker    template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
408*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
409*58b9f456SAndroid Build Coastguard Worker    shared_ptr(const shared_ptr& r) noexcept;
410*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
411*58b9f456SAndroid Build Coastguard Worker    shared_ptr(shared_ptr&& r) noexcept;
412*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
413*58b9f456SAndroid Build Coastguard Worker    template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
414*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr(auto_ptr<Y>&& r);          // removed in C++17
415*58b9f456SAndroid Build Coastguard Worker    template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
416*58b9f456SAndroid Build Coastguard Worker    shared_ptr(nullptr_t) : shared_ptr() { }
417*58b9f456SAndroid Build Coastguard Worker
418*58b9f456SAndroid Build Coastguard Worker    // destructor:
419*58b9f456SAndroid Build Coastguard Worker    ~shared_ptr();
420*58b9f456SAndroid Build Coastguard Worker
421*58b9f456SAndroid Build Coastguard Worker    // assignment:
422*58b9f456SAndroid Build Coastguard Worker    shared_ptr& operator=(const shared_ptr& r) noexcept;
423*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
424*58b9f456SAndroid Build Coastguard Worker    shared_ptr& operator=(shared_ptr&& r) noexcept;
425*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
426*58b9f456SAndroid Build Coastguard Worker    template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
427*58b9f456SAndroid Build Coastguard Worker    template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
428*58b9f456SAndroid Build Coastguard Worker
429*58b9f456SAndroid Build Coastguard Worker    // modifiers:
430*58b9f456SAndroid Build Coastguard Worker    void swap(shared_ptr& r) noexcept;
431*58b9f456SAndroid Build Coastguard Worker    void reset() noexcept;
432*58b9f456SAndroid Build Coastguard Worker    template<class Y> void reset(Y* p);
433*58b9f456SAndroid Build Coastguard Worker    template<class Y, class D> void reset(Y* p, D d);
434*58b9f456SAndroid Build Coastguard Worker    template<class Y, class D, class A> void reset(Y* p, D d, A a);
435*58b9f456SAndroid Build Coastguard Worker
436*58b9f456SAndroid Build Coastguard Worker    // observers:
437*58b9f456SAndroid Build Coastguard Worker    T* get() const noexcept;
438*58b9f456SAndroid Build Coastguard Worker    T& operator*() const noexcept;
439*58b9f456SAndroid Build Coastguard Worker    T* operator->() const noexcept;
440*58b9f456SAndroid Build Coastguard Worker    long use_count() const noexcept;
441*58b9f456SAndroid Build Coastguard Worker    bool unique() const noexcept;
442*58b9f456SAndroid Build Coastguard Worker    explicit operator bool() const noexcept;
443*58b9f456SAndroid Build Coastguard Worker    template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
444*58b9f456SAndroid Build Coastguard Worker    template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
445*58b9f456SAndroid Build Coastguard Worker};
446*58b9f456SAndroid Build Coastguard Worker
447*58b9f456SAndroid Build Coastguard Worker// shared_ptr comparisons:
448*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
449*58b9f456SAndroid Build Coastguard Worker    bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
450*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
451*58b9f456SAndroid Build Coastguard Worker    bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
452*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
453*58b9f456SAndroid Build Coastguard Worker    bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
454*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
455*58b9f456SAndroid Build Coastguard Worker    bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
456*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
457*58b9f456SAndroid Build Coastguard Worker    bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
458*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
459*58b9f456SAndroid Build Coastguard Worker    bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
460*58b9f456SAndroid Build Coastguard Worker
461*58b9f456SAndroid Build Coastguard Workertemplate <class T>
462*58b9f456SAndroid Build Coastguard Worker    bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
463*58b9f456SAndroid Build Coastguard Workertemplate <class T>
464*58b9f456SAndroid Build Coastguard Worker    bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
465*58b9f456SAndroid Build Coastguard Workertemplate <class T>
466*58b9f456SAndroid Build Coastguard Worker    bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
467*58b9f456SAndroid Build Coastguard Workertemplate <class T>
468*58b9f456SAndroid Build Coastguard Worker    bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
469*58b9f456SAndroid Build Coastguard Workertemplate <class T>
470*58b9f456SAndroid Build Coastguard Worker    bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
471*58b9f456SAndroid Build Coastguard Workertemplate <class T>
472*58b9f456SAndroid Build Coastguard Workerbool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
473*58b9f456SAndroid Build Coastguard Workertemplate <class T>
474*58b9f456SAndroid Build Coastguard Worker    bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
475*58b9f456SAndroid Build Coastguard Workertemplate <class T>
476*58b9f456SAndroid Build Coastguard Worker    bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
477*58b9f456SAndroid Build Coastguard Workertemplate <class T>
478*58b9f456SAndroid Build Coastguard Worker    bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
479*58b9f456SAndroid Build Coastguard Workertemplate <class T>
480*58b9f456SAndroid Build Coastguard Worker    bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
481*58b9f456SAndroid Build Coastguard Workertemplate <class T>
482*58b9f456SAndroid Build Coastguard Worker    bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
483*58b9f456SAndroid Build Coastguard Workertemplate <class T>
484*58b9f456SAndroid Build Coastguard Worker    bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
485*58b9f456SAndroid Build Coastguard Worker
486*58b9f456SAndroid Build Coastguard Worker// shared_ptr specialized algorithms:
487*58b9f456SAndroid Build Coastguard Workertemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
488*58b9f456SAndroid Build Coastguard Worker
489*58b9f456SAndroid Build Coastguard Worker// shared_ptr casts:
490*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
491*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
492*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
493*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
494*58b9f456SAndroid Build Coastguard Workertemplate<class T, class U>
495*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
496*58b9f456SAndroid Build Coastguard Worker
497*58b9f456SAndroid Build Coastguard Worker// shared_ptr I/O:
498*58b9f456SAndroid Build Coastguard Workertemplate<class E, class T, class Y>
499*58b9f456SAndroid Build Coastguard Worker    basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
500*58b9f456SAndroid Build Coastguard Worker
501*58b9f456SAndroid Build Coastguard Worker// shared_ptr get_deleter:
502*58b9f456SAndroid Build Coastguard Workertemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
503*58b9f456SAndroid Build Coastguard Worker
504*58b9f456SAndroid Build Coastguard Workertemplate<class T, class... Args>
505*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> make_shared(Args&&... args);
506*58b9f456SAndroid Build Coastguard Workertemplate<class T, class A, class... Args>
507*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
508*58b9f456SAndroid Build Coastguard Worker
509*58b9f456SAndroid Build Coastguard Workertemplate<class T>
510*58b9f456SAndroid Build Coastguard Workerclass weak_ptr
511*58b9f456SAndroid Build Coastguard Worker{
512*58b9f456SAndroid Build Coastguard Workerpublic:
513*58b9f456SAndroid Build Coastguard Worker    typedef T element_type;
514*58b9f456SAndroid Build Coastguard Worker
515*58b9f456SAndroid Build Coastguard Worker    // constructors
516*58b9f456SAndroid Build Coastguard Worker    constexpr weak_ptr() noexcept;
517*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
518*58b9f456SAndroid Build Coastguard Worker    weak_ptr(weak_ptr const& r) noexcept;
519*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
520*58b9f456SAndroid Build Coastguard Worker    weak_ptr(weak_ptr&& r) noexcept;                      // C++14
521*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
522*58b9f456SAndroid Build Coastguard Worker
523*58b9f456SAndroid Build Coastguard Worker    // destructor
524*58b9f456SAndroid Build Coastguard Worker    ~weak_ptr();
525*58b9f456SAndroid Build Coastguard Worker
526*58b9f456SAndroid Build Coastguard Worker    // assignment
527*58b9f456SAndroid Build Coastguard Worker    weak_ptr& operator=(weak_ptr const& r) noexcept;
528*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
529*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
530*58b9f456SAndroid Build Coastguard Worker    weak_ptr& operator=(weak_ptr&& r) noexcept;                      // C++14
531*58b9f456SAndroid Build Coastguard Worker    template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
532*58b9f456SAndroid Build Coastguard Worker
533*58b9f456SAndroid Build Coastguard Worker    // modifiers
534*58b9f456SAndroid Build Coastguard Worker    void swap(weak_ptr& r) noexcept;
535*58b9f456SAndroid Build Coastguard Worker    void reset() noexcept;
536*58b9f456SAndroid Build Coastguard Worker
537*58b9f456SAndroid Build Coastguard Worker    // observers
538*58b9f456SAndroid Build Coastguard Worker    long use_count() const noexcept;
539*58b9f456SAndroid Build Coastguard Worker    bool expired() const noexcept;
540*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> lock() const noexcept;
541*58b9f456SAndroid Build Coastguard Worker    template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
542*58b9f456SAndroid Build Coastguard Worker    template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
543*58b9f456SAndroid Build Coastguard Worker};
544*58b9f456SAndroid Build Coastguard Worker
545*58b9f456SAndroid Build Coastguard Worker// weak_ptr specialized algorithms:
546*58b9f456SAndroid Build Coastguard Workertemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
547*58b9f456SAndroid Build Coastguard Worker
548*58b9f456SAndroid Build Coastguard Worker// class owner_less:
549*58b9f456SAndroid Build Coastguard Workertemplate<class T> struct owner_less;
550*58b9f456SAndroid Build Coastguard Worker
551*58b9f456SAndroid Build Coastguard Workertemplate<class T>
552*58b9f456SAndroid Build Coastguard Workerstruct owner_less<shared_ptr<T>>
553*58b9f456SAndroid Build Coastguard Worker    : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
554*58b9f456SAndroid Build Coastguard Worker{
555*58b9f456SAndroid Build Coastguard Worker    typedef bool result_type;
556*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
557*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
558*58b9f456SAndroid Build Coastguard Worker    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
559*58b9f456SAndroid Build Coastguard Worker};
560*58b9f456SAndroid Build Coastguard Worker
561*58b9f456SAndroid Build Coastguard Workertemplate<class T>
562*58b9f456SAndroid Build Coastguard Workerstruct owner_less<weak_ptr<T>>
563*58b9f456SAndroid Build Coastguard Worker    : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
564*58b9f456SAndroid Build Coastguard Worker{
565*58b9f456SAndroid Build Coastguard Worker    typedef bool result_type;
566*58b9f456SAndroid Build Coastguard Worker    bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
568*58b9f456SAndroid Build Coastguard Worker    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
569*58b9f456SAndroid Build Coastguard Worker};
570*58b9f456SAndroid Build Coastguard Worker
571*58b9f456SAndroid Build Coastguard Workertemplate <>  // Added in C++14
572*58b9f456SAndroid Build Coastguard Workerstruct owner_less<void>
573*58b9f456SAndroid Build Coastguard Worker{
574*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
575*58b9f456SAndroid Build Coastguard Worker    bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
576*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
577*58b9f456SAndroid Build Coastguard Worker    bool operator()( shared_ptr<_Tp> const& __x,   weak_ptr<_Up> const& __y) const noexcept;
578*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
579*58b9f456SAndroid Build Coastguard Worker    bool operator()(   weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
580*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
581*58b9f456SAndroid Build Coastguard Worker    bool operator()(   weak_ptr<_Tp> const& __x,   weak_ptr<_Up> const& __y) const noexcept;
582*58b9f456SAndroid Build Coastguard Worker
583*58b9f456SAndroid Build Coastguard Worker    typedef void is_transparent;
584*58b9f456SAndroid Build Coastguard Worker};
585*58b9f456SAndroid Build Coastguard Worker
586*58b9f456SAndroid Build Coastguard Workertemplate<class T>
587*58b9f456SAndroid Build Coastguard Workerclass enable_shared_from_this
588*58b9f456SAndroid Build Coastguard Worker{
589*58b9f456SAndroid Build Coastguard Workerprotected:
590*58b9f456SAndroid Build Coastguard Worker    constexpr enable_shared_from_this() noexcept;
591*58b9f456SAndroid Build Coastguard Worker    enable_shared_from_this(enable_shared_from_this const&) noexcept;
592*58b9f456SAndroid Build Coastguard Worker    enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
593*58b9f456SAndroid Build Coastguard Worker    ~enable_shared_from_this();
594*58b9f456SAndroid Build Coastguard Workerpublic:
595*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> shared_from_this();
596*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T const> shared_from_this() const;
597*58b9f456SAndroid Build Coastguard Worker};
598*58b9f456SAndroid Build Coastguard Worker
599*58b9f456SAndroid Build Coastguard Workertemplate<class T>
600*58b9f456SAndroid Build Coastguard Worker    bool atomic_is_lock_free(const shared_ptr<T>* p);
601*58b9f456SAndroid Build Coastguard Workertemplate<class T>
602*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> atomic_load(const shared_ptr<T>* p);
603*58b9f456SAndroid Build Coastguard Workertemplate<class T>
604*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
605*58b9f456SAndroid Build Coastguard Workertemplate<class T>
606*58b9f456SAndroid Build Coastguard Worker    void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
607*58b9f456SAndroid Build Coastguard Workertemplate<class T>
608*58b9f456SAndroid Build Coastguard Worker    void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
609*58b9f456SAndroid Build Coastguard Workertemplate<class T>
610*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
611*58b9f456SAndroid Build Coastguard Workertemplate<class T>
612*58b9f456SAndroid Build Coastguard Worker    shared_ptr<T>
613*58b9f456SAndroid Build Coastguard Worker    atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
614*58b9f456SAndroid Build Coastguard Workertemplate<class T>
615*58b9f456SAndroid Build Coastguard Worker    bool
616*58b9f456SAndroid Build Coastguard Worker    atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
617*58b9f456SAndroid Build Coastguard Workertemplate<class T>
618*58b9f456SAndroid Build Coastguard Worker    bool
619*58b9f456SAndroid Build Coastguard Worker    atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
620*58b9f456SAndroid Build Coastguard Workertemplate<class T>
621*58b9f456SAndroid Build Coastguard Worker    bool
622*58b9f456SAndroid Build Coastguard Worker    atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
623*58b9f456SAndroid Build Coastguard Worker                                          shared_ptr<T> w, memory_order success,
624*58b9f456SAndroid Build Coastguard Worker                                          memory_order failure);
625*58b9f456SAndroid Build Coastguard Workertemplate<class T>
626*58b9f456SAndroid Build Coastguard Worker    bool
627*58b9f456SAndroid Build Coastguard Worker    atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
628*58b9f456SAndroid Build Coastguard Worker                                            shared_ptr<T> w, memory_order success,
629*58b9f456SAndroid Build Coastguard Worker                                            memory_order failure);
630*58b9f456SAndroid Build Coastguard Worker// Hash support
631*58b9f456SAndroid Build Coastguard Workertemplate <class T> struct hash;
632*58b9f456SAndroid Build Coastguard Workertemplate <class T, class D> struct hash<unique_ptr<T, D> >;
633*58b9f456SAndroid Build Coastguard Workertemplate <class T> struct hash<shared_ptr<T> >;
634*58b9f456SAndroid Build Coastguard Worker
635*58b9f456SAndroid Build Coastguard Workertemplate <class T, class Alloc>
636*58b9f456SAndroid Build Coastguard Worker  inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
637*58b9f456SAndroid Build Coastguard Worker
638*58b9f456SAndroid Build Coastguard Worker// Pointer safety
639*58b9f456SAndroid Build Coastguard Workerenum class pointer_safety { relaxed, preferred, strict };
640*58b9f456SAndroid Build Coastguard Workervoid declare_reachable(void *p);
641*58b9f456SAndroid Build Coastguard Workertemplate <class T> T *undeclare_reachable(T *p);
642*58b9f456SAndroid Build Coastguard Workervoid declare_no_pointers(char *p, size_t n);
643*58b9f456SAndroid Build Coastguard Workervoid undeclare_no_pointers(char *p, size_t n);
644*58b9f456SAndroid Build Coastguard Workerpointer_safety get_pointer_safety() noexcept;
645*58b9f456SAndroid Build Coastguard Worker
646*58b9f456SAndroid Build Coastguard Workervoid* align(size_t alignment, size_t size, void*& ptr, size_t& space);
647*58b9f456SAndroid Build Coastguard Worker
648*58b9f456SAndroid Build Coastguard Worker}  // std
649*58b9f456SAndroid Build Coastguard Worker
650*58b9f456SAndroid Build Coastguard Worker*/
651*58b9f456SAndroid Build Coastguard Worker
652*58b9f456SAndroid Build Coastguard Worker#include <__config>
653*58b9f456SAndroid Build Coastguard Worker#include <type_traits>
654*58b9f456SAndroid Build Coastguard Worker#include <typeinfo>
655*58b9f456SAndroid Build Coastguard Worker#include <cstddef>
656*58b9f456SAndroid Build Coastguard Worker#include <cstdint>
657*58b9f456SAndroid Build Coastguard Worker#include <new>
658*58b9f456SAndroid Build Coastguard Worker#include <utility>
659*58b9f456SAndroid Build Coastguard Worker#include <limits>
660*58b9f456SAndroid Build Coastguard Worker#include <iterator>
661*58b9f456SAndroid Build Coastguard Worker#include <__functional_base>
662*58b9f456SAndroid Build Coastguard Worker#include <iosfwd>
663*58b9f456SAndroid Build Coastguard Worker#include <tuple>
664*58b9f456SAndroid Build Coastguard Worker#include <stdexcept>
665*58b9f456SAndroid Build Coastguard Worker#include <cstring>
666*58b9f456SAndroid Build Coastguard Worker#include <cassert>
667*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
668*58b9f456SAndroid Build Coastguard Worker#  include <atomic>
669*58b9f456SAndroid Build Coastguard Worker#endif
670*58b9f456SAndroid Build Coastguard Worker#include <version>
671*58b9f456SAndroid Build Coastguard Worker
672*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
673*58b9f456SAndroid Build Coastguard Worker#pragma GCC system_header
674*58b9f456SAndroid Build Coastguard Worker#endif
675*58b9f456SAndroid Build Coastguard Worker
676*58b9f456SAndroid Build Coastguard Worker_LIBCPP_PUSH_MACROS
677*58b9f456SAndroid Build Coastguard Worker#include <__undef_macros>
678*58b9f456SAndroid Build Coastguard Worker
679*58b9f456SAndroid Build Coastguard Worker
680*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_STD
681*58b9f456SAndroid Build Coastguard Worker
682*58b9f456SAndroid Build Coastguard Workertemplate <class _ValueType>
683*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
684*58b9f456SAndroid Build Coastguard Worker_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
685*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_THREADS) && \
686*58b9f456SAndroid Build Coastguard Worker    defined(__ATOMIC_RELAXED) &&        \
687*58b9f456SAndroid Build Coastguard Worker    (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
688*58b9f456SAndroid Build Coastguard Worker    return __atomic_load_n(__value, __ATOMIC_RELAXED);
689*58b9f456SAndroid Build Coastguard Worker#else
690*58b9f456SAndroid Build Coastguard Worker    return *__value;
691*58b9f456SAndroid Build Coastguard Worker#endif
692*58b9f456SAndroid Build Coastguard Worker}
693*58b9f456SAndroid Build Coastguard Worker
694*58b9f456SAndroid Build Coastguard Workertemplate <class _ValueType>
695*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
696*58b9f456SAndroid Build Coastguard Worker_ValueType __libcpp_acquire_load(_ValueType const* __value) {
697*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_THREADS) && \
698*58b9f456SAndroid Build Coastguard Worker    defined(__ATOMIC_ACQUIRE) &&        \
699*58b9f456SAndroid Build Coastguard Worker    (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
700*58b9f456SAndroid Build Coastguard Worker    return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
701*58b9f456SAndroid Build Coastguard Worker#else
702*58b9f456SAndroid Build Coastguard Worker    return *__value;
703*58b9f456SAndroid Build Coastguard Worker#endif
704*58b9f456SAndroid Build Coastguard Worker}
705*58b9f456SAndroid Build Coastguard Worker
706*58b9f456SAndroid Build Coastguard Worker// addressof moved to <type_traits>
707*58b9f456SAndroid Build Coastguard Worker
708*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp> class allocator;
709*58b9f456SAndroid Build Coastguard Worker
710*58b9f456SAndroid Build Coastguard Workertemplate <>
711*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS allocator<void>
712*58b9f456SAndroid Build Coastguard Worker{
713*58b9f456SAndroid Build Coastguard Workerpublic:
714*58b9f456SAndroid Build Coastguard Worker    typedef void*             pointer;
715*58b9f456SAndroid Build Coastguard Worker    typedef const void*       const_pointer;
716*58b9f456SAndroid Build Coastguard Worker    typedef void              value_type;
717*58b9f456SAndroid Build Coastguard Worker
718*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef allocator<_Up> other;};
719*58b9f456SAndroid Build Coastguard Worker};
720*58b9f456SAndroid Build Coastguard Worker
721*58b9f456SAndroid Build Coastguard Workertemplate <>
722*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS allocator<const void>
723*58b9f456SAndroid Build Coastguard Worker{
724*58b9f456SAndroid Build Coastguard Workerpublic:
725*58b9f456SAndroid Build Coastguard Worker    typedef const void*       pointer;
726*58b9f456SAndroid Build Coastguard Worker    typedef const void*       const_pointer;
727*58b9f456SAndroid Build Coastguard Worker    typedef const void        value_type;
728*58b9f456SAndroid Build Coastguard Worker
729*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef allocator<_Up> other;};
730*58b9f456SAndroid Build Coastguard Worker};
731*58b9f456SAndroid Build Coastguard Worker
732*58b9f456SAndroid Build Coastguard Worker// pointer_traits
733*58b9f456SAndroid Build Coastguard Worker
734*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
735*58b9f456SAndroid Build Coastguard Workerstruct __has_element_type : false_type {};
736*58b9f456SAndroid Build Coastguard Worker
737*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
738*58b9f456SAndroid Build Coastguard Workerstruct __has_element_type<_Tp,
739*58b9f456SAndroid Build Coastguard Worker              typename __void_t<typename _Tp::element_type>::type> : true_type {};
740*58b9f456SAndroid Build Coastguard Worker
741*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, bool = __has_element_type<_Ptr>::value>
742*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type;
743*58b9f456SAndroid Build Coastguard Worker
744*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr>
745*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Ptr, true>
746*58b9f456SAndroid Build Coastguard Worker{
747*58b9f456SAndroid Build Coastguard Worker    typedef typename _Ptr::element_type type;
748*58b9f456SAndroid Build Coastguard Worker};
749*58b9f456SAndroid Build Coastguard Worker
750*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
751*58b9f456SAndroid Build Coastguard Worker
752*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
753*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
754*58b9f456SAndroid Build Coastguard Worker{
755*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _Args...>::element_type type;
756*58b9f456SAndroid Build Coastguard Worker};
757*58b9f456SAndroid Build Coastguard Worker
758*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
759*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
760*58b9f456SAndroid Build Coastguard Worker{
761*58b9f456SAndroid Build Coastguard Worker    typedef _Tp type;
762*58b9f456SAndroid Build Coastguard Worker};
763*58b9f456SAndroid Build Coastguard Worker
764*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
765*58b9f456SAndroid Build Coastguard Worker
766*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Sp, class _Tp>
767*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp>, true>
768*58b9f456SAndroid Build Coastguard Worker{
769*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp>::element_type type;
770*58b9f456SAndroid Build Coastguard Worker};
771*58b9f456SAndroid Build Coastguard Worker
772*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Sp, class _Tp>
773*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp>, false>
774*58b9f456SAndroid Build Coastguard Worker{
775*58b9f456SAndroid Build Coastguard Worker    typedef _Tp type;
776*58b9f456SAndroid Build Coastguard Worker};
777*58b9f456SAndroid Build Coastguard Worker
778*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Sp, class _Tp, class _A0>
779*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
780*58b9f456SAndroid Build Coastguard Worker{
781*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0>::element_type type;
782*58b9f456SAndroid Build Coastguard Worker};
783*58b9f456SAndroid Build Coastguard Worker
784*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Sp, class _Tp, class _A0>
785*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
786*58b9f456SAndroid Build Coastguard Worker{
787*58b9f456SAndroid Build Coastguard Worker    typedef _Tp type;
788*58b9f456SAndroid Build Coastguard Worker};
789*58b9f456SAndroid Build Coastguard Worker
790*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
791*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
792*58b9f456SAndroid Build Coastguard Worker{
793*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
794*58b9f456SAndroid Build Coastguard Worker};
795*58b9f456SAndroid Build Coastguard Worker
796*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
797*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
798*58b9f456SAndroid Build Coastguard Worker{
799*58b9f456SAndroid Build Coastguard Worker    typedef _Tp type;
800*58b9f456SAndroid Build Coastguard Worker};
801*58b9f456SAndroid Build Coastguard Worker
802*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
803*58b9f456SAndroid Build Coastguard Worker                                                           class _A1, class _A2>
804*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
805*58b9f456SAndroid Build Coastguard Worker{
806*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
807*58b9f456SAndroid Build Coastguard Worker};
808*58b9f456SAndroid Build Coastguard Worker
809*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
810*58b9f456SAndroid Build Coastguard Worker                                                           class _A1, class _A2>
811*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
812*58b9f456SAndroid Build Coastguard Worker{
813*58b9f456SAndroid Build Coastguard Worker    typedef _Tp type;
814*58b9f456SAndroid Build Coastguard Worker};
815*58b9f456SAndroid Build Coastguard Worker
816*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
817*58b9f456SAndroid Build Coastguard Worker
818*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
819*58b9f456SAndroid Build Coastguard Workerstruct __has_difference_type : false_type {};
820*58b9f456SAndroid Build Coastguard Worker
821*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
822*58b9f456SAndroid Build Coastguard Workerstruct __has_difference_type<_Tp,
823*58b9f456SAndroid Build Coastguard Worker            typename __void_t<typename _Tp::difference_type>::type> : true_type {};
824*58b9f456SAndroid Build Coastguard Worker
825*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value>
826*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_difference_type
827*58b9f456SAndroid Build Coastguard Worker{
828*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t type;
829*58b9f456SAndroid Build Coastguard Worker};
830*58b9f456SAndroid Build Coastguard Worker
831*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr>
832*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_difference_type<_Ptr, true>
833*58b9f456SAndroid Build Coastguard Worker{
834*58b9f456SAndroid Build Coastguard Worker    typedef typename _Ptr::difference_type type;
835*58b9f456SAndroid Build Coastguard Worker};
836*58b9f456SAndroid Build Coastguard Worker
837*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up>
838*58b9f456SAndroid Build Coastguard Workerstruct __has_rebind
839*58b9f456SAndroid Build Coastguard Worker{
840*58b9f456SAndroid Build Coastguard Workerprivate:
841*58b9f456SAndroid Build Coastguard Worker    struct __two {char __lx; char __lxx;};
842*58b9f456SAndroid Build Coastguard Worker    template <class _Xp> static __two __test(...);
843*58b9f456SAndroid Build Coastguard Worker    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
844*58b9f456SAndroid Build Coastguard Workerpublic:
845*58b9f456SAndroid Build Coastguard Worker    static const bool value = sizeof(__test<_Tp>(0)) == 1;
846*58b9f456SAndroid Build Coastguard Worker};
847*58b9f456SAndroid Build Coastguard Worker
848*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
849*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind
850*58b9f456SAndroid Build Coastguard Worker{
851*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
852*58b9f456SAndroid Build Coastguard Worker    typedef typename _Tp::template rebind<_Up> type;
853*58b9f456SAndroid Build Coastguard Worker#else
854*58b9f456SAndroid Build Coastguard Worker    typedef typename _Tp::template rebind<_Up>::other type;
855*58b9f456SAndroid Build Coastguard Worker#endif
856*58b9f456SAndroid Build Coastguard Worker};
857*58b9f456SAndroid Build Coastguard Worker
858*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
859*58b9f456SAndroid Build Coastguard Worker
860*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
861*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
862*58b9f456SAndroid Build Coastguard Worker{
863*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
864*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
865*58b9f456SAndroid Build Coastguard Worker#else
866*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
867*58b9f456SAndroid Build Coastguard Worker#endif
868*58b9f456SAndroid Build Coastguard Worker};
869*58b9f456SAndroid Build Coastguard Worker
870*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
871*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
872*58b9f456SAndroid Build Coastguard Worker{
873*58b9f456SAndroid Build Coastguard Worker    typedef _Sp<_Up, _Args...> type;
874*58b9f456SAndroid Build Coastguard Worker};
875*58b9f456SAndroid Build Coastguard Worker
876*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
877*58b9f456SAndroid Build Coastguard Worker
878*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Sp, class _Tp, class _Up>
879*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
880*58b9f456SAndroid Build Coastguard Worker{
881*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
882*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp>::template rebind<_Up> type;
883*58b9f456SAndroid Build Coastguard Worker#else
884*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
885*58b9f456SAndroid Build Coastguard Worker#endif
886*58b9f456SAndroid Build Coastguard Worker};
887*58b9f456SAndroid Build Coastguard Worker
888*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Sp, class _Tp, class _Up>
889*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
890*58b9f456SAndroid Build Coastguard Worker{
891*58b9f456SAndroid Build Coastguard Worker    typedef _Sp<_Up> type;
892*58b9f456SAndroid Build Coastguard Worker};
893*58b9f456SAndroid Build Coastguard Worker
894*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
895*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
896*58b9f456SAndroid Build Coastguard Worker{
897*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
898*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
899*58b9f456SAndroid Build Coastguard Worker#else
900*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
901*58b9f456SAndroid Build Coastguard Worker#endif
902*58b9f456SAndroid Build Coastguard Worker};
903*58b9f456SAndroid Build Coastguard Worker
904*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
905*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
906*58b9f456SAndroid Build Coastguard Worker{
907*58b9f456SAndroid Build Coastguard Worker    typedef _Sp<_Up, _A0> type;
908*58b9f456SAndroid Build Coastguard Worker};
909*58b9f456SAndroid Build Coastguard Worker
910*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
911*58b9f456SAndroid Build Coastguard Worker                                         class _A1, class _Up>
912*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
913*58b9f456SAndroid Build Coastguard Worker{
914*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
915*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
916*58b9f456SAndroid Build Coastguard Worker#else
917*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
918*58b9f456SAndroid Build Coastguard Worker#endif
919*58b9f456SAndroid Build Coastguard Worker};
920*58b9f456SAndroid Build Coastguard Worker
921*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
922*58b9f456SAndroid Build Coastguard Worker                                         class _A1, class _Up>
923*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
924*58b9f456SAndroid Build Coastguard Worker{
925*58b9f456SAndroid Build Coastguard Worker    typedef _Sp<_Up, _A0, _A1> type;
926*58b9f456SAndroid Build Coastguard Worker};
927*58b9f456SAndroid Build Coastguard Worker
928*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
929*58b9f456SAndroid Build Coastguard Worker                                                class _A1, class _A2, class _Up>
930*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
931*58b9f456SAndroid Build Coastguard Worker{
932*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
933*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
934*58b9f456SAndroid Build Coastguard Worker#else
935*58b9f456SAndroid Build Coastguard Worker    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
936*58b9f456SAndroid Build Coastguard Worker#endif
937*58b9f456SAndroid Build Coastguard Worker};
938*58b9f456SAndroid Build Coastguard Worker
939*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
940*58b9f456SAndroid Build Coastguard Worker                                                class _A1, class _A2, class _Up>
941*58b9f456SAndroid Build Coastguard Workerstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
942*58b9f456SAndroid Build Coastguard Worker{
943*58b9f456SAndroid Build Coastguard Worker    typedef _Sp<_Up, _A0, _A1, _A2> type;
944*58b9f456SAndroid Build Coastguard Worker};
945*58b9f456SAndroid Build Coastguard Worker
946*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
947*58b9f456SAndroid Build Coastguard Worker
948*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr>
949*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS pointer_traits
950*58b9f456SAndroid Build Coastguard Worker{
951*58b9f456SAndroid Build Coastguard Worker    typedef _Ptr                                                     pointer;
952*58b9f456SAndroid Build Coastguard Worker    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
953*58b9f456SAndroid Build Coastguard Worker    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
954*58b9f456SAndroid Build Coastguard Worker
955*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
956*58b9f456SAndroid Build Coastguard Worker    template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
957*58b9f456SAndroid Build Coastguard Worker#else
958*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind
959*58b9f456SAndroid Build Coastguard Worker        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
960*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_CXX03_LANG
961*58b9f456SAndroid Build Coastguard Worker
962*58b9f456SAndroid Build Coastguard Workerprivate:
963*58b9f456SAndroid Build Coastguard Worker    struct __nat {};
964*58b9f456SAndroid Build Coastguard Workerpublic:
965*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
966*58b9f456SAndroid Build Coastguard Worker    static pointer pointer_to(typename conditional<is_void<element_type>::value,
967*58b9f456SAndroid Build Coastguard Worker                                           __nat, element_type>::type& __r)
968*58b9f456SAndroid Build Coastguard Worker        {return pointer::pointer_to(__r);}
969*58b9f456SAndroid Build Coastguard Worker};
970*58b9f456SAndroid Build Coastguard Worker
971*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
972*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
973*58b9f456SAndroid Build Coastguard Worker{
974*58b9f456SAndroid Build Coastguard Worker    typedef _Tp*      pointer;
975*58b9f456SAndroid Build Coastguard Worker    typedef _Tp       element_type;
976*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t difference_type;
977*58b9f456SAndroid Build Coastguard Worker
978*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
979*58b9f456SAndroid Build Coastguard Worker    template <class _Up> using rebind = _Up*;
980*58b9f456SAndroid Build Coastguard Worker#else
981*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef _Up* other;};
982*58b9f456SAndroid Build Coastguard Worker#endif
983*58b9f456SAndroid Build Coastguard Worker
984*58b9f456SAndroid Build Coastguard Workerprivate:
985*58b9f456SAndroid Build Coastguard Worker    struct __nat {};
986*58b9f456SAndroid Build Coastguard Workerpublic:
987*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
988*58b9f456SAndroid Build Coastguard Worker    static pointer pointer_to(typename conditional<is_void<element_type>::value,
989*58b9f456SAndroid Build Coastguard Worker                                      __nat, element_type>::type& __r) _NOEXCEPT
990*58b9f456SAndroid Build Coastguard Worker        {return _VSTD::addressof(__r);}
991*58b9f456SAndroid Build Coastguard Worker};
992*58b9f456SAndroid Build Coastguard Worker
993*58b9f456SAndroid Build Coastguard Workertemplate <class _From, class _To>
994*58b9f456SAndroid Build Coastguard Workerstruct __rebind_pointer {
995*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
996*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_From>::template rebind<_To>        type;
997*58b9f456SAndroid Build Coastguard Worker#else
998*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_From>::template rebind<_To>::other type;
999*58b9f456SAndroid Build Coastguard Worker#endif
1000*58b9f456SAndroid Build Coastguard Worker};
1001*58b9f456SAndroid Build Coastguard Worker
1002*58b9f456SAndroid Build Coastguard Worker// allocator_traits
1003*58b9f456SAndroid Build Coastguard Worker
1004*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1005*58b9f456SAndroid Build Coastguard Workerstruct __has_pointer_type : false_type {};
1006*58b9f456SAndroid Build Coastguard Worker
1007*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1008*58b9f456SAndroid Build Coastguard Workerstruct __has_pointer_type<_Tp,
1009*58b9f456SAndroid Build Coastguard Worker          typename __void_t<typename _Tp::pointer>::type> : true_type {};
1010*58b9f456SAndroid Build Coastguard Worker
1011*58b9f456SAndroid Build Coastguard Workernamespace __pointer_type_imp
1012*58b9f456SAndroid Build Coastguard Worker{
1013*58b9f456SAndroid Build Coastguard Worker
1014*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1015*58b9f456SAndroid Build Coastguard Workerstruct __pointer_type
1016*58b9f456SAndroid Build Coastguard Worker{
1017*58b9f456SAndroid Build Coastguard Worker    typedef typename _Dp::pointer type;
1018*58b9f456SAndroid Build Coastguard Worker};
1019*58b9f456SAndroid Build Coastguard Worker
1020*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
1021*58b9f456SAndroid Build Coastguard Workerstruct __pointer_type<_Tp, _Dp, false>
1022*58b9f456SAndroid Build Coastguard Worker{
1023*58b9f456SAndroid Build Coastguard Worker    typedef _Tp* type;
1024*58b9f456SAndroid Build Coastguard Worker};
1025*58b9f456SAndroid Build Coastguard Worker
1026*58b9f456SAndroid Build Coastguard Worker}  // __pointer_type_imp
1027*58b9f456SAndroid Build Coastguard Worker
1028*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
1029*58b9f456SAndroid Build Coastguard Workerstruct __pointer_type
1030*58b9f456SAndroid Build Coastguard Worker{
1031*58b9f456SAndroid Build Coastguard Worker    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1032*58b9f456SAndroid Build Coastguard Worker};
1033*58b9f456SAndroid Build Coastguard Worker
1034*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1035*58b9f456SAndroid Build Coastguard Workerstruct __has_const_pointer : false_type {};
1036*58b9f456SAndroid Build Coastguard Worker
1037*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1038*58b9f456SAndroid Build Coastguard Workerstruct __has_const_pointer<_Tp,
1039*58b9f456SAndroid Build Coastguard Worker            typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1040*58b9f456SAndroid Build Coastguard Worker
1041*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1042*58b9f456SAndroid Build Coastguard Workerstruct __const_pointer
1043*58b9f456SAndroid Build Coastguard Worker{
1044*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::const_pointer type;
1045*58b9f456SAndroid Build Coastguard Worker};
1046*58b9f456SAndroid Build Coastguard Worker
1047*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Ptr, class _Alloc>
1048*58b9f456SAndroid Build Coastguard Workerstruct __const_pointer<_Tp, _Ptr, _Alloc, false>
1049*58b9f456SAndroid Build Coastguard Worker{
1050*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1051*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1052*58b9f456SAndroid Build Coastguard Worker#else
1053*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1054*58b9f456SAndroid Build Coastguard Worker#endif
1055*58b9f456SAndroid Build Coastguard Worker};
1056*58b9f456SAndroid Build Coastguard Worker
1057*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1058*58b9f456SAndroid Build Coastguard Workerstruct __has_void_pointer : false_type {};
1059*58b9f456SAndroid Build Coastguard Worker
1060*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1061*58b9f456SAndroid Build Coastguard Workerstruct __has_void_pointer<_Tp,
1062*58b9f456SAndroid Build Coastguard Worker               typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1063*58b9f456SAndroid Build Coastguard Worker
1064*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1065*58b9f456SAndroid Build Coastguard Workerstruct __void_pointer
1066*58b9f456SAndroid Build Coastguard Worker{
1067*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::void_pointer type;
1068*58b9f456SAndroid Build Coastguard Worker};
1069*58b9f456SAndroid Build Coastguard Worker
1070*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, class _Alloc>
1071*58b9f456SAndroid Build Coastguard Workerstruct __void_pointer<_Ptr, _Alloc, false>
1072*58b9f456SAndroid Build Coastguard Worker{
1073*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1074*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1075*58b9f456SAndroid Build Coastguard Worker#else
1076*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1077*58b9f456SAndroid Build Coastguard Worker#endif
1078*58b9f456SAndroid Build Coastguard Worker};
1079*58b9f456SAndroid Build Coastguard Worker
1080*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1081*58b9f456SAndroid Build Coastguard Workerstruct __has_const_void_pointer : false_type {};
1082*58b9f456SAndroid Build Coastguard Worker
1083*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1084*58b9f456SAndroid Build Coastguard Workerstruct __has_const_void_pointer<_Tp,
1085*58b9f456SAndroid Build Coastguard Worker            typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1086*58b9f456SAndroid Build Coastguard Worker
1087*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1088*58b9f456SAndroid Build Coastguard Workerstruct __const_void_pointer
1089*58b9f456SAndroid Build Coastguard Worker{
1090*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::const_void_pointer type;
1091*58b9f456SAndroid Build Coastguard Worker};
1092*58b9f456SAndroid Build Coastguard Worker
1093*58b9f456SAndroid Build Coastguard Workertemplate <class _Ptr, class _Alloc>
1094*58b9f456SAndroid Build Coastguard Workerstruct __const_void_pointer<_Ptr, _Alloc, false>
1095*58b9f456SAndroid Build Coastguard Worker{
1096*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1097*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1098*58b9f456SAndroid Build Coastguard Worker#else
1099*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1100*58b9f456SAndroid Build Coastguard Worker#endif
1101*58b9f456SAndroid Build Coastguard Worker};
1102*58b9f456SAndroid Build Coastguard Worker
1103*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1104*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1105*58b9f456SAndroid Build Coastguard Worker_Tp*
1106*58b9f456SAndroid Build Coastguard Worker__to_raw_pointer(_Tp* __p) _NOEXCEPT
1107*58b9f456SAndroid Build Coastguard Worker{
1108*58b9f456SAndroid Build Coastguard Worker    return __p;
1109*58b9f456SAndroid Build Coastguard Worker}
1110*58b9f456SAndroid Build Coastguard Worker
1111*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 17
1112*58b9f456SAndroid Build Coastguard Workertemplate <class _Pointer>
1113*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1114*58b9f456SAndroid Build Coastguard Workertypename pointer_traits<_Pointer>::element_type*
1115*58b9f456SAndroid Build Coastguard Worker__to_raw_pointer(_Pointer __p) _NOEXCEPT
1116*58b9f456SAndroid Build Coastguard Worker{
1117*58b9f456SAndroid Build Coastguard Worker    return _VSTD::__to_raw_pointer(__p.operator->());
1118*58b9f456SAndroid Build Coastguard Worker}
1119*58b9f456SAndroid Build Coastguard Worker#else
1120*58b9f456SAndroid Build Coastguard Workertemplate <class _Pointer>
1121*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1122*58b9f456SAndroid Build Coastguard Workerauto
1123*58b9f456SAndroid Build Coastguard Worker__to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1124*58b9f456SAndroid Build Coastguard Worker-> decltype(pointer_traits<_Pointer>::to_address(__p))
1125*58b9f456SAndroid Build Coastguard Worker{
1126*58b9f456SAndroid Build Coastguard Worker    return pointer_traits<_Pointer>::to_address(__p);
1127*58b9f456SAndroid Build Coastguard Worker}
1128*58b9f456SAndroid Build Coastguard Worker
1129*58b9f456SAndroid Build Coastguard Workertemplate <class _Pointer, class... _None>
1130*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1131*58b9f456SAndroid Build Coastguard Workerauto
1132*58b9f456SAndroid Build Coastguard Worker__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1133*58b9f456SAndroid Build Coastguard Worker{
1134*58b9f456SAndroid Build Coastguard Worker    return _VSTD::__to_raw_pointer(__p.operator->());
1135*58b9f456SAndroid Build Coastguard Worker}
1136*58b9f456SAndroid Build Coastguard Worker
1137*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1138*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY constexpr
1139*58b9f456SAndroid Build Coastguard Worker_Tp*
1140*58b9f456SAndroid Build Coastguard Workerto_address(_Tp* __p) _NOEXCEPT
1141*58b9f456SAndroid Build Coastguard Worker{
1142*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1143*58b9f456SAndroid Build Coastguard Worker    return __p;
1144*58b9f456SAndroid Build Coastguard Worker}
1145*58b9f456SAndroid Build Coastguard Worker
1146*58b9f456SAndroid Build Coastguard Workertemplate <class _Pointer>
1147*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1148*58b9f456SAndroid Build Coastguard Workerauto
1149*58b9f456SAndroid Build Coastguard Workerto_address(const _Pointer& __p) _NOEXCEPT
1150*58b9f456SAndroid Build Coastguard Worker{
1151*58b9f456SAndroid Build Coastguard Worker    return _VSTD::__to_raw_pointer(__p);
1152*58b9f456SAndroid Build Coastguard Worker}
1153*58b9f456SAndroid Build Coastguard Worker#endif
1154*58b9f456SAndroid Build Coastguard Worker
1155*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1156*58b9f456SAndroid Build Coastguard Workerstruct __has_size_type : false_type {};
1157*58b9f456SAndroid Build Coastguard Worker
1158*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1159*58b9f456SAndroid Build Coastguard Workerstruct __has_size_type<_Tp,
1160*58b9f456SAndroid Build Coastguard Worker               typename __void_t<typename _Tp::size_type>::type> : true_type {};
1161*58b9f456SAndroid Build Coastguard Worker
1162*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1163*58b9f456SAndroid Build Coastguard Workerstruct __size_type
1164*58b9f456SAndroid Build Coastguard Worker{
1165*58b9f456SAndroid Build Coastguard Worker    typedef typename make_unsigned<_DiffType>::type type;
1166*58b9f456SAndroid Build Coastguard Worker};
1167*58b9f456SAndroid Build Coastguard Worker
1168*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _DiffType>
1169*58b9f456SAndroid Build Coastguard Workerstruct __size_type<_Alloc, _DiffType, true>
1170*58b9f456SAndroid Build Coastguard Worker{
1171*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::size_type type;
1172*58b9f456SAndroid Build Coastguard Worker};
1173*58b9f456SAndroid Build Coastguard Worker
1174*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1175*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_copy_assignment : false_type {};
1176*58b9f456SAndroid Build Coastguard Worker
1177*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1178*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_copy_assignment<_Tp,
1179*58b9f456SAndroid Build Coastguard Worker    typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1180*58b9f456SAndroid Build Coastguard Worker        : true_type {};
1181*58b9f456SAndroid Build Coastguard Worker
1182*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1183*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_copy_assignment
1184*58b9f456SAndroid Build Coastguard Worker{
1185*58b9f456SAndroid Build Coastguard Worker    typedef false_type type;
1186*58b9f456SAndroid Build Coastguard Worker};
1187*58b9f456SAndroid Build Coastguard Worker
1188*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1189*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_copy_assignment<_Alloc, true>
1190*58b9f456SAndroid Build Coastguard Worker{
1191*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::propagate_on_container_copy_assignment type;
1192*58b9f456SAndroid Build Coastguard Worker};
1193*58b9f456SAndroid Build Coastguard Worker
1194*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1195*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_move_assignment : false_type {};
1196*58b9f456SAndroid Build Coastguard Worker
1197*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1198*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_move_assignment<_Tp,
1199*58b9f456SAndroid Build Coastguard Worker           typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1200*58b9f456SAndroid Build Coastguard Worker               : true_type {};
1201*58b9f456SAndroid Build Coastguard Worker
1202*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1203*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_move_assignment
1204*58b9f456SAndroid Build Coastguard Worker{
1205*58b9f456SAndroid Build Coastguard Worker    typedef false_type type;
1206*58b9f456SAndroid Build Coastguard Worker};
1207*58b9f456SAndroid Build Coastguard Worker
1208*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1209*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_move_assignment<_Alloc, true>
1210*58b9f456SAndroid Build Coastguard Worker{
1211*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::propagate_on_container_move_assignment type;
1212*58b9f456SAndroid Build Coastguard Worker};
1213*58b9f456SAndroid Build Coastguard Worker
1214*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1215*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_swap : false_type {};
1216*58b9f456SAndroid Build Coastguard Worker
1217*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1218*58b9f456SAndroid Build Coastguard Workerstruct __has_propagate_on_container_swap<_Tp,
1219*58b9f456SAndroid Build Coastguard Worker           typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1220*58b9f456SAndroid Build Coastguard Worker               : true_type {};
1221*58b9f456SAndroid Build Coastguard Worker
1222*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1223*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_swap
1224*58b9f456SAndroid Build Coastguard Worker{
1225*58b9f456SAndroid Build Coastguard Worker    typedef false_type type;
1226*58b9f456SAndroid Build Coastguard Worker};
1227*58b9f456SAndroid Build Coastguard Worker
1228*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1229*58b9f456SAndroid Build Coastguard Workerstruct __propagate_on_container_swap<_Alloc, true>
1230*58b9f456SAndroid Build Coastguard Worker{
1231*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::propagate_on_container_swap type;
1232*58b9f456SAndroid Build Coastguard Worker};
1233*58b9f456SAndroid Build Coastguard Worker
1234*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class = void>
1235*58b9f456SAndroid Build Coastguard Workerstruct __has_is_always_equal : false_type {};
1236*58b9f456SAndroid Build Coastguard Worker
1237*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1238*58b9f456SAndroid Build Coastguard Workerstruct __has_is_always_equal<_Tp,
1239*58b9f456SAndroid Build Coastguard Worker           typename __void_t<typename _Tp::is_always_equal>::type>
1240*58b9f456SAndroid Build Coastguard Worker               : true_type {};
1241*58b9f456SAndroid Build Coastguard Worker
1242*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1243*58b9f456SAndroid Build Coastguard Workerstruct __is_always_equal
1244*58b9f456SAndroid Build Coastguard Worker{
1245*58b9f456SAndroid Build Coastguard Worker    typedef typename _VSTD::is_empty<_Alloc>::type type;
1246*58b9f456SAndroid Build Coastguard Worker};
1247*58b9f456SAndroid Build Coastguard Worker
1248*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1249*58b9f456SAndroid Build Coastguard Workerstruct __is_always_equal<_Alloc, true>
1250*58b9f456SAndroid Build Coastguard Worker{
1251*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::is_always_equal type;
1252*58b9f456SAndroid Build Coastguard Worker};
1253*58b9f456SAndroid Build Coastguard Worker
1254*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1255*58b9f456SAndroid Build Coastguard Workerstruct __has_rebind_other
1256*58b9f456SAndroid Build Coastguard Worker{
1257*58b9f456SAndroid Build Coastguard Workerprivate:
1258*58b9f456SAndroid Build Coastguard Worker    struct __two {char __lx; char __lxx;};
1259*58b9f456SAndroid Build Coastguard Worker    template <class _Xp> static __two __test(...);
1260*58b9f456SAndroid Build Coastguard Worker    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1261*58b9f456SAndroid Build Coastguard Workerpublic:
1262*58b9f456SAndroid Build Coastguard Worker    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1263*58b9f456SAndroid Build Coastguard Worker};
1264*58b9f456SAndroid Build Coastguard Worker
1265*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up>
1266*58b9f456SAndroid Build Coastguard Workerstruct __has_rebind_other<_Tp, _Up, false>
1267*58b9f456SAndroid Build Coastguard Worker{
1268*58b9f456SAndroid Build Coastguard Worker    static const bool value = false;
1269*58b9f456SAndroid Build Coastguard Worker};
1270*58b9f456SAndroid Build Coastguard Worker
1271*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1272*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind
1273*58b9f456SAndroid Build Coastguard Worker{
1274*58b9f456SAndroid Build Coastguard Worker    typedef typename _Tp::template rebind<_Up>::other type;
1275*58b9f456SAndroid Build Coastguard Worker};
1276*58b9f456SAndroid Build Coastguard Worker
1277*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
1278*58b9f456SAndroid Build Coastguard Worker
1279*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1280*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1281*58b9f456SAndroid Build Coastguard Worker{
1282*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1283*58b9f456SAndroid Build Coastguard Worker};
1284*58b9f456SAndroid Build Coastguard Worker
1285*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1286*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1287*58b9f456SAndroid Build Coastguard Worker{
1288*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc<_Up, _Args...> type;
1289*58b9f456SAndroid Build Coastguard Worker};
1290*58b9f456SAndroid Build Coastguard Worker
1291*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
1292*58b9f456SAndroid Build Coastguard Worker
1293*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Alloc, class _Tp, class _Up>
1294*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1295*58b9f456SAndroid Build Coastguard Worker{
1296*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1297*58b9f456SAndroid Build Coastguard Worker};
1298*58b9f456SAndroid Build Coastguard Worker
1299*58b9f456SAndroid Build Coastguard Workertemplate <template <class> class _Alloc, class _Tp, class _Up>
1300*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1301*58b9f456SAndroid Build Coastguard Worker{
1302*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc<_Up> type;
1303*58b9f456SAndroid Build Coastguard Worker};
1304*58b9f456SAndroid Build Coastguard Worker
1305*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1306*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1307*58b9f456SAndroid Build Coastguard Worker{
1308*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1309*58b9f456SAndroid Build Coastguard Worker};
1310*58b9f456SAndroid Build Coastguard Worker
1311*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1312*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1313*58b9f456SAndroid Build Coastguard Worker{
1314*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc<_Up, _A0> type;
1315*58b9f456SAndroid Build Coastguard Worker};
1316*58b9f456SAndroid Build Coastguard Worker
1317*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1318*58b9f456SAndroid Build Coastguard Worker                                         class _A1, class _Up>
1319*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1320*58b9f456SAndroid Build Coastguard Worker{
1321*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1322*58b9f456SAndroid Build Coastguard Worker};
1323*58b9f456SAndroid Build Coastguard Worker
1324*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1325*58b9f456SAndroid Build Coastguard Worker                                         class _A1, class _Up>
1326*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1327*58b9f456SAndroid Build Coastguard Worker{
1328*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc<_Up, _A0, _A1> type;
1329*58b9f456SAndroid Build Coastguard Worker};
1330*58b9f456SAndroid Build Coastguard Worker
1331*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1332*58b9f456SAndroid Build Coastguard Worker                                                class _A1, class _A2, class _Up>
1333*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1334*58b9f456SAndroid Build Coastguard Worker{
1335*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1336*58b9f456SAndroid Build Coastguard Worker};
1337*58b9f456SAndroid Build Coastguard Worker
1338*58b9f456SAndroid Build Coastguard Workertemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1339*58b9f456SAndroid Build Coastguard Worker                                                class _A1, class _A2, class _Up>
1340*58b9f456SAndroid Build Coastguard Workerstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1341*58b9f456SAndroid Build Coastguard Worker{
1342*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc<_Up, _A0, _A1, _A2> type;
1343*58b9f456SAndroid Build Coastguard Worker};
1344*58b9f456SAndroid Build Coastguard Worker
1345*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
1346*58b9f456SAndroid Build Coastguard Worker
1347*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1348*58b9f456SAndroid Build Coastguard Worker
1349*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350*58b9f456SAndroid Build Coastguard Workerauto
1351*58b9f456SAndroid Build Coastguard Worker__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1352*58b9f456SAndroid Build Coastguard Worker    -> decltype((void)__a.allocate(__sz, __p), true_type());
1353*58b9f456SAndroid Build Coastguard Worker
1354*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1355*58b9f456SAndroid Build Coastguard Workerauto
1356*58b9f456SAndroid Build Coastguard Worker__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1357*58b9f456SAndroid Build Coastguard Worker    -> false_type;
1358*58b9f456SAndroid Build Coastguard Worker
1359*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1360*58b9f456SAndroid Build Coastguard Workerstruct __has_allocate_hint
1361*58b9f456SAndroid Build Coastguard Worker    : integral_constant<bool,
1362*58b9f456SAndroid Build Coastguard Worker        is_same<
1363*58b9f456SAndroid Build Coastguard Worker            decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1364*58b9f456SAndroid Build Coastguard Worker                                          declval<_SizeType>(),
1365*58b9f456SAndroid Build Coastguard Worker                                          declval<_ConstVoidPtr>())),
1366*58b9f456SAndroid Build Coastguard Worker            true_type>::value>
1367*58b9f456SAndroid Build Coastguard Worker{
1368*58b9f456SAndroid Build Coastguard Worker};
1369*58b9f456SAndroid Build Coastguard Worker
1370*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_CXX03_LANG
1371*58b9f456SAndroid Build Coastguard Worker
1372*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1373*58b9f456SAndroid Build Coastguard Workerstruct __has_allocate_hint
1374*58b9f456SAndroid Build Coastguard Worker    : true_type
1375*58b9f456SAndroid Build Coastguard Worker{
1376*58b9f456SAndroid Build Coastguard Worker};
1377*58b9f456SAndroid Build Coastguard Worker
1378*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_CXX03_LANG
1379*58b9f456SAndroid Build Coastguard Worker
1380*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_CXX03_LANG)
1381*58b9f456SAndroid Build Coastguard Worker
1382*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Tp, class ..._Args>
1383*58b9f456SAndroid Build Coastguard Workerdecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1384*58b9f456SAndroid Build Coastguard Worker                                           _VSTD::declval<_Args>()...),
1385*58b9f456SAndroid Build Coastguard Worker                                           true_type())
1386*58b9f456SAndroid Build Coastguard Worker__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1387*58b9f456SAndroid Build Coastguard Worker
1388*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer, class ..._Args>
1389*58b9f456SAndroid Build Coastguard Workerfalse_type
1390*58b9f456SAndroid Build Coastguard Worker__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1391*58b9f456SAndroid Build Coastguard Worker
1392*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer, class ..._Args>
1393*58b9f456SAndroid Build Coastguard Workerstruct __has_construct
1394*58b9f456SAndroid Build Coastguard Worker    : integral_constant<bool,
1395*58b9f456SAndroid Build Coastguard Worker        is_same<
1396*58b9f456SAndroid Build Coastguard Worker            decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1397*58b9f456SAndroid Build Coastguard Worker                                          declval<_Pointer>(),
1398*58b9f456SAndroid Build Coastguard Worker                                          declval<_Args>()...)),
1399*58b9f456SAndroid Build Coastguard Worker            true_type>::value>
1400*58b9f456SAndroid Build Coastguard Worker{
1401*58b9f456SAndroid Build Coastguard Worker};
1402*58b9f456SAndroid Build Coastguard Worker
1403*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer>
1404*58b9f456SAndroid Build Coastguard Workerauto
1405*58b9f456SAndroid Build Coastguard Worker__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1406*58b9f456SAndroid Build Coastguard Worker    -> decltype(__a.destroy(__p), true_type());
1407*58b9f456SAndroid Build Coastguard Worker
1408*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer>
1409*58b9f456SAndroid Build Coastguard Workerauto
1410*58b9f456SAndroid Build Coastguard Worker__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1411*58b9f456SAndroid Build Coastguard Worker    -> false_type;
1412*58b9f456SAndroid Build Coastguard Worker
1413*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer>
1414*58b9f456SAndroid Build Coastguard Workerstruct __has_destroy
1415*58b9f456SAndroid Build Coastguard Worker    : integral_constant<bool,
1416*58b9f456SAndroid Build Coastguard Worker        is_same<
1417*58b9f456SAndroid Build Coastguard Worker            decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1418*58b9f456SAndroid Build Coastguard Worker                                        declval<_Pointer>())),
1419*58b9f456SAndroid Build Coastguard Worker            true_type>::value>
1420*58b9f456SAndroid Build Coastguard Worker{
1421*58b9f456SAndroid Build Coastguard Worker};
1422*58b9f456SAndroid Build Coastguard Worker
1423*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1424*58b9f456SAndroid Build Coastguard Workerauto
1425*58b9f456SAndroid Build Coastguard Worker__has_max_size_test(_Alloc&& __a)
1426*58b9f456SAndroid Build Coastguard Worker    -> decltype(__a.max_size(), true_type());
1427*58b9f456SAndroid Build Coastguard Worker
1428*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1429*58b9f456SAndroid Build Coastguard Workerauto
1430*58b9f456SAndroid Build Coastguard Worker__has_max_size_test(const volatile _Alloc& __a)
1431*58b9f456SAndroid Build Coastguard Worker    -> false_type;
1432*58b9f456SAndroid Build Coastguard Worker
1433*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1434*58b9f456SAndroid Build Coastguard Workerstruct __has_max_size
1435*58b9f456SAndroid Build Coastguard Worker    : integral_constant<bool,
1436*58b9f456SAndroid Build Coastguard Worker        is_same<
1437*58b9f456SAndroid Build Coastguard Worker            decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1438*58b9f456SAndroid Build Coastguard Worker            true_type>::value>
1439*58b9f456SAndroid Build Coastguard Worker{
1440*58b9f456SAndroid Build Coastguard Worker};
1441*58b9f456SAndroid Build Coastguard Worker
1442*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1443*58b9f456SAndroid Build Coastguard Workerauto
1444*58b9f456SAndroid Build Coastguard Worker__has_select_on_container_copy_construction_test(_Alloc&& __a)
1445*58b9f456SAndroid Build Coastguard Worker    -> decltype(__a.select_on_container_copy_construction(), true_type());
1446*58b9f456SAndroid Build Coastguard Worker
1447*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1448*58b9f456SAndroid Build Coastguard Workerauto
1449*58b9f456SAndroid Build Coastguard Worker__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1450*58b9f456SAndroid Build Coastguard Worker    -> false_type;
1451*58b9f456SAndroid Build Coastguard Worker
1452*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1453*58b9f456SAndroid Build Coastguard Workerstruct __has_select_on_container_copy_construction
1454*58b9f456SAndroid Build Coastguard Worker    : integral_constant<bool,
1455*58b9f456SAndroid Build Coastguard Worker        is_same<
1456*58b9f456SAndroid Build Coastguard Worker            decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1457*58b9f456SAndroid Build Coastguard Worker            true_type>::value>
1458*58b9f456SAndroid Build Coastguard Worker{
1459*58b9f456SAndroid Build Coastguard Worker};
1460*58b9f456SAndroid Build Coastguard Worker
1461*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_CXX03_LANG
1462*58b9f456SAndroid Build Coastguard Worker
1463*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer, class _Tp, class = void>
1464*58b9f456SAndroid Build Coastguard Workerstruct __has_construct : std::false_type {};
1465*58b9f456SAndroid Build Coastguard Worker
1466*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer, class _Tp>
1467*58b9f456SAndroid Build Coastguard Workerstruct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
1468*58b9f456SAndroid Build Coastguard Worker    decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
1469*58b9f456SAndroid Build Coastguard Worker>::type> : std::true_type {};
1470*58b9f456SAndroid Build Coastguard Worker
1471*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer, class = void>
1472*58b9f456SAndroid Build Coastguard Workerstruct __has_destroy : false_type {};
1473*58b9f456SAndroid Build Coastguard Worker
1474*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Pointer>
1475*58b9f456SAndroid Build Coastguard Workerstruct __has_destroy<_Alloc, _Pointer, typename __void_t<
1476*58b9f456SAndroid Build Coastguard Worker    decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
1477*58b9f456SAndroid Build Coastguard Worker>::type> : std::true_type {};
1478*58b9f456SAndroid Build Coastguard Worker
1479*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1480*58b9f456SAndroid Build Coastguard Workerstruct __has_max_size
1481*58b9f456SAndroid Build Coastguard Worker    : true_type
1482*58b9f456SAndroid Build Coastguard Worker{
1483*58b9f456SAndroid Build Coastguard Worker};
1484*58b9f456SAndroid Build Coastguard Worker
1485*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1486*58b9f456SAndroid Build Coastguard Workerstruct __has_select_on_container_copy_construction
1487*58b9f456SAndroid Build Coastguard Worker    : false_type
1488*58b9f456SAndroid Build Coastguard Worker{
1489*58b9f456SAndroid Build Coastguard Worker};
1490*58b9f456SAndroid Build Coastguard Worker
1491*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_CXX03_LANG
1492*58b9f456SAndroid Build Coastguard Worker
1493*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1494*58b9f456SAndroid Build Coastguard Workerstruct __alloc_traits_difference_type
1495*58b9f456SAndroid Build Coastguard Worker{
1496*58b9f456SAndroid Build Coastguard Worker    typedef typename pointer_traits<_Ptr>::difference_type type;
1497*58b9f456SAndroid Build Coastguard Worker};
1498*58b9f456SAndroid Build Coastguard Worker
1499*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc, class _Ptr>
1500*58b9f456SAndroid Build Coastguard Workerstruct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1501*58b9f456SAndroid Build Coastguard Worker{
1502*58b9f456SAndroid Build Coastguard Worker    typedef typename _Alloc::difference_type type;
1503*58b9f456SAndroid Build Coastguard Worker};
1504*58b9f456SAndroid Build Coastguard Worker
1505*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1506*58b9f456SAndroid Build Coastguard Workerstruct __is_default_allocator : false_type {};
1507*58b9f456SAndroid Build Coastguard Worker
1508*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1509*58b9f456SAndroid Build Coastguard Workerstruct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
1510*58b9f456SAndroid Build Coastguard Worker
1511*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
1512*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS allocator_traits
1513*58b9f456SAndroid Build Coastguard Worker{
1514*58b9f456SAndroid Build Coastguard Worker    typedef _Alloc                              allocator_type;
1515*58b9f456SAndroid Build Coastguard Worker    typedef typename allocator_type::value_type value_type;
1516*58b9f456SAndroid Build Coastguard Worker
1517*58b9f456SAndroid Build Coastguard Worker    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1518*58b9f456SAndroid Build Coastguard Worker    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1519*58b9f456SAndroid Build Coastguard Worker    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1520*58b9f456SAndroid Build Coastguard Worker    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1521*58b9f456SAndroid Build Coastguard Worker
1522*58b9f456SAndroid Build Coastguard Worker    typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1523*58b9f456SAndroid Build Coastguard Worker    typedef typename __size_type<allocator_type, difference_type>::type size_type;
1524*58b9f456SAndroid Build Coastguard Worker
1525*58b9f456SAndroid Build Coastguard Worker    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1526*58b9f456SAndroid Build Coastguard Worker                     propagate_on_container_copy_assignment;
1527*58b9f456SAndroid Build Coastguard Worker    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1528*58b9f456SAndroid Build Coastguard Worker                     propagate_on_container_move_assignment;
1529*58b9f456SAndroid Build Coastguard Worker    typedef typename __propagate_on_container_swap<allocator_type>::type
1530*58b9f456SAndroid Build Coastguard Worker                     propagate_on_container_swap;
1531*58b9f456SAndroid Build Coastguard Worker    typedef typename __is_always_equal<allocator_type>::type
1532*58b9f456SAndroid Build Coastguard Worker                     is_always_equal;
1533*58b9f456SAndroid Build Coastguard Worker
1534*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1535*58b9f456SAndroid Build Coastguard Worker    template <class _Tp> using rebind_alloc =
1536*58b9f456SAndroid Build Coastguard Worker                  typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1537*58b9f456SAndroid Build Coastguard Worker    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1538*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_CXX03_LANG
1539*58b9f456SAndroid Build Coastguard Worker    template <class _Tp> struct rebind_alloc
1540*58b9f456SAndroid Build Coastguard Worker        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1541*58b9f456SAndroid Build Coastguard Worker    template <class _Tp> struct rebind_traits
1542*58b9f456SAndroid Build Coastguard Worker        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1543*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_CXX03_LANG
1544*58b9f456SAndroid Build Coastguard Worker
1545*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1546*58b9f456SAndroid Build Coastguard Worker    static pointer allocate(allocator_type& __a, size_type __n)
1547*58b9f456SAndroid Build Coastguard Worker        {return __a.allocate(__n);}
1548*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1549*58b9f456SAndroid Build Coastguard Worker    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1550*58b9f456SAndroid Build Coastguard Worker        {return __allocate(__a, __n, __hint,
1551*58b9f456SAndroid Build Coastguard Worker            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1552*58b9f456SAndroid Build Coastguard Worker
1553*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1554*58b9f456SAndroid Build Coastguard Worker    static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1555*58b9f456SAndroid Build Coastguard Worker        {__a.deallocate(__p, __n);}
1556*58b9f456SAndroid Build Coastguard Worker
1557*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
1558*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class... _Args>
1559*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1560*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1561*58b9f456SAndroid Build Coastguard Worker            {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1562*58b9f456SAndroid Build Coastguard Worker                         __a, __p, _VSTD::forward<_Args>(__args)...);}
1563*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
1564*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1565*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1566*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type&, _Tp* __p)
1567*58b9f456SAndroid Build Coastguard Worker            {
1568*58b9f456SAndroid Build Coastguard Worker                ::new ((void*)__p) _Tp();
1569*58b9f456SAndroid Build Coastguard Worker            }
1570*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _A0>
1571*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1572*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1573*58b9f456SAndroid Build Coastguard Worker            {
1574*58b9f456SAndroid Build Coastguard Worker                __construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
1575*58b9f456SAndroid Build Coastguard Worker                            __a, __p, __a0);
1576*58b9f456SAndroid Build Coastguard Worker            }
1577*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _A0, class _A1>
1578*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1579*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1580*58b9f456SAndroid Build Coastguard Worker                              const _A1& __a1)
1581*58b9f456SAndroid Build Coastguard Worker            {
1582*58b9f456SAndroid Build Coastguard Worker                ::new ((void*)__p) _Tp(__a0, __a1);
1583*58b9f456SAndroid Build Coastguard Worker            }
1584*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _A0, class _A1, class _A2>
1585*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1586*58b9f456SAndroid Build Coastguard Worker        static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1587*58b9f456SAndroid Build Coastguard Worker                              const _A1& __a1, const _A2& __a2)
1588*58b9f456SAndroid Build Coastguard Worker            {
1589*58b9f456SAndroid Build Coastguard Worker                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1590*58b9f456SAndroid Build Coastguard Worker            }
1591*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
1592*58b9f456SAndroid Build Coastguard Worker
1593*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1594*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1595*58b9f456SAndroid Build Coastguard Worker        static void destroy(allocator_type& __a, _Tp* __p)
1596*58b9f456SAndroid Build Coastguard Worker            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1597*58b9f456SAndroid Build Coastguard Worker
1598*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1599*58b9f456SAndroid Build Coastguard Worker    static size_type max_size(const allocator_type& __a) _NOEXCEPT
1600*58b9f456SAndroid Build Coastguard Worker        {return __max_size(__has_max_size<const allocator_type>(), __a);}
1601*58b9f456SAndroid Build Coastguard Worker
1602*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1603*58b9f456SAndroid Build Coastguard Worker    static allocator_type
1604*58b9f456SAndroid Build Coastguard Worker        select_on_container_copy_construction(const allocator_type& __a)
1605*58b9f456SAndroid Build Coastguard Worker            {return __select_on_container_copy_construction(
1606*58b9f456SAndroid Build Coastguard Worker                __has_select_on_container_copy_construction<const allocator_type>(),
1607*58b9f456SAndroid Build Coastguard Worker                __a);}
1608*58b9f456SAndroid Build Coastguard Worker
1609*58b9f456SAndroid Build Coastguard Worker    template <class _Ptr>
1610*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1611*58b9f456SAndroid Build Coastguard Worker        static
1612*58b9f456SAndroid Build Coastguard Worker        void
1613*58b9f456SAndroid Build Coastguard Worker        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1614*58b9f456SAndroid Build Coastguard Worker        {
1615*58b9f456SAndroid Build Coastguard Worker            for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1616*58b9f456SAndroid Build Coastguard Worker                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1617*58b9f456SAndroid Build Coastguard Worker        }
1618*58b9f456SAndroid Build Coastguard Worker
1619*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1620*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1621*58b9f456SAndroid Build Coastguard Worker        static
1622*58b9f456SAndroid Build Coastguard Worker        typename enable_if
1623*58b9f456SAndroid Build Coastguard Worker        <
1624*58b9f456SAndroid Build Coastguard Worker            (__is_default_allocator<allocator_type>::value
1625*58b9f456SAndroid Build Coastguard Worker                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1626*58b9f456SAndroid Build Coastguard Worker             is_trivially_move_constructible<_Tp>::value,
1627*58b9f456SAndroid Build Coastguard Worker            void
1628*58b9f456SAndroid Build Coastguard Worker        >::type
1629*58b9f456SAndroid Build Coastguard Worker        __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1630*58b9f456SAndroid Build Coastguard Worker        {
1631*58b9f456SAndroid Build Coastguard Worker            ptrdiff_t _Np = __end1 - __begin1;
1632*58b9f456SAndroid Build Coastguard Worker            if (_Np > 0)
1633*58b9f456SAndroid Build Coastguard Worker            {
1634*58b9f456SAndroid Build Coastguard Worker                _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1635*58b9f456SAndroid Build Coastguard Worker                __begin2 += _Np;
1636*58b9f456SAndroid Build Coastguard Worker            }
1637*58b9f456SAndroid Build Coastguard Worker        }
1638*58b9f456SAndroid Build Coastguard Worker
1639*58b9f456SAndroid Build Coastguard Worker    template <class _Iter, class _Ptr>
1640*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1641*58b9f456SAndroid Build Coastguard Worker        static
1642*58b9f456SAndroid Build Coastguard Worker        void
1643*58b9f456SAndroid Build Coastguard Worker        __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1644*58b9f456SAndroid Build Coastguard Worker        {
1645*58b9f456SAndroid Build Coastguard Worker            for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1646*58b9f456SAndroid Build Coastguard Worker                construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1647*58b9f456SAndroid Build Coastguard Worker        }
1648*58b9f456SAndroid Build Coastguard Worker
1649*58b9f456SAndroid Build Coastguard Worker    template <class _SourceTp, class _DestTp,
1650*58b9f456SAndroid Build Coastguard Worker              class _RawSourceTp = typename remove_const<_SourceTp>::type,
1651*58b9f456SAndroid Build Coastguard Worker              class _RawDestTp = typename remove_const<_DestTp>::type>
1652*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1653*58b9f456SAndroid Build Coastguard Worker        static
1654*58b9f456SAndroid Build Coastguard Worker        typename enable_if
1655*58b9f456SAndroid Build Coastguard Worker        <
1656*58b9f456SAndroid Build Coastguard Worker            is_trivially_move_constructible<_DestTp>::value &&
1657*58b9f456SAndroid Build Coastguard Worker            is_same<_RawSourceTp, _RawDestTp>::value &&
1658*58b9f456SAndroid Build Coastguard Worker            (__is_default_allocator<allocator_type>::value ||
1659*58b9f456SAndroid Build Coastguard Worker             !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
1660*58b9f456SAndroid Build Coastguard Worker            void
1661*58b9f456SAndroid Build Coastguard Worker        >::type
1662*58b9f456SAndroid Build Coastguard Worker        __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
1663*58b9f456SAndroid Build Coastguard Worker        {
1664*58b9f456SAndroid Build Coastguard Worker            ptrdiff_t _Np = __end1 - __begin1;
1665*58b9f456SAndroid Build Coastguard Worker            if (_Np > 0)
1666*58b9f456SAndroid Build Coastguard Worker            {
1667*58b9f456SAndroid Build Coastguard Worker                _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
1668*58b9f456SAndroid Build Coastguard Worker                __begin2 += _Np;
1669*58b9f456SAndroid Build Coastguard Worker            }
1670*58b9f456SAndroid Build Coastguard Worker        }
1671*58b9f456SAndroid Build Coastguard Worker
1672*58b9f456SAndroid Build Coastguard Worker    template <class _Ptr>
1673*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1674*58b9f456SAndroid Build Coastguard Worker        static
1675*58b9f456SAndroid Build Coastguard Worker        void
1676*58b9f456SAndroid Build Coastguard Worker        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1677*58b9f456SAndroid Build Coastguard Worker        {
1678*58b9f456SAndroid Build Coastguard Worker            while (__end1 != __begin1)
1679*58b9f456SAndroid Build Coastguard Worker            {
1680*58b9f456SAndroid Build Coastguard Worker                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1681*58b9f456SAndroid Build Coastguard Worker                --__end2;
1682*58b9f456SAndroid Build Coastguard Worker            }
1683*58b9f456SAndroid Build Coastguard Worker        }
1684*58b9f456SAndroid Build Coastguard Worker
1685*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1686*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1687*58b9f456SAndroid Build Coastguard Worker        static
1688*58b9f456SAndroid Build Coastguard Worker        typename enable_if
1689*58b9f456SAndroid Build Coastguard Worker        <
1690*58b9f456SAndroid Build Coastguard Worker            (__is_default_allocator<allocator_type>::value
1691*58b9f456SAndroid Build Coastguard Worker                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1692*58b9f456SAndroid Build Coastguard Worker             is_trivially_move_constructible<_Tp>::value,
1693*58b9f456SAndroid Build Coastguard Worker            void
1694*58b9f456SAndroid Build Coastguard Worker        >::type
1695*58b9f456SAndroid Build Coastguard Worker        __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1696*58b9f456SAndroid Build Coastguard Worker        {
1697*58b9f456SAndroid Build Coastguard Worker            ptrdiff_t _Np = __end1 - __begin1;
1698*58b9f456SAndroid Build Coastguard Worker            __end2 -= _Np;
1699*58b9f456SAndroid Build Coastguard Worker            if (_Np > 0)
1700*58b9f456SAndroid Build Coastguard Worker                _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1701*58b9f456SAndroid Build Coastguard Worker        }
1702*58b9f456SAndroid Build Coastguard Worker
1703*58b9f456SAndroid Build Coastguard Workerprivate:
1704*58b9f456SAndroid Build Coastguard Worker
1705*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1706*58b9f456SAndroid Build Coastguard Worker    static pointer __allocate(allocator_type& __a, size_type __n,
1707*58b9f456SAndroid Build Coastguard Worker        const_void_pointer __hint, true_type)
1708*58b9f456SAndroid Build Coastguard Worker        {return __a.allocate(__n, __hint);}
1709*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1710*58b9f456SAndroid Build Coastguard Worker    static pointer __allocate(allocator_type& __a, size_type __n,
1711*58b9f456SAndroid Build Coastguard Worker        const_void_pointer, false_type)
1712*58b9f456SAndroid Build Coastguard Worker        {return __a.allocate(__n);}
1713*58b9f456SAndroid Build Coastguard Worker
1714*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
1715*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class... _Args>
1716*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1717*58b9f456SAndroid Build Coastguard Worker        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1718*58b9f456SAndroid Build Coastguard Worker            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1719*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class... _Args>
1720*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1721*58b9f456SAndroid Build Coastguard Worker        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1722*58b9f456SAndroid Build Coastguard Worker            {
1723*58b9f456SAndroid Build Coastguard Worker                ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1724*58b9f456SAndroid Build Coastguard Worker            }
1725*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
1726*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _A0>
1727*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1728*58b9f456SAndroid Build Coastguard Worker        static void __construct(true_type, allocator_type& __a, _Tp* __p,
1729*58b9f456SAndroid Build Coastguard Worker                                const _A0& __a0)
1730*58b9f456SAndroid Build Coastguard Worker            {__a.construct(__p, __a0);}
1731*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _A0>
1732*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1733*58b9f456SAndroid Build Coastguard Worker        static void __construct(false_type, allocator_type&, _Tp* __p,
1734*58b9f456SAndroid Build Coastguard Worker                                const _A0& __a0)
1735*58b9f456SAndroid Build Coastguard Worker            {
1736*58b9f456SAndroid Build Coastguard Worker                ::new ((void*)__p) _Tp(__a0);
1737*58b9f456SAndroid Build Coastguard Worker            }
1738*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
1739*58b9f456SAndroid Build Coastguard Worker
1740*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1741*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1742*58b9f456SAndroid Build Coastguard Worker        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1743*58b9f456SAndroid Build Coastguard Worker            {__a.destroy(__p);}
1744*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
1745*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1746*58b9f456SAndroid Build Coastguard Worker        static void __destroy(false_type, allocator_type&, _Tp* __p)
1747*58b9f456SAndroid Build Coastguard Worker            {
1748*58b9f456SAndroid Build Coastguard Worker                __p->~_Tp();
1749*58b9f456SAndroid Build Coastguard Worker            }
1750*58b9f456SAndroid Build Coastguard Worker
1751*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1752*58b9f456SAndroid Build Coastguard Worker    static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1753*58b9f456SAndroid Build Coastguard Worker            {return __a.max_size();}
1754*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1755*58b9f456SAndroid Build Coastguard Worker    static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
1756*58b9f456SAndroid Build Coastguard Worker            {return numeric_limits<size_type>::max() / sizeof(value_type);}
1757*58b9f456SAndroid Build Coastguard Worker
1758*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1759*58b9f456SAndroid Build Coastguard Worker    static allocator_type
1760*58b9f456SAndroid Build Coastguard Worker        __select_on_container_copy_construction(true_type, const allocator_type& __a)
1761*58b9f456SAndroid Build Coastguard Worker            {return __a.select_on_container_copy_construction();}
1762*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
1763*58b9f456SAndroid Build Coastguard Worker    static allocator_type
1764*58b9f456SAndroid Build Coastguard Worker        __select_on_container_copy_construction(false_type, const allocator_type& __a)
1765*58b9f456SAndroid Build Coastguard Worker            {return __a;}
1766*58b9f456SAndroid Build Coastguard Worker};
1767*58b9f456SAndroid Build Coastguard Worker
1768*58b9f456SAndroid Build Coastguard Workertemplate <class _Traits, class _Tp>
1769*58b9f456SAndroid Build Coastguard Workerstruct __rebind_alloc_helper
1770*58b9f456SAndroid Build Coastguard Worker{
1771*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
1772*58b9f456SAndroid Build Coastguard Worker    typedef typename _Traits::template rebind_alloc<_Tp>        type;
1773*58b9f456SAndroid Build Coastguard Worker#else
1774*58b9f456SAndroid Build Coastguard Worker    typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1775*58b9f456SAndroid Build Coastguard Worker#endif
1776*58b9f456SAndroid Build Coastguard Worker};
1777*58b9f456SAndroid Build Coastguard Worker
1778*58b9f456SAndroid Build Coastguard Worker// allocator
1779*58b9f456SAndroid Build Coastguard Worker
1780*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1781*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS allocator
1782*58b9f456SAndroid Build Coastguard Worker{
1783*58b9f456SAndroid Build Coastguard Workerpublic:
1784*58b9f456SAndroid Build Coastguard Worker    typedef size_t            size_type;
1785*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t         difference_type;
1786*58b9f456SAndroid Build Coastguard Worker    typedef _Tp*              pointer;
1787*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp*        const_pointer;
1788*58b9f456SAndroid Build Coastguard Worker    typedef _Tp&              reference;
1789*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp&        const_reference;
1790*58b9f456SAndroid Build Coastguard Worker    typedef _Tp               value_type;
1791*58b9f456SAndroid Build Coastguard Worker
1792*58b9f456SAndroid Build Coastguard Worker    typedef true_type propagate_on_container_move_assignment;
1793*58b9f456SAndroid Build Coastguard Worker    typedef true_type is_always_equal;
1794*58b9f456SAndroid Build Coastguard Worker
1795*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1796*58b9f456SAndroid Build Coastguard Worker
1797*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1798*58b9f456SAndroid Build Coastguard Worker    allocator() _NOEXCEPT {}
1799*58b9f456SAndroid Build Coastguard Worker
1800*58b9f456SAndroid Build Coastguard Worker    template <class _Up>
1801*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1802*58b9f456SAndroid Build Coastguard Worker    allocator(const allocator<_Up>&) _NOEXCEPT {}
1803*58b9f456SAndroid Build Coastguard Worker
1804*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1805*58b9f456SAndroid Build Coastguard Worker        {return _VSTD::addressof(__x);}
1806*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1807*58b9f456SAndroid Build Coastguard Worker        {return _VSTD::addressof(__x);}
1808*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1809*58b9f456SAndroid Build Coastguard Worker    pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1810*58b9f456SAndroid Build Coastguard Worker        {
1811*58b9f456SAndroid Build Coastguard Worker        if (__n > max_size())
1812*58b9f456SAndroid Build Coastguard Worker            __throw_length_error("allocator<T>::allocate(size_t n)"
1813*58b9f456SAndroid Build Coastguard Worker                                 " 'n' exceeds maximum supported size");
1814*58b9f456SAndroid Build Coastguard Worker        return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp)));
1815*58b9f456SAndroid Build Coastguard Worker        }
1816*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1817*58b9f456SAndroid Build Coastguard Worker        {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), __alignof(_Tp));}
1818*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1819*58b9f456SAndroid Build Coastguard Worker        {return size_type(~0) / sizeof(_Tp);}
1820*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1821*58b9f456SAndroid Build Coastguard Worker    template <class _Up, class... _Args>
1822*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1823*58b9f456SAndroid Build Coastguard Worker        void
1824*58b9f456SAndroid Build Coastguard Worker        construct(_Up* __p, _Args&&... __args)
1825*58b9f456SAndroid Build Coastguard Worker        {
1826*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1827*58b9f456SAndroid Build Coastguard Worker        }
1828*58b9f456SAndroid Build Coastguard Worker#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1829*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1830*58b9f456SAndroid Build Coastguard Worker        void
1831*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p)
1832*58b9f456SAndroid Build Coastguard Worker        {
1833*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp();
1834*58b9f456SAndroid Build Coastguard Worker        }
1835*58b9f456SAndroid Build Coastguard Worker# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1836*58b9f456SAndroid Build Coastguard Worker
1837*58b9f456SAndroid Build Coastguard Worker    template <class _A0>
1838*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1839*58b9f456SAndroid Build Coastguard Worker        void
1840*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0)
1841*58b9f456SAndroid Build Coastguard Worker        {
1842*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0);
1843*58b9f456SAndroid Build Coastguard Worker        }
1844*58b9f456SAndroid Build Coastguard Worker    template <class _A0>
1845*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1846*58b9f456SAndroid Build Coastguard Worker        void
1847*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0)
1848*58b9f456SAndroid Build Coastguard Worker        {
1849*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0);
1850*58b9f456SAndroid Build Coastguard Worker        }
1851*58b9f456SAndroid Build Coastguard Worker# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1852*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1853*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1854*58b9f456SAndroid Build Coastguard Worker        void
1855*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0, _A1& __a1)
1856*58b9f456SAndroid Build Coastguard Worker        {
1857*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0, __a1);
1858*58b9f456SAndroid Build Coastguard Worker        }
1859*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1860*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1861*58b9f456SAndroid Build Coastguard Worker        void
1862*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0, _A1& __a1)
1863*58b9f456SAndroid Build Coastguard Worker        {
1864*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0, __a1);
1865*58b9f456SAndroid Build Coastguard Worker        }
1866*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1867*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1868*58b9f456SAndroid Build Coastguard Worker        void
1869*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0, const _A1& __a1)
1870*58b9f456SAndroid Build Coastguard Worker        {
1871*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0, __a1);
1872*58b9f456SAndroid Build Coastguard Worker        }
1873*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1874*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1875*58b9f456SAndroid Build Coastguard Worker        void
1876*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1877*58b9f456SAndroid Build Coastguard Worker        {
1878*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Tp(__a0, __a1);
1879*58b9f456SAndroid Build Coastguard Worker        }
1880*58b9f456SAndroid Build Coastguard Worker#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1881*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1882*58b9f456SAndroid Build Coastguard Worker};
1883*58b9f456SAndroid Build Coastguard Worker
1884*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
1885*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1886*58b9f456SAndroid Build Coastguard Worker{
1887*58b9f456SAndroid Build Coastguard Workerpublic:
1888*58b9f456SAndroid Build Coastguard Worker    typedef size_t            size_type;
1889*58b9f456SAndroid Build Coastguard Worker    typedef ptrdiff_t         difference_type;
1890*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp*        pointer;
1891*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp*        const_pointer;
1892*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp&        reference;
1893*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp&        const_reference;
1894*58b9f456SAndroid Build Coastguard Worker    typedef const _Tp         value_type;
1895*58b9f456SAndroid Build Coastguard Worker
1896*58b9f456SAndroid Build Coastguard Worker    typedef true_type propagate_on_container_move_assignment;
1897*58b9f456SAndroid Build Coastguard Worker    typedef true_type is_always_equal;
1898*58b9f456SAndroid Build Coastguard Worker
1899*58b9f456SAndroid Build Coastguard Worker    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1900*58b9f456SAndroid Build Coastguard Worker
1901*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1902*58b9f456SAndroid Build Coastguard Worker    allocator() _NOEXCEPT {}
1903*58b9f456SAndroid Build Coastguard Worker
1904*58b9f456SAndroid Build Coastguard Worker    template <class _Up>
1905*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1906*58b9f456SAndroid Build Coastguard Worker    allocator(const allocator<_Up>&) _NOEXCEPT {}
1907*58b9f456SAndroid Build Coastguard Worker
1908*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1909*58b9f456SAndroid Build Coastguard Worker        {return _VSTD::addressof(__x);}
1910*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1911*58b9f456SAndroid Build Coastguard Worker    {
1912*58b9f456SAndroid Build Coastguard Worker        if (__n > max_size())
1913*58b9f456SAndroid Build Coastguard Worker            __throw_length_error("allocator<const T>::allocate(size_t n)"
1914*58b9f456SAndroid Build Coastguard Worker                                 " 'n' exceeds maximum supported size");
1915*58b9f456SAndroid Build Coastguard Worker        return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp)));
1916*58b9f456SAndroid Build Coastguard Worker    }
1917*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
1918*58b9f456SAndroid Build Coastguard Worker        {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), __alignof(_Tp));}
1919*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1920*58b9f456SAndroid Build Coastguard Worker        {return size_type(~0) / sizeof(_Tp);}
1921*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1922*58b9f456SAndroid Build Coastguard Worker    template <class _Up, class... _Args>
1923*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1924*58b9f456SAndroid Build Coastguard Worker        void
1925*58b9f456SAndroid Build Coastguard Worker        construct(_Up* __p, _Args&&... __args)
1926*58b9f456SAndroid Build Coastguard Worker        {
1927*58b9f456SAndroid Build Coastguard Worker            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1928*58b9f456SAndroid Build Coastguard Worker        }
1929*58b9f456SAndroid Build Coastguard Worker#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1930*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1931*58b9f456SAndroid Build Coastguard Worker        void
1932*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p)
1933*58b9f456SAndroid Build Coastguard Worker        {
1934*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1935*58b9f456SAndroid Build Coastguard Worker        }
1936*58b9f456SAndroid Build Coastguard Worker# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1937*58b9f456SAndroid Build Coastguard Worker
1938*58b9f456SAndroid Build Coastguard Worker    template <class _A0>
1939*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1940*58b9f456SAndroid Build Coastguard Worker        void
1941*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0)
1942*58b9f456SAndroid Build Coastguard Worker        {
1943*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1944*58b9f456SAndroid Build Coastguard Worker        }
1945*58b9f456SAndroid Build Coastguard Worker    template <class _A0>
1946*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1947*58b9f456SAndroid Build Coastguard Worker        void
1948*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0)
1949*58b9f456SAndroid Build Coastguard Worker        {
1950*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1951*58b9f456SAndroid Build Coastguard Worker        }
1952*58b9f456SAndroid Build Coastguard Worker# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1953*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1954*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1955*58b9f456SAndroid Build Coastguard Worker        void
1956*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0, _A1& __a1)
1957*58b9f456SAndroid Build Coastguard Worker        {
1958*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1959*58b9f456SAndroid Build Coastguard Worker        }
1960*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1961*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1962*58b9f456SAndroid Build Coastguard Worker        void
1963*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0, _A1& __a1)
1964*58b9f456SAndroid Build Coastguard Worker        {
1965*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1966*58b9f456SAndroid Build Coastguard Worker        }
1967*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1968*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1969*58b9f456SAndroid Build Coastguard Worker        void
1970*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, _A0& __a0, const _A1& __a1)
1971*58b9f456SAndroid Build Coastguard Worker        {
1972*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1973*58b9f456SAndroid Build Coastguard Worker        }
1974*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
1975*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
1976*58b9f456SAndroid Build Coastguard Worker        void
1977*58b9f456SAndroid Build Coastguard Worker        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1978*58b9f456SAndroid Build Coastguard Worker        {
1979*58b9f456SAndroid Build Coastguard Worker            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1980*58b9f456SAndroid Build Coastguard Worker        }
1981*58b9f456SAndroid Build Coastguard Worker#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1982*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1983*58b9f456SAndroid Build Coastguard Worker};
1984*58b9f456SAndroid Build Coastguard Worker
1985*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up>
1986*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1987*58b9f456SAndroid Build Coastguard Workerbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1988*58b9f456SAndroid Build Coastguard Worker
1989*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Up>
1990*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
1991*58b9f456SAndroid Build Coastguard Workerbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1992*58b9f456SAndroid Build Coastguard Worker
1993*58b9f456SAndroid Build Coastguard Workertemplate <class _OutputIterator, class _Tp>
1994*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1995*58b9f456SAndroid Build Coastguard Worker    : public iterator<output_iterator_tag,
1996*58b9f456SAndroid Build Coastguard Worker                      _Tp,                                         // purposefully not C++03
1997*58b9f456SAndroid Build Coastguard Worker                      ptrdiff_t,                                   // purposefully not C++03
1998*58b9f456SAndroid Build Coastguard Worker                      _Tp*,                                        // purposefully not C++03
1999*58b9f456SAndroid Build Coastguard Worker                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
2000*58b9f456SAndroid Build Coastguard Worker{
2001*58b9f456SAndroid Build Coastguard Workerprivate:
2002*58b9f456SAndroid Build Coastguard Worker    _OutputIterator __x_;
2003*58b9f456SAndroid Build Coastguard Workerpublic:
2004*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
2005*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
2006*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
2007*58b9f456SAndroid Build Coastguard Worker        {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
2008*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER >= 14
2009*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
2010*58b9f456SAndroid Build Coastguard Worker        {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
2011*58b9f456SAndroid Build Coastguard Worker#endif
2012*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
2013*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
2014*58b9f456SAndroid Build Coastguard Worker        {raw_storage_iterator __t(*this); ++__x_; return __t;}
2015*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER >= 14
2016*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
2017*58b9f456SAndroid Build Coastguard Worker#endif
2018*58b9f456SAndroid Build Coastguard Worker};
2019*58b9f456SAndroid Build Coastguard Worker
2020*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2021*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
2022*58b9f456SAndroid Build Coastguard Workerpair<_Tp*, ptrdiff_t>
2023*58b9f456SAndroid Build Coastguard Workerget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
2024*58b9f456SAndroid Build Coastguard Worker{
2025*58b9f456SAndroid Build Coastguard Worker    pair<_Tp*, ptrdiff_t> __r(0, 0);
2026*58b9f456SAndroid Build Coastguard Worker    const ptrdiff_t __m = (~ptrdiff_t(0) ^
2027*58b9f456SAndroid Build Coastguard Worker                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2028*58b9f456SAndroid Build Coastguard Worker                           / sizeof(_Tp);
2029*58b9f456SAndroid Build Coastguard Worker    if (__n > __m)
2030*58b9f456SAndroid Build Coastguard Worker        __n = __m;
2031*58b9f456SAndroid Build Coastguard Worker    while (__n > 0)
2032*58b9f456SAndroid Build Coastguard Worker    {
2033*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2034*58b9f456SAndroid Build Coastguard Worker    if (__is_overaligned_for_new(__alignof(_Tp)))
2035*58b9f456SAndroid Build Coastguard Worker        {
2036*58b9f456SAndroid Build Coastguard Worker            std::align_val_t __al =
2037*58b9f456SAndroid Build Coastguard Worker                std::align_val_t(std::alignment_of<_Tp>::value);
2038*58b9f456SAndroid Build Coastguard Worker            __r.first = static_cast<_Tp*>(::operator new(
2039*58b9f456SAndroid Build Coastguard Worker                __n * sizeof(_Tp), __al, nothrow));
2040*58b9f456SAndroid Build Coastguard Worker        } else {
2041*58b9f456SAndroid Build Coastguard Worker            __r.first = static_cast<_Tp*>(::operator new(
2042*58b9f456SAndroid Build Coastguard Worker                __n * sizeof(_Tp), nothrow));
2043*58b9f456SAndroid Build Coastguard Worker        }
2044*58b9f456SAndroid Build Coastguard Worker#else
2045*58b9f456SAndroid Build Coastguard Worker    if (__is_overaligned_for_new(__alignof(_Tp)))
2046*58b9f456SAndroid Build Coastguard Worker        {
2047*58b9f456SAndroid Build Coastguard Worker            // Since aligned operator new is unavailable, return an empty
2048*58b9f456SAndroid Build Coastguard Worker            // buffer rather than one with invalid alignment.
2049*58b9f456SAndroid Build Coastguard Worker            return __r;
2050*58b9f456SAndroid Build Coastguard Worker        }
2051*58b9f456SAndroid Build Coastguard Worker
2052*58b9f456SAndroid Build Coastguard Worker        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2053*58b9f456SAndroid Build Coastguard Worker#endif
2054*58b9f456SAndroid Build Coastguard Worker
2055*58b9f456SAndroid Build Coastguard Worker        if (__r.first)
2056*58b9f456SAndroid Build Coastguard Worker        {
2057*58b9f456SAndroid Build Coastguard Worker            __r.second = __n;
2058*58b9f456SAndroid Build Coastguard Worker            break;
2059*58b9f456SAndroid Build Coastguard Worker        }
2060*58b9f456SAndroid Build Coastguard Worker        __n /= 2;
2061*58b9f456SAndroid Build Coastguard Worker    }
2062*58b9f456SAndroid Build Coastguard Worker    return __r;
2063*58b9f456SAndroid Build Coastguard Worker}
2064*58b9f456SAndroid Build Coastguard Worker
2065*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2066*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2067*58b9f456SAndroid Build Coastguard Workervoid return_temporary_buffer(_Tp* __p) _NOEXCEPT
2068*58b9f456SAndroid Build Coastguard Worker{
2069*58b9f456SAndroid Build Coastguard Worker  _VSTD::__libcpp_deallocate_unsized((void*)__p, __alignof(_Tp));
2070*58b9f456SAndroid Build Coastguard Worker}
2071*58b9f456SAndroid Build Coastguard Worker
2072*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2073*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2074*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
2075*58b9f456SAndroid Build Coastguard Worker{
2076*58b9f456SAndroid Build Coastguard Worker    _Tp* __ptr_;
2077*58b9f456SAndroid Build Coastguard Worker};
2078*58b9f456SAndroid Build Coastguard Worker
2079*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
2080*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
2081*58b9f456SAndroid Build Coastguard Worker{
2082*58b9f456SAndroid Build Coastguard Workerprivate:
2083*58b9f456SAndroid Build Coastguard Worker    _Tp* __ptr_;
2084*58b9f456SAndroid Build Coastguard Workerpublic:
2085*58b9f456SAndroid Build Coastguard Worker    typedef _Tp element_type;
2086*58b9f456SAndroid Build Coastguard Worker
2087*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2088*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2089*58b9f456SAndroid Build Coastguard Worker    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2090*58b9f456SAndroid Build Coastguard Worker        : __ptr_(__p.release()) {}
2091*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2092*58b9f456SAndroid Build Coastguard Worker        {reset(__p.release()); return *this;}
2093*58b9f456SAndroid Build Coastguard Worker    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2094*58b9f456SAndroid Build Coastguard Worker        {reset(__p.release()); return *this;}
2095*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2096*58b9f456SAndroid Build Coastguard Worker        {reset(__p.__ptr_); return *this;}
2097*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2098*58b9f456SAndroid Build Coastguard Worker
2099*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2100*58b9f456SAndroid Build Coastguard Worker        {return *__ptr_;}
2101*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2102*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2103*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2104*58b9f456SAndroid Build Coastguard Worker    {
2105*58b9f456SAndroid Build Coastguard Worker        _Tp* __t = __ptr_;
2106*58b9f456SAndroid Build Coastguard Worker        __ptr_ = 0;
2107*58b9f456SAndroid Build Coastguard Worker        return __t;
2108*58b9f456SAndroid Build Coastguard Worker    }
2109*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2110*58b9f456SAndroid Build Coastguard Worker    {
2111*58b9f456SAndroid Build Coastguard Worker        if (__ptr_ != __p)
2112*58b9f456SAndroid Build Coastguard Worker            delete __ptr_;
2113*58b9f456SAndroid Build Coastguard Worker        __ptr_ = __p;
2114*58b9f456SAndroid Build Coastguard Worker    }
2115*58b9f456SAndroid Build Coastguard Worker
2116*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2117*58b9f456SAndroid Build Coastguard Worker    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2118*58b9f456SAndroid Build Coastguard Worker        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2119*58b9f456SAndroid Build Coastguard Worker    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2120*58b9f456SAndroid Build Coastguard Worker        {return auto_ptr<_Up>(release());}
2121*58b9f456SAndroid Build Coastguard Worker};
2122*58b9f456SAndroid Build Coastguard Worker
2123*58b9f456SAndroid Build Coastguard Workertemplate <>
2124*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
2125*58b9f456SAndroid Build Coastguard Worker{
2126*58b9f456SAndroid Build Coastguard Workerpublic:
2127*58b9f456SAndroid Build Coastguard Worker    typedef void element_type;
2128*58b9f456SAndroid Build Coastguard Worker};
2129*58b9f456SAndroid Build Coastguard Worker#endif
2130*58b9f456SAndroid Build Coastguard Worker
2131*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, int _Idx,
2132*58b9f456SAndroid Build Coastguard Worker          bool _CanBeEmptyBase =
2133*58b9f456SAndroid Build Coastguard Worker              is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2134*58b9f456SAndroid Build Coastguard Workerstruct __compressed_pair_elem {
2135*58b9f456SAndroid Build Coastguard Worker  typedef _Tp _ParamT;
2136*58b9f456SAndroid Build Coastguard Worker  typedef _Tp& reference;
2137*58b9f456SAndroid Build Coastguard Worker  typedef const _Tp& const_reference;
2138*58b9f456SAndroid Build Coastguard Worker
2139*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2140*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
2141*58b9f456SAndroid Build Coastguard Worker
2142*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class = typename enable_if<
2143*58b9f456SAndroid Build Coastguard Worker      !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2144*58b9f456SAndroid Build Coastguard Worker  >::type>
2145*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2146*58b9f456SAndroid Build Coastguard Worker  constexpr explicit
2147*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(_Up&& __u)
2148*58b9f456SAndroid Build Coastguard Worker      : __value_(_VSTD::forward<_Up>(__u))
2149*58b9f456SAndroid Build Coastguard Worker    {
2150*58b9f456SAndroid Build Coastguard Worker    }
2151*58b9f456SAndroid Build Coastguard Worker
2152*58b9f456SAndroid Build Coastguard Worker  template <class... _Args, size_t... _Indexes>
2153*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2154*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2155*58b9f456SAndroid Build Coastguard Worker                         __tuple_indices<_Indexes...>)
2156*58b9f456SAndroid Build Coastguard Worker      : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2157*58b9f456SAndroid Build Coastguard Worker#else
2158*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2159*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2160*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2161*58b9f456SAndroid Build Coastguard Worker#endif
2162*58b9f456SAndroid Build Coastguard Worker
2163*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2164*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2165*58b9f456SAndroid Build Coastguard Worker  const_reference __get() const _NOEXCEPT { return __value_; }
2166*58b9f456SAndroid Build Coastguard Worker
2167*58b9f456SAndroid Build Coastguard Workerprivate:
2168*58b9f456SAndroid Build Coastguard Worker  _Tp __value_;
2169*58b9f456SAndroid Build Coastguard Worker};
2170*58b9f456SAndroid Build Coastguard Worker
2171*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, int _Idx>
2172*58b9f456SAndroid Build Coastguard Workerstruct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2173*58b9f456SAndroid Build Coastguard Worker  typedef _Tp _ParamT;
2174*58b9f456SAndroid Build Coastguard Worker  typedef _Tp& reference;
2175*58b9f456SAndroid Build Coastguard Worker  typedef const _Tp& const_reference;
2176*58b9f456SAndroid Build Coastguard Worker  typedef _Tp __value_type;
2177*58b9f456SAndroid Build Coastguard Worker
2178*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2179*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
2180*58b9f456SAndroid Build Coastguard Worker
2181*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class = typename enable_if<
2182*58b9f456SAndroid Build Coastguard Worker        !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2183*58b9f456SAndroid Build Coastguard Worker  >::type>
2184*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2185*58b9f456SAndroid Build Coastguard Worker  constexpr explicit
2186*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(_Up&& __u)
2187*58b9f456SAndroid Build Coastguard Worker      : __value_type(_VSTD::forward<_Up>(__u))
2188*58b9f456SAndroid Build Coastguard Worker  {}
2189*58b9f456SAndroid Build Coastguard Worker
2190*58b9f456SAndroid Build Coastguard Worker  template <class... _Args, size_t... _Indexes>
2191*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2192*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2193*58b9f456SAndroid Build Coastguard Worker                         __tuple_indices<_Indexes...>)
2194*58b9f456SAndroid Build Coastguard Worker      : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2195*58b9f456SAndroid Build Coastguard Worker#else
2196*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2197*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2198*58b9f456SAndroid Build Coastguard Worker  __compressed_pair_elem(_ParamT __p)
2199*58b9f456SAndroid Build Coastguard Worker      : __value_type(std::forward<_ParamT>(__p)) {}
2200*58b9f456SAndroid Build Coastguard Worker#endif
2201*58b9f456SAndroid Build Coastguard Worker
2202*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2203*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2204*58b9f456SAndroid Build Coastguard Worker  const_reference __get() const _NOEXCEPT { return *this; }
2205*58b9f456SAndroid Build Coastguard Worker};
2206*58b9f456SAndroid Build Coastguard Worker
2207*58b9f456SAndroid Build Coastguard Worker// Tag used to construct the second element of the compressed pair.
2208*58b9f456SAndroid Build Coastguard Workerstruct __second_tag {};
2209*58b9f456SAndroid Build Coastguard Worker
2210*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _T2>
2211*58b9f456SAndroid Build Coastguard Workerclass __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2212*58b9f456SAndroid Build Coastguard Worker                          private __compressed_pair_elem<_T2, 1> {
2213*58b9f456SAndroid Build Coastguard Worker  typedef __compressed_pair_elem<_T1, 0> _Base1;
2214*58b9f456SAndroid Build Coastguard Worker  typedef __compressed_pair_elem<_T2, 1> _Base2;
2215*58b9f456SAndroid Build Coastguard Worker
2216*58b9f456SAndroid Build Coastguard Worker  // NOTE: This static assert should never fire because __compressed_pair
2217*58b9f456SAndroid Build Coastguard Worker  // is *almost never* used in a scenario where it's possible for T1 == T2.
2218*58b9f456SAndroid Build Coastguard Worker  // (The exception is std::function where it is possible that the function
2219*58b9f456SAndroid Build Coastguard Worker  //  object and the allocator have the same type).
2220*58b9f456SAndroid Build Coastguard Worker  static_assert((!is_same<_T1, _T2>::value),
2221*58b9f456SAndroid Build Coastguard Worker    "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2222*58b9f456SAndroid Build Coastguard Worker    "The current implementation is NOT ABI-compatible with the previous "
2223*58b9f456SAndroid Build Coastguard Worker    "implementation for this configuration");
2224*58b9f456SAndroid Build Coastguard Worker
2225*58b9f456SAndroid Build Coastguard Workerpublic:
2226*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2227*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2228*58b9f456SAndroid Build Coastguard Worker      class = typename enable_if<
2229*58b9f456SAndroid Build Coastguard Worker          __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2230*58b9f456SAndroid Build Coastguard Worker          __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2231*58b9f456SAndroid Build Coastguard Worker      >::type
2232*58b9f456SAndroid Build Coastguard Worker  >
2233*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2234*58b9f456SAndroid Build Coastguard Worker  constexpr __compressed_pair() {}
2235*58b9f456SAndroid Build Coastguard Worker
2236*58b9f456SAndroid Build Coastguard Worker  template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2237*58b9f456SAndroid Build Coastguard Worker                                                   __compressed_pair>::value,
2238*58b9f456SAndroid Build Coastguard Worker                                          bool>::type = true>
2239*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr explicit
2240*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(_Tp&& __t)
2241*58b9f456SAndroid Build Coastguard Worker      : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2242*58b9f456SAndroid Build Coastguard Worker
2243*58b9f456SAndroid Build Coastguard Worker  template <class _Tp>
2244*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr
2245*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(__second_tag, _Tp&& __t)
2246*58b9f456SAndroid Build Coastguard Worker      : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2247*58b9f456SAndroid Build Coastguard Worker
2248*58b9f456SAndroid Build Coastguard Worker  template <class _U1, class _U2>
2249*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr
2250*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(_U1&& __t1, _U2&& __t2)
2251*58b9f456SAndroid Build Coastguard Worker      : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2252*58b9f456SAndroid Build Coastguard Worker
2253*58b9f456SAndroid Build Coastguard Worker  template <class... _Args1, class... _Args2>
2254*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2255*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2256*58b9f456SAndroid Build Coastguard Worker                    tuple<_Args2...> __second_args)
2257*58b9f456SAndroid Build Coastguard Worker      : _Base1(__pc, _VSTD::move(__first_args),
2258*58b9f456SAndroid Build Coastguard Worker               typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2259*58b9f456SAndroid Build Coastguard Worker        _Base2(__pc, _VSTD::move(__second_args),
2260*58b9f456SAndroid Build Coastguard Worker               typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2261*58b9f456SAndroid Build Coastguard Worker
2262*58b9f456SAndroid Build Coastguard Worker#else
2263*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2264*58b9f456SAndroid Build Coastguard Worker  __compressed_pair() {}
2265*58b9f456SAndroid Build Coastguard Worker
2266*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY explicit
2267*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2268*58b9f456SAndroid Build Coastguard Worker
2269*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2270*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(__second_tag, _T2 __t2)
2271*58b9f456SAndroid Build Coastguard Worker      : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2272*58b9f456SAndroid Build Coastguard Worker
2273*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2274*58b9f456SAndroid Build Coastguard Worker  __compressed_pair(_T1 __t1, _T2 __t2)
2275*58b9f456SAndroid Build Coastguard Worker      : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2276*58b9f456SAndroid Build Coastguard Worker#endif
2277*58b9f456SAndroid Build Coastguard Worker
2278*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2279*58b9f456SAndroid Build Coastguard Worker  typename _Base1::reference first() _NOEXCEPT {
2280*58b9f456SAndroid Build Coastguard Worker    return static_cast<_Base1&>(*this).__get();
2281*58b9f456SAndroid Build Coastguard Worker  }
2282*58b9f456SAndroid Build Coastguard Worker
2283*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2284*58b9f456SAndroid Build Coastguard Worker  typename _Base1::const_reference first() const _NOEXCEPT {
2285*58b9f456SAndroid Build Coastguard Worker    return static_cast<_Base1 const&>(*this).__get();
2286*58b9f456SAndroid Build Coastguard Worker  }
2287*58b9f456SAndroid Build Coastguard Worker
2288*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2289*58b9f456SAndroid Build Coastguard Worker  typename _Base2::reference second() _NOEXCEPT {
2290*58b9f456SAndroid Build Coastguard Worker    return static_cast<_Base2&>(*this).__get();
2291*58b9f456SAndroid Build Coastguard Worker  }
2292*58b9f456SAndroid Build Coastguard Worker
2293*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2294*58b9f456SAndroid Build Coastguard Worker  typename _Base2::const_reference second() const _NOEXCEPT {
2295*58b9f456SAndroid Build Coastguard Worker    return static_cast<_Base2 const&>(*this).__get();
2296*58b9f456SAndroid Build Coastguard Worker  }
2297*58b9f456SAndroid Build Coastguard Worker
2298*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2299*58b9f456SAndroid Build Coastguard Worker  void swap(__compressed_pair& __x)
2300*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2301*58b9f456SAndroid Build Coastguard Worker               __is_nothrow_swappable<_T2>::value)
2302*58b9f456SAndroid Build Coastguard Worker  {
2303*58b9f456SAndroid Build Coastguard Worker    using std::swap;
2304*58b9f456SAndroid Build Coastguard Worker    swap(first(), __x.first());
2305*58b9f456SAndroid Build Coastguard Worker    swap(second(), __x.second());
2306*58b9f456SAndroid Build Coastguard Worker  }
2307*58b9f456SAndroid Build Coastguard Worker};
2308*58b9f456SAndroid Build Coastguard Worker
2309*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _T2>
2310*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2311*58b9f456SAndroid Build Coastguard Workervoid swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2312*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2313*58b9f456SAndroid Build Coastguard Worker               __is_nothrow_swappable<_T2>::value) {
2314*58b9f456SAndroid Build Coastguard Worker  __x.swap(__y);
2315*58b9f456SAndroid Build Coastguard Worker}
2316*58b9f456SAndroid Build Coastguard Worker
2317*58b9f456SAndroid Build Coastguard Worker// default_delete
2318*58b9f456SAndroid Build Coastguard Worker
2319*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2320*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS default_delete {
2321*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_function<_Tp>::value,
2322*58b9f456SAndroid Build Coastguard Worker                  "default_delete cannot be instantiated for function types");
2323*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2324*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2325*58b9f456SAndroid Build Coastguard Worker#else
2326*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY default_delete() {}
2327*58b9f456SAndroid Build Coastguard Worker#endif
2328*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2329*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2330*58b9f456SAndroid Build Coastguard Worker  default_delete(const default_delete<_Up>&,
2331*58b9f456SAndroid Build Coastguard Worker                 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2332*58b9f456SAndroid Build Coastguard Worker                     0) _NOEXCEPT {}
2333*58b9f456SAndroid Build Coastguard Worker
2334*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2335*58b9f456SAndroid Build Coastguard Worker    static_assert(sizeof(_Tp) > 0,
2336*58b9f456SAndroid Build Coastguard Worker                  "default_delete can not delete incomplete type");
2337*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_void<_Tp>::value,
2338*58b9f456SAndroid Build Coastguard Worker                  "default_delete can not delete incomplete type");
2339*58b9f456SAndroid Build Coastguard Worker    delete __ptr;
2340*58b9f456SAndroid Build Coastguard Worker  }
2341*58b9f456SAndroid Build Coastguard Worker};
2342*58b9f456SAndroid Build Coastguard Worker
2343*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
2344*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2345*58b9f456SAndroid Build Coastguard Workerprivate:
2346*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2347*58b9f456SAndroid Build Coastguard Worker  struct _EnableIfConvertible
2348*58b9f456SAndroid Build Coastguard Worker      : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2349*58b9f456SAndroid Build Coastguard Worker
2350*58b9f456SAndroid Build Coastguard Workerpublic:
2351*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2352*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2353*58b9f456SAndroid Build Coastguard Worker#else
2354*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY default_delete() {}
2355*58b9f456SAndroid Build Coastguard Worker#endif
2356*58b9f456SAndroid Build Coastguard Worker
2357*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2358*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2359*58b9f456SAndroid Build Coastguard Worker  default_delete(const default_delete<_Up[]>&,
2360*58b9f456SAndroid Build Coastguard Worker                 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2361*58b9f456SAndroid Build Coastguard Worker
2362*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2363*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2364*58b9f456SAndroid Build Coastguard Worker  typename _EnableIfConvertible<_Up>::type
2365*58b9f456SAndroid Build Coastguard Worker  operator()(_Up* __ptr) const _NOEXCEPT {
2366*58b9f456SAndroid Build Coastguard Worker    static_assert(sizeof(_Tp) > 0,
2367*58b9f456SAndroid Build Coastguard Worker                  "default_delete can not delete incomplete type");
2368*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_void<_Tp>::value,
2369*58b9f456SAndroid Build Coastguard Worker                  "default_delete can not delete void type");
2370*58b9f456SAndroid Build Coastguard Worker    delete[] __ptr;
2371*58b9f456SAndroid Build Coastguard Worker  }
2372*58b9f456SAndroid Build Coastguard Worker};
2373*58b9f456SAndroid Build Coastguard Worker
2374*58b9f456SAndroid Build Coastguard Worker
2375*58b9f456SAndroid Build Coastguard Worker
2376*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2377*58b9f456SAndroid Build Coastguard Workertemplate <class _Deleter>
2378*58b9f456SAndroid Build Coastguard Workerstruct __unique_ptr_deleter_sfinae {
2379*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2380*58b9f456SAndroid Build Coastguard Worker  typedef const _Deleter& __lval_ref_type;
2381*58b9f456SAndroid Build Coastguard Worker  typedef _Deleter&& __good_rval_ref_type;
2382*58b9f456SAndroid Build Coastguard Worker  typedef true_type __enable_rval_overload;
2383*58b9f456SAndroid Build Coastguard Worker};
2384*58b9f456SAndroid Build Coastguard Worker
2385*58b9f456SAndroid Build Coastguard Workertemplate <class _Deleter>
2386*58b9f456SAndroid Build Coastguard Workerstruct __unique_ptr_deleter_sfinae<_Deleter const&> {
2387*58b9f456SAndroid Build Coastguard Worker  typedef const _Deleter& __lval_ref_type;
2388*58b9f456SAndroid Build Coastguard Worker  typedef const _Deleter&& __bad_rval_ref_type;
2389*58b9f456SAndroid Build Coastguard Worker  typedef false_type __enable_rval_overload;
2390*58b9f456SAndroid Build Coastguard Worker};
2391*58b9f456SAndroid Build Coastguard Worker
2392*58b9f456SAndroid Build Coastguard Workertemplate <class _Deleter>
2393*58b9f456SAndroid Build Coastguard Workerstruct __unique_ptr_deleter_sfinae<_Deleter&> {
2394*58b9f456SAndroid Build Coastguard Worker  typedef _Deleter& __lval_ref_type;
2395*58b9f456SAndroid Build Coastguard Worker  typedef _Deleter&& __bad_rval_ref_type;
2396*58b9f456SAndroid Build Coastguard Worker  typedef false_type __enable_rval_overload;
2397*58b9f456SAndroid Build Coastguard Worker};
2398*58b9f456SAndroid Build Coastguard Worker#endif // !defined(_LIBCPP_CXX03_LANG)
2399*58b9f456SAndroid Build Coastguard Worker
2400*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp = default_delete<_Tp> >
2401*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS unique_ptr {
2402*58b9f456SAndroid Build Coastguard Workerpublic:
2403*58b9f456SAndroid Build Coastguard Worker  typedef _Tp element_type;
2404*58b9f456SAndroid Build Coastguard Worker  typedef _Dp deleter_type;
2405*58b9f456SAndroid Build Coastguard Worker  typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2406*58b9f456SAndroid Build Coastguard Worker
2407*58b9f456SAndroid Build Coastguard Worker  static_assert(!is_rvalue_reference<deleter_type>::value,
2408*58b9f456SAndroid Build Coastguard Worker                "the specified deleter type cannot be an rvalue reference");
2409*58b9f456SAndroid Build Coastguard Worker
2410*58b9f456SAndroid Build Coastguard Workerprivate:
2411*58b9f456SAndroid Build Coastguard Worker  __compressed_pair<pointer, deleter_type> __ptr_;
2412*58b9f456SAndroid Build Coastguard Worker
2413*58b9f456SAndroid Build Coastguard Worker  struct __nat { int __for_bool_; };
2414*58b9f456SAndroid Build Coastguard Worker
2415*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2416*58b9f456SAndroid Build Coastguard Worker  typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2417*58b9f456SAndroid Build Coastguard Worker
2418*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2419*58b9f456SAndroid Build Coastguard Worker  using _LValRefType =
2420*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2421*58b9f456SAndroid Build Coastguard Worker
2422*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2423*58b9f456SAndroid Build Coastguard Worker  using _GoodRValRefType =
2424*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2425*58b9f456SAndroid Build Coastguard Worker
2426*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2427*58b9f456SAndroid Build Coastguard Worker  using _BadRValRefType =
2428*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2429*58b9f456SAndroid Build Coastguard Worker
2430*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy, class _Deleter = typename __dependent_type<
2431*58b9f456SAndroid Build Coastguard Worker                             __identity<deleter_type>, _Dummy>::type>
2432*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterDefaultConstructible =
2433*58b9f456SAndroid Build Coastguard Worker      typename enable_if<is_default_constructible<_Deleter>::value &&
2434*58b9f456SAndroid Build Coastguard Worker                         !is_pointer<_Deleter>::value>::type;
2435*58b9f456SAndroid Build Coastguard Worker
2436*58b9f456SAndroid Build Coastguard Worker  template <class _ArgType>
2437*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterConstructible =
2438*58b9f456SAndroid Build Coastguard Worker      typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2439*58b9f456SAndroid Build Coastguard Worker
2440*58b9f456SAndroid Build Coastguard Worker  template <class _UPtr, class _Up>
2441*58b9f456SAndroid Build Coastguard Worker  using _EnableIfMoveConvertible = typename enable_if<
2442*58b9f456SAndroid Build Coastguard Worker      is_convertible<typename _UPtr::pointer, pointer>::value &&
2443*58b9f456SAndroid Build Coastguard Worker      !is_array<_Up>::value
2444*58b9f456SAndroid Build Coastguard Worker  >::type;
2445*58b9f456SAndroid Build Coastguard Worker
2446*58b9f456SAndroid Build Coastguard Worker  template <class _UDel>
2447*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterConvertible = typename enable_if<
2448*58b9f456SAndroid Build Coastguard Worker      (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2449*58b9f456SAndroid Build Coastguard Worker      (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2450*58b9f456SAndroid Build Coastguard Worker    >::type;
2451*58b9f456SAndroid Build Coastguard Worker
2452*58b9f456SAndroid Build Coastguard Worker  template <class _UDel>
2453*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterAssignable = typename enable_if<
2454*58b9f456SAndroid Build Coastguard Worker      is_assignable<_Dp&, _UDel&&>::value
2455*58b9f456SAndroid Build Coastguard Worker    >::type;
2456*58b9f456SAndroid Build Coastguard Worker
2457*58b9f456SAndroid Build Coastguard Workerpublic:
2458*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2459*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2460*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2461*58b9f456SAndroid Build Coastguard Worker  constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2462*58b9f456SAndroid Build Coastguard Worker
2463*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2464*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2465*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2466*58b9f456SAndroid Build Coastguard Worker  constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2467*58b9f456SAndroid Build Coastguard Worker
2468*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2469*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2470*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2471*58b9f456SAndroid Build Coastguard Worker  explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2472*58b9f456SAndroid Build Coastguard Worker
2473*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2474*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2475*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2476*58b9f456SAndroid Build Coastguard Worker  unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2477*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p, __d) {}
2478*58b9f456SAndroid Build Coastguard Worker
2479*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2480*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2481*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2482*58b9f456SAndroid Build Coastguard Worker  unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2483*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p, _VSTD::move(__d)) {
2484*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_reference<deleter_type>::value,
2485*58b9f456SAndroid Build Coastguard Worker                  "rvalue deleter bound to reference");
2486*58b9f456SAndroid Build Coastguard Worker  }
2487*58b9f456SAndroid Build Coastguard Worker
2488*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2489*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2490*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2491*58b9f456SAndroid Build Coastguard Worker  unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2492*58b9f456SAndroid Build Coastguard Worker
2493*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2494*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr&& __u) noexcept
2495*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2496*58b9f456SAndroid Build Coastguard Worker  }
2497*58b9f456SAndroid Build Coastguard Worker
2498*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep,
2499*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2500*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfDeleterConvertible<_Ep>
2501*58b9f456SAndroid Build Coastguard Worker  >
2502*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2503*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2504*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2505*58b9f456SAndroid Build Coastguard Worker
2506*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2507*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2508*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2509*58b9f456SAndroid Build Coastguard Worker  unique_ptr(auto_ptr<_Up>&& __p,
2510*58b9f456SAndroid Build Coastguard Worker             typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2511*58b9f456SAndroid Build Coastguard Worker                                    is_same<_Dp, default_delete<_Tp>>::value,
2512*58b9f456SAndroid Build Coastguard Worker                                __nat>::type = __nat()) _NOEXCEPT
2513*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p.release()) {}
2514*58b9f456SAndroid Build Coastguard Worker#endif
2515*58b9f456SAndroid Build Coastguard Worker
2516*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2517*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2518*58b9f456SAndroid Build Coastguard Worker    reset(__u.release());
2519*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2520*58b9f456SAndroid Build Coastguard Worker    return *this;
2521*58b9f456SAndroid Build Coastguard Worker  }
2522*58b9f456SAndroid Build Coastguard Worker
2523*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep,
2524*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2525*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfDeleterAssignable<_Ep>
2526*58b9f456SAndroid Build Coastguard Worker  >
2527*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2528*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2529*58b9f456SAndroid Build Coastguard Worker    reset(__u.release());
2530*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2531*58b9f456SAndroid Build Coastguard Worker    return *this;
2532*58b9f456SAndroid Build Coastguard Worker  }
2533*58b9f456SAndroid Build Coastguard Worker
2534*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_CXX03_LANG
2535*58b9f456SAndroid Build Coastguard Workerprivate:
2536*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr&);
2537*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2538*58b9f456SAndroid Build Coastguard Worker
2539*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(unique_ptr&);
2540*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2541*58b9f456SAndroid Build Coastguard Worker
2542*58b9f456SAndroid Build Coastguard Workerpublic:
2543*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2544*58b9f456SAndroid Build Coastguard Worker  unique_ptr() : __ptr_(pointer())
2545*58b9f456SAndroid Build Coastguard Worker  {
2546*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2547*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2548*58b9f456SAndroid Build Coastguard Worker    static_assert(is_default_constructible<deleter_type>::value,
2549*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr::deleter_type is not default constructible");
2550*58b9f456SAndroid Build Coastguard Worker  }
2551*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2552*58b9f456SAndroid Build Coastguard Worker  unique_ptr(nullptr_t) : __ptr_(pointer())
2553*58b9f456SAndroid Build Coastguard Worker  {
2554*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2555*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2556*58b9f456SAndroid Build Coastguard Worker  }
2557*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2558*58b9f456SAndroid Build Coastguard Worker  explicit unique_ptr(pointer __p)
2559*58b9f456SAndroid Build Coastguard Worker      : __ptr_(_VSTD::move(__p)) {
2560*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2561*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2562*58b9f456SAndroid Build Coastguard Worker  }
2563*58b9f456SAndroid Build Coastguard Worker
2564*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2565*58b9f456SAndroid Build Coastguard Worker  operator __rv<unique_ptr>() {
2566*58b9f456SAndroid Build Coastguard Worker    return __rv<unique_ptr>(*this);
2567*58b9f456SAndroid Build Coastguard Worker  }
2568*58b9f456SAndroid Build Coastguard Worker
2569*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2570*58b9f456SAndroid Build Coastguard Worker  unique_ptr(__rv<unique_ptr> __u)
2571*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u->release(),
2572*58b9f456SAndroid Build Coastguard Worker               _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2573*58b9f456SAndroid Build Coastguard Worker
2574*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep>
2575*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2576*58b9f456SAndroid Build Coastguard Worker  typename enable_if<
2577*58b9f456SAndroid Build Coastguard Worker      !is_array<_Up>::value &&
2578*58b9f456SAndroid Build Coastguard Worker          is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2579*58b9f456SAndroid Build Coastguard Worker                         pointer>::value &&
2580*58b9f456SAndroid Build Coastguard Worker          is_assignable<deleter_type&, _Ep&>::value,
2581*58b9f456SAndroid Build Coastguard Worker      unique_ptr&>::type
2582*58b9f456SAndroid Build Coastguard Worker  operator=(unique_ptr<_Up, _Ep> __u) {
2583*58b9f456SAndroid Build Coastguard Worker    reset(__u.release());
2584*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2585*58b9f456SAndroid Build Coastguard Worker    return *this;
2586*58b9f456SAndroid Build Coastguard Worker  }
2587*58b9f456SAndroid Build Coastguard Worker
2588*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2589*58b9f456SAndroid Build Coastguard Worker  unique_ptr(pointer __p, deleter_type __d)
2590*58b9f456SAndroid Build Coastguard Worker      : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2591*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG
2592*58b9f456SAndroid Build Coastguard Worker
2593*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2594*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2595*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2596*58b9f456SAndroid Build Coastguard Worker      typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2597*58b9f456SAndroid Build Coastguard Worker                             is_same<_Dp, default_delete<_Tp> >::value,
2598*58b9f456SAndroid Build Coastguard Worker                         unique_ptr&>::type
2599*58b9f456SAndroid Build Coastguard Worker      operator=(auto_ptr<_Up> __p) {
2600*58b9f456SAndroid Build Coastguard Worker    reset(__p.release());
2601*58b9f456SAndroid Build Coastguard Worker    return *this;
2602*58b9f456SAndroid Build Coastguard Worker  }
2603*58b9f456SAndroid Build Coastguard Worker#endif
2604*58b9f456SAndroid Build Coastguard Worker
2605*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2606*58b9f456SAndroid Build Coastguard Worker  ~unique_ptr() { reset(); }
2607*58b9f456SAndroid Build Coastguard Worker
2608*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2609*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2610*58b9f456SAndroid Build Coastguard Worker    reset();
2611*58b9f456SAndroid Build Coastguard Worker    return *this;
2612*58b9f456SAndroid Build Coastguard Worker  }
2613*58b9f456SAndroid Build Coastguard Worker
2614*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2615*58b9f456SAndroid Build Coastguard Worker  typename add_lvalue_reference<_Tp>::type
2616*58b9f456SAndroid Build Coastguard Worker  operator*() const {
2617*58b9f456SAndroid Build Coastguard Worker    return *__ptr_.first();
2618*58b9f456SAndroid Build Coastguard Worker  }
2619*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2620*58b9f456SAndroid Build Coastguard Worker  pointer operator->() const _NOEXCEPT {
2621*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first();
2622*58b9f456SAndroid Build Coastguard Worker  }
2623*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2624*58b9f456SAndroid Build Coastguard Worker  pointer get() const _NOEXCEPT {
2625*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first();
2626*58b9f456SAndroid Build Coastguard Worker  }
2627*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2628*58b9f456SAndroid Build Coastguard Worker  deleter_type& get_deleter() _NOEXCEPT {
2629*58b9f456SAndroid Build Coastguard Worker    return __ptr_.second();
2630*58b9f456SAndroid Build Coastguard Worker  }
2631*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2632*58b9f456SAndroid Build Coastguard Worker  const deleter_type& get_deleter() const _NOEXCEPT {
2633*58b9f456SAndroid Build Coastguard Worker    return __ptr_.second();
2634*58b9f456SAndroid Build Coastguard Worker  }
2635*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2636*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2637*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first() != nullptr;
2638*58b9f456SAndroid Build Coastguard Worker  }
2639*58b9f456SAndroid Build Coastguard Worker
2640*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2641*58b9f456SAndroid Build Coastguard Worker  pointer release() _NOEXCEPT {
2642*58b9f456SAndroid Build Coastguard Worker    pointer __t = __ptr_.first();
2643*58b9f456SAndroid Build Coastguard Worker    __ptr_.first() = pointer();
2644*58b9f456SAndroid Build Coastguard Worker    return __t;
2645*58b9f456SAndroid Build Coastguard Worker  }
2646*58b9f456SAndroid Build Coastguard Worker
2647*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2648*58b9f456SAndroid Build Coastguard Worker  void reset(pointer __p = pointer()) _NOEXCEPT {
2649*58b9f456SAndroid Build Coastguard Worker    pointer __tmp = __ptr_.first();
2650*58b9f456SAndroid Build Coastguard Worker    __ptr_.first() = __p;
2651*58b9f456SAndroid Build Coastguard Worker    if (__tmp)
2652*58b9f456SAndroid Build Coastguard Worker      __ptr_.second()(__tmp);
2653*58b9f456SAndroid Build Coastguard Worker  }
2654*58b9f456SAndroid Build Coastguard Worker
2655*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2656*58b9f456SAndroid Build Coastguard Worker  void swap(unique_ptr& __u) _NOEXCEPT {
2657*58b9f456SAndroid Build Coastguard Worker    __ptr_.swap(__u.__ptr_);
2658*58b9f456SAndroid Build Coastguard Worker  }
2659*58b9f456SAndroid Build Coastguard Worker};
2660*58b9f456SAndroid Build Coastguard Worker
2661*58b9f456SAndroid Build Coastguard Worker
2662*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
2663*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2664*58b9f456SAndroid Build Coastguard Workerpublic:
2665*58b9f456SAndroid Build Coastguard Worker  typedef _Tp element_type;
2666*58b9f456SAndroid Build Coastguard Worker  typedef _Dp deleter_type;
2667*58b9f456SAndroid Build Coastguard Worker  typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2668*58b9f456SAndroid Build Coastguard Worker
2669*58b9f456SAndroid Build Coastguard Workerprivate:
2670*58b9f456SAndroid Build Coastguard Worker  __compressed_pair<pointer, deleter_type> __ptr_;
2671*58b9f456SAndroid Build Coastguard Worker
2672*58b9f456SAndroid Build Coastguard Worker  template <class _From>
2673*58b9f456SAndroid Build Coastguard Worker  struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2674*58b9f456SAndroid Build Coastguard Worker
2675*58b9f456SAndroid Build Coastguard Worker  template <class _FromElem>
2676*58b9f456SAndroid Build Coastguard Worker  struct _CheckArrayPointerConversion<_FromElem*>
2677*58b9f456SAndroid Build Coastguard Worker      : integral_constant<bool,
2678*58b9f456SAndroid Build Coastguard Worker          is_same<_FromElem*, pointer>::value ||
2679*58b9f456SAndroid Build Coastguard Worker            (is_same<pointer, element_type*>::value &&
2680*58b9f456SAndroid Build Coastguard Worker             is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2681*58b9f456SAndroid Build Coastguard Worker      >
2682*58b9f456SAndroid Build Coastguard Worker  {};
2683*58b9f456SAndroid Build Coastguard Worker
2684*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_CXX03_LANG
2685*58b9f456SAndroid Build Coastguard Worker  typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2686*58b9f456SAndroid Build Coastguard Worker
2687*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2688*58b9f456SAndroid Build Coastguard Worker  using _LValRefType =
2689*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2690*58b9f456SAndroid Build Coastguard Worker
2691*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2692*58b9f456SAndroid Build Coastguard Worker  using _GoodRValRefType =
2693*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2694*58b9f456SAndroid Build Coastguard Worker
2695*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy>
2696*58b9f456SAndroid Build Coastguard Worker  using _BadRValRefType =
2697*58b9f456SAndroid Build Coastguard Worker      typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2698*58b9f456SAndroid Build Coastguard Worker
2699*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy, class _Deleter = typename __dependent_type<
2700*58b9f456SAndroid Build Coastguard Worker                             __identity<deleter_type>, _Dummy>::type>
2701*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterDefaultConstructible =
2702*58b9f456SAndroid Build Coastguard Worker      typename enable_if<is_default_constructible<_Deleter>::value &&
2703*58b9f456SAndroid Build Coastguard Worker                         !is_pointer<_Deleter>::value>::type;
2704*58b9f456SAndroid Build Coastguard Worker
2705*58b9f456SAndroid Build Coastguard Worker  template <class _ArgType>
2706*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterConstructible =
2707*58b9f456SAndroid Build Coastguard Worker      typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2708*58b9f456SAndroid Build Coastguard Worker
2709*58b9f456SAndroid Build Coastguard Worker  template <class _Pp>
2710*58b9f456SAndroid Build Coastguard Worker  using _EnableIfPointerConvertible = typename enable_if<
2711*58b9f456SAndroid Build Coastguard Worker      _CheckArrayPointerConversion<_Pp>::value
2712*58b9f456SAndroid Build Coastguard Worker  >::type;
2713*58b9f456SAndroid Build Coastguard Worker
2714*58b9f456SAndroid Build Coastguard Worker  template <class _UPtr, class _Up,
2715*58b9f456SAndroid Build Coastguard Worker        class _ElemT = typename _UPtr::element_type>
2716*58b9f456SAndroid Build Coastguard Worker  using _EnableIfMoveConvertible = typename enable_if<
2717*58b9f456SAndroid Build Coastguard Worker      is_array<_Up>::value &&
2718*58b9f456SAndroid Build Coastguard Worker      is_same<pointer, element_type*>::value &&
2719*58b9f456SAndroid Build Coastguard Worker      is_same<typename _UPtr::pointer, _ElemT*>::value &&
2720*58b9f456SAndroid Build Coastguard Worker      is_convertible<_ElemT(*)[], element_type(*)[]>::value
2721*58b9f456SAndroid Build Coastguard Worker    >::type;
2722*58b9f456SAndroid Build Coastguard Worker
2723*58b9f456SAndroid Build Coastguard Worker  template <class _UDel>
2724*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterConvertible = typename enable_if<
2725*58b9f456SAndroid Build Coastguard Worker      (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2726*58b9f456SAndroid Build Coastguard Worker      (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2727*58b9f456SAndroid Build Coastguard Worker    >::type;
2728*58b9f456SAndroid Build Coastguard Worker
2729*58b9f456SAndroid Build Coastguard Worker  template <class _UDel>
2730*58b9f456SAndroid Build Coastguard Worker  using _EnableIfDeleterAssignable = typename enable_if<
2731*58b9f456SAndroid Build Coastguard Worker      is_assignable<_Dp&, _UDel&&>::value
2732*58b9f456SAndroid Build Coastguard Worker    >::type;
2733*58b9f456SAndroid Build Coastguard Worker
2734*58b9f456SAndroid Build Coastguard Workerpublic:
2735*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2736*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2737*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2738*58b9f456SAndroid Build Coastguard Worker  constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2739*58b9f456SAndroid Build Coastguard Worker
2740*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2741*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2742*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2743*58b9f456SAndroid Build Coastguard Worker  constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2744*58b9f456SAndroid Build Coastguard Worker
2745*58b9f456SAndroid Build Coastguard Worker  template <class _Pp, bool _Dummy = true,
2746*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2747*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfPointerConvertible<_Pp>>
2748*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2749*58b9f456SAndroid Build Coastguard Worker  explicit unique_ptr(_Pp __p) noexcept
2750*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p) {}
2751*58b9f456SAndroid Build Coastguard Worker
2752*58b9f456SAndroid Build Coastguard Worker  template <class _Pp, bool _Dummy = true,
2753*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2754*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfPointerConvertible<_Pp>>
2755*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2756*58b9f456SAndroid Build Coastguard Worker  unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2757*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p, __d) {}
2758*58b9f456SAndroid Build Coastguard Worker
2759*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2760*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2761*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2762*58b9f456SAndroid Build Coastguard Worker  unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2763*58b9f456SAndroid Build Coastguard Worker      : __ptr_(nullptr, __d) {}
2764*58b9f456SAndroid Build Coastguard Worker
2765*58b9f456SAndroid Build Coastguard Worker  template <class _Pp, bool _Dummy = true,
2766*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2767*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfPointerConvertible<_Pp>>
2768*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2769*58b9f456SAndroid Build Coastguard Worker  unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2770*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p, _VSTD::move(__d)) {
2771*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_reference<deleter_type>::value,
2772*58b9f456SAndroid Build Coastguard Worker                  "rvalue deleter bound to reference");
2773*58b9f456SAndroid Build Coastguard Worker  }
2774*58b9f456SAndroid Build Coastguard Worker
2775*58b9f456SAndroid Build Coastguard Worker  template <bool _Dummy = true,
2776*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2777*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2778*58b9f456SAndroid Build Coastguard Worker  unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2779*58b9f456SAndroid Build Coastguard Worker      : __ptr_(nullptr, _VSTD::move(__d)) {
2780*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_reference<deleter_type>::value,
2781*58b9f456SAndroid Build Coastguard Worker                  "rvalue deleter bound to reference");
2782*58b9f456SAndroid Build Coastguard Worker  }
2783*58b9f456SAndroid Build Coastguard Worker
2784*58b9f456SAndroid Build Coastguard Worker  template <class _Pp, bool _Dummy = true,
2785*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2786*58b9f456SAndroid Build Coastguard Worker            class = _EnableIfPointerConvertible<_Pp>>
2787*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2788*58b9f456SAndroid Build Coastguard Worker  unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2789*58b9f456SAndroid Build Coastguard Worker
2790*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2791*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr&& __u) noexcept
2792*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2793*58b9f456SAndroid Build Coastguard Worker  }
2794*58b9f456SAndroid Build Coastguard Worker
2795*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2796*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(unique_ptr&& __u) noexcept {
2797*58b9f456SAndroid Build Coastguard Worker    reset(__u.release());
2798*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2799*58b9f456SAndroid Build Coastguard Worker    return *this;
2800*58b9f456SAndroid Build Coastguard Worker  }
2801*58b9f456SAndroid Build Coastguard Worker
2802*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep,
2803*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2804*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfDeleterConvertible<_Ep>
2805*58b9f456SAndroid Build Coastguard Worker  >
2806*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2807*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
2808*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2809*58b9f456SAndroid Build Coastguard Worker  }
2810*58b9f456SAndroid Build Coastguard Worker
2811*58b9f456SAndroid Build Coastguard Worker  template <class _Up, class _Ep,
2812*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2813*58b9f456SAndroid Build Coastguard Worker      class = _EnableIfDeleterAssignable<_Ep>
2814*58b9f456SAndroid Build Coastguard Worker  >
2815*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2816*58b9f456SAndroid Build Coastguard Worker  unique_ptr&
2817*58b9f456SAndroid Build Coastguard Worker  operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2818*58b9f456SAndroid Build Coastguard Worker    reset(__u.release());
2819*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2820*58b9f456SAndroid Build Coastguard Worker    return *this;
2821*58b9f456SAndroid Build Coastguard Worker  }
2822*58b9f456SAndroid Build Coastguard Worker
2823*58b9f456SAndroid Build Coastguard Worker#else // _LIBCPP_CXX03_LANG
2824*58b9f456SAndroid Build Coastguard Workerprivate:
2825*58b9f456SAndroid Build Coastguard Worker  template <class _Up> explicit unique_ptr(_Up);
2826*58b9f456SAndroid Build Coastguard Worker
2827*58b9f456SAndroid Build Coastguard Worker  unique_ptr(unique_ptr&);
2828*58b9f456SAndroid Build Coastguard Worker  template <class _Up> unique_ptr(unique_ptr<_Up>&);
2829*58b9f456SAndroid Build Coastguard Worker
2830*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(unique_ptr&);
2831*58b9f456SAndroid Build Coastguard Worker  template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2832*58b9f456SAndroid Build Coastguard Worker
2833*58b9f456SAndroid Build Coastguard Worker  template <class _Up>
2834*58b9f456SAndroid Build Coastguard Worker  unique_ptr(_Up __u,
2835*58b9f456SAndroid Build Coastguard Worker             typename conditional<
2836*58b9f456SAndroid Build Coastguard Worker                 is_reference<deleter_type>::value, deleter_type,
2837*58b9f456SAndroid Build Coastguard Worker                 typename add_lvalue_reference<const deleter_type>::type>::type,
2838*58b9f456SAndroid Build Coastguard Worker             typename enable_if<is_convertible<_Up, pointer>::value,
2839*58b9f456SAndroid Build Coastguard Worker                                __nat>::type = __nat());
2840*58b9f456SAndroid Build Coastguard Workerpublic:
2841*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2842*58b9f456SAndroid Build Coastguard Worker  unique_ptr() : __ptr_(pointer()) {
2843*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2844*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2845*58b9f456SAndroid Build Coastguard Worker  }
2846*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2847*58b9f456SAndroid Build Coastguard Worker  unique_ptr(nullptr_t) : __ptr_(pointer()) {
2848*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2849*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2850*58b9f456SAndroid Build Coastguard Worker  }
2851*58b9f456SAndroid Build Coastguard Worker
2852*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2853*58b9f456SAndroid Build Coastguard Worker  explicit unique_ptr(pointer __p) : __ptr_(__p) {
2854*58b9f456SAndroid Build Coastguard Worker    static_assert(!is_pointer<deleter_type>::value,
2855*58b9f456SAndroid Build Coastguard Worker                  "unique_ptr constructed with null function pointer deleter");
2856*58b9f456SAndroid Build Coastguard Worker  }
2857*58b9f456SAndroid Build Coastguard Worker
2858*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2859*58b9f456SAndroid Build Coastguard Worker  unique_ptr(pointer __p, deleter_type __d)
2860*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2861*58b9f456SAndroid Build Coastguard Worker
2862*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2863*58b9f456SAndroid Build Coastguard Worker  unique_ptr(nullptr_t, deleter_type __d)
2864*58b9f456SAndroid Build Coastguard Worker      : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2865*58b9f456SAndroid Build Coastguard Worker
2866*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2867*58b9f456SAndroid Build Coastguard Worker  operator __rv<unique_ptr>() {
2868*58b9f456SAndroid Build Coastguard Worker    return __rv<unique_ptr>(*this);
2869*58b9f456SAndroid Build Coastguard Worker  }
2870*58b9f456SAndroid Build Coastguard Worker
2871*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2872*58b9f456SAndroid Build Coastguard Worker  unique_ptr(__rv<unique_ptr> __u)
2873*58b9f456SAndroid Build Coastguard Worker      : __ptr_(__u->release(),
2874*58b9f456SAndroid Build Coastguard Worker               _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2875*58b9f456SAndroid Build Coastguard Worker
2876*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2877*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(__rv<unique_ptr> __u) {
2878*58b9f456SAndroid Build Coastguard Worker    reset(__u->release());
2879*58b9f456SAndroid Build Coastguard Worker    __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2880*58b9f456SAndroid Build Coastguard Worker    return *this;
2881*58b9f456SAndroid Build Coastguard Worker  }
2882*58b9f456SAndroid Build Coastguard Worker
2883*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_CXX03_LANG
2884*58b9f456SAndroid Build Coastguard Worker
2885*58b9f456SAndroid Build Coastguard Workerpublic:
2886*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2887*58b9f456SAndroid Build Coastguard Worker  ~unique_ptr() { reset(); }
2888*58b9f456SAndroid Build Coastguard Worker
2889*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2890*58b9f456SAndroid Build Coastguard Worker  unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2891*58b9f456SAndroid Build Coastguard Worker    reset();
2892*58b9f456SAndroid Build Coastguard Worker    return *this;
2893*58b9f456SAndroid Build Coastguard Worker  }
2894*58b9f456SAndroid Build Coastguard Worker
2895*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2896*58b9f456SAndroid Build Coastguard Worker  typename add_lvalue_reference<_Tp>::type
2897*58b9f456SAndroid Build Coastguard Worker  operator[](size_t __i) const {
2898*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first()[__i];
2899*58b9f456SAndroid Build Coastguard Worker  }
2900*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2901*58b9f456SAndroid Build Coastguard Worker  pointer get() const _NOEXCEPT {
2902*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first();
2903*58b9f456SAndroid Build Coastguard Worker  }
2904*58b9f456SAndroid Build Coastguard Worker
2905*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2906*58b9f456SAndroid Build Coastguard Worker  deleter_type& get_deleter() _NOEXCEPT {
2907*58b9f456SAndroid Build Coastguard Worker    return __ptr_.second();
2908*58b9f456SAndroid Build Coastguard Worker  }
2909*58b9f456SAndroid Build Coastguard Worker
2910*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2911*58b9f456SAndroid Build Coastguard Worker  const deleter_type& get_deleter() const _NOEXCEPT {
2912*58b9f456SAndroid Build Coastguard Worker    return __ptr_.second();
2913*58b9f456SAndroid Build Coastguard Worker  }
2914*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2915*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2916*58b9f456SAndroid Build Coastguard Worker    return __ptr_.first() != nullptr;
2917*58b9f456SAndroid Build Coastguard Worker  }
2918*58b9f456SAndroid Build Coastguard Worker
2919*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2920*58b9f456SAndroid Build Coastguard Worker  pointer release() _NOEXCEPT {
2921*58b9f456SAndroid Build Coastguard Worker    pointer __t = __ptr_.first();
2922*58b9f456SAndroid Build Coastguard Worker    __ptr_.first() = pointer();
2923*58b9f456SAndroid Build Coastguard Worker    return __t;
2924*58b9f456SAndroid Build Coastguard Worker  }
2925*58b9f456SAndroid Build Coastguard Worker
2926*58b9f456SAndroid Build Coastguard Worker  template <class _Pp>
2927*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2928*58b9f456SAndroid Build Coastguard Worker  typename enable_if<
2929*58b9f456SAndroid Build Coastguard Worker      _CheckArrayPointerConversion<_Pp>::value
2930*58b9f456SAndroid Build Coastguard Worker  >::type
2931*58b9f456SAndroid Build Coastguard Worker  reset(_Pp __p) _NOEXCEPT {
2932*58b9f456SAndroid Build Coastguard Worker    pointer __tmp = __ptr_.first();
2933*58b9f456SAndroid Build Coastguard Worker    __ptr_.first() = __p;
2934*58b9f456SAndroid Build Coastguard Worker    if (__tmp)
2935*58b9f456SAndroid Build Coastguard Worker      __ptr_.second()(__tmp);
2936*58b9f456SAndroid Build Coastguard Worker  }
2937*58b9f456SAndroid Build Coastguard Worker
2938*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2939*58b9f456SAndroid Build Coastguard Worker  void reset(nullptr_t = nullptr) _NOEXCEPT {
2940*58b9f456SAndroid Build Coastguard Worker    pointer __tmp = __ptr_.first();
2941*58b9f456SAndroid Build Coastguard Worker    __ptr_.first() = nullptr;
2942*58b9f456SAndroid Build Coastguard Worker    if (__tmp)
2943*58b9f456SAndroid Build Coastguard Worker      __ptr_.second()(__tmp);
2944*58b9f456SAndroid Build Coastguard Worker  }
2945*58b9f456SAndroid Build Coastguard Worker
2946*58b9f456SAndroid Build Coastguard Worker  _LIBCPP_INLINE_VISIBILITY
2947*58b9f456SAndroid Build Coastguard Worker  void swap(unique_ptr& __u) _NOEXCEPT {
2948*58b9f456SAndroid Build Coastguard Worker    __ptr_.swap(__u.__ptr_);
2949*58b9f456SAndroid Build Coastguard Worker  }
2950*58b9f456SAndroid Build Coastguard Worker
2951*58b9f456SAndroid Build Coastguard Worker};
2952*58b9f456SAndroid Build Coastguard Worker
2953*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
2954*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2955*58b9f456SAndroid Build Coastguard Workertypename enable_if<
2956*58b9f456SAndroid Build Coastguard Worker    __is_swappable<_Dp>::value,
2957*58b9f456SAndroid Build Coastguard Worker    void
2958*58b9f456SAndroid Build Coastguard Worker>::type
2959*58b9f456SAndroid Build Coastguard Workerswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2960*58b9f456SAndroid Build Coastguard Worker
2961*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2962*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2963*58b9f456SAndroid Build Coastguard Workerbool
2964*58b9f456SAndroid Build Coastguard Workeroperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2965*58b9f456SAndroid Build Coastguard Worker
2966*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2967*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2968*58b9f456SAndroid Build Coastguard Workerbool
2969*58b9f456SAndroid Build Coastguard Workeroperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2970*58b9f456SAndroid Build Coastguard Worker
2971*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2972*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2973*58b9f456SAndroid Build Coastguard Workerbool
2974*58b9f456SAndroid Build Coastguard Workeroperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2975*58b9f456SAndroid Build Coastguard Worker{
2976*58b9f456SAndroid Build Coastguard Worker    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2977*58b9f456SAndroid Build Coastguard Worker    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2978*58b9f456SAndroid Build Coastguard Worker    typedef typename common_type<_P1, _P2>::type _Vp;
2979*58b9f456SAndroid Build Coastguard Worker    return less<_Vp>()(__x.get(), __y.get());
2980*58b9f456SAndroid Build Coastguard Worker}
2981*58b9f456SAndroid Build Coastguard Worker
2982*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2983*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2984*58b9f456SAndroid Build Coastguard Workerbool
2985*58b9f456SAndroid Build Coastguard Workeroperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2986*58b9f456SAndroid Build Coastguard Worker
2987*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2988*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2989*58b9f456SAndroid Build Coastguard Workerbool
2990*58b9f456SAndroid Build Coastguard Workeroperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2991*58b9f456SAndroid Build Coastguard Worker
2992*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1, class _T2, class _D2>
2993*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2994*58b9f456SAndroid Build Coastguard Workerbool
2995*58b9f456SAndroid Build Coastguard Workeroperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2996*58b9f456SAndroid Build Coastguard Worker
2997*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
2998*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
2999*58b9f456SAndroid Build Coastguard Workerbool
3000*58b9f456SAndroid Build Coastguard Workeroperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3001*58b9f456SAndroid Build Coastguard Worker{
3002*58b9f456SAndroid Build Coastguard Worker    return !__x;
3003*58b9f456SAndroid Build Coastguard Worker}
3004*58b9f456SAndroid Build Coastguard Worker
3005*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3006*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3007*58b9f456SAndroid Build Coastguard Workerbool
3008*58b9f456SAndroid Build Coastguard Workeroperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3009*58b9f456SAndroid Build Coastguard Worker{
3010*58b9f456SAndroid Build Coastguard Worker    return !__x;
3011*58b9f456SAndroid Build Coastguard Worker}
3012*58b9f456SAndroid Build Coastguard Worker
3013*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3014*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3015*58b9f456SAndroid Build Coastguard Workerbool
3016*58b9f456SAndroid Build Coastguard Workeroperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3017*58b9f456SAndroid Build Coastguard Worker{
3018*58b9f456SAndroid Build Coastguard Worker    return static_cast<bool>(__x);
3019*58b9f456SAndroid Build Coastguard Worker}
3020*58b9f456SAndroid Build Coastguard Worker
3021*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3022*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3023*58b9f456SAndroid Build Coastguard Workerbool
3024*58b9f456SAndroid Build Coastguard Workeroperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3025*58b9f456SAndroid Build Coastguard Worker{
3026*58b9f456SAndroid Build Coastguard Worker    return static_cast<bool>(__x);
3027*58b9f456SAndroid Build Coastguard Worker}
3028*58b9f456SAndroid Build Coastguard Worker
3029*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3030*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3031*58b9f456SAndroid Build Coastguard Workerbool
3032*58b9f456SAndroid Build Coastguard Workeroperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3033*58b9f456SAndroid Build Coastguard Worker{
3034*58b9f456SAndroid Build Coastguard Worker    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3035*58b9f456SAndroid Build Coastguard Worker    return less<_P1>()(__x.get(), nullptr);
3036*58b9f456SAndroid Build Coastguard Worker}
3037*58b9f456SAndroid Build Coastguard Worker
3038*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3039*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3040*58b9f456SAndroid Build Coastguard Workerbool
3041*58b9f456SAndroid Build Coastguard Workeroperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3042*58b9f456SAndroid Build Coastguard Worker{
3043*58b9f456SAndroid Build Coastguard Worker    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3044*58b9f456SAndroid Build Coastguard Worker    return less<_P1>()(nullptr, __x.get());
3045*58b9f456SAndroid Build Coastguard Worker}
3046*58b9f456SAndroid Build Coastguard Worker
3047*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3048*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3049*58b9f456SAndroid Build Coastguard Workerbool
3050*58b9f456SAndroid Build Coastguard Workeroperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3051*58b9f456SAndroid Build Coastguard Worker{
3052*58b9f456SAndroid Build Coastguard Worker    return nullptr < __x;
3053*58b9f456SAndroid Build Coastguard Worker}
3054*58b9f456SAndroid Build Coastguard Worker
3055*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3056*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3057*58b9f456SAndroid Build Coastguard Workerbool
3058*58b9f456SAndroid Build Coastguard Workeroperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3059*58b9f456SAndroid Build Coastguard Worker{
3060*58b9f456SAndroid Build Coastguard Worker    return __x < nullptr;
3061*58b9f456SAndroid Build Coastguard Worker}
3062*58b9f456SAndroid Build Coastguard Worker
3063*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3064*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3065*58b9f456SAndroid Build Coastguard Workerbool
3066*58b9f456SAndroid Build Coastguard Workeroperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3067*58b9f456SAndroid Build Coastguard Worker{
3068*58b9f456SAndroid Build Coastguard Worker    return !(nullptr < __x);
3069*58b9f456SAndroid Build Coastguard Worker}
3070*58b9f456SAndroid Build Coastguard Worker
3071*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3072*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3073*58b9f456SAndroid Build Coastguard Workerbool
3074*58b9f456SAndroid Build Coastguard Workeroperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3075*58b9f456SAndroid Build Coastguard Worker{
3076*58b9f456SAndroid Build Coastguard Worker    return !(__x < nullptr);
3077*58b9f456SAndroid Build Coastguard Worker}
3078*58b9f456SAndroid Build Coastguard Worker
3079*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3080*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3081*58b9f456SAndroid Build Coastguard Workerbool
3082*58b9f456SAndroid Build Coastguard Workeroperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3083*58b9f456SAndroid Build Coastguard Worker{
3084*58b9f456SAndroid Build Coastguard Worker    return !(__x < nullptr);
3085*58b9f456SAndroid Build Coastguard Worker}
3086*58b9f456SAndroid Build Coastguard Worker
3087*58b9f456SAndroid Build Coastguard Workertemplate <class _T1, class _D1>
3088*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3089*58b9f456SAndroid Build Coastguard Workerbool
3090*58b9f456SAndroid Build Coastguard Workeroperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3091*58b9f456SAndroid Build Coastguard Worker{
3092*58b9f456SAndroid Build Coastguard Worker    return !(nullptr < __x);
3093*58b9f456SAndroid Build Coastguard Worker}
3094*58b9f456SAndroid Build Coastguard Worker
3095*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3096*58b9f456SAndroid Build Coastguard Worker
3097*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
3098*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3099*58b9f456SAndroid Build Coastguard Workerunique_ptr<_Tp, _Dp>
3100*58b9f456SAndroid Build Coastguard Workermove(unique_ptr<_Tp, _Dp>& __t)
3101*58b9f456SAndroid Build Coastguard Worker{
3102*58b9f456SAndroid Build Coastguard Worker    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3103*58b9f456SAndroid Build Coastguard Worker}
3104*58b9f456SAndroid Build Coastguard Worker
3105*58b9f456SAndroid Build Coastguard Worker#endif
3106*58b9f456SAndroid Build Coastguard Worker
3107*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 11
3108*58b9f456SAndroid Build Coastguard Worker
3109*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
3110*58b9f456SAndroid Build Coastguard Workerstruct __unique_if
3111*58b9f456SAndroid Build Coastguard Worker{
3112*58b9f456SAndroid Build Coastguard Worker    typedef unique_ptr<_Tp> __unique_single;
3113*58b9f456SAndroid Build Coastguard Worker};
3114*58b9f456SAndroid Build Coastguard Worker
3115*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
3116*58b9f456SAndroid Build Coastguard Workerstruct __unique_if<_Tp[]>
3117*58b9f456SAndroid Build Coastguard Worker{
3118*58b9f456SAndroid Build Coastguard Worker    typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3119*58b9f456SAndroid Build Coastguard Worker};
3120*58b9f456SAndroid Build Coastguard Worker
3121*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, size_t _Np>
3122*58b9f456SAndroid Build Coastguard Workerstruct __unique_if<_Tp[_Np]>
3123*58b9f456SAndroid Build Coastguard Worker{
3124*58b9f456SAndroid Build Coastguard Worker    typedef void __unique_array_known_bound;
3125*58b9f456SAndroid Build Coastguard Worker};
3126*58b9f456SAndroid Build Coastguard Worker
3127*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class... _Args>
3128*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3129*58b9f456SAndroid Build Coastguard Workertypename __unique_if<_Tp>::__unique_single
3130*58b9f456SAndroid Build Coastguard Workermake_unique(_Args&&... __args)
3131*58b9f456SAndroid Build Coastguard Worker{
3132*58b9f456SAndroid Build Coastguard Worker    return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3133*58b9f456SAndroid Build Coastguard Worker}
3134*58b9f456SAndroid Build Coastguard Worker
3135*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
3136*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3137*58b9f456SAndroid Build Coastguard Workertypename __unique_if<_Tp>::__unique_array_unknown_bound
3138*58b9f456SAndroid Build Coastguard Workermake_unique(size_t __n)
3139*58b9f456SAndroid Build Coastguard Worker{
3140*58b9f456SAndroid Build Coastguard Worker    typedef typename remove_extent<_Tp>::type _Up;
3141*58b9f456SAndroid Build Coastguard Worker    return unique_ptr<_Tp>(new _Up[__n]());
3142*58b9f456SAndroid Build Coastguard Worker}
3143*58b9f456SAndroid Build Coastguard Worker
3144*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class... _Args>
3145*58b9f456SAndroid Build Coastguard Worker    typename __unique_if<_Tp>::__unique_array_known_bound
3146*58b9f456SAndroid Build Coastguard Worker    make_unique(_Args&&...) = delete;
3147*58b9f456SAndroid Build Coastguard Worker
3148*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_STD_VER > 11
3149*58b9f456SAndroid Build Coastguard Worker
3150*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp>
3151*58b9f456SAndroid Build Coastguard Worker#ifdef _LIBCPP_CXX03_LANG
3152*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3153*58b9f456SAndroid Build Coastguard Worker#else
3154*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3155*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3156*58b9f456SAndroid Build Coastguard Worker#endif
3157*58b9f456SAndroid Build Coastguard Worker{
3158*58b9f456SAndroid Build Coastguard Worker    typedef unique_ptr<_Tp, _Dp> argument_type;
3159*58b9f456SAndroid Build Coastguard Worker    typedef size_t               result_type;
3160*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3161*58b9f456SAndroid Build Coastguard Worker    result_type operator()(const argument_type& __ptr) const
3162*58b9f456SAndroid Build Coastguard Worker    {
3163*58b9f456SAndroid Build Coastguard Worker        typedef typename argument_type::pointer pointer;
3164*58b9f456SAndroid Build Coastguard Worker        return hash<pointer>()(__ptr.get());
3165*58b9f456SAndroid Build Coastguard Worker    }
3166*58b9f456SAndroid Build Coastguard Worker};
3167*58b9f456SAndroid Build Coastguard Worker
3168*58b9f456SAndroid Build Coastguard Workerstruct __destruct_n
3169*58b9f456SAndroid Build Coastguard Worker{
3170*58b9f456SAndroid Build Coastguard Workerprivate:
3171*58b9f456SAndroid Build Coastguard Worker    size_t __size_;
3172*58b9f456SAndroid Build Coastguard Worker
3173*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
3174*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3175*58b9f456SAndroid Build Coastguard Worker        {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3176*58b9f456SAndroid Build Coastguard Worker
3177*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
3178*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3179*58b9f456SAndroid Build Coastguard Worker        {}
3180*58b9f456SAndroid Build Coastguard Worker
3181*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3182*58b9f456SAndroid Build Coastguard Worker        {++__size_;}
3183*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3184*58b9f456SAndroid Build Coastguard Worker        {}
3185*58b9f456SAndroid Build Coastguard Worker
3186*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3187*58b9f456SAndroid Build Coastguard Worker        {__size_ = __s;}
3188*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3189*58b9f456SAndroid Build Coastguard Worker        {}
3190*58b9f456SAndroid Build Coastguard Workerpublic:
3191*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3192*58b9f456SAndroid Build Coastguard Worker        : __size_(__s) {}
3193*58b9f456SAndroid Build Coastguard Worker
3194*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
3195*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3196*58b9f456SAndroid Build Coastguard Worker        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3197*58b9f456SAndroid Build Coastguard Worker
3198*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
3199*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3200*58b9f456SAndroid Build Coastguard Worker        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3201*58b9f456SAndroid Build Coastguard Worker
3202*58b9f456SAndroid Build Coastguard Worker    template <class _Tp>
3203*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3204*58b9f456SAndroid Build Coastguard Worker        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3205*58b9f456SAndroid Build Coastguard Worker};
3206*58b9f456SAndroid Build Coastguard Worker
3207*58b9f456SAndroid Build Coastguard Workertemplate <class _Alloc>
3208*58b9f456SAndroid Build Coastguard Workerclass __allocator_destructor
3209*58b9f456SAndroid Build Coastguard Worker{
3210*58b9f456SAndroid Build Coastguard Worker    typedef allocator_traits<_Alloc> __alloc_traits;
3211*58b9f456SAndroid Build Coastguard Workerpublic:
3212*58b9f456SAndroid Build Coastguard Worker    typedef typename __alloc_traits::pointer pointer;
3213*58b9f456SAndroid Build Coastguard Worker    typedef typename __alloc_traits::size_type size_type;
3214*58b9f456SAndroid Build Coastguard Workerprivate:
3215*58b9f456SAndroid Build Coastguard Worker    _Alloc& __alloc_;
3216*58b9f456SAndroid Build Coastguard Worker    size_type __s_;
3217*58b9f456SAndroid Build Coastguard Workerpublic:
3218*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3219*58b9f456SAndroid Build Coastguard Worker             _NOEXCEPT
3220*58b9f456SAndroid Build Coastguard Worker        : __alloc_(__a), __s_(__s) {}
3221*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3222*58b9f456SAndroid Build Coastguard Worker    void operator()(pointer __p) _NOEXCEPT
3223*58b9f456SAndroid Build Coastguard Worker        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3224*58b9f456SAndroid Build Coastguard Worker};
3225*58b9f456SAndroid Build Coastguard Worker
3226*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIterator, class _ForwardIterator>
3227*58b9f456SAndroid Build Coastguard Worker_ForwardIterator
3228*58b9f456SAndroid Build Coastguard Workeruninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3229*58b9f456SAndroid Build Coastguard Worker{
3230*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3231*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3232*58b9f456SAndroid Build Coastguard Worker    _ForwardIterator __s = __r;
3233*58b9f456SAndroid Build Coastguard Worker    try
3234*58b9f456SAndroid Build Coastguard Worker    {
3235*58b9f456SAndroid Build Coastguard Worker#endif
3236*58b9f456SAndroid Build Coastguard Worker        for (; __f != __l; ++__f, (void) ++__r)
3237*58b9f456SAndroid Build Coastguard Worker            ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3238*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3239*58b9f456SAndroid Build Coastguard Worker    }
3240*58b9f456SAndroid Build Coastguard Worker    catch (...)
3241*58b9f456SAndroid Build Coastguard Worker    {
3242*58b9f456SAndroid Build Coastguard Worker        for (; __s != __r; ++__s)
3243*58b9f456SAndroid Build Coastguard Worker            __s->~value_type();
3244*58b9f456SAndroid Build Coastguard Worker        throw;
3245*58b9f456SAndroid Build Coastguard Worker    }
3246*58b9f456SAndroid Build Coastguard Worker#endif
3247*58b9f456SAndroid Build Coastguard Worker    return __r;
3248*58b9f456SAndroid Build Coastguard Worker}
3249*58b9f456SAndroid Build Coastguard Worker
3250*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIterator, class _Size, class _ForwardIterator>
3251*58b9f456SAndroid Build Coastguard Worker_ForwardIterator
3252*58b9f456SAndroid Build Coastguard Workeruninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3253*58b9f456SAndroid Build Coastguard Worker{
3254*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3255*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3256*58b9f456SAndroid Build Coastguard Worker    _ForwardIterator __s = __r;
3257*58b9f456SAndroid Build Coastguard Worker    try
3258*58b9f456SAndroid Build Coastguard Worker    {
3259*58b9f456SAndroid Build Coastguard Worker#endif
3260*58b9f456SAndroid Build Coastguard Worker        for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3261*58b9f456SAndroid Build Coastguard Worker            ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3262*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3263*58b9f456SAndroid Build Coastguard Worker    }
3264*58b9f456SAndroid Build Coastguard Worker    catch (...)
3265*58b9f456SAndroid Build Coastguard Worker    {
3266*58b9f456SAndroid Build Coastguard Worker        for (; __s != __r; ++__s)
3267*58b9f456SAndroid Build Coastguard Worker            __s->~value_type();
3268*58b9f456SAndroid Build Coastguard Worker        throw;
3269*58b9f456SAndroid Build Coastguard Worker    }
3270*58b9f456SAndroid Build Coastguard Worker#endif
3271*58b9f456SAndroid Build Coastguard Worker    return __r;
3272*58b9f456SAndroid Build Coastguard Worker}
3273*58b9f456SAndroid Build Coastguard Worker
3274*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator, class _Tp>
3275*58b9f456SAndroid Build Coastguard Workervoid
3276*58b9f456SAndroid Build Coastguard Workeruninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3277*58b9f456SAndroid Build Coastguard Worker{
3278*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3279*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3280*58b9f456SAndroid Build Coastguard Worker    _ForwardIterator __s = __f;
3281*58b9f456SAndroid Build Coastguard Worker    try
3282*58b9f456SAndroid Build Coastguard Worker    {
3283*58b9f456SAndroid Build Coastguard Worker#endif
3284*58b9f456SAndroid Build Coastguard Worker        for (; __f != __l; ++__f)
3285*58b9f456SAndroid Build Coastguard Worker            ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3286*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3287*58b9f456SAndroid Build Coastguard Worker    }
3288*58b9f456SAndroid Build Coastguard Worker    catch (...)
3289*58b9f456SAndroid Build Coastguard Worker    {
3290*58b9f456SAndroid Build Coastguard Worker        for (; __s != __f; ++__s)
3291*58b9f456SAndroid Build Coastguard Worker            __s->~value_type();
3292*58b9f456SAndroid Build Coastguard Worker        throw;
3293*58b9f456SAndroid Build Coastguard Worker    }
3294*58b9f456SAndroid Build Coastguard Worker#endif
3295*58b9f456SAndroid Build Coastguard Worker}
3296*58b9f456SAndroid Build Coastguard Worker
3297*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator, class _Size, class _Tp>
3298*58b9f456SAndroid Build Coastguard Worker_ForwardIterator
3299*58b9f456SAndroid Build Coastguard Workeruninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3300*58b9f456SAndroid Build Coastguard Worker{
3301*58b9f456SAndroid Build Coastguard Worker    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3302*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3303*58b9f456SAndroid Build Coastguard Worker    _ForwardIterator __s = __f;
3304*58b9f456SAndroid Build Coastguard Worker    try
3305*58b9f456SAndroid Build Coastguard Worker    {
3306*58b9f456SAndroid Build Coastguard Worker#endif
3307*58b9f456SAndroid Build Coastguard Worker        for (; __n > 0; ++__f, (void) --__n)
3308*58b9f456SAndroid Build Coastguard Worker            ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3309*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3310*58b9f456SAndroid Build Coastguard Worker    }
3311*58b9f456SAndroid Build Coastguard Worker    catch (...)
3312*58b9f456SAndroid Build Coastguard Worker    {
3313*58b9f456SAndroid Build Coastguard Worker        for (; __s != __f; ++__s)
3314*58b9f456SAndroid Build Coastguard Worker            __s->~value_type();
3315*58b9f456SAndroid Build Coastguard Worker        throw;
3316*58b9f456SAndroid Build Coastguard Worker    }
3317*58b9f456SAndroid Build Coastguard Worker#endif
3318*58b9f456SAndroid Build Coastguard Worker    return __f;
3319*58b9f456SAndroid Build Coastguard Worker}
3320*58b9f456SAndroid Build Coastguard Worker
3321*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
3322*58b9f456SAndroid Build Coastguard Worker
3323*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
3324*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3325*58b9f456SAndroid Build Coastguard Workervoid destroy_at(_Tp* __loc) {
3326*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3327*58b9f456SAndroid Build Coastguard Worker    __loc->~_Tp();
3328*58b9f456SAndroid Build Coastguard Worker}
3329*58b9f456SAndroid Build Coastguard Worker
3330*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator>
3331*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3332*58b9f456SAndroid Build Coastguard Workervoid destroy(_ForwardIterator __first, _ForwardIterator __last) {
3333*58b9f456SAndroid Build Coastguard Worker    for (; __first != __last; ++__first)
3334*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy_at(_VSTD::addressof(*__first));
3335*58b9f456SAndroid Build Coastguard Worker}
3336*58b9f456SAndroid Build Coastguard Worker
3337*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator, class _Size>
3338*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3339*58b9f456SAndroid Build Coastguard Worker_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3340*58b9f456SAndroid Build Coastguard Worker    for (; __n > 0; (void)++__first, --__n)
3341*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy_at(_VSTD::addressof(*__first));
3342*58b9f456SAndroid Build Coastguard Worker    return __first;
3343*58b9f456SAndroid Build Coastguard Worker}
3344*58b9f456SAndroid Build Coastguard Worker
3345*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator>
3346*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3347*58b9f456SAndroid Build Coastguard Workervoid uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3348*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3349*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first;
3350*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3351*58b9f456SAndroid Build Coastguard Worker    try {
3352*58b9f456SAndroid Build Coastguard Worker#endif
3353*58b9f456SAndroid Build Coastguard Worker    for (; __idx != __last; ++__idx)
3354*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3355*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3356*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3357*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first, __idx);
3358*58b9f456SAndroid Build Coastguard Worker        throw;
3359*58b9f456SAndroid Build Coastguard Worker    }
3360*58b9f456SAndroid Build Coastguard Worker#endif
3361*58b9f456SAndroid Build Coastguard Worker}
3362*58b9f456SAndroid Build Coastguard Worker
3363*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator, class _Size>
3364*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3365*58b9f456SAndroid Build Coastguard Worker_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3366*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3367*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first;
3368*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3369*58b9f456SAndroid Build Coastguard Worker    try {
3370*58b9f456SAndroid Build Coastguard Worker#endif
3371*58b9f456SAndroid Build Coastguard Worker    for (; __n > 0; (void)++__idx, --__n)
3372*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3373*58b9f456SAndroid Build Coastguard Worker    return __idx;
3374*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3375*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3376*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first, __idx);
3377*58b9f456SAndroid Build Coastguard Worker        throw;
3378*58b9f456SAndroid Build Coastguard Worker    }
3379*58b9f456SAndroid Build Coastguard Worker#endif
3380*58b9f456SAndroid Build Coastguard Worker}
3381*58b9f456SAndroid Build Coastguard Worker
3382*58b9f456SAndroid Build Coastguard Worker
3383*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator>
3384*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3385*58b9f456SAndroid Build Coastguard Workervoid uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3386*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3387*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first;
3388*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3389*58b9f456SAndroid Build Coastguard Worker    try {
3390*58b9f456SAndroid Build Coastguard Worker#endif
3391*58b9f456SAndroid Build Coastguard Worker    for (; __idx != __last; ++__idx)
3392*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3393*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3394*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3395*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first, __idx);
3396*58b9f456SAndroid Build Coastguard Worker        throw;
3397*58b9f456SAndroid Build Coastguard Worker    }
3398*58b9f456SAndroid Build Coastguard Worker#endif
3399*58b9f456SAndroid Build Coastguard Worker}
3400*58b9f456SAndroid Build Coastguard Worker
3401*58b9f456SAndroid Build Coastguard Workertemplate <class _ForwardIterator, class _Size>
3402*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3403*58b9f456SAndroid Build Coastguard Worker_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3404*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3405*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first;
3406*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3407*58b9f456SAndroid Build Coastguard Worker    try {
3408*58b9f456SAndroid Build Coastguard Worker#endif
3409*58b9f456SAndroid Build Coastguard Worker    for (; __n > 0; (void)++__idx, --__n)
3410*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3411*58b9f456SAndroid Build Coastguard Worker    return __idx;
3412*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3413*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3414*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first, __idx);
3415*58b9f456SAndroid Build Coastguard Worker        throw;
3416*58b9f456SAndroid Build Coastguard Worker    }
3417*58b9f456SAndroid Build Coastguard Worker#endif
3418*58b9f456SAndroid Build Coastguard Worker}
3419*58b9f456SAndroid Build Coastguard Worker
3420*58b9f456SAndroid Build Coastguard Worker
3421*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIt, class _ForwardIt>
3422*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3423*58b9f456SAndroid Build Coastguard Worker_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3424*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3425*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first_res;
3426*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3427*58b9f456SAndroid Build Coastguard Worker    try {
3428*58b9f456SAndroid Build Coastguard Worker#endif
3429*58b9f456SAndroid Build Coastguard Worker    for (; __first != __last; (void)++__idx, ++__first)
3430*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3431*58b9f456SAndroid Build Coastguard Worker    return __idx;
3432*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3433*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3434*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first_res, __idx);
3435*58b9f456SAndroid Build Coastguard Worker        throw;
3436*58b9f456SAndroid Build Coastguard Worker    }
3437*58b9f456SAndroid Build Coastguard Worker#endif
3438*58b9f456SAndroid Build Coastguard Worker}
3439*58b9f456SAndroid Build Coastguard Worker
3440*58b9f456SAndroid Build Coastguard Workertemplate <class _InputIt, class _Size, class _ForwardIt>
3441*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
3442*58b9f456SAndroid Build Coastguard Workerpair<_InputIt, _ForwardIt>
3443*58b9f456SAndroid Build Coastguard Workeruninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3444*58b9f456SAndroid Build Coastguard Worker    using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3445*58b9f456SAndroid Build Coastguard Worker    auto __idx = __first_res;
3446*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3447*58b9f456SAndroid Build Coastguard Worker    try {
3448*58b9f456SAndroid Build Coastguard Worker#endif
3449*58b9f456SAndroid Build Coastguard Worker    for (; __n > 0; ++__idx, (void)++__first, --__n)
3450*58b9f456SAndroid Build Coastguard Worker        ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3451*58b9f456SAndroid Build Coastguard Worker    return {__first, __idx};
3452*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3453*58b9f456SAndroid Build Coastguard Worker    } catch (...) {
3454*58b9f456SAndroid Build Coastguard Worker        _VSTD::destroy(__first_res, __idx);
3455*58b9f456SAndroid Build Coastguard Worker        throw;
3456*58b9f456SAndroid Build Coastguard Worker    }
3457*58b9f456SAndroid Build Coastguard Worker#endif
3458*58b9f456SAndroid Build Coastguard Worker}
3459*58b9f456SAndroid Build Coastguard Worker
3460*58b9f456SAndroid Build Coastguard Worker
3461*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_STD_VER > 14
3462*58b9f456SAndroid Build Coastguard Worker
3463*58b9f456SAndroid Build Coastguard Worker// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3464*58b9f456SAndroid Build Coastguard Worker// should be sufficient for thread safety.
3465*58b9f456SAndroid Build Coastguard Worker// See https://bugs.llvm.org/show_bug.cgi?id=22803
3466*58b9f456SAndroid Build Coastguard Worker#if defined(__clang__) && __has_builtin(__atomic_add_fetch)          \
3467*58b9f456SAndroid Build Coastguard Worker                       && defined(__ATOMIC_RELAXED)                  \
3468*58b9f456SAndroid Build Coastguard Worker                       && defined(__ATOMIC_ACQ_REL)
3469*58b9f456SAndroid Build Coastguard Worker#   define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3470*58b9f456SAndroid Build Coastguard Worker#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3471*58b9f456SAndroid Build Coastguard Worker#   define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3472*58b9f456SAndroid Build Coastguard Worker#endif
3473*58b9f456SAndroid Build Coastguard Worker
3474*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
3475*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY _Tp
3476*58b9f456SAndroid Build Coastguard Worker__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3477*58b9f456SAndroid Build Coastguard Worker{
3478*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3479*58b9f456SAndroid Build Coastguard Worker    return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3480*58b9f456SAndroid Build Coastguard Worker#else
3481*58b9f456SAndroid Build Coastguard Worker    return __t += 1;
3482*58b9f456SAndroid Build Coastguard Worker#endif
3483*58b9f456SAndroid Build Coastguard Worker}
3484*58b9f456SAndroid Build Coastguard Worker
3485*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
3486*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY _Tp
3487*58b9f456SAndroid Build Coastguard Worker__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3488*58b9f456SAndroid Build Coastguard Worker{
3489*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3490*58b9f456SAndroid Build Coastguard Worker    return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3491*58b9f456SAndroid Build Coastguard Worker#else
3492*58b9f456SAndroid Build Coastguard Worker    return __t -= 1;
3493*58b9f456SAndroid Build Coastguard Worker#endif
3494*58b9f456SAndroid Build Coastguard Worker}
3495*58b9f456SAndroid Build Coastguard Worker
3496*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3497*58b9f456SAndroid Build Coastguard Worker    : public std::exception
3498*58b9f456SAndroid Build Coastguard Worker{
3499*58b9f456SAndroid Build Coastguard Workerpublic:
3500*58b9f456SAndroid Build Coastguard Worker    virtual ~bad_weak_ptr() _NOEXCEPT;
3501*58b9f456SAndroid Build Coastguard Worker    virtual const char* what() const  _NOEXCEPT;
3502*58b9f456SAndroid Build Coastguard Worker};
3503*58b9f456SAndroid Build Coastguard Worker
3504*58b9f456SAndroid Build Coastguard Worker_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
3505*58b9f456SAndroid Build Coastguard Workervoid __throw_bad_weak_ptr()
3506*58b9f456SAndroid Build Coastguard Worker{
3507*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
3508*58b9f456SAndroid Build Coastguard Worker    throw bad_weak_ptr();
3509*58b9f456SAndroid Build Coastguard Worker#else
3510*58b9f456SAndroid Build Coastguard Worker    _VSTD::abort();
3511*58b9f456SAndroid Build Coastguard Worker#endif
3512*58b9f456SAndroid Build Coastguard Worker}
3513*58b9f456SAndroid Build Coastguard Worker
3514*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3515*58b9f456SAndroid Build Coastguard Worker
3516*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS __shared_count
3517*58b9f456SAndroid Build Coastguard Worker{
3518*58b9f456SAndroid Build Coastguard Worker    __shared_count(const __shared_count&);
3519*58b9f456SAndroid Build Coastguard Worker    __shared_count& operator=(const __shared_count&);
3520*58b9f456SAndroid Build Coastguard Worker
3521*58b9f456SAndroid Build Coastguard Workerprotected:
3522*58b9f456SAndroid Build Coastguard Worker    long __shared_owners_;
3523*58b9f456SAndroid Build Coastguard Worker    virtual ~__shared_count();
3524*58b9f456SAndroid Build Coastguard Workerprivate:
3525*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared() _NOEXCEPT = 0;
3526*58b9f456SAndroid Build Coastguard Worker
3527*58b9f456SAndroid Build Coastguard Workerpublic:
3528*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3529*58b9f456SAndroid Build Coastguard Worker    explicit __shared_count(long __refs = 0) _NOEXCEPT
3530*58b9f456SAndroid Build Coastguard Worker        : __shared_owners_(__refs) {}
3531*58b9f456SAndroid Build Coastguard Worker
3532*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_BUILDING_LIBRARY) && \
3533*58b9f456SAndroid Build Coastguard Worker    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3534*58b9f456SAndroid Build Coastguard Worker    void __add_shared() _NOEXCEPT;
3535*58b9f456SAndroid Build Coastguard Worker    bool __release_shared() _NOEXCEPT;
3536*58b9f456SAndroid Build Coastguard Worker#else
3537*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3538*58b9f456SAndroid Build Coastguard Worker    void __add_shared() _NOEXCEPT {
3539*58b9f456SAndroid Build Coastguard Worker      __libcpp_atomic_refcount_increment(__shared_owners_);
3540*58b9f456SAndroid Build Coastguard Worker    }
3541*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3542*58b9f456SAndroid Build Coastguard Worker    bool __release_shared() _NOEXCEPT {
3543*58b9f456SAndroid Build Coastguard Worker      if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3544*58b9f456SAndroid Build Coastguard Worker        __on_zero_shared();
3545*58b9f456SAndroid Build Coastguard Worker        return true;
3546*58b9f456SAndroid Build Coastguard Worker      }
3547*58b9f456SAndroid Build Coastguard Worker      return false;
3548*58b9f456SAndroid Build Coastguard Worker    }
3549*58b9f456SAndroid Build Coastguard Worker#endif
3550*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3551*58b9f456SAndroid Build Coastguard Worker    long use_count() const _NOEXCEPT {
3552*58b9f456SAndroid Build Coastguard Worker        return __libcpp_relaxed_load(&__shared_owners_) + 1;
3553*58b9f456SAndroid Build Coastguard Worker    }
3554*58b9f456SAndroid Build Coastguard Worker};
3555*58b9f456SAndroid Build Coastguard Worker
3556*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS __shared_weak_count
3557*58b9f456SAndroid Build Coastguard Worker    : private __shared_count
3558*58b9f456SAndroid Build Coastguard Worker{
3559*58b9f456SAndroid Build Coastguard Worker    long __shared_weak_owners_;
3560*58b9f456SAndroid Build Coastguard Worker
3561*58b9f456SAndroid Build Coastguard Workerpublic:
3562*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3563*58b9f456SAndroid Build Coastguard Worker    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3564*58b9f456SAndroid Build Coastguard Worker        : __shared_count(__refs),
3565*58b9f456SAndroid Build Coastguard Worker          __shared_weak_owners_(__refs) {}
3566*58b9f456SAndroid Build Coastguard Workerprotected:
3567*58b9f456SAndroid Build Coastguard Worker    virtual ~__shared_weak_count();
3568*58b9f456SAndroid Build Coastguard Worker
3569*58b9f456SAndroid Build Coastguard Workerpublic:
3570*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_BUILDING_LIBRARY) && \
3571*58b9f456SAndroid Build Coastguard Worker    defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3572*58b9f456SAndroid Build Coastguard Worker    void __add_shared() _NOEXCEPT;
3573*58b9f456SAndroid Build Coastguard Worker    void __add_weak() _NOEXCEPT;
3574*58b9f456SAndroid Build Coastguard Worker    void __release_shared() _NOEXCEPT;
3575*58b9f456SAndroid Build Coastguard Worker#else
3576*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3577*58b9f456SAndroid Build Coastguard Worker    void __add_shared() _NOEXCEPT {
3578*58b9f456SAndroid Build Coastguard Worker      __shared_count::__add_shared();
3579*58b9f456SAndroid Build Coastguard Worker    }
3580*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3581*58b9f456SAndroid Build Coastguard Worker    void __add_weak() _NOEXCEPT {
3582*58b9f456SAndroid Build Coastguard Worker      __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3583*58b9f456SAndroid Build Coastguard Worker    }
3584*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3585*58b9f456SAndroid Build Coastguard Worker    void __release_shared() _NOEXCEPT {
3586*58b9f456SAndroid Build Coastguard Worker      if (__shared_count::__release_shared())
3587*58b9f456SAndroid Build Coastguard Worker        __release_weak();
3588*58b9f456SAndroid Build Coastguard Worker    }
3589*58b9f456SAndroid Build Coastguard Worker#endif
3590*58b9f456SAndroid Build Coastguard Worker    void __release_weak() _NOEXCEPT;
3591*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3592*58b9f456SAndroid Build Coastguard Worker    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3593*58b9f456SAndroid Build Coastguard Worker    __shared_weak_count* lock() _NOEXCEPT;
3594*58b9f456SAndroid Build Coastguard Worker
3595*58b9f456SAndroid Build Coastguard Worker    // Define the function out only if we build static libc++ without RTTI.
3596*58b9f456SAndroid Build Coastguard Worker    // Otherwise we may break clients who need to compile their projects with
3597*58b9f456SAndroid Build Coastguard Worker    // -fno-rtti and yet link against a libc++.dylib compiled
3598*58b9f456SAndroid Build Coastguard Worker    // without -fno-rtti.
3599*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3600*58b9f456SAndroid Build Coastguard Worker    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3601*58b9f456SAndroid Build Coastguard Worker#endif
3602*58b9f456SAndroid Build Coastguard Workerprivate:
3603*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3604*58b9f456SAndroid Build Coastguard Worker};
3605*58b9f456SAndroid Build Coastguard Worker
3606*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp, class _Alloc>
3607*58b9f456SAndroid Build Coastguard Workerclass __shared_ptr_pointer
3608*58b9f456SAndroid Build Coastguard Worker    : public __shared_weak_count
3609*58b9f456SAndroid Build Coastguard Worker{
3610*58b9f456SAndroid Build Coastguard Worker    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3611*58b9f456SAndroid Build Coastguard Workerpublic:
3612*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3613*58b9f456SAndroid Build Coastguard Worker    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3614*58b9f456SAndroid Build Coastguard Worker        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3615*58b9f456SAndroid Build Coastguard Worker
3616*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_RTTI
3617*58b9f456SAndroid Build Coastguard Worker    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3618*58b9f456SAndroid Build Coastguard Worker#endif
3619*58b9f456SAndroid Build Coastguard Worker
3620*58b9f456SAndroid Build Coastguard Workerprivate:
3621*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared() _NOEXCEPT;
3622*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared_weak() _NOEXCEPT;
3623*58b9f456SAndroid Build Coastguard Worker};
3624*58b9f456SAndroid Build Coastguard Worker
3625*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_RTTI
3626*58b9f456SAndroid Build Coastguard Worker
3627*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp, class _Alloc>
3628*58b9f456SAndroid Build Coastguard Workerconst void*
3629*58b9f456SAndroid Build Coastguard Worker__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3630*58b9f456SAndroid Build Coastguard Worker{
3631*58b9f456SAndroid Build Coastguard Worker    return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3632*58b9f456SAndroid Build Coastguard Worker}
3633*58b9f456SAndroid Build Coastguard Worker
3634*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_RTTI
3635*58b9f456SAndroid Build Coastguard Worker
3636*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp, class _Alloc>
3637*58b9f456SAndroid Build Coastguard Workervoid
3638*58b9f456SAndroid Build Coastguard Worker__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3639*58b9f456SAndroid Build Coastguard Worker{
3640*58b9f456SAndroid Build Coastguard Worker    __data_.first().second()(__data_.first().first());
3641*58b9f456SAndroid Build Coastguard Worker    __data_.first().second().~_Dp();
3642*58b9f456SAndroid Build Coastguard Worker}
3643*58b9f456SAndroid Build Coastguard Worker
3644*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Dp, class _Alloc>
3645*58b9f456SAndroid Build Coastguard Workervoid
3646*58b9f456SAndroid Build Coastguard Worker__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3647*58b9f456SAndroid Build Coastguard Worker{
3648*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3649*58b9f456SAndroid Build Coastguard Worker    typedef allocator_traits<_Al> _ATraits;
3650*58b9f456SAndroid Build Coastguard Worker    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3651*58b9f456SAndroid Build Coastguard Worker
3652*58b9f456SAndroid Build Coastguard Worker    _Al __a(__data_.second());
3653*58b9f456SAndroid Build Coastguard Worker    __data_.second().~_Alloc();
3654*58b9f456SAndroid Build Coastguard Worker    __a.deallocate(_PTraits::pointer_to(*this), 1);
3655*58b9f456SAndroid Build Coastguard Worker}
3656*58b9f456SAndroid Build Coastguard Worker
3657*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Alloc>
3658*58b9f456SAndroid Build Coastguard Workerclass __shared_ptr_emplace
3659*58b9f456SAndroid Build Coastguard Worker    : public __shared_weak_count
3660*58b9f456SAndroid Build Coastguard Worker{
3661*58b9f456SAndroid Build Coastguard Worker    __compressed_pair<_Alloc, _Tp> __data_;
3662*58b9f456SAndroid Build Coastguard Workerpublic:
3663*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
3664*58b9f456SAndroid Build Coastguard Worker
3665*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3666*58b9f456SAndroid Build Coastguard Worker    __shared_ptr_emplace(_Alloc __a)
3667*58b9f456SAndroid Build Coastguard Worker        :  __data_(_VSTD::move(__a)) {}
3668*58b9f456SAndroid Build Coastguard Worker
3669*58b9f456SAndroid Build Coastguard Worker    template <class ..._Args>
3670*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3671*58b9f456SAndroid Build Coastguard Worker        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3672*58b9f456SAndroid Build Coastguard Worker            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3673*58b9f456SAndroid Build Coastguard Worker                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3674*58b9f456SAndroid Build Coastguard Worker
3675*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
3676*58b9f456SAndroid Build Coastguard Worker
3677*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3678*58b9f456SAndroid Build Coastguard Worker    __shared_ptr_emplace(_Alloc __a)
3679*58b9f456SAndroid Build Coastguard Worker        :  __data_(__a) {}
3680*58b9f456SAndroid Build Coastguard Worker
3681*58b9f456SAndroid Build Coastguard Worker    template <class _A0>
3682*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3683*58b9f456SAndroid Build Coastguard Worker        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3684*58b9f456SAndroid Build Coastguard Worker            :  __data_(__a, _Tp(__a0)) {}
3685*58b9f456SAndroid Build Coastguard Worker
3686*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1>
3687*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3688*58b9f456SAndroid Build Coastguard Worker        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3689*58b9f456SAndroid Build Coastguard Worker            :  __data_(__a, _Tp(__a0, __a1)) {}
3690*58b9f456SAndroid Build Coastguard Worker
3691*58b9f456SAndroid Build Coastguard Worker    template <class _A0, class _A1, class _A2>
3692*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3693*58b9f456SAndroid Build Coastguard Worker        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3694*58b9f456SAndroid Build Coastguard Worker            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3695*58b9f456SAndroid Build Coastguard Worker
3696*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
3697*58b9f456SAndroid Build Coastguard Worker
3698*58b9f456SAndroid Build Coastguard Workerprivate:
3699*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared() _NOEXCEPT;
3700*58b9f456SAndroid Build Coastguard Worker    virtual void __on_zero_shared_weak() _NOEXCEPT;
3701*58b9f456SAndroid Build Coastguard Workerpublic:
3702*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3703*58b9f456SAndroid Build Coastguard Worker    _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
3704*58b9f456SAndroid Build Coastguard Worker};
3705*58b9f456SAndroid Build Coastguard Worker
3706*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Alloc>
3707*58b9f456SAndroid Build Coastguard Workervoid
3708*58b9f456SAndroid Build Coastguard Worker__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3709*58b9f456SAndroid Build Coastguard Worker{
3710*58b9f456SAndroid Build Coastguard Worker    __data_.second().~_Tp();
3711*58b9f456SAndroid Build Coastguard Worker}
3712*58b9f456SAndroid Build Coastguard Worker
3713*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Alloc>
3714*58b9f456SAndroid Build Coastguard Workervoid
3715*58b9f456SAndroid Build Coastguard Worker__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3716*58b9f456SAndroid Build Coastguard Worker{
3717*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3718*58b9f456SAndroid Build Coastguard Worker    typedef allocator_traits<_Al> _ATraits;
3719*58b9f456SAndroid Build Coastguard Worker    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3720*58b9f456SAndroid Build Coastguard Worker    _Al __a(__data_.first());
3721*58b9f456SAndroid Build Coastguard Worker    __data_.first().~_Alloc();
3722*58b9f456SAndroid Build Coastguard Worker    __a.deallocate(_PTraits::pointer_to(*this), 1);
3723*58b9f456SAndroid Build Coastguard Worker}
3724*58b9f456SAndroid Build Coastguard Worker
3725*58b9f456SAndroid Build Coastguard Workerstruct __shared_ptr_dummy_rebind_allocator_type;
3726*58b9f456SAndroid Build Coastguard Workertemplate <>
3727*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3728*58b9f456SAndroid Build Coastguard Worker{
3729*58b9f456SAndroid Build Coastguard Workerpublic:
3730*58b9f456SAndroid Build Coastguard Worker    template <class _Other>
3731*58b9f456SAndroid Build Coastguard Worker    struct rebind
3732*58b9f456SAndroid Build Coastguard Worker    {
3733*58b9f456SAndroid Build Coastguard Worker        typedef allocator<_Other> other;
3734*58b9f456SAndroid Build Coastguard Worker    };
3735*58b9f456SAndroid Build Coastguard Worker};
3736*58b9f456SAndroid Build Coastguard Worker
3737*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3738*58b9f456SAndroid Build Coastguard Worker
3739*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
3740*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS shared_ptr
3741*58b9f456SAndroid Build Coastguard Worker{
3742*58b9f456SAndroid Build Coastguard Workerpublic:
3743*58b9f456SAndroid Build Coastguard Worker    typedef _Tp element_type;
3744*58b9f456SAndroid Build Coastguard Worker
3745*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
3746*58b9f456SAndroid Build Coastguard Worker    typedef weak_ptr<_Tp> weak_type;
3747*58b9f456SAndroid Build Coastguard Worker#endif
3748*58b9f456SAndroid Build Coastguard Workerprivate:
3749*58b9f456SAndroid Build Coastguard Worker    element_type*      __ptr_;
3750*58b9f456SAndroid Build Coastguard Worker    __shared_weak_count* __cntrl_;
3751*58b9f456SAndroid Build Coastguard Worker
3752*58b9f456SAndroid Build Coastguard Worker    struct __nat {int __for_bool_;};
3753*58b9f456SAndroid Build Coastguard Workerpublic:
3754*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3755*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3756*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3757*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3758*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3759*58b9f456SAndroid Build Coastguard Worker        explicit shared_ptr(_Yp* __p,
3760*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3761*58b9f456SAndroid Build Coastguard Worker    template<class _Yp, class _Dp>
3762*58b9f456SAndroid Build Coastguard Worker        shared_ptr(_Yp* __p, _Dp __d,
3763*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3764*58b9f456SAndroid Build Coastguard Worker    template<class _Yp, class _Dp, class _Alloc>
3765*58b9f456SAndroid Build Coastguard Worker        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3766*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3767*58b9f456SAndroid Build Coastguard Worker    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3768*58b9f456SAndroid Build Coastguard Worker    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3769*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3770*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3771*58b9f456SAndroid Build Coastguard Worker    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3772*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3773*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3774*58b9f456SAndroid Build Coastguard Worker        shared_ptr(const shared_ptr<_Yp>& __r,
3775*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3776*58b9f456SAndroid Build Coastguard Worker                       _NOEXCEPT;
3777*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3778*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3779*58b9f456SAndroid Build Coastguard Worker    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3780*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> _LIBCPP_INLINE_VISIBILITY  shared_ptr(shared_ptr<_Yp>&& __r,
3781*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3782*58b9f456SAndroid Build Coastguard Worker                       _NOEXCEPT;
3783*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3784*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3785*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3786*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3787*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3788*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3789*58b9f456SAndroid Build Coastguard Worker        shared_ptr(auto_ptr<_Yp>&& __r,
3790*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3791*58b9f456SAndroid Build Coastguard Worker#else
3792*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3793*58b9f456SAndroid Build Coastguard Worker        shared_ptr(auto_ptr<_Yp> __r,
3794*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3795*58b9f456SAndroid Build Coastguard Worker#endif
3796*58b9f456SAndroid Build Coastguard Worker#endif
3797*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3798*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _Dp>
3799*58b9f456SAndroid Build Coastguard Worker        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3800*58b9f456SAndroid Build Coastguard Worker                   typename enable_if
3801*58b9f456SAndroid Build Coastguard Worker                   <
3802*58b9f456SAndroid Build Coastguard Worker                       !is_lvalue_reference<_Dp>::value &&
3803*58b9f456SAndroid Build Coastguard Worker                       !is_array<_Yp>::value &&
3804*58b9f456SAndroid Build Coastguard Worker                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3805*58b9f456SAndroid Build Coastguard Worker                       __nat
3806*58b9f456SAndroid Build Coastguard Worker                   >::type = __nat());
3807*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _Dp>
3808*58b9f456SAndroid Build Coastguard Worker        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3809*58b9f456SAndroid Build Coastguard Worker                   typename enable_if
3810*58b9f456SAndroid Build Coastguard Worker                   <
3811*58b9f456SAndroid Build Coastguard Worker                       is_lvalue_reference<_Dp>::value &&
3812*58b9f456SAndroid Build Coastguard Worker                       !is_array<_Yp>::value &&
3813*58b9f456SAndroid Build Coastguard Worker                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3814*58b9f456SAndroid Build Coastguard Worker                       __nat
3815*58b9f456SAndroid Build Coastguard Worker                   >::type = __nat());
3816*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3817*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _Dp>
3818*58b9f456SAndroid Build Coastguard Worker        shared_ptr(unique_ptr<_Yp, _Dp>,
3819*58b9f456SAndroid Build Coastguard Worker                   typename enable_if
3820*58b9f456SAndroid Build Coastguard Worker                   <
3821*58b9f456SAndroid Build Coastguard Worker                       !is_lvalue_reference<_Dp>::value &&
3822*58b9f456SAndroid Build Coastguard Worker                       !is_array<_Yp>::value &&
3823*58b9f456SAndroid Build Coastguard Worker                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3824*58b9f456SAndroid Build Coastguard Worker                       __nat
3825*58b9f456SAndroid Build Coastguard Worker                   >::type = __nat());
3826*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _Dp>
3827*58b9f456SAndroid Build Coastguard Worker        shared_ptr(unique_ptr<_Yp, _Dp>,
3828*58b9f456SAndroid Build Coastguard Worker                   typename enable_if
3829*58b9f456SAndroid Build Coastguard Worker                   <
3830*58b9f456SAndroid Build Coastguard Worker                       is_lvalue_reference<_Dp>::value &&
3831*58b9f456SAndroid Build Coastguard Worker                       !is_array<_Yp>::value &&
3832*58b9f456SAndroid Build Coastguard Worker                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3833*58b9f456SAndroid Build Coastguard Worker                       __nat
3834*58b9f456SAndroid Build Coastguard Worker                   >::type = __nat());
3835*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3836*58b9f456SAndroid Build Coastguard Worker
3837*58b9f456SAndroid Build Coastguard Worker    ~shared_ptr();
3838*58b9f456SAndroid Build Coastguard Worker
3839*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3840*58b9f456SAndroid Build Coastguard Worker    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3841*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3842*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3843*58b9f456SAndroid Build Coastguard Worker        <
3844*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3845*58b9f456SAndroid Build Coastguard Worker            shared_ptr&
3846*58b9f456SAndroid Build Coastguard Worker        >::type
3847*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3848*58b9f456SAndroid Build Coastguard Worker        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3849*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3850*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3851*58b9f456SAndroid Build Coastguard Worker    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3852*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3853*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3854*58b9f456SAndroid Build Coastguard Worker        <
3855*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3856*58b9f456SAndroid Build Coastguard Worker            shared_ptr<_Tp>&
3857*58b9f456SAndroid Build Coastguard Worker        >::type
3858*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3859*58b9f456SAndroid Build Coastguard Worker        operator=(shared_ptr<_Yp>&& __r);
3860*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3861*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3862*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3863*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3864*58b9f456SAndroid Build Coastguard Worker        <
3865*58b9f456SAndroid Build Coastguard Worker            !is_array<_Yp>::value &&
3866*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3867*58b9f456SAndroid Build Coastguard Worker            shared_ptr
3868*58b9f456SAndroid Build Coastguard Worker        >::type&
3869*58b9f456SAndroid Build Coastguard Worker        operator=(auto_ptr<_Yp>&& __r);
3870*58b9f456SAndroid Build Coastguard Worker#endif
3871*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3872*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3873*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3874*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3875*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3876*58b9f456SAndroid Build Coastguard Worker        <
3877*58b9f456SAndroid Build Coastguard Worker            !is_array<_Yp>::value &&
3878*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3879*58b9f456SAndroid Build Coastguard Worker            shared_ptr&
3880*58b9f456SAndroid Build Coastguard Worker        >::type
3881*58b9f456SAndroid Build Coastguard Worker        operator=(auto_ptr<_Yp> __r);
3882*58b9f456SAndroid Build Coastguard Worker#endif
3883*58b9f456SAndroid Build Coastguard Worker#endif
3884*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _Dp>
3885*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3886*58b9f456SAndroid Build Coastguard Worker        <
3887*58b9f456SAndroid Build Coastguard Worker            !is_array<_Yp>::value &&
3888*58b9f456SAndroid Build Coastguard Worker            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3889*58b9f456SAndroid Build Coastguard Worker            shared_ptr&
3890*58b9f456SAndroid Build Coastguard Worker        >::type
3891*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3892*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3893*58b9f456SAndroid Build Coastguard Worker        operator=(unique_ptr<_Yp, _Dp>&& __r);
3894*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3895*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3896*58b9f456SAndroid Build Coastguard Worker        operator=(unique_ptr<_Yp, _Dp> __r);
3897*58b9f456SAndroid Build Coastguard Worker#endif
3898*58b9f456SAndroid Build Coastguard Worker
3899*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3900*58b9f456SAndroid Build Coastguard Worker    void swap(shared_ptr& __r) _NOEXCEPT;
3901*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3902*58b9f456SAndroid Build Coastguard Worker    void reset() _NOEXCEPT;
3903*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
3904*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3905*58b9f456SAndroid Build Coastguard Worker        <
3906*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3907*58b9f456SAndroid Build Coastguard Worker            void
3908*58b9f456SAndroid Build Coastguard Worker        >::type
3909*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3910*58b9f456SAndroid Build Coastguard Worker        reset(_Yp* __p);
3911*58b9f456SAndroid Build Coastguard Worker    template<class _Yp, class _Dp>
3912*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3913*58b9f456SAndroid Build Coastguard Worker        <
3914*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3915*58b9f456SAndroid Build Coastguard Worker            void
3916*58b9f456SAndroid Build Coastguard Worker        >::type
3917*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3918*58b9f456SAndroid Build Coastguard Worker        reset(_Yp* __p, _Dp __d);
3919*58b9f456SAndroid Build Coastguard Worker    template<class _Yp, class _Dp, class _Alloc>
3920*58b9f456SAndroid Build Coastguard Worker        typename enable_if
3921*58b9f456SAndroid Build Coastguard Worker        <
3922*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
3923*58b9f456SAndroid Build Coastguard Worker            void
3924*58b9f456SAndroid Build Coastguard Worker        >::type
3925*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3926*58b9f456SAndroid Build Coastguard Worker        reset(_Yp* __p, _Dp __d, _Alloc __a);
3927*58b9f456SAndroid Build Coastguard Worker
3928*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3929*58b9f456SAndroid Build Coastguard Worker    element_type* get() const _NOEXCEPT {return __ptr_;}
3930*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3931*58b9f456SAndroid Build Coastguard Worker    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3932*58b9f456SAndroid Build Coastguard Worker        {return *__ptr_;}
3933*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3934*58b9f456SAndroid Build Coastguard Worker    element_type* operator->() const _NOEXCEPT {return __ptr_;}
3935*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3936*58b9f456SAndroid Build Coastguard Worker    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3937*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3938*58b9f456SAndroid Build Coastguard Worker    bool unique() const _NOEXCEPT {return use_count() == 1;}
3939*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3940*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3941*58b9f456SAndroid Build Coastguard Worker    template <class _Up>
3942*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3943*58b9f456SAndroid Build Coastguard Worker        bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3944*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ < __p.__cntrl_;}
3945*58b9f456SAndroid Build Coastguard Worker    template <class _Up>
3946*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3947*58b9f456SAndroid Build Coastguard Worker        bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3948*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ < __p.__cntrl_;}
3949*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
3950*58b9f456SAndroid Build Coastguard Worker    bool
3951*58b9f456SAndroid Build Coastguard Worker    __owner_equivalent(const shared_ptr& __p) const
3952*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ == __p.__cntrl_;}
3953*58b9f456SAndroid Build Coastguard Worker
3954*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_RTTI
3955*58b9f456SAndroid Build Coastguard Worker    template <class _Dp>
3956*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
3957*58b9f456SAndroid Build Coastguard Worker        _Dp* __get_deleter() const _NOEXCEPT
3958*58b9f456SAndroid Build Coastguard Worker            {return static_cast<_Dp*>(__cntrl_
3959*58b9f456SAndroid Build Coastguard Worker                    ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3960*58b9f456SAndroid Build Coastguard Worker                      : nullptr);}
3961*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_RTTI
3962*58b9f456SAndroid Build Coastguard Worker
3963*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
3964*58b9f456SAndroid Build Coastguard Worker
3965*58b9f456SAndroid Build Coastguard Worker    template<class ..._Args>
3966*58b9f456SAndroid Build Coastguard Worker        static
3967*58b9f456SAndroid Build Coastguard Worker        shared_ptr<_Tp>
3968*58b9f456SAndroid Build Coastguard Worker        make_shared(_Args&& ...__args);
3969*58b9f456SAndroid Build Coastguard Worker
3970*58b9f456SAndroid Build Coastguard Worker    template<class _Alloc, class ..._Args>
3971*58b9f456SAndroid Build Coastguard Worker        static
3972*58b9f456SAndroid Build Coastguard Worker        shared_ptr<_Tp>
3973*58b9f456SAndroid Build Coastguard Worker        allocate_shared(const _Alloc& __a, _Args&& ...__args);
3974*58b9f456SAndroid Build Coastguard Worker
3975*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
3976*58b9f456SAndroid Build Coastguard Worker
3977*58b9f456SAndroid Build Coastguard Worker    static shared_ptr<_Tp> make_shared();
3978*58b9f456SAndroid Build Coastguard Worker
3979*58b9f456SAndroid Build Coastguard Worker    template<class _A0>
3980*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp> make_shared(_A0&);
3981*58b9f456SAndroid Build Coastguard Worker
3982*58b9f456SAndroid Build Coastguard Worker    template<class _A0, class _A1>
3983*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3984*58b9f456SAndroid Build Coastguard Worker
3985*58b9f456SAndroid Build Coastguard Worker    template<class _A0, class _A1, class _A2>
3986*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3987*58b9f456SAndroid Build Coastguard Worker
3988*58b9f456SAndroid Build Coastguard Worker    template<class _Alloc>
3989*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp>
3990*58b9f456SAndroid Build Coastguard Worker        allocate_shared(const _Alloc& __a);
3991*58b9f456SAndroid Build Coastguard Worker
3992*58b9f456SAndroid Build Coastguard Worker    template<class _Alloc, class _A0>
3993*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp>
3994*58b9f456SAndroid Build Coastguard Worker        allocate_shared(const _Alloc& __a, _A0& __a0);
3995*58b9f456SAndroid Build Coastguard Worker
3996*58b9f456SAndroid Build Coastguard Worker    template<class _Alloc, class _A0, class _A1>
3997*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp>
3998*58b9f456SAndroid Build Coastguard Worker        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3999*58b9f456SAndroid Build Coastguard Worker
4000*58b9f456SAndroid Build Coastguard Worker    template<class _Alloc, class _A0, class _A1, class _A2>
4001*58b9f456SAndroid Build Coastguard Worker        static shared_ptr<_Tp>
4002*58b9f456SAndroid Build Coastguard Worker        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4003*58b9f456SAndroid Build Coastguard Worker
4004*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
4005*58b9f456SAndroid Build Coastguard Worker
4006*58b9f456SAndroid Build Coastguard Workerprivate:
4007*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, bool = is_function<_Yp>::value>
4008*58b9f456SAndroid Build Coastguard Worker        struct __shared_ptr_default_allocator
4009*58b9f456SAndroid Build Coastguard Worker        {
4010*58b9f456SAndroid Build Coastguard Worker            typedef allocator<_Yp> type;
4011*58b9f456SAndroid Build Coastguard Worker        };
4012*58b9f456SAndroid Build Coastguard Worker
4013*58b9f456SAndroid Build Coastguard Worker    template <class _Yp>
4014*58b9f456SAndroid Build Coastguard Worker        struct __shared_ptr_default_allocator<_Yp, true>
4015*58b9f456SAndroid Build Coastguard Worker        {
4016*58b9f456SAndroid Build Coastguard Worker            typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
4017*58b9f456SAndroid Build Coastguard Worker        };
4018*58b9f456SAndroid Build Coastguard Worker
4019*58b9f456SAndroid Build Coastguard Worker    template <class _Yp, class _OrigPtr>
4020*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
4021*58b9f456SAndroid Build Coastguard Worker        typename enable_if<is_convertible<_OrigPtr*,
4022*58b9f456SAndroid Build Coastguard Worker                                          const enable_shared_from_this<_Yp>*
4023*58b9f456SAndroid Build Coastguard Worker        >::value,
4024*58b9f456SAndroid Build Coastguard Worker            void>::type
4025*58b9f456SAndroid Build Coastguard Worker        __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4026*58b9f456SAndroid Build Coastguard Worker                           _OrigPtr* __ptr) _NOEXCEPT
4027*58b9f456SAndroid Build Coastguard Worker        {
4028*58b9f456SAndroid Build Coastguard Worker            typedef typename remove_cv<_Yp>::type _RawYp;
4029*58b9f456SAndroid Build Coastguard Worker            if (__e && __e->__weak_this_.expired())
4030*58b9f456SAndroid Build Coastguard Worker            {
4031*58b9f456SAndroid Build Coastguard Worker                __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4032*58b9f456SAndroid Build Coastguard Worker                    const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
4033*58b9f456SAndroid Build Coastguard Worker            }
4034*58b9f456SAndroid Build Coastguard Worker        }
4035*58b9f456SAndroid Build Coastguard Worker
4036*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
4037*58b9f456SAndroid Build Coastguard Worker
4038*58b9f456SAndroid Build Coastguard Worker    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4039*58b9f456SAndroid Build Coastguard Worker    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4040*58b9f456SAndroid Build Coastguard Worker};
4041*58b9f456SAndroid Build Coastguard Worker
4042*58b9f456SAndroid Build Coastguard Worker
4043*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4044*58b9f456SAndroid Build Coastguard Workerinline
4045*58b9f456SAndroid Build Coastguard Worker_LIBCPP_CONSTEXPR
4046*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4047*58b9f456SAndroid Build Coastguard Worker    : __ptr_(0),
4048*58b9f456SAndroid Build Coastguard Worker      __cntrl_(0)
4049*58b9f456SAndroid Build Coastguard Worker{
4050*58b9f456SAndroid Build Coastguard Worker}
4051*58b9f456SAndroid Build Coastguard Worker
4052*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4053*58b9f456SAndroid Build Coastguard Workerinline
4054*58b9f456SAndroid Build Coastguard Worker_LIBCPP_CONSTEXPR
4055*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4056*58b9f456SAndroid Build Coastguard Worker    : __ptr_(0),
4057*58b9f456SAndroid Build Coastguard Worker      __cntrl_(0)
4058*58b9f456SAndroid Build Coastguard Worker{
4059*58b9f456SAndroid Build Coastguard Worker}
4060*58b9f456SAndroid Build Coastguard Worker
4061*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4062*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4063*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(_Yp* __p,
4064*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4065*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__p)
4066*58b9f456SAndroid Build Coastguard Worker{
4067*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_Yp> __hold(__p);
4068*58b9f456SAndroid Build Coastguard Worker    typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4069*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
4070*58b9f456SAndroid Build Coastguard Worker    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
4071*58b9f456SAndroid Build Coastguard Worker    __hold.release();
4072*58b9f456SAndroid Build Coastguard Worker    __enable_weak_this(__p, __p);
4073*58b9f456SAndroid Build Coastguard Worker}
4074*58b9f456SAndroid Build Coastguard Worker
4075*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4076*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp, class _Dp>
4077*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4078*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4079*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__p)
4080*58b9f456SAndroid Build Coastguard Worker{
4081*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4082*58b9f456SAndroid Build Coastguard Worker    try
4083*58b9f456SAndroid Build Coastguard Worker    {
4084*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4085*58b9f456SAndroid Build Coastguard Worker        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4086*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4087*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4088*58b9f456SAndroid Build Coastguard Worker        __enable_weak_this(__p, __p);
4089*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4090*58b9f456SAndroid Build Coastguard Worker    }
4091*58b9f456SAndroid Build Coastguard Worker    catch (...)
4092*58b9f456SAndroid Build Coastguard Worker    {
4093*58b9f456SAndroid Build Coastguard Worker        __d(__p);
4094*58b9f456SAndroid Build Coastguard Worker        throw;
4095*58b9f456SAndroid Build Coastguard Worker    }
4096*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4097*58b9f456SAndroid Build Coastguard Worker}
4098*58b9f456SAndroid Build Coastguard Worker
4099*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4100*58b9f456SAndroid Build Coastguard Workertemplate<class _Dp>
4101*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4102*58b9f456SAndroid Build Coastguard Worker    : __ptr_(0)
4103*58b9f456SAndroid Build Coastguard Worker{
4104*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4105*58b9f456SAndroid Build Coastguard Worker    try
4106*58b9f456SAndroid Build Coastguard Worker    {
4107*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4108*58b9f456SAndroid Build Coastguard Worker        typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4109*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4110*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4111*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4112*58b9f456SAndroid Build Coastguard Worker    }
4113*58b9f456SAndroid Build Coastguard Worker    catch (...)
4114*58b9f456SAndroid Build Coastguard Worker    {
4115*58b9f456SAndroid Build Coastguard Worker        __d(__p);
4116*58b9f456SAndroid Build Coastguard Worker        throw;
4117*58b9f456SAndroid Build Coastguard Worker    }
4118*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4119*58b9f456SAndroid Build Coastguard Worker}
4120*58b9f456SAndroid Build Coastguard Worker
4121*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4122*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp, class _Dp, class _Alloc>
4123*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4124*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4125*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__p)
4126*58b9f456SAndroid Build Coastguard Worker{
4127*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4128*58b9f456SAndroid Build Coastguard Worker    try
4129*58b9f456SAndroid Build Coastguard Worker    {
4130*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4131*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4132*58b9f456SAndroid Build Coastguard Worker        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4133*58b9f456SAndroid Build Coastguard Worker        typedef __allocator_destructor<_A2> _D2;
4134*58b9f456SAndroid Build Coastguard Worker        _A2 __a2(__a);
4135*58b9f456SAndroid Build Coastguard Worker        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4136*58b9f456SAndroid Build Coastguard Worker        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4137*58b9f456SAndroid Build Coastguard Worker            _CntrlBlk(__p, __d, __a);
4138*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = _VSTD::addressof(*__hold2.release());
4139*58b9f456SAndroid Build Coastguard Worker        __enable_weak_this(__p, __p);
4140*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4141*58b9f456SAndroid Build Coastguard Worker    }
4142*58b9f456SAndroid Build Coastguard Worker    catch (...)
4143*58b9f456SAndroid Build Coastguard Worker    {
4144*58b9f456SAndroid Build Coastguard Worker        __d(__p);
4145*58b9f456SAndroid Build Coastguard Worker        throw;
4146*58b9f456SAndroid Build Coastguard Worker    }
4147*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4148*58b9f456SAndroid Build Coastguard Worker}
4149*58b9f456SAndroid Build Coastguard Worker
4150*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4151*58b9f456SAndroid Build Coastguard Workertemplate<class _Dp, class _Alloc>
4152*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4153*58b9f456SAndroid Build Coastguard Worker    : __ptr_(0)
4154*58b9f456SAndroid Build Coastguard Worker{
4155*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4156*58b9f456SAndroid Build Coastguard Worker    try
4157*58b9f456SAndroid Build Coastguard Worker    {
4158*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4159*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4160*58b9f456SAndroid Build Coastguard Worker        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4161*58b9f456SAndroid Build Coastguard Worker        typedef __allocator_destructor<_A2> _D2;
4162*58b9f456SAndroid Build Coastguard Worker        _A2 __a2(__a);
4163*58b9f456SAndroid Build Coastguard Worker        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4164*58b9f456SAndroid Build Coastguard Worker        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4165*58b9f456SAndroid Build Coastguard Worker            _CntrlBlk(__p, __d, __a);
4166*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = _VSTD::addressof(*__hold2.release());
4167*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_EXCEPTIONS
4168*58b9f456SAndroid Build Coastguard Worker    }
4169*58b9f456SAndroid Build Coastguard Worker    catch (...)
4170*58b9f456SAndroid Build Coastguard Worker    {
4171*58b9f456SAndroid Build Coastguard Worker        __d(__p);
4172*58b9f456SAndroid Build Coastguard Worker        throw;
4173*58b9f456SAndroid Build Coastguard Worker    }
4174*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_EXCEPTIONS
4175*58b9f456SAndroid Build Coastguard Worker}
4176*58b9f456SAndroid Build Coastguard Worker
4177*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4178*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4179*58b9f456SAndroid Build Coastguard Workerinline
4180*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4181*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__p),
4182*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
4183*58b9f456SAndroid Build Coastguard Worker{
4184*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
4185*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_shared();
4186*58b9f456SAndroid Build Coastguard Worker}
4187*58b9f456SAndroid Build Coastguard Worker
4188*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4189*58b9f456SAndroid Build Coastguard Workerinline
4190*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4191*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
4192*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
4193*58b9f456SAndroid Build Coastguard Worker{
4194*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
4195*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_shared();
4196*58b9f456SAndroid Build Coastguard Worker}
4197*58b9f456SAndroid Build Coastguard Worker
4198*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4199*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4200*58b9f456SAndroid Build Coastguard Workerinline
4201*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4202*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4203*58b9f456SAndroid Build Coastguard Worker         _NOEXCEPT
4204*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
4205*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
4206*58b9f456SAndroid Build Coastguard Worker{
4207*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
4208*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_shared();
4209*58b9f456SAndroid Build Coastguard Worker}
4210*58b9f456SAndroid Build Coastguard Worker
4211*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4212*58b9f456SAndroid Build Coastguard Worker
4213*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4214*58b9f456SAndroid Build Coastguard Workerinline
4215*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4216*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
4217*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
4218*58b9f456SAndroid Build Coastguard Worker{
4219*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = 0;
4220*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = 0;
4221*58b9f456SAndroid Build Coastguard Worker}
4222*58b9f456SAndroid Build Coastguard Worker
4223*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4224*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4225*58b9f456SAndroid Build Coastguard Workerinline
4226*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4227*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4228*58b9f456SAndroid Build Coastguard Worker         _NOEXCEPT
4229*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
4230*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
4231*58b9f456SAndroid Build Coastguard Worker{
4232*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = 0;
4233*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = 0;
4234*58b9f456SAndroid Build Coastguard Worker}
4235*58b9f456SAndroid Build Coastguard Worker
4236*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4237*58b9f456SAndroid Build Coastguard Worker
4238*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4239*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4240*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4241*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4242*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4243*58b9f456SAndroid Build Coastguard Worker#else
4244*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4245*58b9f456SAndroid Build Coastguard Worker#endif
4246*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4247*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.get())
4248*58b9f456SAndroid Build Coastguard Worker{
4249*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4250*58b9f456SAndroid Build Coastguard Worker    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4251*58b9f456SAndroid Build Coastguard Worker    __enable_weak_this(__r.get(), __r.get());
4252*58b9f456SAndroid Build Coastguard Worker    __r.release();
4253*58b9f456SAndroid Build Coastguard Worker}
4254*58b9f456SAndroid Build Coastguard Worker#endif
4255*58b9f456SAndroid Build Coastguard Worker
4256*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4257*58b9f456SAndroid Build Coastguard Workertemplate <class _Yp, class _Dp>
4258*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4259*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4260*58b9f456SAndroid Build Coastguard Worker#else
4261*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4262*58b9f456SAndroid Build Coastguard Worker#endif
4263*58b9f456SAndroid Build Coastguard Worker                            typename enable_if
4264*58b9f456SAndroid Build Coastguard Worker                            <
4265*58b9f456SAndroid Build Coastguard Worker                                !is_lvalue_reference<_Dp>::value &&
4266*58b9f456SAndroid Build Coastguard Worker                                !is_array<_Yp>::value &&
4267*58b9f456SAndroid Build Coastguard Worker                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4268*58b9f456SAndroid Build Coastguard Worker                                __nat
4269*58b9f456SAndroid Build Coastguard Worker                            >::type)
4270*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.get())
4271*58b9f456SAndroid Build Coastguard Worker{
4272*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 11
4273*58b9f456SAndroid Build Coastguard Worker    if (__ptr_ == nullptr)
4274*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = nullptr;
4275*58b9f456SAndroid Build Coastguard Worker    else
4276*58b9f456SAndroid Build Coastguard Worker#endif
4277*58b9f456SAndroid Build Coastguard Worker    {
4278*58b9f456SAndroid Build Coastguard Worker        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4279*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4280*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4281*58b9f456SAndroid Build Coastguard Worker        __enable_weak_this(__r.get(), __r.get());
4282*58b9f456SAndroid Build Coastguard Worker    }
4283*58b9f456SAndroid Build Coastguard Worker    __r.release();
4284*58b9f456SAndroid Build Coastguard Worker}
4285*58b9f456SAndroid Build Coastguard Worker
4286*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4287*58b9f456SAndroid Build Coastguard Workertemplate <class _Yp, class _Dp>
4288*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4289*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4290*58b9f456SAndroid Build Coastguard Worker#else
4291*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4292*58b9f456SAndroid Build Coastguard Worker#endif
4293*58b9f456SAndroid Build Coastguard Worker                            typename enable_if
4294*58b9f456SAndroid Build Coastguard Worker                            <
4295*58b9f456SAndroid Build Coastguard Worker                                is_lvalue_reference<_Dp>::value &&
4296*58b9f456SAndroid Build Coastguard Worker                                !is_array<_Yp>::value &&
4297*58b9f456SAndroid Build Coastguard Worker                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4298*58b9f456SAndroid Build Coastguard Worker                                __nat
4299*58b9f456SAndroid Build Coastguard Worker                            >::type)
4300*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.get())
4301*58b9f456SAndroid Build Coastguard Worker{
4302*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 11
4303*58b9f456SAndroid Build Coastguard Worker    if (__ptr_ == nullptr)
4304*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = nullptr;
4305*58b9f456SAndroid Build Coastguard Worker    else
4306*58b9f456SAndroid Build Coastguard Worker#endif
4307*58b9f456SAndroid Build Coastguard Worker    {
4308*58b9f456SAndroid Build Coastguard Worker        typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4309*58b9f456SAndroid Build Coastguard Worker        typedef __shared_ptr_pointer<_Yp*,
4310*58b9f456SAndroid Build Coastguard Worker                                     reference_wrapper<typename remove_reference<_Dp>::type>,
4311*58b9f456SAndroid Build Coastguard Worker                                     _AllocT > _CntrlBlk;
4312*58b9f456SAndroid Build Coastguard Worker        __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4313*58b9f456SAndroid Build Coastguard Worker        __enable_weak_this(__r.get(), __r.get());
4314*58b9f456SAndroid Build Coastguard Worker    }
4315*58b9f456SAndroid Build Coastguard Worker    __r.release();
4316*58b9f456SAndroid Build Coastguard Worker}
4317*58b9f456SAndroid Build Coastguard Worker
4318*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
4319*58b9f456SAndroid Build Coastguard Worker
4320*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4321*58b9f456SAndroid Build Coastguard Workertemplate<class ..._Args>
4322*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4323*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::make_shared(_Args&& ...__args)
4324*58b9f456SAndroid Build Coastguard Worker{
4325*58b9f456SAndroid Build Coastguard Worker    static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
4326*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4327*58b9f456SAndroid Build Coastguard Worker    typedef allocator<_CntrlBlk> _A2;
4328*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_A2> _D2;
4329*58b9f456SAndroid Build Coastguard Worker    _A2 __a2;
4330*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4331*58b9f456SAndroid Build Coastguard Worker    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4332*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4333*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4334*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __hold2.release();
4335*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4336*58b9f456SAndroid Build Coastguard Worker    return __r;
4337*58b9f456SAndroid Build Coastguard Worker}
4338*58b9f456SAndroid Build Coastguard Worker
4339*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4340*58b9f456SAndroid Build Coastguard Workertemplate<class _Alloc, class ..._Args>
4341*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4342*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4343*58b9f456SAndroid Build Coastguard Worker{
4344*58b9f456SAndroid Build Coastguard Worker    static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4345*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4346*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4347*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_A2> _D2;
4348*58b9f456SAndroid Build Coastguard Worker    _A2 __a2(__a);
4349*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4350*58b9f456SAndroid Build Coastguard Worker    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4351*58b9f456SAndroid Build Coastguard Worker        _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4352*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4353*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4354*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4355*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4356*58b9f456SAndroid Build Coastguard Worker    return __r;
4357*58b9f456SAndroid Build Coastguard Worker}
4358*58b9f456SAndroid Build Coastguard Worker
4359*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
4360*58b9f456SAndroid Build Coastguard Worker
4361*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4362*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4363*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::make_shared()
4364*58b9f456SAndroid Build Coastguard Worker{
4365*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
4366*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4367*58b9f456SAndroid Build Coastguard Worker    typedef allocator<_CntrlBlk> _Alloc2;
4368*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4369*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2;
4370*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4371*58b9f456SAndroid Build Coastguard Worker    ::new(__hold2.get()) _CntrlBlk(__alloc2);
4372*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4373*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4374*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __hold2.release();
4375*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4376*58b9f456SAndroid Build Coastguard Worker    return __r;
4377*58b9f456SAndroid Build Coastguard Worker}
4378*58b9f456SAndroid Build Coastguard Worker
4379*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4380*58b9f456SAndroid Build Coastguard Workertemplate<class _A0>
4381*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4382*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::make_shared(_A0& __a0)
4383*58b9f456SAndroid Build Coastguard Worker{
4384*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
4385*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4386*58b9f456SAndroid Build Coastguard Worker    typedef allocator<_CntrlBlk> _Alloc2;
4387*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4388*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2;
4389*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4390*58b9f456SAndroid Build Coastguard Worker    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4391*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4392*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4393*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __hold2.release();
4394*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4395*58b9f456SAndroid Build Coastguard Worker    return __r;
4396*58b9f456SAndroid Build Coastguard Worker}
4397*58b9f456SAndroid Build Coastguard Worker
4398*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4399*58b9f456SAndroid Build Coastguard Workertemplate<class _A0, class _A1>
4400*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4401*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4402*58b9f456SAndroid Build Coastguard Worker{
4403*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
4404*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4405*58b9f456SAndroid Build Coastguard Worker    typedef allocator<_CntrlBlk> _Alloc2;
4406*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4407*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2;
4408*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4409*58b9f456SAndroid Build Coastguard Worker    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4410*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4411*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4412*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __hold2.release();
4413*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4414*58b9f456SAndroid Build Coastguard Worker    return __r;
4415*58b9f456SAndroid Build Coastguard Worker}
4416*58b9f456SAndroid Build Coastguard Worker
4417*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4418*58b9f456SAndroid Build Coastguard Workertemplate<class _A0, class _A1, class _A2>
4419*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4420*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4421*58b9f456SAndroid Build Coastguard Worker{
4422*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
4423*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4424*58b9f456SAndroid Build Coastguard Worker    typedef allocator<_CntrlBlk> _Alloc2;
4425*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4426*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2;
4427*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4428*58b9f456SAndroid Build Coastguard Worker    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4429*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4430*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4431*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __hold2.release();
4432*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4433*58b9f456SAndroid Build Coastguard Worker    return __r;
4434*58b9f456SAndroid Build Coastguard Worker}
4435*58b9f456SAndroid Build Coastguard Worker
4436*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4437*58b9f456SAndroid Build Coastguard Workertemplate<class _Alloc>
4438*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4439*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4440*58b9f456SAndroid Build Coastguard Worker{
4441*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
4442*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4443*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4444*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4445*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2(__a);
4446*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4447*58b9f456SAndroid Build Coastguard Worker    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4448*58b9f456SAndroid Build Coastguard Worker        _CntrlBlk(__a);
4449*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4450*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4451*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4452*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4453*58b9f456SAndroid Build Coastguard Worker    return __r;
4454*58b9f456SAndroid Build Coastguard Worker}
4455*58b9f456SAndroid Build Coastguard Worker
4456*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4457*58b9f456SAndroid Build Coastguard Workertemplate<class _Alloc, class _A0>
4458*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4459*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4460*58b9f456SAndroid Build Coastguard Worker{
4461*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
4462*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4463*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4464*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4465*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2(__a);
4466*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4467*58b9f456SAndroid Build Coastguard Worker    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4468*58b9f456SAndroid Build Coastguard Worker        _CntrlBlk(__a, __a0);
4469*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4470*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4471*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4472*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4473*58b9f456SAndroid Build Coastguard Worker    return __r;
4474*58b9f456SAndroid Build Coastguard Worker}
4475*58b9f456SAndroid Build Coastguard Worker
4476*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4477*58b9f456SAndroid Build Coastguard Workertemplate<class _Alloc, class _A0, class _A1>
4478*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4479*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4480*58b9f456SAndroid Build Coastguard Worker{
4481*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
4482*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4483*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4484*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4485*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2(__a);
4486*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4487*58b9f456SAndroid Build Coastguard Worker    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4488*58b9f456SAndroid Build Coastguard Worker        _CntrlBlk(__a, __a0, __a1);
4489*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4490*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4491*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4492*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4493*58b9f456SAndroid Build Coastguard Worker    return __r;
4494*58b9f456SAndroid Build Coastguard Worker}
4495*58b9f456SAndroid Build Coastguard Worker
4496*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4497*58b9f456SAndroid Build Coastguard Workertemplate<class _Alloc, class _A0, class _A1, class _A2>
4498*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4499*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4500*58b9f456SAndroid Build Coastguard Worker{
4501*58b9f456SAndroid Build Coastguard Worker    static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
4502*58b9f456SAndroid Build Coastguard Worker    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4503*58b9f456SAndroid Build Coastguard Worker    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4504*58b9f456SAndroid Build Coastguard Worker    typedef __allocator_destructor<_Alloc2> _D2;
4505*58b9f456SAndroid Build Coastguard Worker    _Alloc2 __alloc2(__a);
4506*58b9f456SAndroid Build Coastguard Worker    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4507*58b9f456SAndroid Build Coastguard Worker    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4508*58b9f456SAndroid Build Coastguard Worker        _CntrlBlk(__a, __a0, __a1, __a2);
4509*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
4510*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = __hold2.get()->get();
4511*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4512*58b9f456SAndroid Build Coastguard Worker    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4513*58b9f456SAndroid Build Coastguard Worker    return __r;
4514*58b9f456SAndroid Build Coastguard Worker}
4515*58b9f456SAndroid Build Coastguard Worker
4516*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
4517*58b9f456SAndroid Build Coastguard Worker
4518*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4519*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::~shared_ptr()
4520*58b9f456SAndroid Build Coastguard Worker{
4521*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
4522*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__release_shared();
4523*58b9f456SAndroid Build Coastguard Worker}
4524*58b9f456SAndroid Build Coastguard Worker
4525*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4526*58b9f456SAndroid Build Coastguard Workerinline
4527*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>&
4528*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4529*58b9f456SAndroid Build Coastguard Worker{
4530*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__r).swap(*this);
4531*58b9f456SAndroid Build Coastguard Worker    return *this;
4532*58b9f456SAndroid Build Coastguard Worker}
4533*58b9f456SAndroid Build Coastguard Worker
4534*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4535*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4536*58b9f456SAndroid Build Coastguard Workerinline
4537*58b9f456SAndroid Build Coastguard Workertypename enable_if
4538*58b9f456SAndroid Build Coastguard Worker<
4539*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4540*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>&
4541*58b9f456SAndroid Build Coastguard Worker>::type
4542*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4543*58b9f456SAndroid Build Coastguard Worker{
4544*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__r).swap(*this);
4545*58b9f456SAndroid Build Coastguard Worker    return *this;
4546*58b9f456SAndroid Build Coastguard Worker}
4547*58b9f456SAndroid Build Coastguard Worker
4548*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4549*58b9f456SAndroid Build Coastguard Worker
4550*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4551*58b9f456SAndroid Build Coastguard Workerinline
4552*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>&
4553*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4554*58b9f456SAndroid Build Coastguard Worker{
4555*58b9f456SAndroid Build Coastguard Worker    shared_ptr(_VSTD::move(__r)).swap(*this);
4556*58b9f456SAndroid Build Coastguard Worker    return *this;
4557*58b9f456SAndroid Build Coastguard Worker}
4558*58b9f456SAndroid Build Coastguard Worker
4559*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4560*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4561*58b9f456SAndroid Build Coastguard Workerinline
4562*58b9f456SAndroid Build Coastguard Workertypename enable_if
4563*58b9f456SAndroid Build Coastguard Worker<
4564*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4565*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>&
4566*58b9f456SAndroid Build Coastguard Worker>::type
4567*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4568*58b9f456SAndroid Build Coastguard Worker{
4569*58b9f456SAndroid Build Coastguard Worker    shared_ptr(_VSTD::move(__r)).swap(*this);
4570*58b9f456SAndroid Build Coastguard Worker    return *this;
4571*58b9f456SAndroid Build Coastguard Worker}
4572*58b9f456SAndroid Build Coastguard Worker
4573*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4574*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4575*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4576*58b9f456SAndroid Build Coastguard Workerinline
4577*58b9f456SAndroid Build Coastguard Workertypename enable_if
4578*58b9f456SAndroid Build Coastguard Worker<
4579*58b9f456SAndroid Build Coastguard Worker    !is_array<_Yp>::value &&
4580*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4581*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4582*58b9f456SAndroid Build Coastguard Worker>::type&
4583*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4584*58b9f456SAndroid Build Coastguard Worker{
4585*58b9f456SAndroid Build Coastguard Worker    shared_ptr(_VSTD::move(__r)).swap(*this);
4586*58b9f456SAndroid Build Coastguard Worker    return *this;
4587*58b9f456SAndroid Build Coastguard Worker}
4588*58b9f456SAndroid Build Coastguard Worker#endif
4589*58b9f456SAndroid Build Coastguard Worker
4590*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4591*58b9f456SAndroid Build Coastguard Workertemplate <class _Yp, class _Dp>
4592*58b9f456SAndroid Build Coastguard Workerinline
4593*58b9f456SAndroid Build Coastguard Workertypename enable_if
4594*58b9f456SAndroid Build Coastguard Worker<
4595*58b9f456SAndroid Build Coastguard Worker    !is_array<_Yp>::value &&
4596*58b9f456SAndroid Build Coastguard Worker    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4597*58b9f456SAndroid Build Coastguard Worker                   typename shared_ptr<_Tp>::element_type*>::value,
4598*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>&
4599*58b9f456SAndroid Build Coastguard Worker>::type
4600*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4601*58b9f456SAndroid Build Coastguard Worker{
4602*58b9f456SAndroid Build Coastguard Worker    shared_ptr(_VSTD::move(__r)).swap(*this);
4603*58b9f456SAndroid Build Coastguard Worker    return *this;
4604*58b9f456SAndroid Build Coastguard Worker}
4605*58b9f456SAndroid Build Coastguard Worker
4606*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4607*58b9f456SAndroid Build Coastguard Worker
4608*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4609*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4610*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4611*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4612*58b9f456SAndroid Build Coastguard Workertypename enable_if
4613*58b9f456SAndroid Build Coastguard Worker<
4614*58b9f456SAndroid Build Coastguard Worker    !is_array<_Yp>::value &&
4615*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4616*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>&
4617*58b9f456SAndroid Build Coastguard Worker>::type
4618*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4619*58b9f456SAndroid Build Coastguard Worker{
4620*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__r).swap(*this);
4621*58b9f456SAndroid Build Coastguard Worker    return *this;
4622*58b9f456SAndroid Build Coastguard Worker}
4623*58b9f456SAndroid Build Coastguard Worker#endif
4624*58b9f456SAndroid Build Coastguard Worker
4625*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4626*58b9f456SAndroid Build Coastguard Workertemplate <class _Yp, class _Dp>
4627*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4628*58b9f456SAndroid Build Coastguard Workertypename enable_if
4629*58b9f456SAndroid Build Coastguard Worker<
4630*58b9f456SAndroid Build Coastguard Worker    !is_array<_Yp>::value &&
4631*58b9f456SAndroid Build Coastguard Worker    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4632*58b9f456SAndroid Build Coastguard Worker                   typename shared_ptr<_Tp>::element_type*>::value,
4633*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>&
4634*58b9f456SAndroid Build Coastguard Worker>::type
4635*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4636*58b9f456SAndroid Build Coastguard Worker{
4637*58b9f456SAndroid Build Coastguard Worker    shared_ptr(_VSTD::move(__r)).swap(*this);
4638*58b9f456SAndroid Build Coastguard Worker    return *this;
4639*58b9f456SAndroid Build Coastguard Worker}
4640*58b9f456SAndroid Build Coastguard Worker
4641*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4642*58b9f456SAndroid Build Coastguard Worker
4643*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4644*58b9f456SAndroid Build Coastguard Workerinline
4645*58b9f456SAndroid Build Coastguard Workervoid
4646*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4647*58b9f456SAndroid Build Coastguard Worker{
4648*58b9f456SAndroid Build Coastguard Worker    _VSTD::swap(__ptr_, __r.__ptr_);
4649*58b9f456SAndroid Build Coastguard Worker    _VSTD::swap(__cntrl_, __r.__cntrl_);
4650*58b9f456SAndroid Build Coastguard Worker}
4651*58b9f456SAndroid Build Coastguard Worker
4652*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4653*58b9f456SAndroid Build Coastguard Workerinline
4654*58b9f456SAndroid Build Coastguard Workervoid
4655*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::reset() _NOEXCEPT
4656*58b9f456SAndroid Build Coastguard Worker{
4657*58b9f456SAndroid Build Coastguard Worker    shared_ptr().swap(*this);
4658*58b9f456SAndroid Build Coastguard Worker}
4659*58b9f456SAndroid Build Coastguard Worker
4660*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4661*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
4662*58b9f456SAndroid Build Coastguard Workerinline
4663*58b9f456SAndroid Build Coastguard Workertypename enable_if
4664*58b9f456SAndroid Build Coastguard Worker<
4665*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4666*58b9f456SAndroid Build Coastguard Worker    void
4667*58b9f456SAndroid Build Coastguard Worker>::type
4668*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::reset(_Yp* __p)
4669*58b9f456SAndroid Build Coastguard Worker{
4670*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__p).swap(*this);
4671*58b9f456SAndroid Build Coastguard Worker}
4672*58b9f456SAndroid Build Coastguard Worker
4673*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4674*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp, class _Dp>
4675*58b9f456SAndroid Build Coastguard Workerinline
4676*58b9f456SAndroid Build Coastguard Workertypename enable_if
4677*58b9f456SAndroid Build Coastguard Worker<
4678*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4679*58b9f456SAndroid Build Coastguard Worker    void
4680*58b9f456SAndroid Build Coastguard Worker>::type
4681*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4682*58b9f456SAndroid Build Coastguard Worker{
4683*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__p, __d).swap(*this);
4684*58b9f456SAndroid Build Coastguard Worker}
4685*58b9f456SAndroid Build Coastguard Worker
4686*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4687*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp, class _Dp, class _Alloc>
4688*58b9f456SAndroid Build Coastguard Workerinline
4689*58b9f456SAndroid Build Coastguard Workertypename enable_if
4690*58b9f456SAndroid Build Coastguard Worker<
4691*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4692*58b9f456SAndroid Build Coastguard Worker    void
4693*58b9f456SAndroid Build Coastguard Worker>::type
4694*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4695*58b9f456SAndroid Build Coastguard Worker{
4696*58b9f456SAndroid Build Coastguard Worker    shared_ptr(__p, __d, __a).swap(*this);
4697*58b9f456SAndroid Build Coastguard Worker}
4698*58b9f456SAndroid Build Coastguard Worker
4699*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
4700*58b9f456SAndroid Build Coastguard Worker
4701*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class ..._Args>
4702*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4703*58b9f456SAndroid Build Coastguard Workertypename enable_if
4704*58b9f456SAndroid Build Coastguard Worker<
4705*58b9f456SAndroid Build Coastguard Worker    !is_array<_Tp>::value,
4706*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4707*58b9f456SAndroid Build Coastguard Worker>::type
4708*58b9f456SAndroid Build Coastguard Workermake_shared(_Args&& ...__args)
4709*58b9f456SAndroid Build Coastguard Worker{
4710*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4711*58b9f456SAndroid Build Coastguard Worker}
4712*58b9f456SAndroid Build Coastguard Worker
4713*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Alloc, class ..._Args>
4714*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4715*58b9f456SAndroid Build Coastguard Workertypename enable_if
4716*58b9f456SAndroid Build Coastguard Worker<
4717*58b9f456SAndroid Build Coastguard Worker    !is_array<_Tp>::value,
4718*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4719*58b9f456SAndroid Build Coastguard Worker>::type
4720*58b9f456SAndroid Build Coastguard Workerallocate_shared(const _Alloc& __a, _Args&& ...__args)
4721*58b9f456SAndroid Build Coastguard Worker{
4722*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4723*58b9f456SAndroid Build Coastguard Worker}
4724*58b9f456SAndroid Build Coastguard Worker
4725*58b9f456SAndroid Build Coastguard Worker#else  // _LIBCPP_HAS_NO_VARIADICS
4726*58b9f456SAndroid Build Coastguard Worker
4727*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4728*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4729*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4730*58b9f456SAndroid Build Coastguard Workermake_shared()
4731*58b9f456SAndroid Build Coastguard Worker{
4732*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::make_shared();
4733*58b9f456SAndroid Build Coastguard Worker}
4734*58b9f456SAndroid Build Coastguard Worker
4735*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _A0>
4736*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4737*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4738*58b9f456SAndroid Build Coastguard Workermake_shared(_A0& __a0)
4739*58b9f456SAndroid Build Coastguard Worker{
4740*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::make_shared(__a0);
4741*58b9f456SAndroid Build Coastguard Worker}
4742*58b9f456SAndroid Build Coastguard Worker
4743*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _A0, class _A1>
4744*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4745*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4746*58b9f456SAndroid Build Coastguard Workermake_shared(_A0& __a0, _A1& __a1)
4747*58b9f456SAndroid Build Coastguard Worker{
4748*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4749*58b9f456SAndroid Build Coastguard Worker}
4750*58b9f456SAndroid Build Coastguard Worker
4751*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _A0, class _A1, class _A2>
4752*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4753*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4754*58b9f456SAndroid Build Coastguard Workermake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4755*58b9f456SAndroid Build Coastguard Worker{
4756*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4757*58b9f456SAndroid Build Coastguard Worker}
4758*58b9f456SAndroid Build Coastguard Worker
4759*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Alloc>
4760*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4761*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4762*58b9f456SAndroid Build Coastguard Workerallocate_shared(const _Alloc& __a)
4763*58b9f456SAndroid Build Coastguard Worker{
4764*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::allocate_shared(__a);
4765*58b9f456SAndroid Build Coastguard Worker}
4766*58b9f456SAndroid Build Coastguard Worker
4767*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Alloc, class _A0>
4768*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4769*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4770*58b9f456SAndroid Build Coastguard Workerallocate_shared(const _Alloc& __a, _A0& __a0)
4771*58b9f456SAndroid Build Coastguard Worker{
4772*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4773*58b9f456SAndroid Build Coastguard Worker}
4774*58b9f456SAndroid Build Coastguard Worker
4775*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Alloc, class _A0, class _A1>
4776*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4777*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4778*58b9f456SAndroid Build Coastguard Workerallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4779*58b9f456SAndroid Build Coastguard Worker{
4780*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4781*58b9f456SAndroid Build Coastguard Worker}
4782*58b9f456SAndroid Build Coastguard Worker
4783*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4784*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4785*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
4786*58b9f456SAndroid Build Coastguard Workerallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4787*58b9f456SAndroid Build Coastguard Worker{
4788*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4789*58b9f456SAndroid Build Coastguard Worker}
4790*58b9f456SAndroid Build Coastguard Worker
4791*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_VARIADICS
4792*58b9f456SAndroid Build Coastguard Worker
4793*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4794*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4795*58b9f456SAndroid Build Coastguard Workerbool
4796*58b9f456SAndroid Build Coastguard Workeroperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4797*58b9f456SAndroid Build Coastguard Worker{
4798*58b9f456SAndroid Build Coastguard Worker    return __x.get() == __y.get();
4799*58b9f456SAndroid Build Coastguard Worker}
4800*58b9f456SAndroid Build Coastguard Worker
4801*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4802*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4803*58b9f456SAndroid Build Coastguard Workerbool
4804*58b9f456SAndroid Build Coastguard Workeroperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4805*58b9f456SAndroid Build Coastguard Worker{
4806*58b9f456SAndroid Build Coastguard Worker    return !(__x == __y);
4807*58b9f456SAndroid Build Coastguard Worker}
4808*58b9f456SAndroid Build Coastguard Worker
4809*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4810*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4811*58b9f456SAndroid Build Coastguard Workerbool
4812*58b9f456SAndroid Build Coastguard Workeroperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4813*58b9f456SAndroid Build Coastguard Worker{
4814*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER <= 11
4815*58b9f456SAndroid Build Coastguard Worker    typedef typename common_type<_Tp*, _Up*>::type _Vp;
4816*58b9f456SAndroid Build Coastguard Worker    return less<_Vp>()(__x.get(), __y.get());
4817*58b9f456SAndroid Build Coastguard Worker#else
4818*58b9f456SAndroid Build Coastguard Worker    return less<>()(__x.get(), __y.get());
4819*58b9f456SAndroid Build Coastguard Worker#endif
4820*58b9f456SAndroid Build Coastguard Worker
4821*58b9f456SAndroid Build Coastguard Worker}
4822*58b9f456SAndroid Build Coastguard Worker
4823*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4824*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4825*58b9f456SAndroid Build Coastguard Workerbool
4826*58b9f456SAndroid Build Coastguard Workeroperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4827*58b9f456SAndroid Build Coastguard Worker{
4828*58b9f456SAndroid Build Coastguard Worker    return __y < __x;
4829*58b9f456SAndroid Build Coastguard Worker}
4830*58b9f456SAndroid Build Coastguard Worker
4831*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4832*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4833*58b9f456SAndroid Build Coastguard Workerbool
4834*58b9f456SAndroid Build Coastguard Workeroperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4835*58b9f456SAndroid Build Coastguard Worker{
4836*58b9f456SAndroid Build Coastguard Worker    return !(__y < __x);
4837*58b9f456SAndroid Build Coastguard Worker}
4838*58b9f456SAndroid Build Coastguard Worker
4839*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4840*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4841*58b9f456SAndroid Build Coastguard Workerbool
4842*58b9f456SAndroid Build Coastguard Workeroperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4843*58b9f456SAndroid Build Coastguard Worker{
4844*58b9f456SAndroid Build Coastguard Worker    return !(__x < __y);
4845*58b9f456SAndroid Build Coastguard Worker}
4846*58b9f456SAndroid Build Coastguard Worker
4847*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4848*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4849*58b9f456SAndroid Build Coastguard Workerbool
4850*58b9f456SAndroid Build Coastguard Workeroperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4851*58b9f456SAndroid Build Coastguard Worker{
4852*58b9f456SAndroid Build Coastguard Worker    return !__x;
4853*58b9f456SAndroid Build Coastguard Worker}
4854*58b9f456SAndroid Build Coastguard Worker
4855*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4856*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4857*58b9f456SAndroid Build Coastguard Workerbool
4858*58b9f456SAndroid Build Coastguard Workeroperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4859*58b9f456SAndroid Build Coastguard Worker{
4860*58b9f456SAndroid Build Coastguard Worker    return !__x;
4861*58b9f456SAndroid Build Coastguard Worker}
4862*58b9f456SAndroid Build Coastguard Worker
4863*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4864*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4865*58b9f456SAndroid Build Coastguard Workerbool
4866*58b9f456SAndroid Build Coastguard Workeroperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4867*58b9f456SAndroid Build Coastguard Worker{
4868*58b9f456SAndroid Build Coastguard Worker    return static_cast<bool>(__x);
4869*58b9f456SAndroid Build Coastguard Worker}
4870*58b9f456SAndroid Build Coastguard Worker
4871*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4872*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4873*58b9f456SAndroid Build Coastguard Workerbool
4874*58b9f456SAndroid Build Coastguard Workeroperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4875*58b9f456SAndroid Build Coastguard Worker{
4876*58b9f456SAndroid Build Coastguard Worker    return static_cast<bool>(__x);
4877*58b9f456SAndroid Build Coastguard Worker}
4878*58b9f456SAndroid Build Coastguard Worker
4879*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4880*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4881*58b9f456SAndroid Build Coastguard Workerbool
4882*58b9f456SAndroid Build Coastguard Workeroperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4883*58b9f456SAndroid Build Coastguard Worker{
4884*58b9f456SAndroid Build Coastguard Worker    return less<_Tp*>()(__x.get(), nullptr);
4885*58b9f456SAndroid Build Coastguard Worker}
4886*58b9f456SAndroid Build Coastguard Worker
4887*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4888*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4889*58b9f456SAndroid Build Coastguard Workerbool
4890*58b9f456SAndroid Build Coastguard Workeroperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4891*58b9f456SAndroid Build Coastguard Worker{
4892*58b9f456SAndroid Build Coastguard Worker    return less<_Tp*>()(nullptr, __x.get());
4893*58b9f456SAndroid Build Coastguard Worker}
4894*58b9f456SAndroid Build Coastguard Worker
4895*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4896*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4897*58b9f456SAndroid Build Coastguard Workerbool
4898*58b9f456SAndroid Build Coastguard Workeroperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4899*58b9f456SAndroid Build Coastguard Worker{
4900*58b9f456SAndroid Build Coastguard Worker    return nullptr < __x;
4901*58b9f456SAndroid Build Coastguard Worker}
4902*58b9f456SAndroid Build Coastguard Worker
4903*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4904*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4905*58b9f456SAndroid Build Coastguard Workerbool
4906*58b9f456SAndroid Build Coastguard Workeroperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4907*58b9f456SAndroid Build Coastguard Worker{
4908*58b9f456SAndroid Build Coastguard Worker    return __x < nullptr;
4909*58b9f456SAndroid Build Coastguard Worker}
4910*58b9f456SAndroid Build Coastguard Worker
4911*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4912*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4913*58b9f456SAndroid Build Coastguard Workerbool
4914*58b9f456SAndroid Build Coastguard Workeroperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4915*58b9f456SAndroid Build Coastguard Worker{
4916*58b9f456SAndroid Build Coastguard Worker    return !(nullptr < __x);
4917*58b9f456SAndroid Build Coastguard Worker}
4918*58b9f456SAndroid Build Coastguard Worker
4919*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4920*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4921*58b9f456SAndroid Build Coastguard Workerbool
4922*58b9f456SAndroid Build Coastguard Workeroperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4923*58b9f456SAndroid Build Coastguard Worker{
4924*58b9f456SAndroid Build Coastguard Worker    return !(__x < nullptr);
4925*58b9f456SAndroid Build Coastguard Worker}
4926*58b9f456SAndroid Build Coastguard Worker
4927*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4928*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4929*58b9f456SAndroid Build Coastguard Workerbool
4930*58b9f456SAndroid Build Coastguard Workeroperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4931*58b9f456SAndroid Build Coastguard Worker{
4932*58b9f456SAndroid Build Coastguard Worker    return !(__x < nullptr);
4933*58b9f456SAndroid Build Coastguard Worker}
4934*58b9f456SAndroid Build Coastguard Worker
4935*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4936*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4937*58b9f456SAndroid Build Coastguard Workerbool
4938*58b9f456SAndroid Build Coastguard Workeroperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4939*58b9f456SAndroid Build Coastguard Worker{
4940*58b9f456SAndroid Build Coastguard Worker    return !(nullptr < __x);
4941*58b9f456SAndroid Build Coastguard Worker}
4942*58b9f456SAndroid Build Coastguard Worker
4943*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
4944*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4945*58b9f456SAndroid Build Coastguard Workervoid
4946*58b9f456SAndroid Build Coastguard Workerswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4947*58b9f456SAndroid Build Coastguard Worker{
4948*58b9f456SAndroid Build Coastguard Worker    __x.swap(__y);
4949*58b9f456SAndroid Build Coastguard Worker}
4950*58b9f456SAndroid Build Coastguard Worker
4951*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4952*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4953*58b9f456SAndroid Build Coastguard Workertypename enable_if
4954*58b9f456SAndroid Build Coastguard Worker<
4955*58b9f456SAndroid Build Coastguard Worker    !is_array<_Tp>::value && !is_array<_Up>::value,
4956*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4957*58b9f456SAndroid Build Coastguard Worker>::type
4958*58b9f456SAndroid Build Coastguard Workerstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4959*58b9f456SAndroid Build Coastguard Worker{
4960*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4961*58b9f456SAndroid Build Coastguard Worker}
4962*58b9f456SAndroid Build Coastguard Worker
4963*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4964*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4965*58b9f456SAndroid Build Coastguard Workertypename enable_if
4966*58b9f456SAndroid Build Coastguard Worker<
4967*58b9f456SAndroid Build Coastguard Worker    !is_array<_Tp>::value && !is_array<_Up>::value,
4968*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4969*58b9f456SAndroid Build Coastguard Worker>::type
4970*58b9f456SAndroid Build Coastguard Workerdynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4971*58b9f456SAndroid Build Coastguard Worker{
4972*58b9f456SAndroid Build Coastguard Worker    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4973*58b9f456SAndroid Build Coastguard Worker    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4974*58b9f456SAndroid Build Coastguard Worker}
4975*58b9f456SAndroid Build Coastguard Worker
4976*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp, class _Up>
4977*58b9f456SAndroid Build Coastguard Workertypename enable_if
4978*58b9f456SAndroid Build Coastguard Worker<
4979*58b9f456SAndroid Build Coastguard Worker    is_array<_Tp>::value == is_array<_Up>::value,
4980*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp>
4981*58b9f456SAndroid Build Coastguard Worker>::type
4982*58b9f456SAndroid Build Coastguard Workerconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4983*58b9f456SAndroid Build Coastguard Worker{
4984*58b9f456SAndroid Build Coastguard Worker    typedef typename remove_extent<_Tp>::type _RTp;
4985*58b9f456SAndroid Build Coastguard Worker    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4986*58b9f456SAndroid Build Coastguard Worker}
4987*58b9f456SAndroid Build Coastguard Worker
4988*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_NO_RTTI
4989*58b9f456SAndroid Build Coastguard Worker
4990*58b9f456SAndroid Build Coastguard Workertemplate<class _Dp, class _Tp>
4991*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
4992*58b9f456SAndroid Build Coastguard Worker_Dp*
4993*58b9f456SAndroid Build Coastguard Workerget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4994*58b9f456SAndroid Build Coastguard Worker{
4995*58b9f456SAndroid Build Coastguard Worker    return __p.template __get_deleter<_Dp>();
4996*58b9f456SAndroid Build Coastguard Worker}
4997*58b9f456SAndroid Build Coastguard Worker
4998*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_NO_RTTI
4999*58b9f456SAndroid Build Coastguard Worker
5000*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5001*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS weak_ptr
5002*58b9f456SAndroid Build Coastguard Worker{
5003*58b9f456SAndroid Build Coastguard Workerpublic:
5004*58b9f456SAndroid Build Coastguard Worker    typedef _Tp element_type;
5005*58b9f456SAndroid Build Coastguard Workerprivate:
5006*58b9f456SAndroid Build Coastguard Worker    element_type*        __ptr_;
5007*58b9f456SAndroid Build Coastguard Worker    __shared_weak_count* __cntrl_;
5008*58b9f456SAndroid Build Coastguard Worker
5009*58b9f456SAndroid Build Coastguard Workerpublic:
5010*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5011*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
5012*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
5013*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5014*58b9f456SAndroid Build Coastguard Worker                        _NOEXCEPT;
5015*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5016*58b9f456SAndroid Build Coastguard Worker    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
5017*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
5018*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5019*58b9f456SAndroid Build Coastguard Worker                         _NOEXCEPT;
5020*58b9f456SAndroid Build Coastguard Worker
5021*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5022*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5023*58b9f456SAndroid Build Coastguard Worker    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5024*58b9f456SAndroid Build Coastguard Worker    template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
5025*58b9f456SAndroid Build Coastguard Worker                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5026*58b9f456SAndroid Build Coastguard Worker                         _NOEXCEPT;
5027*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5028*58b9f456SAndroid Build Coastguard Worker    ~weak_ptr();
5029*58b9f456SAndroid Build Coastguard Worker
5030*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5031*58b9f456SAndroid Build Coastguard Worker    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5032*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
5033*58b9f456SAndroid Build Coastguard Worker        typename enable_if
5034*58b9f456SAndroid Build Coastguard Worker        <
5035*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
5036*58b9f456SAndroid Build Coastguard Worker            weak_ptr&
5037*58b9f456SAndroid Build Coastguard Worker        >::type
5038*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
5039*58b9f456SAndroid Build Coastguard Worker        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5040*58b9f456SAndroid Build Coastguard Worker
5041*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5042*58b9f456SAndroid Build Coastguard Worker
5043*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5044*58b9f456SAndroid Build Coastguard Worker    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5045*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
5046*58b9f456SAndroid Build Coastguard Worker        typename enable_if
5047*58b9f456SAndroid Build Coastguard Worker        <
5048*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
5049*58b9f456SAndroid Build Coastguard Worker            weak_ptr&
5050*58b9f456SAndroid Build Coastguard Worker        >::type
5051*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
5052*58b9f456SAndroid Build Coastguard Worker        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5053*58b9f456SAndroid Build Coastguard Worker
5054*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5055*58b9f456SAndroid Build Coastguard Worker
5056*58b9f456SAndroid Build Coastguard Worker    template<class _Yp>
5057*58b9f456SAndroid Build Coastguard Worker        typename enable_if
5058*58b9f456SAndroid Build Coastguard Worker        <
5059*58b9f456SAndroid Build Coastguard Worker            is_convertible<_Yp*, element_type*>::value,
5060*58b9f456SAndroid Build Coastguard Worker            weak_ptr&
5061*58b9f456SAndroid Build Coastguard Worker        >::type
5062*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
5063*58b9f456SAndroid Build Coastguard Worker        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5064*58b9f456SAndroid Build Coastguard Worker
5065*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5066*58b9f456SAndroid Build Coastguard Worker    void swap(weak_ptr& __r) _NOEXCEPT;
5067*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5068*58b9f456SAndroid Build Coastguard Worker    void reset() _NOEXCEPT;
5069*58b9f456SAndroid Build Coastguard Worker
5070*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5071*58b9f456SAndroid Build Coastguard Worker    long use_count() const _NOEXCEPT
5072*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ ? __cntrl_->use_count() : 0;}
5073*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5074*58b9f456SAndroid Build Coastguard Worker    bool expired() const _NOEXCEPT
5075*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5076*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> lock() const _NOEXCEPT;
5077*58b9f456SAndroid Build Coastguard Worker    template<class _Up>
5078*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
5079*58b9f456SAndroid Build Coastguard Worker        bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
5080*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ < __r.__cntrl_;}
5081*58b9f456SAndroid Build Coastguard Worker    template<class _Up>
5082*58b9f456SAndroid Build Coastguard Worker        _LIBCPP_INLINE_VISIBILITY
5083*58b9f456SAndroid Build Coastguard Worker        bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
5084*58b9f456SAndroid Build Coastguard Worker        {return __cntrl_ < __r.__cntrl_;}
5085*58b9f456SAndroid Build Coastguard Worker
5086*58b9f456SAndroid Build Coastguard Worker    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5087*58b9f456SAndroid Build Coastguard Worker    template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
5088*58b9f456SAndroid Build Coastguard Worker};
5089*58b9f456SAndroid Build Coastguard Worker
5090*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5091*58b9f456SAndroid Build Coastguard Workerinline
5092*58b9f456SAndroid Build Coastguard Worker_LIBCPP_CONSTEXPR
5093*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5094*58b9f456SAndroid Build Coastguard Worker    : __ptr_(0),
5095*58b9f456SAndroid Build Coastguard Worker      __cntrl_(0)
5096*58b9f456SAndroid Build Coastguard Worker{
5097*58b9f456SAndroid Build Coastguard Worker}
5098*58b9f456SAndroid Build Coastguard Worker
5099*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5100*58b9f456SAndroid Build Coastguard Workerinline
5101*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5102*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5103*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
5104*58b9f456SAndroid Build Coastguard Worker{
5105*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
5106*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_weak();
5107*58b9f456SAndroid Build Coastguard Worker}
5108*58b9f456SAndroid Build Coastguard Worker
5109*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5110*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5111*58b9f456SAndroid Build Coastguard Workerinline
5112*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5113*58b9f456SAndroid Build Coastguard Worker                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5114*58b9f456SAndroid Build Coastguard Worker                         _NOEXCEPT
5115*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5116*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
5117*58b9f456SAndroid Build Coastguard Worker{
5118*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
5119*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_weak();
5120*58b9f456SAndroid Build Coastguard Worker}
5121*58b9f456SAndroid Build Coastguard Worker
5122*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5123*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5124*58b9f456SAndroid Build Coastguard Workerinline
5125*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5126*58b9f456SAndroid Build Coastguard Worker                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5127*58b9f456SAndroid Build Coastguard Worker         _NOEXCEPT
5128*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5129*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
5130*58b9f456SAndroid Build Coastguard Worker{
5131*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
5132*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__add_weak();
5133*58b9f456SAndroid Build Coastguard Worker}
5134*58b9f456SAndroid Build Coastguard Worker
5135*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5136*58b9f456SAndroid Build Coastguard Worker
5137*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5138*58b9f456SAndroid Build Coastguard Workerinline
5139*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5140*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5141*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
5142*58b9f456SAndroid Build Coastguard Worker{
5143*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = 0;
5144*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = 0;
5145*58b9f456SAndroid Build Coastguard Worker}
5146*58b9f456SAndroid Build Coastguard Worker
5147*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5148*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5149*58b9f456SAndroid Build Coastguard Workerinline
5150*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5151*58b9f456SAndroid Build Coastguard Worker                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5152*58b9f456SAndroid Build Coastguard Worker         _NOEXCEPT
5153*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5154*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_)
5155*58b9f456SAndroid Build Coastguard Worker{
5156*58b9f456SAndroid Build Coastguard Worker    __r.__ptr_ = 0;
5157*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = 0;
5158*58b9f456SAndroid Build Coastguard Worker}
5159*58b9f456SAndroid Build Coastguard Worker
5160*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5161*58b9f456SAndroid Build Coastguard Worker
5162*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5163*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::~weak_ptr()
5164*58b9f456SAndroid Build Coastguard Worker{
5165*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_)
5166*58b9f456SAndroid Build Coastguard Worker        __cntrl_->__release_weak();
5167*58b9f456SAndroid Build Coastguard Worker}
5168*58b9f456SAndroid Build Coastguard Worker
5169*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5170*58b9f456SAndroid Build Coastguard Workerinline
5171*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>&
5172*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5173*58b9f456SAndroid Build Coastguard Worker{
5174*58b9f456SAndroid Build Coastguard Worker    weak_ptr(__r).swap(*this);
5175*58b9f456SAndroid Build Coastguard Worker    return *this;
5176*58b9f456SAndroid Build Coastguard Worker}
5177*58b9f456SAndroid Build Coastguard Worker
5178*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5179*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5180*58b9f456SAndroid Build Coastguard Workerinline
5181*58b9f456SAndroid Build Coastguard Workertypename enable_if
5182*58b9f456SAndroid Build Coastguard Worker<
5183*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, _Tp*>::value,
5184*58b9f456SAndroid Build Coastguard Worker    weak_ptr<_Tp>&
5185*58b9f456SAndroid Build Coastguard Worker>::type
5186*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5187*58b9f456SAndroid Build Coastguard Worker{
5188*58b9f456SAndroid Build Coastguard Worker    weak_ptr(__r).swap(*this);
5189*58b9f456SAndroid Build Coastguard Worker    return *this;
5190*58b9f456SAndroid Build Coastguard Worker}
5191*58b9f456SAndroid Build Coastguard Worker
5192*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5193*58b9f456SAndroid Build Coastguard Worker
5194*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5195*58b9f456SAndroid Build Coastguard Workerinline
5196*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>&
5197*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5198*58b9f456SAndroid Build Coastguard Worker{
5199*58b9f456SAndroid Build Coastguard Worker    weak_ptr(_VSTD::move(__r)).swap(*this);
5200*58b9f456SAndroid Build Coastguard Worker    return *this;
5201*58b9f456SAndroid Build Coastguard Worker}
5202*58b9f456SAndroid Build Coastguard Worker
5203*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5204*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5205*58b9f456SAndroid Build Coastguard Workerinline
5206*58b9f456SAndroid Build Coastguard Workertypename enable_if
5207*58b9f456SAndroid Build Coastguard Worker<
5208*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, _Tp*>::value,
5209*58b9f456SAndroid Build Coastguard Worker    weak_ptr<_Tp>&
5210*58b9f456SAndroid Build Coastguard Worker>::type
5211*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5212*58b9f456SAndroid Build Coastguard Worker{
5213*58b9f456SAndroid Build Coastguard Worker    weak_ptr(_VSTD::move(__r)).swap(*this);
5214*58b9f456SAndroid Build Coastguard Worker    return *this;
5215*58b9f456SAndroid Build Coastguard Worker}
5216*58b9f456SAndroid Build Coastguard Worker
5217*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5218*58b9f456SAndroid Build Coastguard Worker
5219*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5220*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5221*58b9f456SAndroid Build Coastguard Workerinline
5222*58b9f456SAndroid Build Coastguard Workertypename enable_if
5223*58b9f456SAndroid Build Coastguard Worker<
5224*58b9f456SAndroid Build Coastguard Worker    is_convertible<_Yp*, _Tp*>::value,
5225*58b9f456SAndroid Build Coastguard Worker    weak_ptr<_Tp>&
5226*58b9f456SAndroid Build Coastguard Worker>::type
5227*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5228*58b9f456SAndroid Build Coastguard Worker{
5229*58b9f456SAndroid Build Coastguard Worker    weak_ptr(__r).swap(*this);
5230*58b9f456SAndroid Build Coastguard Worker    return *this;
5231*58b9f456SAndroid Build Coastguard Worker}
5232*58b9f456SAndroid Build Coastguard Worker
5233*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5234*58b9f456SAndroid Build Coastguard Workerinline
5235*58b9f456SAndroid Build Coastguard Workervoid
5236*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5237*58b9f456SAndroid Build Coastguard Worker{
5238*58b9f456SAndroid Build Coastguard Worker    _VSTD::swap(__ptr_, __r.__ptr_);
5239*58b9f456SAndroid Build Coastguard Worker    _VSTD::swap(__cntrl_, __r.__cntrl_);
5240*58b9f456SAndroid Build Coastguard Worker}
5241*58b9f456SAndroid Build Coastguard Worker
5242*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5243*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5244*58b9f456SAndroid Build Coastguard Workervoid
5245*58b9f456SAndroid Build Coastguard Workerswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5246*58b9f456SAndroid Build Coastguard Worker{
5247*58b9f456SAndroid Build Coastguard Worker    __x.swap(__y);
5248*58b9f456SAndroid Build Coastguard Worker}
5249*58b9f456SAndroid Build Coastguard Worker
5250*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5251*58b9f456SAndroid Build Coastguard Workerinline
5252*58b9f456SAndroid Build Coastguard Workervoid
5253*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::reset() _NOEXCEPT
5254*58b9f456SAndroid Build Coastguard Worker{
5255*58b9f456SAndroid Build Coastguard Worker    weak_ptr().swap(*this);
5256*58b9f456SAndroid Build Coastguard Worker}
5257*58b9f456SAndroid Build Coastguard Worker
5258*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5259*58b9f456SAndroid Build Coastguard Workertemplate<class _Yp>
5260*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5261*58b9f456SAndroid Build Coastguard Worker                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5262*58b9f456SAndroid Build Coastguard Worker    : __ptr_(__r.__ptr_),
5263*58b9f456SAndroid Build Coastguard Worker      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5264*58b9f456SAndroid Build Coastguard Worker{
5265*58b9f456SAndroid Build Coastguard Worker    if (__cntrl_ == 0)
5266*58b9f456SAndroid Build Coastguard Worker        __throw_bad_weak_ptr();
5267*58b9f456SAndroid Build Coastguard Worker}
5268*58b9f456SAndroid Build Coastguard Worker
5269*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5270*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
5271*58b9f456SAndroid Build Coastguard Workerweak_ptr<_Tp>::lock() const _NOEXCEPT
5272*58b9f456SAndroid Build Coastguard Worker{
5273*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __r;
5274*58b9f456SAndroid Build Coastguard Worker    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5275*58b9f456SAndroid Build Coastguard Worker    if (__r.__cntrl_)
5276*58b9f456SAndroid Build Coastguard Worker        __r.__ptr_ = __ptr_;
5277*58b9f456SAndroid Build Coastguard Worker    return __r;
5278*58b9f456SAndroid Build Coastguard Worker}
5279*58b9f456SAndroid Build Coastguard Worker
5280*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
5281*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp = void> struct owner_less;
5282*58b9f456SAndroid Build Coastguard Worker#else
5283*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp> struct owner_less;
5284*58b9f456SAndroid Build Coastguard Worker#endif
5285*58b9f456SAndroid Build Coastguard Worker
5286*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5287*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5288*58b9f456SAndroid Build Coastguard Worker    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5289*58b9f456SAndroid Build Coastguard Worker{
5290*58b9f456SAndroid Build Coastguard Worker    typedef bool result_type;
5291*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5292*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5293*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5294*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5295*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const _NOEXCEPT
5296*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5297*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5298*58b9f456SAndroid Build Coastguard Worker    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5299*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5300*58b9f456SAndroid Build Coastguard Worker};
5301*58b9f456SAndroid Build Coastguard Worker
5302*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5303*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5304*58b9f456SAndroid Build Coastguard Worker    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5305*58b9f456SAndroid Build Coastguard Worker{
5306*58b9f456SAndroid Build Coastguard Worker    typedef bool result_type;
5307*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5308*58b9f456SAndroid Build Coastguard Worker    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const _NOEXCEPT
5309*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5310*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5311*58b9f456SAndroid Build Coastguard Worker    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const _NOEXCEPT
5312*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5313*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5314*58b9f456SAndroid Build Coastguard Worker    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5315*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5316*58b9f456SAndroid Build Coastguard Worker};
5317*58b9f456SAndroid Build Coastguard Worker
5318*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
5319*58b9f456SAndroid Build Coastguard Workertemplate <>
5320*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS owner_less<void>
5321*58b9f456SAndroid Build Coastguard Worker{
5322*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
5323*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5324*58b9f456SAndroid Build Coastguard Worker    bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5325*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5326*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
5327*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5328*58b9f456SAndroid Build Coastguard Worker    bool operator()( shared_ptr<_Tp> const& __x,   weak_ptr<_Up> const& __y) const _NOEXCEPT
5329*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5330*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
5331*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5332*58b9f456SAndroid Build Coastguard Worker    bool operator()(   weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5333*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5334*58b9f456SAndroid Build Coastguard Worker    template <class _Tp, class _Up>
5335*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5336*58b9f456SAndroid Build Coastguard Worker    bool operator()(   weak_ptr<_Tp> const& __x,   weak_ptr<_Up> const& __y) const _NOEXCEPT
5337*58b9f456SAndroid Build Coastguard Worker        {return __x.owner_before(__y);}
5338*58b9f456SAndroid Build Coastguard Worker    typedef void is_transparent;
5339*58b9f456SAndroid Build Coastguard Worker};
5340*58b9f456SAndroid Build Coastguard Worker#endif
5341*58b9f456SAndroid Build Coastguard Worker
5342*58b9f456SAndroid Build Coastguard Workertemplate<class _Tp>
5343*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5344*58b9f456SAndroid Build Coastguard Worker{
5345*58b9f456SAndroid Build Coastguard Worker    mutable weak_ptr<_Tp> __weak_this_;
5346*58b9f456SAndroid Build Coastguard Workerprotected:
5347*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5348*58b9f456SAndroid Build Coastguard Worker    enable_shared_from_this() _NOEXCEPT {}
5349*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5350*58b9f456SAndroid Build Coastguard Worker    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5351*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5352*58b9f456SAndroid Build Coastguard Worker    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5353*58b9f456SAndroid Build Coastguard Worker        {return *this;}
5354*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5355*58b9f456SAndroid Build Coastguard Worker    ~enable_shared_from_this() {}
5356*58b9f456SAndroid Build Coastguard Workerpublic:
5357*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5358*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> shared_from_this()
5359*58b9f456SAndroid Build Coastguard Worker        {return shared_ptr<_Tp>(__weak_this_);}
5360*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5361*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp const> shared_from_this() const
5362*58b9f456SAndroid Build Coastguard Worker        {return shared_ptr<const _Tp>(__weak_this_);}
5363*58b9f456SAndroid Build Coastguard Worker
5364*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
5365*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5366*58b9f456SAndroid Build Coastguard Worker    weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5367*58b9f456SAndroid Build Coastguard Worker       { return __weak_this_; }
5368*58b9f456SAndroid Build Coastguard Worker
5369*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5370*58b9f456SAndroid Build Coastguard Worker    weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5371*58b9f456SAndroid Build Coastguard Worker        { return __weak_this_; }
5372*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_STD_VER > 14
5373*58b9f456SAndroid Build Coastguard Worker
5374*58b9f456SAndroid Build Coastguard Worker    template <class _Up> friend class shared_ptr;
5375*58b9f456SAndroid Build Coastguard Worker};
5376*58b9f456SAndroid Build Coastguard Worker
5377*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5378*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5379*58b9f456SAndroid Build Coastguard Worker{
5380*58b9f456SAndroid Build Coastguard Worker    typedef shared_ptr<_Tp>      argument_type;
5381*58b9f456SAndroid Build Coastguard Worker    typedef size_t               result_type;
5382*58b9f456SAndroid Build Coastguard Worker
5383*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5384*58b9f456SAndroid Build Coastguard Worker    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5385*58b9f456SAndroid Build Coastguard Worker    {
5386*58b9f456SAndroid Build Coastguard Worker        return hash<_Tp*>()(__ptr.get());
5387*58b9f456SAndroid Build Coastguard Worker    }
5388*58b9f456SAndroid Build Coastguard Worker};
5389*58b9f456SAndroid Build Coastguard Worker
5390*58b9f456SAndroid Build Coastguard Workertemplate<class _CharT, class _Traits, class _Yp>
5391*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5392*58b9f456SAndroid Build Coastguard Workerbasic_ostream<_CharT, _Traits>&
5393*58b9f456SAndroid Build Coastguard Workeroperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5394*58b9f456SAndroid Build Coastguard Worker
5395*58b9f456SAndroid Build Coastguard Worker
5396*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5397*58b9f456SAndroid Build Coastguard Worker
5398*58b9f456SAndroid Build Coastguard Workerclass _LIBCPP_TYPE_VIS __sp_mut
5399*58b9f456SAndroid Build Coastguard Worker{
5400*58b9f456SAndroid Build Coastguard Worker    void* __lx;
5401*58b9f456SAndroid Build Coastguard Workerpublic:
5402*58b9f456SAndroid Build Coastguard Worker    void lock() _NOEXCEPT;
5403*58b9f456SAndroid Build Coastguard Worker    void unlock() _NOEXCEPT;
5404*58b9f456SAndroid Build Coastguard Worker
5405*58b9f456SAndroid Build Coastguard Workerprivate:
5406*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5407*58b9f456SAndroid Build Coastguard Worker    __sp_mut(const __sp_mut&);
5408*58b9f456SAndroid Build Coastguard Worker    __sp_mut& operator=(const __sp_mut&);
5409*58b9f456SAndroid Build Coastguard Worker
5410*58b9f456SAndroid Build Coastguard Worker    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5411*58b9f456SAndroid Build Coastguard Worker};
5412*58b9f456SAndroid Build Coastguard Worker
5413*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5414*58b9f456SAndroid Build Coastguard Worker__sp_mut& __get_sp_mut(const void*);
5415*58b9f456SAndroid Build Coastguard Worker
5416*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5417*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5418*58b9f456SAndroid Build Coastguard Workerbool
5419*58b9f456SAndroid Build Coastguard Workeratomic_is_lock_free(const shared_ptr<_Tp>*)
5420*58b9f456SAndroid Build Coastguard Worker{
5421*58b9f456SAndroid Build Coastguard Worker    return false;
5422*58b9f456SAndroid Build Coastguard Worker}
5423*58b9f456SAndroid Build Coastguard Worker
5424*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5425*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5426*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
5427*58b9f456SAndroid Build Coastguard Workeratomic_load(const shared_ptr<_Tp>* __p)
5428*58b9f456SAndroid Build Coastguard Worker{
5429*58b9f456SAndroid Build Coastguard Worker    __sp_mut& __m = __get_sp_mut(__p);
5430*58b9f456SAndroid Build Coastguard Worker    __m.lock();
5431*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __q = *__p;
5432*58b9f456SAndroid Build Coastguard Worker    __m.unlock();
5433*58b9f456SAndroid Build Coastguard Worker    return __q;
5434*58b9f456SAndroid Build Coastguard Worker}
5435*58b9f456SAndroid Build Coastguard Worker
5436*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5437*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5438*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5439*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
5440*58b9f456SAndroid Build Coastguard Workeratomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5441*58b9f456SAndroid Build Coastguard Worker{
5442*58b9f456SAndroid Build Coastguard Worker    return atomic_load(__p);
5443*58b9f456SAndroid Build Coastguard Worker}
5444*58b9f456SAndroid Build Coastguard Worker
5445*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5446*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5447*58b9f456SAndroid Build Coastguard Workervoid
5448*58b9f456SAndroid Build Coastguard Workeratomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5449*58b9f456SAndroid Build Coastguard Worker{
5450*58b9f456SAndroid Build Coastguard Worker    __sp_mut& __m = __get_sp_mut(__p);
5451*58b9f456SAndroid Build Coastguard Worker    __m.lock();
5452*58b9f456SAndroid Build Coastguard Worker    __p->swap(__r);
5453*58b9f456SAndroid Build Coastguard Worker    __m.unlock();
5454*58b9f456SAndroid Build Coastguard Worker}
5455*58b9f456SAndroid Build Coastguard Worker
5456*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5457*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5458*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5459*58b9f456SAndroid Build Coastguard Workervoid
5460*58b9f456SAndroid Build Coastguard Workeratomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5461*58b9f456SAndroid Build Coastguard Worker{
5462*58b9f456SAndroid Build Coastguard Worker    atomic_store(__p, __r);
5463*58b9f456SAndroid Build Coastguard Worker}
5464*58b9f456SAndroid Build Coastguard Worker
5465*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5466*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5467*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
5468*58b9f456SAndroid Build Coastguard Workeratomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5469*58b9f456SAndroid Build Coastguard Worker{
5470*58b9f456SAndroid Build Coastguard Worker    __sp_mut& __m = __get_sp_mut(__p);
5471*58b9f456SAndroid Build Coastguard Worker    __m.lock();
5472*58b9f456SAndroid Build Coastguard Worker    __p->swap(__r);
5473*58b9f456SAndroid Build Coastguard Worker    __m.unlock();
5474*58b9f456SAndroid Build Coastguard Worker    return __r;
5475*58b9f456SAndroid Build Coastguard Worker}
5476*58b9f456SAndroid Build Coastguard Worker
5477*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5478*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5479*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5480*58b9f456SAndroid Build Coastguard Workershared_ptr<_Tp>
5481*58b9f456SAndroid Build Coastguard Workeratomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5482*58b9f456SAndroid Build Coastguard Worker{
5483*58b9f456SAndroid Build Coastguard Worker    return atomic_exchange(__p, __r);
5484*58b9f456SAndroid Build Coastguard Worker}
5485*58b9f456SAndroid Build Coastguard Worker
5486*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5487*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5488*58b9f456SAndroid Build Coastguard Workerbool
5489*58b9f456SAndroid Build Coastguard Workeratomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5490*58b9f456SAndroid Build Coastguard Worker{
5491*58b9f456SAndroid Build Coastguard Worker    shared_ptr<_Tp> __temp;
5492*58b9f456SAndroid Build Coastguard Worker    __sp_mut& __m = __get_sp_mut(__p);
5493*58b9f456SAndroid Build Coastguard Worker    __m.lock();
5494*58b9f456SAndroid Build Coastguard Worker    if (__p->__owner_equivalent(*__v))
5495*58b9f456SAndroid Build Coastguard Worker    {
5496*58b9f456SAndroid Build Coastguard Worker        _VSTD::swap(__temp, *__p);
5497*58b9f456SAndroid Build Coastguard Worker        *__p = __w;
5498*58b9f456SAndroid Build Coastguard Worker        __m.unlock();
5499*58b9f456SAndroid Build Coastguard Worker        return true;
5500*58b9f456SAndroid Build Coastguard Worker    }
5501*58b9f456SAndroid Build Coastguard Worker    _VSTD::swap(__temp, *__v);
5502*58b9f456SAndroid Build Coastguard Worker    *__v = *__p;
5503*58b9f456SAndroid Build Coastguard Worker    __m.unlock();
5504*58b9f456SAndroid Build Coastguard Worker    return false;
5505*58b9f456SAndroid Build Coastguard Worker}
5506*58b9f456SAndroid Build Coastguard Worker
5507*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5508*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5509*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5510*58b9f456SAndroid Build Coastguard Workerbool
5511*58b9f456SAndroid Build Coastguard Workeratomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5512*58b9f456SAndroid Build Coastguard Worker{
5513*58b9f456SAndroid Build Coastguard Worker    return atomic_compare_exchange_strong(__p, __v, __w);
5514*58b9f456SAndroid Build Coastguard Worker}
5515*58b9f456SAndroid Build Coastguard Worker
5516*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5517*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5518*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5519*58b9f456SAndroid Build Coastguard Workerbool
5520*58b9f456SAndroid Build Coastguard Workeratomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5521*58b9f456SAndroid Build Coastguard Worker                                        shared_ptr<_Tp> __w, memory_order, memory_order)
5522*58b9f456SAndroid Build Coastguard Worker{
5523*58b9f456SAndroid Build Coastguard Worker    return atomic_compare_exchange_strong(__p, __v, __w);
5524*58b9f456SAndroid Build Coastguard Worker}
5525*58b9f456SAndroid Build Coastguard Worker
5526*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5527*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5528*58b9f456SAndroid Build Coastguard Worker_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5529*58b9f456SAndroid Build Coastguard Workerbool
5530*58b9f456SAndroid Build Coastguard Workeratomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5531*58b9f456SAndroid Build Coastguard Worker                                      shared_ptr<_Tp> __w, memory_order, memory_order)
5532*58b9f456SAndroid Build Coastguard Worker{
5533*58b9f456SAndroid Build Coastguard Worker    return atomic_compare_exchange_weak(__p, __v, __w);
5534*58b9f456SAndroid Build Coastguard Worker}
5535*58b9f456SAndroid Build Coastguard Worker
5536*58b9f456SAndroid Build Coastguard Worker#endif  // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5537*58b9f456SAndroid Build Coastguard Worker
5538*58b9f456SAndroid Build Coastguard Worker//enum class
5539*58b9f456SAndroid Build Coastguard Worker#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5540*58b9f456SAndroid Build Coastguard Worker# ifndef _LIBCPP_CXX03_LANG
5541*58b9f456SAndroid Build Coastguard Workerenum class pointer_safety : unsigned char {
5542*58b9f456SAndroid Build Coastguard Worker  relaxed,
5543*58b9f456SAndroid Build Coastguard Worker  preferred,
5544*58b9f456SAndroid Build Coastguard Worker  strict
5545*58b9f456SAndroid Build Coastguard Worker};
5546*58b9f456SAndroid Build Coastguard Worker# endif
5547*58b9f456SAndroid Build Coastguard Worker#else
5548*58b9f456SAndroid Build Coastguard Workerstruct _LIBCPP_TYPE_VIS pointer_safety
5549*58b9f456SAndroid Build Coastguard Worker{
5550*58b9f456SAndroid Build Coastguard Worker    enum __lx
5551*58b9f456SAndroid Build Coastguard Worker    {
5552*58b9f456SAndroid Build Coastguard Worker        relaxed,
5553*58b9f456SAndroid Build Coastguard Worker        preferred,
5554*58b9f456SAndroid Build Coastguard Worker        strict
5555*58b9f456SAndroid Build Coastguard Worker    };
5556*58b9f456SAndroid Build Coastguard Worker
5557*58b9f456SAndroid Build Coastguard Worker    __lx __v_;
5558*58b9f456SAndroid Build Coastguard Worker
5559*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5560*58b9f456SAndroid Build Coastguard Worker    pointer_safety() : __v_() {}
5561*58b9f456SAndroid Build Coastguard Worker
5562*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5563*58b9f456SAndroid Build Coastguard Worker    pointer_safety(__lx __v) : __v_(__v) {}
5564*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_INLINE_VISIBILITY
5565*58b9f456SAndroid Build Coastguard Worker    operator int() const {return __v_;}
5566*58b9f456SAndroid Build Coastguard Worker};
5567*58b9f456SAndroid Build Coastguard Worker#endif
5568*58b9f456SAndroid Build Coastguard Worker
5569*58b9f456SAndroid Build Coastguard Worker#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5570*58b9f456SAndroid Build Coastguard Worker    defined(_LIBCPP_BUILDING_LIBRARY)
5571*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5572*58b9f456SAndroid Build Coastguard Worker#else
5573*58b9f456SAndroid Build Coastguard Worker// This function is only offered in C++03 under ABI v1.
5574*58b9f456SAndroid Build Coastguard Worker# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5575*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5576*58b9f456SAndroid Build Coastguard Workerpointer_safety get_pointer_safety() _NOEXCEPT {
5577*58b9f456SAndroid Build Coastguard Worker  return pointer_safety::relaxed;
5578*58b9f456SAndroid Build Coastguard Worker}
5579*58b9f456SAndroid Build Coastguard Worker# endif
5580*58b9f456SAndroid Build Coastguard Worker#endif
5581*58b9f456SAndroid Build Coastguard Worker
5582*58b9f456SAndroid Build Coastguard Worker
5583*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5584*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5585*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5586*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5587*58b9f456SAndroid Build Coastguard Worker
5588*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp>
5589*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5590*58b9f456SAndroid Build Coastguard Worker_Tp*
5591*58b9f456SAndroid Build Coastguard Workerundeclare_reachable(_Tp* __p)
5592*58b9f456SAndroid Build Coastguard Worker{
5593*58b9f456SAndroid Build Coastguard Worker    return static_cast<_Tp*>(__undeclare_reachable(__p));
5594*58b9f456SAndroid Build Coastguard Worker}
5595*58b9f456SAndroid Build Coastguard Worker
5596*58b9f456SAndroid Build Coastguard Worker_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5597*58b9f456SAndroid Build Coastguard Worker
5598*58b9f456SAndroid Build Coastguard Worker// --- Helper for container swap --
5599*58b9f456SAndroid Build Coastguard Workertemplate <typename _Alloc>
5600*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5601*58b9f456SAndroid Build Coastguard Workervoid __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5602*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER >= 14
5603*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT
5604*58b9f456SAndroid Build Coastguard Worker#else
5605*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5606*58b9f456SAndroid Build Coastguard Worker#endif
5607*58b9f456SAndroid Build Coastguard Worker{
5608*58b9f456SAndroid Build Coastguard Worker    __swap_allocator(__a1, __a2,
5609*58b9f456SAndroid Build Coastguard Worker      integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5610*58b9f456SAndroid Build Coastguard Worker}
5611*58b9f456SAndroid Build Coastguard Worker
5612*58b9f456SAndroid Build Coastguard Workertemplate <typename _Alloc>
5613*58b9f456SAndroid Build Coastguard Worker_LIBCPP_INLINE_VISIBILITY
5614*58b9f456SAndroid Build Coastguard Workervoid __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5615*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER >= 14
5616*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT
5617*58b9f456SAndroid Build Coastguard Worker#else
5618*58b9f456SAndroid Build Coastguard Worker    _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5619*58b9f456SAndroid Build Coastguard Worker#endif
5620*58b9f456SAndroid Build Coastguard Worker{
5621*58b9f456SAndroid Build Coastguard Worker    using _VSTD::swap;
5622*58b9f456SAndroid Build Coastguard Worker    swap(__a1, __a2);
5623*58b9f456SAndroid Build Coastguard Worker}
5624*58b9f456SAndroid Build Coastguard Worker
5625*58b9f456SAndroid Build Coastguard Workertemplate <typename _Alloc>
5626*58b9f456SAndroid Build Coastguard Workerinline _LIBCPP_INLINE_VISIBILITY
5627*58b9f456SAndroid Build Coastguard Workervoid __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5628*58b9f456SAndroid Build Coastguard Worker
5629*58b9f456SAndroid Build Coastguard Workertemplate <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5630*58b9f456SAndroid Build Coastguard Workerstruct __noexcept_move_assign_container : public integral_constant<bool,
5631*58b9f456SAndroid Build Coastguard Worker    _Traits::propagate_on_container_move_assignment::value
5632*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 14
5633*58b9f456SAndroid Build Coastguard Worker        || _Traits::is_always_equal::value
5634*58b9f456SAndroid Build Coastguard Worker#else
5635*58b9f456SAndroid Build Coastguard Worker        && is_nothrow_move_assignable<_Alloc>::value
5636*58b9f456SAndroid Build Coastguard Worker#endif
5637*58b9f456SAndroid Build Coastguard Worker    > {};
5638*58b9f456SAndroid Build Coastguard Worker
5639*58b9f456SAndroid Build Coastguard Worker
5640*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_HAS_NO_VARIADICS
5641*58b9f456SAndroid Build Coastguard Workertemplate <class _Tp, class _Alloc>
5642*58b9f456SAndroid Build Coastguard Workerstruct __temp_value {
5643*58b9f456SAndroid Build Coastguard Worker    typedef allocator_traits<_Alloc> _Traits;
5644*58b9f456SAndroid Build Coastguard Worker
5645*58b9f456SAndroid Build Coastguard Worker    typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5646*58b9f456SAndroid Build Coastguard Worker    _Alloc &__a;
5647*58b9f456SAndroid Build Coastguard Worker
5648*58b9f456SAndroid Build Coastguard Worker    _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5649*58b9f456SAndroid Build Coastguard Worker    _Tp &   get() { return *__addr(); }
5650*58b9f456SAndroid Build Coastguard Worker
5651*58b9f456SAndroid Build Coastguard Worker    template<class... _Args>
5652*58b9f456SAndroid Build Coastguard Worker    _LIBCPP_NO_CFI
5653*58b9f456SAndroid Build Coastguard Worker    __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
5654*58b9f456SAndroid Build Coastguard Worker      _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
5655*58b9f456SAndroid Build Coastguard Worker                         _VSTD::forward<_Args>(__args)...);
5656*58b9f456SAndroid Build Coastguard Worker    }
5657*58b9f456SAndroid Build Coastguard Worker
5658*58b9f456SAndroid Build Coastguard Worker    ~__temp_value() { _Traits::destroy(__a, __addr()); }
5659*58b9f456SAndroid Build Coastguard Worker    };
5660*58b9f456SAndroid Build Coastguard Worker#endif
5661*58b9f456SAndroid Build Coastguard Worker
5662*58b9f456SAndroid Build Coastguard Workertemplate<typename _Alloc, typename = void, typename = void>
5663*58b9f456SAndroid Build Coastguard Workerstruct __is_allocator : false_type {};
5664*58b9f456SAndroid Build Coastguard Worker
5665*58b9f456SAndroid Build Coastguard Workertemplate<typename _Alloc>
5666*58b9f456SAndroid Build Coastguard Workerstruct __is_allocator<_Alloc,
5667*58b9f456SAndroid Build Coastguard Worker       typename __void_t<typename _Alloc::value_type>::type,
5668*58b9f456SAndroid Build Coastguard Worker       typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
5669*58b9f456SAndroid Build Coastguard Worker     >
5670*58b9f456SAndroid Build Coastguard Worker   : true_type {};
5671*58b9f456SAndroid Build Coastguard Worker
5672*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_STD
5673*58b9f456SAndroid Build Coastguard Worker
5674*58b9f456SAndroid Build Coastguard Worker_LIBCPP_POP_MACROS
5675*58b9f456SAndroid Build Coastguard Worker
5676*58b9f456SAndroid Build Coastguard Worker#endif  // _LIBCPP_MEMORY
5677