memory revision 253159
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===-------------------------- memory ------------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_MEMORY
12227825Stheraven#define _LIBCPP_MEMORY
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    memory synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheravenstruct allocator_arg_t { };
21227825Stheravenconstexpr allocator_arg_t allocator_arg = allocator_arg_t();
22227825Stheraven
23227825Stheraventemplate <class T, class Alloc> struct uses_allocator;
24227825Stheraven
25227825Stheraventemplate <class Ptr>
26227825Stheravenstruct pointer_traits
27227825Stheraven{
28227825Stheraven    typedef Ptr pointer;
29227825Stheraven    typedef <details> element_type;
30227825Stheraven    typedef <details> difference_type;
31227825Stheraven
32227825Stheraven    template <class U> using rebind = <details>;
33227825Stheraven
34227825Stheraven    static pointer pointer_to(<details>);
35227825Stheraven};
36227825Stheraven
37227825Stheraventemplate <class T>
38227825Stheravenstruct pointer_traits<T*>
39227825Stheraven{
40227825Stheraven    typedef T* pointer;
41227825Stheraven    typedef T element_type;
42227825Stheraven    typedef ptrdiff_t difference_type;
43227825Stheraven
44227825Stheraven    template <class U> using rebind = U*;
45227825Stheraven
46227825Stheraven    static pointer pointer_to(<details>) noexcept;
47227825Stheraven};
48227825Stheraven
49227825Stheraventemplate <class Alloc>
50227825Stheravenstruct allocator_traits
51227825Stheraven{
52227825Stheraven    typedef Alloc                        allocator_type;
53227825Stheraven    typedef typename allocator_type::value_type
54227825Stheraven                                         value_type;
55227825Stheraven
56227825Stheraven    typedef Alloc::pointer | value_type* pointer;
57227825Stheraven    typedef Alloc::const_pointer
58227825Stheraven          | pointer_traits<pointer>::rebind<const value_type>
59227825Stheraven                                         const_pointer;
60227825Stheraven    typedef Alloc::void_pointer
61227825Stheraven          | pointer_traits<pointer>::rebind<void>
62227825Stheraven                                         void_pointer;
63227825Stheraven    typedef Alloc::const_void_pointer
64227825Stheraven          | pointer_traits<pointer>::rebind<const void>
65227825Stheraven                                         const_void_pointer;
66227825Stheraven    typedef Alloc::difference_type
67227825Stheraven          | pointer_traits<pointer>::difference_type
68227825Stheraven                                         difference_type;
69227825Stheraven    typedef Alloc::size_type
70227825Stheraven          | make_unsigned<difference_type>::type
71227825Stheraven                                         size_type;
72227825Stheraven    typedef Alloc::propagate_on_container_copy_assignment
73227825Stheraven          | false_type                   propagate_on_container_copy_assignment;
74227825Stheraven    typedef Alloc::propagate_on_container_move_assignment
75227825Stheraven          | false_type                   propagate_on_container_move_assignment;
76227825Stheraven    typedef Alloc::propagate_on_container_swap
77227825Stheraven          | false_type                   propagate_on_container_swap;
78227825Stheraven
79227825Stheraven    template <class T> using rebind_alloc  = Alloc::rebind<U>::other | Alloc<T, Args...>;
80227825Stheraven    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
81227825Stheraven
82227825Stheraven    static pointer allocate(allocator_type& a, size_type n);
83227825Stheraven    static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
84227825Stheraven
85227825Stheraven    static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
86227825Stheraven
87227825Stheraven    template <class T, class... Args>
88227825Stheraven        static void construct(allocator_type& a, T* p, Args&&... args);
89227825Stheraven
90227825Stheraven    template <class T>
91227825Stheraven        static void destroy(allocator_type& a, T* p);
92227825Stheraven
93227825Stheraven    static size_type max_size(const allocator_type& a);
94227825Stheraven
95227825Stheraven    static allocator_type
96227825Stheraven        select_on_container_copy_construction(const allocator_type& a);
97227825Stheraven};
98227825Stheraven
99227825Stheraventemplate <>
100227825Stheravenclass allocator<void>
101227825Stheraven{
102227825Stheravenpublic:
103227825Stheraven    typedef void*                                 pointer;
104227825Stheraven    typedef const void*                           const_pointer;
105227825Stheraven    typedef void                                  value_type;
106227825Stheraven
107227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
108227825Stheraven};
109227825Stheraven
110227825Stheraventemplate <class T>
111227825Stheravenclass allocator
112227825Stheraven{
113227825Stheravenpublic:
114227825Stheraven    typedef size_t                                size_type;
115227825Stheraven    typedef ptrdiff_t                             difference_type;
116227825Stheraven    typedef T*                                    pointer;
117227825Stheraven    typedef const T*                              const_pointer;
118227825Stheraven    typedef typename add_lvalue_reference<T>::type       reference;
119227825Stheraven    typedef typename add_lvalue_reference<const T>::type const_reference;
120227825Stheraven    typedef T                                     value_type;
121227825Stheraven
122227825Stheraven    template <class U> struct rebind {typedef allocator<U> other;};
123227825Stheraven
124227825Stheraven    allocator() noexcept;
125227825Stheraven    allocator(const allocator&) noexcept;
126227825Stheraven    template <class U> allocator(const allocator<U>&) noexcept;
127227825Stheraven    ~allocator();
128227825Stheraven    pointer address(reference x) const noexcept;
129227825Stheraven    const_pointer address(const_reference x) const noexcept;
130227825Stheraven    pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
131227825Stheraven    void deallocate(pointer p, size_type n) noexcept;
132227825Stheraven    size_type max_size() const noexcept;
133227825Stheraven    template<class U, class... Args>
134227825Stheraven        void construct(U* p, Args&&... args);
135227825Stheraven    template <class U>
136227825Stheraven        void destroy(U* p);
137227825Stheraven};
138227825Stheraven
139227825Stheraventemplate <class T, class U>
140227825Stheravenbool operator==(const allocator<T>&, const allocator<U>&) noexcept;
141227825Stheraven
142227825Stheraventemplate <class T, class U>
143227825Stheravenbool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
144227825Stheraven
145227825Stheraventemplate <class OutputIterator, class T>
146227825Stheravenclass raw_storage_iterator
147227825Stheraven    : public iterator<output_iterator_tag,
148227825Stheraven                      T,                               // purposefully not C++03
149227825Stheraven                      ptrdiff_t,                       // purposefully not C++03
150227825Stheraven                      T*,                              // purposefully not C++03
151227825Stheraven                      raw_storage_iterator&>           // purposefully not C++03
152227825Stheraven{
153227825Stheravenpublic:
154227825Stheraven    explicit raw_storage_iterator(OutputIterator x);
155227825Stheraven    raw_storage_iterator& operator*();
156227825Stheraven    raw_storage_iterator& operator=(const T& element);
157227825Stheraven    raw_storage_iterator& operator++();
158227825Stheraven    raw_storage_iterator  operator++(int);
159227825Stheraven};
160227825Stheraven
161227825Stheraventemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162227825Stheraventemplate <class T> void               return_temporary_buffer(T* p) noexcept;
163227825Stheraven
164227825Stheraventemplate <class T> T* addressof(T& r) noexcept;
165227825Stheraven
166227825Stheraventemplate <class InputIterator, class ForwardIterator>
167227825StheravenForwardIterator
168227825Stheravenuninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
169227825Stheraven
170227825Stheraventemplate <class InputIterator, class Size, class ForwardIterator>
171227825StheravenForwardIterator
172227825Stheravenuninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
173227825Stheraven
174227825Stheraventemplate <class ForwardIterator, class T>
175227825Stheravenvoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
176227825Stheraven
177227825Stheraventemplate <class ForwardIterator, class Size, class T>
178227825StheravenForwardIterator
179227825Stheravenuninitialized_fill_n(ForwardIterator first, Size n, const T& x);
180227825Stheraven
181227825Stheraventemplate <class Y> struct auto_ptr_ref {};
182227825Stheraven
183227825Stheraventemplate<class X>
184227825Stheravenclass auto_ptr
185227825Stheraven{
186227825Stheravenpublic:
187227825Stheraven    typedef X element_type;
188227825Stheraven
189227825Stheraven    explicit auto_ptr(X* p =0) throw();
190227825Stheraven    auto_ptr(auto_ptr&) throw();
191227825Stheraven    template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192227825Stheraven    auto_ptr& operator=(auto_ptr&) throw();
193227825Stheraven    template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194227825Stheraven    auto_ptr& operator=(auto_ptr_ref<X> r) throw();
195227825Stheraven    ~auto_ptr() throw();
196227825Stheraven
197227825Stheraven    typename add_lvalue_reference<X>::type operator*() const throw();
198227825Stheraven    X* operator->() const throw();
199227825Stheraven    X* get() const throw();
200227825Stheraven    X* release() throw();
201227825Stheraven    void reset(X* p =0) throw();
202227825Stheraven
203227825Stheraven    auto_ptr(auto_ptr_ref<X>) throw();
204227825Stheraven    template<class Y> operator auto_ptr_ref<Y>() throw();
205227825Stheraven    template<class Y> operator auto_ptr<Y>() throw();
206227825Stheraven};
207227825Stheraven
208227825Stheraventemplate <class T>
209227825Stheravenstruct default_delete
210227825Stheraven{
211227825Stheraven    constexpr default_delete() noexcept = default;
212227825Stheraven    template <class U> default_delete(const default_delete<U>&) noexcept;
213227825Stheraven
214227825Stheraven    void operator()(T*) const noexcept;
215227825Stheraven};
216227825Stheraven
217227825Stheraventemplate <class T>
218227825Stheravenstruct default_delete<T[]>
219227825Stheraven{
220227825Stheraven    constexpr default_delete() noexcept = default;
221227825Stheraven    void operator()(T*) const noexcept;
222227825Stheraven    template <class U> void operator()(U*) const = delete;
223227825Stheraven};
224227825Stheraven
225227825Stheraventemplate <class T, class D = default_delete<T>>
226227825Stheravenclass unique_ptr
227227825Stheraven{
228227825Stheravenpublic:
229227825Stheraven    typedef see below pointer;
230227825Stheraven    typedef T element_type;
231227825Stheraven    typedef D deleter_type;
232227825Stheraven
233227825Stheraven    // constructors
234227825Stheraven    constexpr unique_ptr() noexcept;
235227825Stheraven    explicit unique_ptr(pointer p) noexcept;
236227825Stheraven    unique_ptr(pointer p, see below d1) noexcept;
237227825Stheraven    unique_ptr(pointer p, see below d2) noexcept;
238227825Stheraven    unique_ptr(unique_ptr&& u) noexcept;
239227825Stheraven    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
240227825Stheraven    template <class U, class E>
241227825Stheraven        unique_ptr(unique_ptr<U, E>&& u) noexcept;
242227825Stheraven    template <class U>
243227825Stheraven        unique_ptr(auto_ptr<U>&& u) noexcept;
244227825Stheraven
245227825Stheraven    // destructor
246227825Stheraven    ~unique_ptr();
247227825Stheraven
248227825Stheraven    // assignment
249227825Stheraven    unique_ptr& operator=(unique_ptr&& u) noexcept;
250227825Stheraven    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251227825Stheraven    unique_ptr& operator=(nullptr_t) noexcept;
252227825Stheraven
253227825Stheraven    // observers
254227825Stheraven    typename add_lvalue_reference<T>::type operator*() const;
255227825Stheraven    pointer operator->() const noexcept;
256227825Stheraven    pointer get() const noexcept;
257227825Stheraven    deleter_type& get_deleter() noexcept;
258227825Stheraven    const deleter_type& get_deleter() const noexcept;
259227825Stheraven    explicit operator bool() const noexcept;
260227825Stheraven
261227825Stheraven    // modifiers
262227825Stheraven    pointer release() noexcept;
263227825Stheraven    void reset(pointer p = pointer()) noexcept;
264227825Stheraven    void swap(unique_ptr& u) noexcept;
265227825Stheraven};
266227825Stheraven
267227825Stheraventemplate <class T, class D>
268227825Stheravenclass unique_ptr<T[], D>
269227825Stheraven{
270227825Stheravenpublic:
271227825Stheraven    typedef implementation-defined pointer;
272227825Stheraven    typedef T element_type;
273227825Stheraven    typedef D deleter_type;
274227825Stheraven
275227825Stheraven    // constructors
276227825Stheraven    constexpr unique_ptr() noexcept;
277227825Stheraven    explicit unique_ptr(pointer p) noexcept;
278227825Stheraven    unique_ptr(pointer p, see below d) noexcept;
279227825Stheraven    unique_ptr(pointer p, see below d) noexcept;
280227825Stheraven    unique_ptr(unique_ptr&& u) noexcept;
281227825Stheraven    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
282227825Stheraven
283227825Stheraven    // destructor
284227825Stheraven    ~unique_ptr();
285227825Stheraven
286227825Stheraven    // assignment
287227825Stheraven    unique_ptr& operator=(unique_ptr&& u) noexcept;
288227825Stheraven    unique_ptr& operator=(nullptr_t) noexcept;
289227825Stheraven
290227825Stheraven    // observers
291227825Stheraven    T& operator[](size_t i) const;
292227825Stheraven    pointer get() const noexcept;
293227825Stheraven    deleter_type& get_deleter() noexcept;
294227825Stheraven    const deleter_type& get_deleter() const noexcept;
295227825Stheraven    explicit operator bool() const noexcept;
296227825Stheraven
297227825Stheraven    // modifiers
298227825Stheraven    pointer release() noexcept;
299227825Stheraven    void reset(pointer p = pointer()) noexcept;
300227825Stheraven    void reset(nullptr_t) noexcept;
301227825Stheraven    template <class U> void reset(U) = delete;
302227825Stheraven    void swap(unique_ptr& u) noexcept;
303227825Stheraven};
304227825Stheraven
305227825Stheraventemplate <class T, class D>
306227825Stheraven    void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
307227825Stheraven
308227825Stheraventemplate <class T1, class D1, class T2, class D2>
309227825Stheraven    bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
310227825Stheraventemplate <class T1, class D1, class T2, class D2>
311227825Stheraven    bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312227825Stheraventemplate <class T1, class D1, class T2, class D2>
313227825Stheraven    bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314227825Stheraventemplate <class T1, class D1, class T2, class D2>
315227825Stheraven    bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316227825Stheraventemplate <class T1, class D1, class T2, class D2>
317227825Stheraven    bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318227825Stheraventemplate <class T1, class D1, class T2, class D2>
319227825Stheraven    bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
320227825Stheraven
321227825Stheraventemplate <class T, class D>
322227825Stheraven    bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323227825Stheraventemplate <class T, class D>
324227825Stheraven    bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325227825Stheraventemplate <class T, class D>
326227825Stheraven    bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327227825Stheraventemplate <class T, class D>
328227825Stheraven    bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
329227825Stheraven
330227825Stheraventemplate <class T, class D>
331227825Stheraven    bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332227825Stheraventemplate <class T, class D>
333227825Stheraven    bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334227825Stheraventemplate <class T, class D>
335227825Stheraven    bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336227825Stheraventemplate <class T, class D>
337227825Stheraven    bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338227825Stheraventemplate <class T, class D>
339227825Stheraven    bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340227825Stheraventemplate <class T, class D>
341227825Stheraven    bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342227825Stheraventemplate <class T, class D>
343227825Stheraven    bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344227825Stheraventemplate <class T, class D>
345227825Stheraven    bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
346227825Stheraven
347227825Stheravenclass bad_weak_ptr
348227825Stheraven    : public std::exception
349227825Stheraven{
350227825Stheraven    bad_weak_ptr() noexcept;
351227825Stheraven};
352227825Stheraven
353253159Stheraventemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);     // C++14
354253159Stheraventemplate<class T>                unique_ptr<T> make_unique(size_t n);           // C++14
355253159Stheraventemplate<class T, class... Args> unspecified   make_unique(Args&&...) = delete; // C++14, T == U[N]
356253159Stheraven
357227825Stheraventemplate<class T>
358227825Stheravenclass shared_ptr
359227825Stheraven{
360227825Stheravenpublic:
361227825Stheraven    typedef T element_type;
362227825Stheraven
363227825Stheraven    // constructors:
364227825Stheraven    constexpr shared_ptr() noexcept;
365227825Stheraven    template<class Y> explicit shared_ptr(Y* p);
366227825Stheraven    template<class Y, class D> shared_ptr(Y* p, D d);
367227825Stheraven    template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
368227825Stheraven    template <class D> shared_ptr(nullptr_t p, D d);
369227825Stheraven    template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
370227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
371227825Stheraven    shared_ptr(const shared_ptr& r) noexcept;
372227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
373227825Stheraven    shared_ptr(shared_ptr&& r) noexcept;
374227825Stheraven    template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
375227825Stheraven    template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
376227825Stheraven    template<class Y> shared_ptr(auto_ptr<Y>&& r);
377227825Stheraven    template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
378227825Stheraven    shared_ptr(nullptr_t) : shared_ptr() { }
379227825Stheraven
380227825Stheraven    // destructor:
381227825Stheraven    ~shared_ptr();
382227825Stheraven
383227825Stheraven    // assignment:
384227825Stheraven    shared_ptr& operator=(const shared_ptr& r) noexcept;
385227825Stheraven    template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
386227825Stheraven    shared_ptr& operator=(shared_ptr&& r) noexcept;
387227825Stheraven    template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
388227825Stheraven    template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
389227825Stheraven    template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
390227825Stheraven
391227825Stheraven    // modifiers:
392227825Stheraven    void swap(shared_ptr& r) noexcept;
393227825Stheraven    void reset() noexcept;
394227825Stheraven    template<class Y> void reset(Y* p);
395227825Stheraven    template<class Y, class D> void reset(Y* p, D d);
396227825Stheraven    template<class Y, class D, class A> void reset(Y* p, D d, A a);
397227825Stheraven
398227825Stheraven    // observers:
399227825Stheraven    T* get() const noexcept;
400227825Stheraven    T& operator*() const noexcept;
401227825Stheraven    T* operator->() const noexcept;
402227825Stheraven    long use_count() const noexcept;
403227825Stheraven    bool unique() const noexcept;
404227825Stheraven    explicit operator bool() const noexcept;
405227825Stheraven    template<class U> bool owner_before(shared_ptr<U> const& b) const;
406227825Stheraven    template<class U> bool owner_before(weak_ptr<U> const& b) const;
407227825Stheraven};
408227825Stheraven
409227825Stheraven// shared_ptr comparisons:
410227825Stheraventemplate<class T, class U>
411227825Stheraven    bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
412227825Stheraventemplate<class T, class U>
413227825Stheraven    bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
414227825Stheraventemplate<class T, class U>
415227825Stheraven    bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
416227825Stheraventemplate<class T, class U>
417227825Stheraven    bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
418227825Stheraventemplate<class T, class U>
419227825Stheraven    bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
420227825Stheraventemplate<class T, class U>
421227825Stheraven    bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
422227825Stheraven
423227825Stheraventemplate <class T>
424227825Stheraven    bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
425227825Stheraventemplate <class T>
426227825Stheraven    bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
427227825Stheraventemplate <class T>
428227825Stheraven    bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
429227825Stheraventemplate <class T>
430227825Stheraven    bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
431227825Stheraventemplate <class T>
432227825Stheraven    bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
433227825Stheraventemplate <class T>
434227825Stheravenbool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
435227825Stheraventemplate <class T>
436227825Stheraven    bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
437227825Stheraventemplate <class T>
438227825Stheraven    bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
439227825Stheraventemplate <class T>
440227825Stheraven    bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
441227825Stheraventemplate <class T>
442227825Stheraven    bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
443227825Stheraventemplate <class T>
444227825Stheraven    bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
445227825Stheraventemplate <class T>
446227825Stheraven    bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
447227825Stheraven
448227825Stheraven// shared_ptr specialized algorithms:
449227825Stheraventemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
450227825Stheraven
451227825Stheraven// shared_ptr casts:
452227825Stheraventemplate<class T, class U>
453227825Stheraven    shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
454227825Stheraventemplate<class T, class U>
455227825Stheraven    shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
456227825Stheraventemplate<class T, class U>
457227825Stheraven    shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
458227825Stheraven
459227825Stheraven// shared_ptr I/O:
460227825Stheraventemplate<class E, class T, class Y>
461227825Stheraven    basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
462227825Stheraven
463227825Stheraven// shared_ptr get_deleter:
464227825Stheraventemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
465227825Stheraven
466227825Stheraventemplate<class T, class... Args>
467227825Stheraven    shared_ptr<T> make_shared(Args&&... args);
468227825Stheraventemplate<class T, class A, class... Args>
469227825Stheraven    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
470227825Stheraven
471227825Stheraventemplate<class T>
472227825Stheravenclass weak_ptr
473227825Stheraven{
474227825Stheravenpublic:
475227825Stheraven    typedef T element_type;
476227825Stheraven
477227825Stheraven    // constructors
478227825Stheraven    constexpr weak_ptr() noexcept;
479227825Stheraven    template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
480227825Stheraven    weak_ptr(weak_ptr const& r) noexcept;
481227825Stheraven    template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
482227825Stheraven
483227825Stheraven    // destructor
484227825Stheraven    ~weak_ptr();
485227825Stheraven
486227825Stheraven    // assignment
487227825Stheraven    weak_ptr& operator=(weak_ptr const& r) noexcept;
488227825Stheraven    template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
489227825Stheraven    template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
490227825Stheraven
491227825Stheraven    // modifiers
492227825Stheraven    void swap(weak_ptr& r) noexcept;
493227825Stheraven    void reset() noexcept;
494227825Stheraven
495227825Stheraven    // observers
496227825Stheraven    long use_count() const noexcept;
497227825Stheraven    bool expired() const noexcept;
498227825Stheraven    shared_ptr<T> lock() const noexcept;
499227825Stheraven    template<class U> bool owner_before(shared_ptr<U> const& b);
500227825Stheraven    template<class U> bool owner_before(weak_ptr<U> const& b);
501227825Stheraven};
502227825Stheraven
503227825Stheraven// weak_ptr specialized algorithms:
504227825Stheraventemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
505227825Stheraven
506227825Stheraven// class owner_less:
507227825Stheraventemplate<class T> struct owner_less;
508227825Stheraven
509227825Stheraventemplate<class T>
510227825Stheravenstruct owner_less<shared_ptr<T>>
511227825Stheraven    : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
512227825Stheraven{
513227825Stheraven    typedef bool result_type;
514227825Stheraven    bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
515227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
516227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
517227825Stheraven};
518227825Stheraven
519227825Stheraventemplate<class T>
520227825Stheravenstruct owner_less<weak_ptr<T>>
521227825Stheraven    : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
522227825Stheraven{
523227825Stheraven    typedef bool result_type;
524227825Stheraven    bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
525227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
526227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
527227825Stheraven};
528227825Stheraven
529227825Stheraventemplate<class T>
530227825Stheravenclass enable_shared_from_this
531227825Stheraven{
532227825Stheravenprotected:
533227825Stheraven    constexpr enable_shared_from_this() noexcept;
534227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) noexcept;
535227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
536227825Stheraven    ~enable_shared_from_this();
537227825Stheravenpublic:
538227825Stheraven    shared_ptr<T> shared_from_this();
539227825Stheraven    shared_ptr<T const> shared_from_this() const;
540227825Stheraven};
541227825Stheraven
542227825Stheraventemplate<class T>
543227825Stheraven    bool atomic_is_lock_free(const shared_ptr<T>* p);
544227825Stheraventemplate<class T>
545227825Stheraven    shared_ptr<T> atomic_load(const shared_ptr<T>* p);
546227825Stheraventemplate<class T>
547227825Stheraven    shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
548227825Stheraventemplate<class T>
549227825Stheraven    void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
550227825Stheraventemplate<class T>
551227825Stheraven    void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
552227825Stheraventemplate<class T>
553227825Stheraven    shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
554227825Stheraventemplate<class T>
555227825Stheraven    shared_ptr<T>
556227825Stheraven    atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
557227825Stheraventemplate<class T>
558227825Stheraven    bool
559227825Stheraven    atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
560227825Stheraventemplate<class T>
561227825Stheraven    bool
562227825Stheraven    atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
563227825Stheraventemplate<class T>
564227825Stheraven    bool
565227825Stheraven    atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
566227825Stheraven                                          shared_ptr<T> w, memory_order success,
567227825Stheraven                                          memory_order failure);
568227825Stheraventemplate<class T>
569227825Stheraven    bool
570227825Stheraven    atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
571227825Stheraven                                            shared_ptr<T> w, memory_order success,
572227825Stheraven                                            memory_order failure);
573227825Stheraven// Hash support
574227825Stheraventemplate <class T> struct hash;
575227825Stheraventemplate <class T, class D> struct hash<unique_ptr<T, D> >;
576227825Stheraventemplate <class T> struct hash<shared_ptr<T> >;
577227825Stheraven
578227825Stheraven// Pointer safety
579227825Stheravenenum class pointer_safety { relaxed, preferred, strict };
580227825Stheravenvoid declare_reachable(void *p);
581227825Stheraventemplate <class T> T *undeclare_reachable(T *p);
582227825Stheravenvoid declare_no_pointers(char *p, size_t n);
583227825Stheravenvoid undeclare_no_pointers(char *p, size_t n);
584227825Stheravenpointer_safety get_pointer_safety() noexcept;
585227825Stheraven
586227825Stheravenvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space);
587227825Stheraven
588227825Stheraven}  // std
589227825Stheraven
590227825Stheraven*/
591227825Stheraven
592227825Stheraven#include <__config>
593227825Stheraven#include <type_traits>
594227825Stheraven#include <typeinfo>
595227825Stheraven#include <cstddef>
596227825Stheraven#include <cstdint>
597227825Stheraven#include <new>
598227825Stheraven#include <utility>
599227825Stheraven#include <limits>
600227825Stheraven#include <iterator>
601227825Stheraven#include <__functional_base>
602227825Stheraven#include <iosfwd>
603232950Stheraven#include <tuple>
604232950Stheraven#include <cstring>
605227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS)
606227825Stheraven    #include <cassert>
607227825Stheraven#endif
608227825Stheraven
609241903Sdim#if __has_feature(cxx_atomic)
610241903Sdim#  include <atomic>
611241903Sdim#endif
612241903Sdim
613232950Stheraven#include <__undef_min_max>
614232950Stheraven
615227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
616227825Stheraven#pragma GCC system_header
617227825Stheraven#endif
618227825Stheraven
619227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
620227825Stheraven
621227825Stheraven// addressof
622227825Stheraven
623227825Stheraventemplate <class _Tp>
624227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
625227825Stheraven_Tp*
626227825Stheravenaddressof(_Tp& __x) _NOEXCEPT
627227825Stheraven{
628249998Sdim    return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
629227825Stheraven}
630227825Stheraven
631227825Stheraven#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
632227825Stheraven// Objective-C++ Automatic Reference Counting uses qualified pointers
633227825Stheraven// that require special addressof() signatures. When
634227825Stheraven// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
635227825Stheraven// itself is providing these definitions. Otherwise, we provide them.
636227825Stheraventemplate <class _Tp>
637227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
638227825Stheraven__strong _Tp*
639227825Stheravenaddressof(__strong _Tp& __x) _NOEXCEPT
640227825Stheraven{
641227825Stheraven  return &__x;
642227825Stheraven}
643227825Stheraven
644227825Stheraven#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
645227825Stheraventemplate <class _Tp>
646227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
647227825Stheraven__weak _Tp*
648227825Stheravenaddressof(__weak _Tp& __x) _NOEXCEPT
649227825Stheraven{
650227825Stheraven  return &__x;
651227825Stheraven}
652227825Stheraven#endif
653227825Stheraven
654227825Stheraventemplate <class _Tp>
655227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
656227825Stheraven__autoreleasing _Tp*
657227825Stheravenaddressof(__autoreleasing _Tp& __x) _NOEXCEPT
658227825Stheraven{
659227825Stheraven  return &__x;
660227825Stheraven}
661227825Stheraven
662227825Stheraventemplate <class _Tp>
663227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
664227825Stheraven__unsafe_unretained _Tp*
665227825Stheravenaddressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
666227825Stheraven{
667227825Stheraven  return &__x;
668227825Stheraven}
669227825Stheraven#endif
670227825Stheraven
671227825Stheraventemplate <class _Tp> class allocator;
672227825Stheraven
673227825Stheraventemplate <>
674249998Sdimclass _LIBCPP_TYPE_VIS allocator<void>
675227825Stheraven{
676227825Stheravenpublic:
677227825Stheraven    typedef void*             pointer;
678227825Stheraven    typedef const void*       const_pointer;
679227825Stheraven    typedef void              value_type;
680227825Stheraven
681227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
682227825Stheraven};
683227825Stheraven
684232950Stheraventemplate <>
685249998Sdimclass _LIBCPP_TYPE_VIS allocator<const void>
686232950Stheraven{
687232950Stheravenpublic:
688232950Stheraven    typedef const void*       pointer;
689232950Stheraven    typedef const void*       const_pointer;
690232950Stheraven    typedef const void        value_type;
691232950Stheraven
692232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
693232950Stheraven};
694232950Stheraven
695227825Stheraven// pointer_traits
696227825Stheraven
697227825Stheraventemplate <class _Tp>
698227825Stheravenstruct __has_element_type
699227825Stheraven{
700227825Stheravenprivate:
701242945Stheraven    struct __two {char __lx; char __lxx;};
702227825Stheraven    template <class _Up> static __two __test(...);
703227825Stheraven    template <class _Up> static char __test(typename _Up::element_type* = 0);
704227825Stheravenpublic:
705227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
706227825Stheraven};
707227825Stheraven
708227825Stheraventemplate <class _Ptr, bool = __has_element_type<_Ptr>::value>
709227825Stheravenstruct __pointer_traits_element_type;
710227825Stheraven
711227825Stheraventemplate <class _Ptr>
712227825Stheravenstruct __pointer_traits_element_type<_Ptr, true>
713227825Stheraven{
714227825Stheraven    typedef typename _Ptr::element_type type;
715227825Stheraven};
716227825Stheraven
717227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
718227825Stheraven
719227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
720227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
721227825Stheraven{
722227825Stheraven    typedef typename _Sp<_Tp, _Args...>::element_type type;
723227825Stheraven};
724227825Stheraven
725227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
726227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
727227825Stheraven{
728227825Stheraven    typedef _Tp type;
729227825Stheraven};
730227825Stheraven
731227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
732227825Stheraven
733227825Stheraventemplate <template <class> class _Sp, class _Tp>
734227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, true>
735227825Stheraven{
736227825Stheraven    typedef typename _Sp<_Tp>::element_type type;
737227825Stheraven};
738227825Stheraven
739227825Stheraventemplate <template <class> class _Sp, class _Tp>
740227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, false>
741227825Stheraven{
742227825Stheraven    typedef _Tp type;
743227825Stheraven};
744227825Stheraven
745227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
746227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
747227825Stheraven{
748227825Stheraven    typedef typename _Sp<_Tp, _A0>::element_type type;
749227825Stheraven};
750227825Stheraven
751227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
752227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
753227825Stheraven{
754227825Stheraven    typedef _Tp type;
755227825Stheraven};
756227825Stheraven
757227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
758227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
759227825Stheraven{
760227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
761227825Stheraven};
762227825Stheraven
763227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
764227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
765227825Stheraven{
766227825Stheraven    typedef _Tp type;
767227825Stheraven};
768227825Stheraven
769227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
770227825Stheraven                                                           class _A1, class _A2>
771227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
772227825Stheraven{
773227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
774227825Stheraven};
775227825Stheraven
776227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
777227825Stheraven                                                           class _A1, class _A2>
778227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
779227825Stheraven{
780227825Stheraven    typedef _Tp type;
781227825Stheraven};
782227825Stheraven
783227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
784227825Stheraven
785227825Stheraventemplate <class _Tp>
786227825Stheravenstruct __has_difference_type
787227825Stheraven{
788227825Stheravenprivate:
789242945Stheraven    struct __two {char __lx; char __lxx;};
790227825Stheraven    template <class _Up> static __two __test(...);
791227825Stheraven    template <class _Up> static char __test(typename _Up::difference_type* = 0);
792227825Stheravenpublic:
793227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
794227825Stheraven};
795227825Stheraven
796227825Stheraventemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value>
797227825Stheravenstruct __pointer_traits_difference_type
798227825Stheraven{
799227825Stheraven    typedef ptrdiff_t type;
800227825Stheraven};
801227825Stheraven
802227825Stheraventemplate <class _Ptr>
803227825Stheravenstruct __pointer_traits_difference_type<_Ptr, true>
804227825Stheraven{
805227825Stheraven    typedef typename _Ptr::difference_type type;
806227825Stheraven};
807227825Stheraven
808227825Stheraventemplate <class _Tp, class _Up>
809227825Stheravenstruct __has_rebind
810227825Stheraven{
811227825Stheravenprivate:
812242945Stheraven    struct __two {char __lx; char __lxx;};
813227825Stheraven    template <class _Xp> static __two __test(...);
814227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
815227825Stheravenpublic:
816227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
817227825Stheraven};
818227825Stheraven
819227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
820227825Stheravenstruct __pointer_traits_rebind
821227825Stheraven{
822227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
823227825Stheraven    typedef typename _Tp::template rebind<_Up> type;
824227825Stheraven#else
825227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
826227825Stheraven#endif
827227825Stheraven};
828227825Stheraven
829227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
830227825Stheraven
831227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
832227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
833227825Stheraven{
834227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
835227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
836227825Stheraven#else
837227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
838227825Stheraven#endif
839227825Stheraven};
840227825Stheraven
841227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
842227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
843227825Stheraven{
844227825Stheraven    typedef _Sp<_Up, _Args...> type;
845227825Stheraven};
846227825Stheraven
847227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
848227825Stheraven
849227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
850227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
851227825Stheraven{
852227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
853227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up> type;
854227825Stheraven#else
855227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
856227825Stheraven#endif
857227825Stheraven};
858227825Stheraven
859227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
860227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
861227825Stheraven{
862227825Stheraven    typedef _Sp<_Up> type;
863227825Stheraven};
864227825Stheraven
865227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
866227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
867227825Stheraven{
868227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
869227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
870227825Stheraven#else
871227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
872227825Stheraven#endif
873227825Stheraven};
874227825Stheraven
875227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
876227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
877227825Stheraven{
878227825Stheraven    typedef _Sp<_Up, _A0> type;
879227825Stheraven};
880227825Stheraven
881227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
882227825Stheraven                                         class _A1, class _Up>
883227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
884227825Stheraven{
885227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
886227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
887227825Stheraven#else
888227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
889227825Stheraven#endif
890227825Stheraven};
891227825Stheraven
892227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
893227825Stheraven                                         class _A1, class _Up>
894227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
895227825Stheraven{
896227825Stheraven    typedef _Sp<_Up, _A0, _A1> type;
897227825Stheraven};
898227825Stheraven
899227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
900227825Stheraven                                                class _A1, class _A2, class _Up>
901227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
902227825Stheraven{
903227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
904227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
905227825Stheraven#else
906227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
907227825Stheraven#endif
908227825Stheraven};
909227825Stheraven
910227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
911227825Stheraven                                                class _A1, class _A2, class _Up>
912227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
913227825Stheraven{
914227825Stheraven    typedef _Sp<_Up, _A0, _A1, _A2> type;
915227825Stheraven};
916227825Stheraven
917227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
918227825Stheraven
919227825Stheraventemplate <class _Ptr>
920249998Sdimstruct _LIBCPP_TYPE_VIS pointer_traits
921227825Stheraven{
922227825Stheraven    typedef _Ptr                                                     pointer;
923227825Stheraven    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
924227825Stheraven    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
925227825Stheraven
926227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
927227825Stheraven    template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
928227825Stheraven#else
929227825Stheraven    template <class _Up> struct rebind
930227825Stheraven        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
931227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
932227825Stheraven
933227825Stheravenprivate:
934227825Stheraven    struct __nat {};
935227825Stheravenpublic:
936227825Stheraven    _LIBCPP_INLINE_VISIBILITY
937227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
938227825Stheraven                                           __nat, element_type>::type& __r)
939227825Stheraven        {return pointer::pointer_to(__r);}
940227825Stheraven};
941227825Stheraven
942227825Stheraventemplate <class _Tp>
943249998Sdimstruct _LIBCPP_TYPE_VIS pointer_traits<_Tp*>
944227825Stheraven{
945227825Stheraven    typedef _Tp*      pointer;
946227825Stheraven    typedef _Tp       element_type;
947227825Stheraven    typedef ptrdiff_t difference_type;
948227825Stheraven
949227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
950227825Stheraven    template <class _Up> using rebind = _Up*;
951227825Stheraven#else
952227825Stheraven    template <class _Up> struct rebind {typedef _Up* other;};
953227825Stheraven#endif
954227825Stheraven
955227825Stheravenprivate:
956227825Stheraven    struct __nat {};
957227825Stheravenpublic:
958227825Stheraven    _LIBCPP_INLINE_VISIBILITY
959227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
960227825Stheraven                                      __nat, element_type>::type& __r) _NOEXCEPT
961227825Stheraven        {return _VSTD::addressof(__r);}
962227825Stheraven};
963227825Stheraven
964227825Stheraven// allocator_traits
965227825Stheraven
966227825Stheravennamespace __has_pointer_type_imp
967227825Stheraven{
968227825Stheraven    template <class _Up> static __two test(...);
969227825Stheraven    template <class _Up> static char test(typename _Up::pointer* = 0);
970227825Stheraven}
971227825Stheraven
972227825Stheraventemplate <class _Tp>
973227825Stheravenstruct __has_pointer_type
974227825Stheraven    : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
975227825Stheraven{
976227825Stheraven};
977227825Stheraven
978227825Stheravennamespace __pointer_type_imp
979227825Stheraven{
980227825Stheraven
981227825Stheraventemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
982227825Stheravenstruct __pointer_type
983227825Stheraven{
984227825Stheraven    typedef typename _Dp::pointer type;
985227825Stheraven};
986227825Stheraven
987227825Stheraventemplate <class _Tp, class _Dp>
988227825Stheravenstruct __pointer_type<_Tp, _Dp, false>
989227825Stheraven{
990227825Stheraven    typedef _Tp* type;
991227825Stheraven};
992227825Stheraven
993227825Stheraven}  // __pointer_type_imp
994227825Stheraven
995227825Stheraventemplate <class _Tp, class _Dp>
996227825Stheravenstruct __pointer_type
997227825Stheraven{
998227825Stheraven    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
999227825Stheraven};
1000227825Stheraven
1001227825Stheraventemplate <class _Tp>
1002227825Stheravenstruct __has_const_pointer
1003227825Stheraven{
1004227825Stheravenprivate:
1005242945Stheraven    struct __two {char __lx; char __lxx;};
1006227825Stheraven    template <class _Up> static __two __test(...);
1007227825Stheraven    template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1008227825Stheravenpublic:
1009227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1010227825Stheraven};
1011227825Stheraven
1012227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1013227825Stheravenstruct __const_pointer
1014227825Stheraven{
1015227825Stheraven    typedef typename _Alloc::const_pointer type;
1016227825Stheraven};
1017227825Stheraven
1018227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc>
1019227825Stheravenstruct __const_pointer<_Tp, _Ptr, _Alloc, false>
1020227825Stheraven{
1021227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1022227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1023227825Stheraven#else
1024227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1025227825Stheraven#endif
1026227825Stheraven};
1027227825Stheraven
1028227825Stheraventemplate <class _Tp>
1029227825Stheravenstruct __has_void_pointer
1030227825Stheraven{
1031227825Stheravenprivate:
1032242945Stheraven    struct __two {char __lx; char __lxx;};
1033227825Stheraven    template <class _Up> static __two __test(...);
1034227825Stheraven    template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1035227825Stheravenpublic:
1036227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1037227825Stheraven};
1038227825Stheraven
1039227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1040227825Stheravenstruct __void_pointer
1041227825Stheraven{
1042227825Stheraven    typedef typename _Alloc::void_pointer type;
1043227825Stheraven};
1044227825Stheraven
1045227825Stheraventemplate <class _Ptr, class _Alloc>
1046227825Stheravenstruct __void_pointer<_Ptr, _Alloc, false>
1047227825Stheraven{
1048227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1049227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1050227825Stheraven#else
1051227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1052227825Stheraven#endif
1053227825Stheraven};
1054227825Stheraven
1055227825Stheraventemplate <class _Tp>
1056227825Stheravenstruct __has_const_void_pointer
1057227825Stheraven{
1058227825Stheravenprivate:
1059242945Stheraven    struct __two {char __lx; char __lxx;};
1060227825Stheraven    template <class _Up> static __two __test(...);
1061227825Stheraven    template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1062227825Stheravenpublic:
1063227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1064227825Stheraven};
1065227825Stheraven
1066227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1067227825Stheravenstruct __const_void_pointer
1068227825Stheraven{
1069227825Stheraven    typedef typename _Alloc::const_void_pointer type;
1070227825Stheraven};
1071227825Stheraven
1072227825Stheraventemplate <class _Ptr, class _Alloc>
1073227825Stheravenstruct __const_void_pointer<_Ptr, _Alloc, false>
1074227825Stheraven{
1075227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1076227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1077227825Stheraven#else
1078227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1079227825Stheraven#endif
1080227825Stheraven};
1081227825Stheraven
1082232950Stheraventemplate <class _Tp>
1083227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1084232950Stheraven_Tp*
1085232950Stheraven__to_raw_pointer(_Tp* __p) _NOEXCEPT
1086227825Stheraven{
1087227825Stheraven    return __p;
1088227825Stheraven}
1089227825Stheraven
1090227825Stheraventemplate <class _Pointer>
1091227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1092227825Stheraventypename pointer_traits<_Pointer>::element_type*
1093227825Stheraven__to_raw_pointer(_Pointer __p) _NOEXCEPT
1094227825Stheraven{
1095227825Stheraven    return _VSTD::__to_raw_pointer(__p.operator->());
1096227825Stheraven}
1097227825Stheraven
1098227825Stheraventemplate <class _Tp>
1099227825Stheravenstruct __has_size_type
1100227825Stheraven{
1101227825Stheravenprivate:
1102242945Stheraven    struct __two {char __lx; char __lxx;};
1103227825Stheraven    template <class _Up> static __two __test(...);
1104227825Stheraven    template <class _Up> static char __test(typename _Up::size_type* = 0);
1105227825Stheravenpublic:
1106227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1107227825Stheraven};
1108227825Stheraven
1109227825Stheraventemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1110227825Stheravenstruct __size_type
1111227825Stheraven{
1112227825Stheraven    typedef typename make_unsigned<_DiffType>::type type;
1113227825Stheraven};
1114227825Stheraven
1115227825Stheraventemplate <class _Alloc, class _DiffType>
1116227825Stheravenstruct __size_type<_Alloc, _DiffType, true>
1117227825Stheraven{
1118227825Stheraven    typedef typename _Alloc::size_type type;
1119227825Stheraven};
1120227825Stheraven
1121227825Stheraventemplate <class _Tp>
1122227825Stheravenstruct __has_propagate_on_container_copy_assignment
1123227825Stheraven{
1124227825Stheravenprivate:
1125242945Stheraven    struct __two {char __lx; char __lxx;};
1126227825Stheraven    template <class _Up> static __two __test(...);
1127227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1128227825Stheravenpublic:
1129227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1130227825Stheraven};
1131227825Stheraven
1132227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1133227825Stheravenstruct __propagate_on_container_copy_assignment
1134227825Stheraven{
1135227825Stheraven    typedef false_type type;
1136227825Stheraven};
1137227825Stheraven
1138227825Stheraventemplate <class _Alloc>
1139227825Stheravenstruct __propagate_on_container_copy_assignment<_Alloc, true>
1140227825Stheraven{
1141227825Stheraven    typedef typename _Alloc::propagate_on_container_copy_assignment type;
1142227825Stheraven};
1143227825Stheraven
1144227825Stheraventemplate <class _Tp>
1145227825Stheravenstruct __has_propagate_on_container_move_assignment
1146227825Stheraven{
1147227825Stheravenprivate:
1148242945Stheraven    struct __two {char __lx; char __lxx;};
1149227825Stheraven    template <class _Up> static __two __test(...);
1150227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1151227825Stheravenpublic:
1152227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1153227825Stheraven};
1154227825Stheraven
1155227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1156227825Stheravenstruct __propagate_on_container_move_assignment
1157227825Stheraven{
1158227825Stheraven    typedef false_type type;
1159227825Stheraven};
1160227825Stheraven
1161227825Stheraventemplate <class _Alloc>
1162227825Stheravenstruct __propagate_on_container_move_assignment<_Alloc, true>
1163227825Stheraven{
1164227825Stheraven    typedef typename _Alloc::propagate_on_container_move_assignment type;
1165227825Stheraven};
1166227825Stheraven
1167227825Stheraventemplate <class _Tp>
1168227825Stheravenstruct __has_propagate_on_container_swap
1169227825Stheraven{
1170227825Stheravenprivate:
1171242945Stheraven    struct __two {char __lx; char __lxx;};
1172227825Stheraven    template <class _Up> static __two __test(...);
1173227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1174227825Stheravenpublic:
1175227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1176227825Stheraven};
1177227825Stheraven
1178227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1179227825Stheravenstruct __propagate_on_container_swap
1180227825Stheraven{
1181227825Stheraven    typedef false_type type;
1182227825Stheraven};
1183227825Stheraven
1184227825Stheraventemplate <class _Alloc>
1185227825Stheravenstruct __propagate_on_container_swap<_Alloc, true>
1186227825Stheraven{
1187227825Stheraven    typedef typename _Alloc::propagate_on_container_swap type;
1188227825Stheraven};
1189227825Stheraven
1190227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1191227825Stheravenstruct __has_rebind_other
1192227825Stheraven{
1193227825Stheravenprivate:
1194242945Stheraven    struct __two {char __lx; char __lxx;};
1195227825Stheraven    template <class _Xp> static __two __test(...);
1196227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1197227825Stheravenpublic:
1198227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1199227825Stheraven};
1200227825Stheraven
1201227825Stheraventemplate <class _Tp, class _Up>
1202227825Stheravenstruct __has_rebind_other<_Tp, _Up, false>
1203227825Stheraven{
1204227825Stheraven    static const bool value = false;
1205227825Stheraven};
1206227825Stheraven
1207227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1208227825Stheravenstruct __allocator_traits_rebind
1209227825Stheraven{
1210227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
1211227825Stheraven};
1212227825Stheraven
1213227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1214227825Stheraven
1215227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1216227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1217227825Stheraven{
1218227825Stheraven    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1219227825Stheraven};
1220227825Stheraven
1221227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1222227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1223227825Stheraven{
1224227825Stheraven    typedef _Alloc<_Up, _Args...> type;
1225227825Stheraven};
1226227825Stheraven
1227227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1228227825Stheraven
1229227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1230227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1231227825Stheraven{
1232227825Stheraven    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1233227825Stheraven};
1234227825Stheraven
1235227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1236227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1237227825Stheraven{
1238227825Stheraven    typedef _Alloc<_Up> type;
1239227825Stheraven};
1240227825Stheraven
1241227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1242227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1243227825Stheraven{
1244227825Stheraven    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1245227825Stheraven};
1246227825Stheraven
1247227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1248227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1249227825Stheraven{
1250227825Stheraven    typedef _Alloc<_Up, _A0> type;
1251227825Stheraven};
1252227825Stheraven
1253227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1254227825Stheraven                                         class _A1, class _Up>
1255227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1256227825Stheraven{
1257227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1258227825Stheraven};
1259227825Stheraven
1260227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1261227825Stheraven                                         class _A1, class _Up>
1262227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1263227825Stheraven{
1264227825Stheraven    typedef _Alloc<_Up, _A0, _A1> type;
1265227825Stheraven};
1266227825Stheraven
1267227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1268227825Stheraven                                                class _A1, class _A2, class _Up>
1269227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1270227825Stheraven{
1271227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1272227825Stheraven};
1273227825Stheraven
1274227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1275227825Stheraven                                                class _A1, class _A2, class _Up>
1276227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1277227825Stheraven{
1278227825Stheraven    typedef _Alloc<_Up, _A0, _A1, _A2> type;
1279227825Stheraven};
1280227825Stheraven
1281227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1282227825Stheraven
1283227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1284227825Stheraven
1285227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1286227825Stheravenauto
1287227825Stheraven__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1288227825Stheraven    -> decltype(__a.allocate(__sz, __p), true_type());
1289227825Stheraven
1290227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1291227825Stheravenauto
1292227825Stheraven__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1293227825Stheraven    -> false_type;
1294227825Stheraven
1295227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1296227825Stheravenstruct __has_allocate_hint
1297227825Stheraven    : integral_constant<bool,
1298227825Stheraven        is_same<
1299227825Stheraven            decltype(__has_allocate_hint_test(declval<_Alloc>(),
1300227825Stheraven                                          declval<_SizeType>(),
1301227825Stheraven                                          declval<_ConstVoidPtr>())),
1302227825Stheraven            true_type>::value>
1303227825Stheraven{
1304227825Stheraven};
1305227825Stheraven
1306227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1307227825Stheraven
1308227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1309227825Stheravenstruct __has_allocate_hint
1310227825Stheraven    : true_type
1311227825Stheraven{
1312227825Stheraven};
1313227825Stheraven
1314227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1315227825Stheraven
1316227825Stheraven#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1317227825Stheraven
1318227825Stheraventemplate <class _Alloc, class _Tp, class ..._Args>
1319227825Stheravendecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1320227825Stheraven                                           _VSTD::declval<_Args>()...),
1321227825Stheraven                                           true_type())
1322227825Stheraven__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1323227825Stheraven
1324227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1325227825Stheravenfalse_type
1326227825Stheraven__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1327227825Stheraven
1328227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1329227825Stheravenstruct __has_construct
1330227825Stheraven    : integral_constant<bool,
1331227825Stheraven        is_same<
1332227825Stheraven            decltype(__has_construct_test(declval<_Alloc>(),
1333227825Stheraven                                          declval<_Pointer>(),
1334227825Stheraven                                          declval<_Args>()...)),
1335227825Stheraven            true_type>::value>
1336227825Stheraven{
1337227825Stheraven};
1338227825Stheraven
1339227825Stheraventemplate <class _Alloc, class _Pointer>
1340227825Stheravenauto
1341227825Stheraven__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1342227825Stheraven    -> decltype(__a.destroy(__p), true_type());
1343227825Stheraven
1344227825Stheraventemplate <class _Alloc, class _Pointer>
1345227825Stheravenauto
1346227825Stheraven__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1347227825Stheraven    -> false_type;
1348227825Stheraven
1349227825Stheraventemplate <class _Alloc, class _Pointer>
1350227825Stheravenstruct __has_destroy
1351227825Stheraven    : integral_constant<bool,
1352227825Stheraven        is_same<
1353227825Stheraven            decltype(__has_destroy_test(declval<_Alloc>(),
1354227825Stheraven                                        declval<_Pointer>())),
1355227825Stheraven            true_type>::value>
1356227825Stheraven{
1357227825Stheraven};
1358227825Stheraven
1359227825Stheraventemplate <class _Alloc>
1360227825Stheravenauto
1361227825Stheraven__has_max_size_test(_Alloc&& __a)
1362227825Stheraven    -> decltype(__a.max_size(), true_type());
1363227825Stheraven
1364227825Stheraventemplate <class _Alloc>
1365227825Stheravenauto
1366227825Stheraven__has_max_size_test(const volatile _Alloc& __a)
1367227825Stheraven    -> false_type;
1368227825Stheraven
1369227825Stheraventemplate <class _Alloc>
1370227825Stheravenstruct __has_max_size
1371227825Stheraven    : integral_constant<bool,
1372227825Stheraven        is_same<
1373227825Stheraven            decltype(__has_max_size_test(declval<_Alloc&>())),
1374227825Stheraven            true_type>::value>
1375227825Stheraven{
1376227825Stheraven};
1377227825Stheraven
1378227825Stheraventemplate <class _Alloc>
1379227825Stheravenauto
1380227825Stheraven__has_select_on_container_copy_construction_test(_Alloc&& __a)
1381227825Stheraven    -> decltype(__a.select_on_container_copy_construction(), true_type());
1382227825Stheraven
1383227825Stheraventemplate <class _Alloc>
1384227825Stheravenauto
1385227825Stheraven__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1386227825Stheraven    -> false_type;
1387227825Stheraven
1388227825Stheraventemplate <class _Alloc>
1389227825Stheravenstruct __has_select_on_container_copy_construction
1390227825Stheraven    : integral_constant<bool,
1391227825Stheraven        is_same<
1392227825Stheraven            decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1393227825Stheraven            true_type>::value>
1394227825Stheraven{
1395227825Stheraven};
1396227825Stheraven
1397227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1398227825Stheraven
1399227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1400227825Stheraven
1401227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1402227825Stheravenstruct __has_construct
1403227825Stheraven    : false_type
1404227825Stheraven{
1405227825Stheraven};
1406227825Stheraven
1407232950Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1408232950Stheraven
1409232950Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1410232950Stheravenstruct __has_construct
1411232950Stheraven    : false_type
1412232950Stheraven{
1413232950Stheraven};
1414232950Stheraven
1415227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1416227825Stheraven
1417227825Stheraventemplate <class _Alloc, class _Pointer>
1418227825Stheravenstruct __has_destroy
1419227825Stheraven    : false_type
1420227825Stheraven{
1421227825Stheraven};
1422227825Stheraven
1423227825Stheraventemplate <class _Alloc>
1424227825Stheravenstruct __has_max_size
1425227825Stheraven    : true_type
1426227825Stheraven{
1427227825Stheraven};
1428227825Stheraven
1429227825Stheraventemplate <class _Alloc>
1430227825Stheravenstruct __has_select_on_container_copy_construction
1431227825Stheraven    : false_type
1432227825Stheraven{
1433227825Stheraven};
1434227825Stheraven
1435227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1436227825Stheraven
1437227825Stheraventemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1438227825Stheravenstruct __alloc_traits_difference_type
1439227825Stheraven{
1440227825Stheraven    typedef typename pointer_traits<_Ptr>::difference_type type;
1441227825Stheraven};
1442227825Stheraven
1443227825Stheraventemplate <class _Alloc, class _Ptr>
1444227825Stheravenstruct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1445227825Stheraven{
1446227825Stheraven    typedef typename _Alloc::difference_type type;
1447227825Stheraven};
1448227825Stheraven
1449227825Stheraventemplate <class _Alloc>
1450249998Sdimstruct _LIBCPP_TYPE_VIS allocator_traits
1451227825Stheraven{
1452227825Stheraven    typedef _Alloc                              allocator_type;
1453227825Stheraven    typedef typename allocator_type::value_type value_type;
1454227825Stheraven
1455227825Stheraven    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1456227825Stheraven    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1457227825Stheraven    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1458227825Stheraven    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1459227825Stheraven
1460227825Stheraven    typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1461227825Stheraven    typedef typename __size_type<allocator_type, difference_type>::type size_type;
1462227825Stheraven
1463227825Stheraven    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1464227825Stheraven                     propagate_on_container_copy_assignment;
1465227825Stheraven    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1466227825Stheraven                     propagate_on_container_move_assignment;
1467227825Stheraven    typedef typename __propagate_on_container_swap<allocator_type>::type
1468227825Stheraven                     propagate_on_container_swap;
1469227825Stheraven
1470227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1471227825Stheraven    template <class _Tp> using rebind_alloc =
1472227825Stheraven                  typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1473227825Stheraven    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1474227825Stheraven#else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1475227825Stheraven    template <class _Tp> struct rebind_alloc
1476227825Stheraven        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1477227825Stheraven    template <class _Tp> struct rebind_traits
1478227825Stheraven        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1479227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1480227825Stheraven
1481227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1482227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n)
1483227825Stheraven        {return __a.allocate(__n);}
1484227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1485227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1486227825Stheraven        {return allocate(__a, __n, __hint,
1487227825Stheraven            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1488227825Stheraven
1489227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1490227825Stheraven    static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1491227825Stheraven        {__a.deallocate(__p, __n);}
1492227825Stheraven
1493227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1494227825Stheraven    template <class _Tp, class... _Args>
1495227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1496227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1497227825Stheraven            {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1498227825Stheraven                         __a, __p, _VSTD::forward<_Args>(__args)...);}
1499227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1500227825Stheraven    template <class _Tp>
1501227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1502227825Stheraven        static void construct(allocator_type& __a, _Tp* __p)
1503227825Stheraven            {
1504227825Stheraven                ::new ((void*)__p) _Tp();
1505227825Stheraven            }
1506227825Stheraven    template <class _Tp, class _A0>
1507227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1508227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1509227825Stheraven            {
1510227825Stheraven                ::new ((void*)__p) _Tp(__a0);
1511227825Stheraven            }
1512227825Stheraven    template <class _Tp, class _A0, class _A1>
1513227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1514227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1515227825Stheraven                              const _A1& __a1)
1516227825Stheraven            {
1517227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1);
1518227825Stheraven            }
1519227825Stheraven    template <class _Tp, class _A0, class _A1, class _A2>
1520227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1521227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1522227825Stheraven                              const _A1& __a1, const _A2& __a2)
1523227825Stheraven            {
1524227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1525227825Stheraven            }
1526227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1527227825Stheraven
1528227825Stheraven    template <class _Tp>
1529227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1530227825Stheraven        static void destroy(allocator_type& __a, _Tp* __p)
1531227825Stheraven            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1532227825Stheraven
1533227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1534227825Stheraven    static size_type max_size(const allocator_type& __a)
1535227825Stheraven        {return __max_size(__has_max_size<const allocator_type>(), __a);}
1536227825Stheraven
1537227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1538227825Stheraven    static allocator_type
1539227825Stheraven        select_on_container_copy_construction(const allocator_type& __a)
1540227825Stheraven            {return select_on_container_copy_construction(
1541227825Stheraven                __has_select_on_container_copy_construction<const allocator_type>(),
1542227825Stheraven                __a);}
1543227825Stheraven
1544232950Stheraven    template <class _Ptr>
1545232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1546232950Stheraven        static
1547232950Stheraven        void
1548232950Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1549232950Stheraven        {
1550232950Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1551232950Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1552232950Stheraven        }
1553232950Stheraven
1554232950Stheraven    template <class _Tp>
1555232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1556232950Stheraven        static
1557232950Stheraven        typename enable_if
1558232950Stheraven        <
1559232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1560232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1561232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1562232950Stheraven            void
1563232950Stheraven        >::type
1564232950Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1565232950Stheraven        {
1566232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1567232950Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1568232950Stheraven            __begin2 += _Np;
1569232950Stheraven        }
1570232950Stheraven
1571232950Stheraven    template <class _Ptr>
1572232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1573232950Stheraven        static
1574232950Stheraven        void
1575232950Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1576232950Stheraven        {
1577232950Stheraven            while (__end1 != __begin1)
1578246487Stheraven            {
1579246487Stheraven                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1580246487Stheraven                --__end2;
1581246487Stheraven            }
1582232950Stheraven        }
1583232950Stheraven
1584232950Stheraven    template <class _Tp>
1585232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1586232950Stheraven        static
1587232950Stheraven        typename enable_if
1588232950Stheraven        <
1589232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1590232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1591232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1592232950Stheraven            void
1593232950Stheraven        >::type
1594232950Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1595232950Stheraven        {
1596232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1597232950Stheraven            __end2 -= _Np;
1598232950Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1599232950Stheraven        }
1600232950Stheraven
1601227825Stheravenprivate:
1602227825Stheraven
1603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1604227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1605227825Stheraven        const_void_pointer __hint, true_type)
1606227825Stheraven        {return __a.allocate(__n, __hint);}
1607227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1608227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1609232950Stheraven        const_void_pointer, false_type)
1610227825Stheraven        {return __a.allocate(__n);}
1611227825Stheraven
1612227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1613227825Stheraven    template <class _Tp, class... _Args>
1614227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1615227825Stheraven        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1616227825Stheraven            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1617227825Stheraven    template <class _Tp, class... _Args>
1618227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1619227825Stheraven        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1620227825Stheraven            {
1621227825Stheraven                ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1622227825Stheraven            }
1623227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1624227825Stheraven
1625227825Stheraven    template <class _Tp>
1626227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1627227825Stheraven        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1628227825Stheraven            {__a.destroy(__p);}
1629227825Stheraven    template <class _Tp>
1630227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1631227825Stheraven        static void __destroy(false_type, allocator_type&, _Tp* __p)
1632227825Stheraven            {
1633227825Stheraven                __p->~_Tp();
1634227825Stheraven            }
1635227825Stheraven
1636227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1637227825Stheraven    static size_type __max_size(true_type, const allocator_type& __a)
1638227825Stheraven            {return __a.max_size();}
1639227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1640227825Stheraven    static size_type __max_size(false_type, const allocator_type&)
1641227825Stheraven            {return numeric_limits<size_type>::max();}
1642227825Stheraven
1643227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1644227825Stheraven    static allocator_type
1645227825Stheraven        select_on_container_copy_construction(true_type, const allocator_type& __a)
1646227825Stheraven            {return __a.select_on_container_copy_construction();}
1647227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1648227825Stheraven    static allocator_type
1649227825Stheraven        select_on_container_copy_construction(false_type, const allocator_type& __a)
1650227825Stheraven            {return __a;}
1651227825Stheraven};
1652227825Stheraven
1653232950Stheraven// allocator
1654227825Stheraven
1655227825Stheraventemplate <class _Tp>
1656249998Sdimclass _LIBCPP_TYPE_VIS allocator
1657227825Stheraven{
1658227825Stheravenpublic:
1659232950Stheraven    typedef size_t            size_type;
1660232950Stheraven    typedef ptrdiff_t         difference_type;
1661232950Stheraven    typedef _Tp*              pointer;
1662232950Stheraven    typedef const _Tp*        const_pointer;
1663232950Stheraven    typedef _Tp&              reference;
1664232950Stheraven    typedef const _Tp&        const_reference;
1665232950Stheraven    typedef _Tp               value_type;
1666227825Stheraven
1667232950Stheraven    typedef true_type propagate_on_container_move_assignment;
1668227825Stheraven
1669232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1670227825Stheraven
1671232950Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1672232950Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1673232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1674232950Stheraven        {return _VSTD::addressof(__x);}
1675232950Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1676232950Stheraven        {return _VSTD::addressof(__x);}
1677232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1678232950Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1679232950Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1680232950Stheraven        {::operator delete((void*)__p);}
1681232950Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1682232950Stheraven        {return size_type(~0) / sizeof(_Tp);}
1683232950Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1684232950Stheraven    template <class _Up, class... _Args>
1685232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1686232950Stheraven        void
1687232950Stheraven        construct(_Up* __p, _Args&&... __args)
1688232950Stheraven        {
1689232950Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1690232950Stheraven        }
1691232950Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1692232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1693232950Stheraven        void
1694232950Stheraven        construct(pointer __p)
1695232950Stheraven        {
1696232950Stheraven            ::new((void*)__p) _Tp();
1697232950Stheraven        }
1698232950Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1699234976Stheraven
1700232950Stheraven    template <class _A0>
1701232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1702234976Stheraven        void
1703232950Stheraven        construct(pointer __p, _A0& __a0)
1704232950Stheraven        {
1705232950Stheraven            ::new((void*)__p) _Tp(__a0);
1706232950Stheraven        }
1707232950Stheraven    template <class _A0>
1708232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1709234976Stheraven        void
1710232950Stheraven        construct(pointer __p, const _A0& __a0)
1711232950Stheraven        {
1712232950Stheraven            ::new((void*)__p) _Tp(__a0);
1713232950Stheraven        }
1714232950Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1715232950Stheraven    template <class _A0, class _A1>
1716232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1717232950Stheraven        void
1718232950Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1719232950Stheraven        {
1720232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1721232950Stheraven        }
1722232950Stheraven    template <class _A0, class _A1>
1723232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1724232950Stheraven        void
1725232950Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1726232950Stheraven        {
1727232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1728232950Stheraven        }
1729232950Stheraven    template <class _A0, class _A1>
1730232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1731232950Stheraven        void
1732232950Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1733232950Stheraven        {
1734232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1735232950Stheraven        }
1736232950Stheraven    template <class _A0, class _A1>
1737232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1738232950Stheraven        void
1739232950Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1740232950Stheraven        {
1741232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1742232950Stheraven        }
1743232950Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1744232950Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1745227825Stheraven};
1746227825Stheraven
1747227825Stheraventemplate <class _Tp>
1748249998Sdimclass _LIBCPP_TYPE_VIS allocator<const _Tp>
1749227825Stheraven{
1750227825Stheravenpublic:
1751227825Stheraven    typedef size_t            size_type;
1752227825Stheraven    typedef ptrdiff_t         difference_type;
1753232950Stheraven    typedef const _Tp*        pointer;
1754227825Stheraven    typedef const _Tp*        const_pointer;
1755232950Stheraven    typedef const _Tp&        reference;
1756227825Stheraven    typedef const _Tp&        const_reference;
1757253159Stheraven    typedef const _Tp         value_type;
1758227825Stheraven
1759227825Stheraven    typedef true_type propagate_on_container_move_assignment;
1760227825Stheraven
1761227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1762227825Stheraven
1763227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1764227825Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1765227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1766227825Stheraven        {return _VSTD::addressof(__x);}
1767227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1768227825Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1769227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1770227825Stheraven        {::operator delete((void*)__p);}
1771227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1772227825Stheraven        {return size_type(~0) / sizeof(_Tp);}
1773227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1774227825Stheraven    template <class _Up, class... _Args>
1775227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1776227825Stheraven        void
1777227825Stheraven        construct(_Up* __p, _Args&&... __args)
1778227825Stheraven        {
1779227825Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1780227825Stheraven        }
1781227825Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1782227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1783227825Stheraven        void
1784227825Stheraven        construct(pointer __p)
1785227825Stheraven        {
1786227825Stheraven            ::new((void*)__p) _Tp();
1787227825Stheraven        }
1788227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1789234976Stheraven
1790227825Stheraven    template <class _A0>
1791227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1792234976Stheraven        void
1793227825Stheraven        construct(pointer __p, _A0& __a0)
1794227825Stheraven        {
1795227825Stheraven            ::new((void*)__p) _Tp(__a0);
1796227825Stheraven        }
1797227825Stheraven    template <class _A0>
1798227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1799234976Stheraven        void
1800227825Stheraven        construct(pointer __p, const _A0& __a0)
1801227825Stheraven        {
1802227825Stheraven            ::new((void*)__p) _Tp(__a0);
1803227825Stheraven        }
1804227825Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1805227825Stheraven    template <class _A0, class _A1>
1806227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1807227825Stheraven        void
1808227825Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1809227825Stheraven        {
1810227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1811227825Stheraven        }
1812227825Stheraven    template <class _A0, class _A1>
1813227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1814227825Stheraven        void
1815227825Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1816227825Stheraven        {
1817227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1818227825Stheraven        }
1819227825Stheraven    template <class _A0, class _A1>
1820227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1821227825Stheraven        void
1822227825Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1823227825Stheraven        {
1824227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1825227825Stheraven        }
1826227825Stheraven    template <class _A0, class _A1>
1827227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1828227825Stheraven        void
1829227825Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1830227825Stheraven        {
1831227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1832227825Stheraven        }
1833227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1834227825Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1835227825Stheraven};
1836227825Stheraven
1837227825Stheraventemplate <class _Tp, class _Up>
1838227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1839227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1840227825Stheraven
1841227825Stheraventemplate <class _Tp, class _Up>
1842227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1843227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1844227825Stheraven
1845227825Stheraventemplate <class _OutputIterator, class _Tp>
1846249998Sdimclass _LIBCPP_TYPE_VIS raw_storage_iterator
1847227825Stheraven    : public iterator<output_iterator_tag,
1848227825Stheraven                      _Tp,                                         // purposefully not C++03
1849227825Stheraven                      ptrdiff_t,                                   // purposefully not C++03
1850227825Stheraven                      _Tp*,                                        // purposefully not C++03
1851227825Stheraven                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1852227825Stheraven{
1853227825Stheravenprivate:
1854227825Stheraven    _OutputIterator __x_;
1855227825Stheravenpublic:
1856227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1857227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1858227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1859227825Stheraven        {::new(&*__x_) _Tp(__element); return *this;}
1860227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1861227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
1862227825Stheraven        {raw_storage_iterator __t(*this); ++__x_; return __t;}
1863227825Stheraven};
1864227825Stheraven
1865227825Stheraventemplate <class _Tp>
1866227825Stheravenpair<_Tp*, ptrdiff_t>
1867227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1868227825Stheraven{
1869227825Stheraven    pair<_Tp*, ptrdiff_t> __r(0, 0);
1870227825Stheraven    const ptrdiff_t __m = (~ptrdiff_t(0) ^
1871227825Stheraven                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1872227825Stheraven                           / sizeof(_Tp);
1873227825Stheraven    if (__n > __m)
1874227825Stheraven        __n = __m;
1875227825Stheraven    while (__n > 0)
1876227825Stheraven    {
1877227825Stheraven        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1878227825Stheraven        if (__r.first)
1879227825Stheraven        {
1880227825Stheraven            __r.second = __n;
1881227825Stheraven            break;
1882227825Stheraven        }
1883227825Stheraven        __n /= 2;
1884227825Stheraven    }
1885227825Stheraven    return __r;
1886227825Stheraven}
1887227825Stheraven
1888227825Stheraventemplate <class _Tp>
1889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1890227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1891227825Stheraven
1892227825Stheraventemplate <class _Tp>
1893227825Stheravenstruct auto_ptr_ref
1894227825Stheraven{
1895227825Stheraven    _Tp* __ptr_;
1896227825Stheraven};
1897227825Stheraven
1898227825Stheraventemplate<class _Tp>
1899249998Sdimclass _LIBCPP_TYPE_VIS auto_ptr
1900227825Stheraven{
1901227825Stheravenprivate:
1902227825Stheraven    _Tp* __ptr_;
1903227825Stheravenpublic:
1904227825Stheraven    typedef _Tp element_type;
1905227825Stheraven
1906227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1907227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1908227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1909227825Stheraven        : __ptr_(__p.release()) {}
1910227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1911227825Stheraven        {reset(__p.release()); return *this;}
1912227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1913227825Stheraven        {reset(__p.release()); return *this;}
1914227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1915227825Stheraven        {reset(__p.__ptr_); return *this;}
1916227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1917227825Stheraven
1918227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1919227825Stheraven        {return *__ptr_;}
1920227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1921227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1922227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1923227825Stheraven    {
1924227825Stheraven        _Tp* __t = __ptr_;
1925227825Stheraven        __ptr_ = 0;
1926227825Stheraven        return __t;
1927227825Stheraven    }
1928227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1929227825Stheraven    {
1930227825Stheraven        if (__ptr_ != __p)
1931227825Stheraven            delete __ptr_;
1932227825Stheraven        __ptr_ = __p;
1933227825Stheraven    }
1934227825Stheraven
1935227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1936227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1937227825Stheraven        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1938227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1939227825Stheraven        {return auto_ptr<_Up>(release());}
1940227825Stheraven};
1941227825Stheraven
1942227825Stheraventemplate <>
1943249998Sdimclass _LIBCPP_TYPE_VIS auto_ptr<void>
1944227825Stheraven{
1945227825Stheravenpublic:
1946227825Stheraven    typedef void element_type;
1947227825Stheraven};
1948227825Stheraven
1949227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1950227825Stheraven                                                     typename remove_cv<_T2>::type>::value,
1951232950Stheraven                                bool = is_empty<_T1>::value
1952232950Stheraven#if __has_feature(is_final)
1953232950Stheraven                                       && !__is_final(_T1)
1954232950Stheraven#endif
1955232950Stheraven                                ,
1956232950Stheraven                                bool = is_empty<_T2>::value
1957232950Stheraven#if __has_feature(is_final)
1958232950Stheraven                                       && !__is_final(_T2)
1959232950Stheraven#endif
1960232950Stheraven         >
1961227825Stheravenstruct __libcpp_compressed_pair_switch;
1962227825Stheraven
1963227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1964227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1965227825Stheraven
1966227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1967227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
1968227825Stheraven
1969227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1970227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
1971227825Stheraven
1972227825Stheraventemplate <class _T1, class _T2>
1973227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
1974227825Stheraven
1975227825Stheraventemplate <class _T1, class _T2>
1976227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
1977227825Stheraven
1978227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1979227825Stheravenclass __libcpp_compressed_pair_imp;
1980227825Stheraven
1981227825Stheraventemplate <class _T1, class _T2>
1982227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0>
1983227825Stheraven{
1984227825Stheravenprivate:
1985227825Stheraven    _T1 __first_;
1986227825Stheraven    _T2 __second_;
1987227825Stheravenpublic:
1988227825Stheraven    typedef _T1 _T1_param;
1989227825Stheraven    typedef _T2 _T2_param;
1990227825Stheraven
1991227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
1992227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
1993227825Stheraven
1994227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1995227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1996227825Stheraven
1997227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1998232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1999227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2000232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2001227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2002227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2003227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2004227825Stheraven
2005227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2006227825Stheraven
2007227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2008227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2009227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2010227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2011227825Stheraven        : __first_(__p.first()),
2012227825Stheraven          __second_(__p.second()) {}
2013227825Stheraven
2014227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2015227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2016227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2017227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2018227825Stheraven        {
2019227825Stheraven            __first_ = __p.first();
2020227825Stheraven            __second_ = __p.second();
2021227825Stheraven            return *this;
2022227825Stheraven        }
2023227825Stheraven
2024227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2025227825Stheraven
2026227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2027227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2028227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2029227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2030227825Stheraven        : __first_(_VSTD::forward<_T1>(__p.first())),
2031227825Stheraven          __second_(_VSTD::forward<_T2>(__p.second())) {}
2032227825Stheraven
2033227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2034227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2035227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2036227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2037227825Stheraven        {
2038227825Stheraven            __first_ = _VSTD::forward<_T1>(__p.first());
2039227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2040227825Stheraven            return *this;
2041227825Stheraven        }
2042227825Stheraven
2043253159Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2044253159Stheraven
2045253159Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2046253159Stheraven
2047232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2048232950Stheraven
2049232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2050232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2051232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2052232950Stheraven                                     tuple<_Args1...> __first_args,
2053232950Stheraven                                     tuple<_Args2...> __second_args,
2054232950Stheraven                                     __tuple_indices<_I1...>,
2055232950Stheraven                                     __tuple_indices<_I2...>)
2056232950Stheraven            : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2057232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2058232950Stheraven            {}
2059232950Stheraven
2060232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2061232950Stheraven
2062227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2063227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2064227825Stheraven
2065227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2066227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2067227825Stheraven
2068227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2069227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2070227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2071227825Stheraven    {
2072227825Stheraven        using _VSTD::swap;
2073227825Stheraven        swap(__first_, __x.__first_);
2074227825Stheraven        swap(__second_, __x.__second_);
2075227825Stheraven    }
2076227825Stheraven};
2077227825Stheraven
2078227825Stheraventemplate <class _T1, class _T2>
2079227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1>
2080227825Stheraven    : private _T1
2081227825Stheraven{
2082227825Stheravenprivate:
2083227825Stheraven    _T2 __second_;
2084227825Stheravenpublic:
2085227825Stheraven    typedef _T1 _T1_param;
2086227825Stheraven    typedef _T2 _T2_param;
2087227825Stheraven
2088227825Stheraven    typedef _T1&                                        _T1_reference;
2089227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2090227825Stheraven
2091227825Stheraven    typedef const _T1&                                        _T1_const_reference;
2092227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2093227825Stheraven
2094227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2095232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2096227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2097232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2098227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2099227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2100227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2101227825Stheraven
2102227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2103227825Stheraven
2104227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2105227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2106227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2107227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2108227825Stheraven        : _T1(__p.first()), __second_(__p.second()) {}
2109227825Stheraven
2110227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2111227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2112227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2113227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2114227825Stheraven        {
2115227825Stheraven            _T1::operator=(__p.first());
2116227825Stheraven            __second_ = __p.second();
2117227825Stheraven            return *this;
2118227825Stheraven        }
2119227825Stheraven
2120227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2121227825Stheraven
2122227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2123227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2124227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2125227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2126227825Stheraven        : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2127227825Stheraven
2128227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2129227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2130227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2131227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2132227825Stheraven        {
2133227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2134227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2135227825Stheraven            return *this;
2136227825Stheraven        }
2137227825Stheraven
2138253159Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2139253159Stheraven
2140253159Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2141253159Stheraven
2142232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2143232950Stheraven
2144232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2145232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2146232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2147232950Stheraven                                     tuple<_Args1...> __first_args,
2148232950Stheraven                                     tuple<_Args2...> __second_args,
2149232950Stheraven                                     __tuple_indices<_I1...>,
2150232950Stheraven                                     __tuple_indices<_I2...>)
2151232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2152232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2153232950Stheraven            {}
2154232950Stheraven
2155232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2156232950Stheraven
2157227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2158227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2159227825Stheraven
2160227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2161227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2162227825Stheraven
2163227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2164227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2165227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2166227825Stheraven    {
2167227825Stheraven        using _VSTD::swap;
2168227825Stheraven        swap(__second_, __x.__second_);
2169227825Stheraven    }
2170227825Stheraven};
2171227825Stheraven
2172227825Stheraventemplate <class _T1, class _T2>
2173227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2>
2174227825Stheraven    : private _T2
2175227825Stheraven{
2176227825Stheravenprivate:
2177227825Stheraven    _T1 __first_;
2178227825Stheravenpublic:
2179227825Stheraven    typedef _T1 _T1_param;
2180227825Stheraven    typedef _T2 _T2_param;
2181227825Stheraven
2182227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2183227825Stheraven    typedef _T2&                                        _T2_reference;
2184227825Stheraven
2185227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2186227825Stheraven    typedef const _T2&                                        _T2_const_reference;
2187227825Stheraven
2188227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2189227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2190227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2191227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2192227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2193227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2194227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2195227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2196227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2197227825Stheraven
2198227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2199227825Stheraven
2200227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2201227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2202227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2203227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2204227825Stheraven        : _T2(__p.second()), __first_(__p.first()) {}
2205227825Stheraven
2206227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2207227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2208227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2209227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2210227825Stheraven        {
2211227825Stheraven            _T2::operator=(__p.second());
2212227825Stheraven            __first_ = __p.first();
2213227825Stheraven            return *this;
2214227825Stheraven        }
2215227825Stheraven
2216227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2217227825Stheraven
2218227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2219227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2220227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2221227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2222227825Stheraven        : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2223227825Stheraven
2224227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2225227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2226227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2227227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2228227825Stheraven        {
2229227825Stheraven            _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2230227825Stheraven            __first_ = _VSTD::move(__p.first());
2231227825Stheraven            return *this;
2232227825Stheraven        }
2233227825Stheraven
2234253159Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2235253159Stheraven
2236253159Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2237253159Stheraven
2238232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2239232950Stheraven
2240232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2241232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2242232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2243232950Stheraven                                     tuple<_Args1...> __first_args,
2244232950Stheraven                                     tuple<_Args2...> __second_args,
2245232950Stheraven                                     __tuple_indices<_I1...>,
2246232950Stheraven                                     __tuple_indices<_I2...>)
2247232950Stheraven            : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2248232950Stheraven              __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2249232950Stheraven              
2250232950Stheraven            {}
2251232950Stheraven
2252232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2253232950Stheraven
2254227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2255227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2256227825Stheraven
2257227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2258227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2259227825Stheraven
2260227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2261227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2262227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2263227825Stheraven    {
2264227825Stheraven        using _VSTD::swap;
2265227825Stheraven        swap(__first_, __x.__first_);
2266227825Stheraven    }
2267227825Stheraven};
2268227825Stheraven
2269227825Stheraventemplate <class _T1, class _T2>
2270227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3>
2271227825Stheraven    : private _T1,
2272227825Stheraven      private _T2
2273227825Stheraven{
2274227825Stheravenpublic:
2275227825Stheraven    typedef _T1 _T1_param;
2276227825Stheraven    typedef _T2 _T2_param;
2277227825Stheraven
2278227825Stheraven    typedef _T1& _T1_reference;
2279227825Stheraven    typedef _T2& _T2_reference;
2280227825Stheraven
2281227825Stheraven    typedef const _T1& _T1_const_reference;
2282227825Stheraven    typedef const _T2& _T2_const_reference;
2283227825Stheraven
2284227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2285227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2286227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2287227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2288227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2289227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2290227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2291227825Stheraven
2292227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2293227825Stheraven
2294227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2295227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2296227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2297227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2298227825Stheraven        : _T1(__p.first()), _T2(__p.second()) {}
2299227825Stheraven
2300227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2301227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2302227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2303227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2304227825Stheraven        {
2305227825Stheraven            _T1::operator=(__p.first());
2306227825Stheraven            _T2::operator=(__p.second());
2307227825Stheraven            return *this;
2308227825Stheraven        }
2309227825Stheraven
2310227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2311227825Stheraven
2312227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2313227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2314227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2315227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2316227825Stheraven        : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2317227825Stheraven
2318227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2319227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2320227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2321227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2322227825Stheraven        {
2323227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2324227825Stheraven            _T2::operator=(_VSTD::move(__p.second()));
2325227825Stheraven            return *this;
2326227825Stheraven        }
2327227825Stheraven
2328253159Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2329253159Stheraven
2330253159Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2331253159Stheraven
2332232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2333232950Stheraven
2334232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2335232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2336232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2337232950Stheraven                                     tuple<_Args1...> __first_args,
2338232950Stheraven                                     tuple<_Args2...> __second_args,
2339232950Stheraven                                     __tuple_indices<_I1...>,
2340232950Stheraven                                     __tuple_indices<_I2...>)
2341232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2342232950Stheraven              _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2343232950Stheraven            {}
2344232950Stheraven
2345232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2346232950Stheraven
2347227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2348227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2349227825Stheraven
2350227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2351227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2352227825Stheraven
2353232950Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2354227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2355227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2356227825Stheraven    {
2357227825Stheraven    }
2358227825Stheraven};
2359227825Stheraven
2360227825Stheraventemplate <class _T1, class _T2>
2361227825Stheravenclass __compressed_pair
2362227825Stheraven    : private __libcpp_compressed_pair_imp<_T1, _T2>
2363227825Stheraven{
2364227825Stheraven    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2365227825Stheravenpublic:
2366227825Stheraven    typedef typename base::_T1_param _T1_param;
2367227825Stheraven    typedef typename base::_T2_param _T2_param;
2368227825Stheraven
2369227825Stheraven    typedef typename base::_T1_reference _T1_reference;
2370227825Stheraven    typedef typename base::_T2_reference _T2_reference;
2371227825Stheraven
2372227825Stheraven    typedef typename base::_T1_const_reference _T1_const_reference;
2373227825Stheraven    typedef typename base::_T2_const_reference _T2_const_reference;
2374227825Stheraven
2375227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2376232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2377227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2378232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2379227825Stheraven        : base(_VSTD::forward<_T2_param>(__t2)) {}
2380227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2381227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2382227825Stheraven
2383227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2384227825Stheraven
2385227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2386227825Stheraven    __compressed_pair(const __compressed_pair& __p)
2387227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2388227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2389227825Stheraven        : base(__p) {}
2390227825Stheraven
2391227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2392227825Stheraven    __compressed_pair& operator=(const __compressed_pair& __p)
2393227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2394227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2395227825Stheraven        {
2396227825Stheraven            base::operator=(__p);
2397227825Stheraven            return *this;
2398227825Stheraven        }
2399227825Stheraven
2400227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2401227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2402227825Stheraven    __compressed_pair(__compressed_pair&& __p)
2403227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2404227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2405227825Stheraven        : base(_VSTD::move(__p)) {}
2406227825Stheraven
2407227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2408227825Stheraven    __compressed_pair& operator=(__compressed_pair&& __p)
2409227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2410227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2411227825Stheraven        {
2412227825Stheraven            base::operator=(_VSTD::move(__p));
2413227825Stheraven            return *this;
2414227825Stheraven        }
2415232950Stheraven
2416253159Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2417253159Stheraven
2418253159Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2419253159Stheraven
2420232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2421232950Stheraven
2422232950Stheraven    template <class... _Args1, class... _Args2>
2423232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2424232950Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2425232950Stheraven                                                      tuple<_Args2...> __second_args)
2426232950Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2427232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2428232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2429232950Stheraven            {}
2430232950Stheraven
2431232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2432232950Stheraven
2433227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
2434227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2435227825Stheraven
2436227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return base::second();}
2437227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2438227825Stheraven
2439227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2440227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2441227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2442227825Stheraven        {base::swap(__x);}
2443227825Stheraven};
2444227825Stheraven
2445227825Stheraventemplate <class _T1, class _T2>
2446227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2447227825Stheravenvoid
2448227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2449227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2450227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2451227825Stheraven    {__x.swap(__y);}
2452227825Stheraven
2453232950Stheraven// __same_or_less_cv_qualified
2454232950Stheraven
2455232950Stheraventemplate <class _Ptr1, class _Ptr2,
2456232950Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2457232950Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2458232950Stheraven                        >::value
2459232950Stheraven         >
2460232950Stheravenstruct __same_or_less_cv_qualified_imp
2461232950Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2462232950Stheraven
2463232950Stheraventemplate <class _Ptr1, class _Ptr2>
2464232950Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2465232950Stheraven    : false_type {};
2466232950Stheraven
2467232950Stheraventemplate <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2468232950Stheraven                                         !is_pointer<_Ptr1>::value>
2469232950Stheravenstruct __same_or_less_cv_qualified
2470232950Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2471232950Stheraven
2472232950Stheraventemplate <class _Ptr1, class _Ptr2>
2473232950Stheravenstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2474232950Stheraven    : false_type {};
2475232950Stheraven
2476232950Stheraven// default_delete
2477232950Stheraven
2478227825Stheraventemplate <class _Tp>
2479249998Sdimstruct _LIBCPP_TYPE_VIS default_delete
2480227825Stheraven{
2481241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2482241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2483241903Sdim#else
2484241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2485241903Sdim#endif
2486227825Stheraven    template <class _Up>
2487227825Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2488227825Stheraven             typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2489227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2490227825Stheraven        {
2491227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2492249998Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2493227825Stheraven            delete __ptr;
2494227825Stheraven        }
2495227825Stheraven};
2496227825Stheraven
2497227825Stheraventemplate <class _Tp>
2498249998Sdimstruct _LIBCPP_TYPE_VIS default_delete<_Tp[]>
2499227825Stheraven{
2500232950Stheravenpublic:
2501241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2502241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2503241903Sdim#else
2504241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2505241903Sdim#endif
2506232950Stheraven    template <class _Up>
2507232950Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2508232950Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2509232950Stheraven    template <class _Up>
2510232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2511232950Stheraven        void operator() (_Up* __ptr,
2512232950Stheraven                         typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2513227825Stheraven        {
2514227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2515249998Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2516227825Stheraven            delete [] __ptr;
2517227825Stheraven        }
2518227825Stheraven};
2519227825Stheraven
2520227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> >
2521249998Sdimclass _LIBCPP_TYPE_VIS unique_ptr
2522227825Stheraven{
2523227825Stheravenpublic:
2524227825Stheraven    typedef _Tp element_type;
2525227825Stheraven    typedef _Dp deleter_type;
2526227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2527227825Stheravenprivate:
2528227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2529227825Stheraven
2530232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2531227825Stheraven    unique_ptr(unique_ptr&);
2532227825Stheraven    template <class _Up, class _Ep>
2533227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&);
2534227825Stheraven    unique_ptr& operator=(unique_ptr&);
2535227825Stheraven    template <class _Up, class _Ep>
2536227825Stheraven        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2537227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2538227825Stheraven
2539227825Stheraven    struct __nat {int __for_bool_;};
2540227825Stheraven
2541227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2542227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2543227825Stheravenpublic:
2544241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2545227825Stheraven        : __ptr_(pointer())
2546227825Stheraven        {
2547227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2548227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2549227825Stheraven        }
2550241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2551227825Stheraven        : __ptr_(pointer())
2552227825Stheraven        {
2553227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2554227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2555227825Stheraven        }
2556227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2557227825Stheraven        : __ptr_(_VSTD::move(__p))
2558227825Stheraven        {
2559227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2560227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2561227825Stheraven        }
2562227825Stheraven
2563227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2564227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2565227825Stheraven                                        is_reference<deleter_type>::value,
2566227825Stheraven                                        deleter_type,
2567227825Stheraven                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
2568227825Stheraven             _NOEXCEPT
2569227825Stheraven        : __ptr_(__p, __d) {}
2570227825Stheraven
2571227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2572227825Stheraven             _NOEXCEPT
2573227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2574227825Stheraven        {
2575227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2576227825Stheraven        }
2577227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2578227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2579227825Stheraven    template <class _Up, class _Ep>
2580227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2581227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2582227825Stheraven                   typename enable_if
2583227825Stheraven                      <
2584227825Stheraven                        !is_array<_Up>::value &&
2585227825Stheraven                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2586227825Stheraven                         is_convertible<_Ep, deleter_type>::value &&
2587227825Stheraven                         (
2588227825Stheraven                            !is_reference<deleter_type>::value ||
2589227825Stheraven                            is_same<deleter_type, _Ep>::value
2590227825Stheraven                         ),
2591227825Stheraven                         __nat
2592227825Stheraven                      >::type = __nat()) _NOEXCEPT
2593227825Stheraven            : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2594227825Stheraven
2595227825Stheraven    template <class _Up>
2596227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2597227825Stheraven                typename enable_if<
2598227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2599227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2600227825Stheraven                                      __nat
2601227825Stheraven                                  >::type = __nat()) _NOEXCEPT
2602227825Stheraven            : __ptr_(__p.release())
2603227825Stheraven            {
2604227825Stheraven            }
2605227825Stheraven
2606227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2607227825Stheraven            {
2608227825Stheraven                reset(__u.release());
2609227825Stheraven                __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2610227825Stheraven                return *this;
2611227825Stheraven            }
2612227825Stheraven
2613227825Stheraven        template <class _Up, class _Ep>
2614227825Stheraven            _LIBCPP_INLINE_VISIBILITY
2615227825Stheraven            typename enable_if
2616227825Stheraven            <
2617232950Stheraven                !is_array<_Up>::value &&
2618232950Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2619232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2620227825Stheraven                unique_ptr&
2621227825Stheraven            >::type
2622227825Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2623227825Stheraven            {
2624227825Stheraven                reset(__u.release());
2625227825Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2626227825Stheraven                return *this;
2627227825Stheraven            }
2628227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2629227825Stheraven
2630227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2631227825Stheraven    {
2632227825Stheraven        return __rv<unique_ptr>(*this);
2633227825Stheraven    }
2634227825Stheraven
2635227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2636227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2637227825Stheraven
2638227825Stheraven    template <class _Up, class _Ep>
2639227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2640227825Stheraven    {
2641227825Stheraven        reset(__u.release());
2642227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2643227825Stheraven        return *this;
2644227825Stheraven    }
2645227825Stheraven
2646227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2647227825Stheraven        : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2648227825Stheraven
2649227825Stheraven    template <class _Up>
2650227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2651227825Stheraven                typename enable_if<
2652227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2653227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2654227825Stheraven                                      unique_ptr&
2655227825Stheraven                                  >::type
2656227825Stheraven        operator=(auto_ptr<_Up> __p)
2657227825Stheraven            {reset(__p.release()); return *this;}
2658227825Stheraven
2659227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2660227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2661227825Stheraven
2662227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2663227825Stheraven    {
2664227825Stheraven        reset();
2665227825Stheraven        return *this;
2666227825Stheraven    }
2667227825Stheraven
2668227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2669227825Stheraven        {return *__ptr_.first();}
2670227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2671227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2672227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2673227825Stheraven        {return __ptr_.second();}
2674227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2675227825Stheraven        {return __ptr_.second();}
2676232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2677232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2678232950Stheraven        {return __ptr_.first() != nullptr;}
2679227825Stheraven
2680227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2681227825Stheraven    {
2682227825Stheraven        pointer __t = __ptr_.first();
2683227825Stheraven        __ptr_.first() = pointer();
2684227825Stheraven        return __t;
2685227825Stheraven    }
2686227825Stheraven
2687227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2688227825Stheraven    {
2689227825Stheraven        pointer __tmp = __ptr_.first();
2690227825Stheraven        __ptr_.first() = __p;
2691227825Stheraven        if (__tmp)
2692227825Stheraven            __ptr_.second()(__tmp);
2693227825Stheraven    }
2694227825Stheraven
2695227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2696227825Stheraven        {__ptr_.swap(__u.__ptr_);}
2697227825Stheraven};
2698227825Stheraven
2699227825Stheraventemplate <class _Tp, class _Dp>
2700249998Sdimclass _LIBCPP_TYPE_VIS unique_ptr<_Tp[], _Dp>
2701227825Stheraven{
2702227825Stheravenpublic:
2703227825Stheraven    typedef _Tp element_type;
2704227825Stheraven    typedef _Dp deleter_type;
2705227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2706227825Stheravenprivate:
2707227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2708227825Stheraven
2709232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2710227825Stheraven    unique_ptr(unique_ptr&);
2711227825Stheraven    template <class _Up>
2712227825Stheraven        unique_ptr(unique_ptr<_Up>&);
2713227825Stheraven    unique_ptr& operator=(unique_ptr&);
2714227825Stheraven    template <class _Up>
2715227825Stheraven        unique_ptr& operator=(unique_ptr<_Up>&);
2716227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2717227825Stheraven
2718227825Stheraven    struct __nat {int __for_bool_;};
2719227825Stheraven
2720227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2721227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2722227825Stheravenpublic:
2723241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2724227825Stheraven        : __ptr_(pointer())
2725227825Stheraven        {
2726227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2727227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2728227825Stheraven        }
2729241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2730227825Stheraven        : __ptr_(pointer())
2731227825Stheraven        {
2732227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2733227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2734227825Stheraven        }
2735227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2736232950Stheraven    template <class _Pp,
2737232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2738227825Stheraven             >
2739232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2740227825Stheraven        : __ptr_(__p)
2741227825Stheraven        {
2742227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2743227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2744227825Stheraven        }
2745227825Stheraven
2746232950Stheraven    template <class _Pp,
2747232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2748227825Stheraven             >
2749232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2750227825Stheraven                                       is_reference<deleter_type>::value,
2751227825Stheraven                                       deleter_type,
2752227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2753227825Stheraven             _NOEXCEPT
2754227825Stheraven        : __ptr_(__p, __d) {}
2755227825Stheraven
2756227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2757227825Stheraven                                       is_reference<deleter_type>::value,
2758227825Stheraven                                       deleter_type,
2759227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2760227825Stheraven             _NOEXCEPT
2761227825Stheraven        : __ptr_(pointer(), __d) {}
2762227825Stheraven
2763232950Stheraven    template <class _Pp,
2764232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2765227825Stheraven             >
2766232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2767227825Stheraven             _NOEXCEPT
2768227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2769227825Stheraven        {
2770227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2771227825Stheraven        }
2772227825Stheraven
2773227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2774227825Stheraven             _NOEXCEPT
2775227825Stheraven        : __ptr_(pointer(), _VSTD::move(__d))
2776227825Stheraven        {
2777227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2778227825Stheraven        }
2779227825Stheraven
2780227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2781227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2782227825Stheraven
2783227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2784227825Stheraven        {
2785227825Stheraven            reset(__u.release());
2786227825Stheraven            __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2787227825Stheraven            return *this;
2788227825Stheraven        }
2789232950Stheraven
2790232950Stheraven    template <class _Up, class _Ep>
2791232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2792232950Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2793232950Stheraven                   typename enable_if
2794232950Stheraven                            <
2795232950Stheraven                                is_array<_Up>::value &&
2796232950Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2797232950Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2798232950Stheraven                                (
2799232950Stheraven                                    !is_reference<deleter_type>::value ||
2800232950Stheraven                                    is_same<deleter_type, _Ep>::value
2801232950Stheraven                                ),
2802232950Stheraven                                __nat
2803232950Stheraven                            >::type = __nat()
2804232950Stheraven                  ) _NOEXCEPT
2805232950Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2806232950Stheraven
2807232950Stheraven
2808232950Stheraven        template <class _Up, class _Ep>
2809232950Stheraven            _LIBCPP_INLINE_VISIBILITY
2810232950Stheraven            typename enable_if
2811232950Stheraven            <
2812232950Stheraven                is_array<_Up>::value &&
2813232950Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2814232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2815232950Stheraven                unique_ptr&
2816232950Stheraven            >::type
2817232950Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2818232950Stheraven            {
2819232950Stheraven                reset(__u.release());
2820232950Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2821232950Stheraven                return *this;
2822232950Stheraven            }
2823227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2824227825Stheraven
2825227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2826227825Stheraven        : __ptr_(__p)
2827227825Stheraven        {
2828227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2829227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2830227825Stheraven        }
2831227825Stheraven
2832227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2833227825Stheraven        : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2834227825Stheraven
2835227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2836227825Stheraven        : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2837227825Stheraven
2838227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2839227825Stheraven    {
2840227825Stheraven        return __rv<unique_ptr>(*this);
2841227825Stheraven    }
2842227825Stheraven
2843227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2844227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2845227825Stheraven
2846227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2847227825Stheraven    {
2848227825Stheraven        reset(__u->release());
2849227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2850227825Stheraven        return *this;
2851227825Stheraven    }
2852227825Stheraven
2853227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2854227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2855227825Stheraven
2856227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2857227825Stheraven    {
2858227825Stheraven        reset();
2859227825Stheraven        return *this;
2860227825Stheraven    }
2861227825Stheraven
2862227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2863227825Stheraven        {return __ptr_.first()[__i];}
2864227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2865227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2866227825Stheraven        {return __ptr_.second();}
2867227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2868227825Stheraven        {return __ptr_.second();}
2869232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2870232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2871232950Stheraven        {return __ptr_.first() != nullptr;}
2872227825Stheraven
2873227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2874227825Stheraven    {
2875227825Stheraven        pointer __t = __ptr_.first();
2876227825Stheraven        __ptr_.first() = pointer();
2877227825Stheraven        return __t;
2878227825Stheraven    }
2879227825Stheraven
2880227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2881232950Stheraven    template <class _Pp,
2882232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2883227825Stheraven             >
2884232950Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2885227825Stheraven    {
2886227825Stheraven        pointer __tmp = __ptr_.first();
2887227825Stheraven        __ptr_.first() = __p;
2888227825Stheraven        if (__tmp)
2889227825Stheraven            __ptr_.second()(__tmp);
2890227825Stheraven    }
2891227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2892227825Stheraven    {
2893227825Stheraven        pointer __tmp = __ptr_.first();
2894227825Stheraven        __ptr_.first() = nullptr;
2895227825Stheraven        if (__tmp)
2896227825Stheraven            __ptr_.second()(__tmp);
2897227825Stheraven    }
2898227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2899227825Stheraven    {
2900227825Stheraven        pointer __tmp = __ptr_.first();
2901227825Stheraven        __ptr_.first() = nullptr;
2902227825Stheraven        if (__tmp)
2903227825Stheraven            __ptr_.second()(__tmp);
2904227825Stheraven    }
2905227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2906227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2907227825Stheraven    {
2908227825Stheraven        pointer __tmp = __ptr_.first();
2909227825Stheraven        __ptr_.first() = __p;
2910227825Stheraven        if (__tmp)
2911227825Stheraven            __ptr_.second()(__tmp);
2912227825Stheraven    }
2913227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2914227825Stheraven
2915227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2916227825Stheravenprivate:
2917227825Stheraven
2918227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2919227825Stheraven    template <class _Up>
2920227825Stheraven        explicit unique_ptr(_Up);
2921227825Stheraven    template <class _Up>
2922227825Stheraven        unique_ptr(_Up __u,
2923227825Stheraven                   typename conditional<
2924227825Stheraven                                       is_reference<deleter_type>::value,
2925227825Stheraven                                       deleter_type,
2926227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type,
2927227825Stheraven                   typename enable_if
2928227825Stheraven                      <
2929227825Stheraven                         is_convertible<_Up, pointer>::value,
2930227825Stheraven                         __nat
2931227825Stheraven                      >::type = __nat());
2932227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2933227825Stheraven};
2934227825Stheraven
2935227825Stheraventemplate <class _Tp, class _Dp>
2936227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2937227825Stheravenvoid
2938227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2939227825Stheraven
2940227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2941227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2942227825Stheravenbool
2943227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2944227825Stheraven
2945227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2946227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2947227825Stheravenbool
2948227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2949227825Stheraven
2950227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2951227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2952227825Stheravenbool
2953232950Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2954232950Stheraven{
2955232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2956232950Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2957232950Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2958232950Stheraven    return less<_V>()(__x.get(), __y.get());
2959232950Stheraven}
2960227825Stheraven
2961227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2962227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2963227825Stheravenbool
2964227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2965227825Stheraven
2966227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2967227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2968227825Stheravenbool
2969227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2970227825Stheraven
2971227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2972227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2973227825Stheravenbool
2974227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2975227825Stheraven
2976232950Stheraventemplate <class _T1, class _D1>
2977232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2978232950Stheravenbool
2979241903Sdimoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2980232950Stheraven{
2981232950Stheraven    return !__x;
2982232950Stheraven}
2983232950Stheraven
2984232950Stheraventemplate <class _T1, class _D1>
2985232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2986232950Stheravenbool
2987241903Sdimoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2988232950Stheraven{
2989232950Stheraven    return !__x;
2990232950Stheraven}
2991232950Stheraven
2992232950Stheraventemplate <class _T1, class _D1>
2993232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2994232950Stheravenbool
2995241903Sdimoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2996232950Stheraven{
2997232950Stheraven    return static_cast<bool>(__x);
2998232950Stheraven}
2999232950Stheraven
3000232950Stheraventemplate <class _T1, class _D1>
3001232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3002232950Stheravenbool
3003241903Sdimoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3004232950Stheraven{
3005232950Stheraven    return static_cast<bool>(__x);
3006232950Stheraven}
3007232950Stheraven
3008232950Stheraventemplate <class _T1, class _D1>
3009232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3010232950Stheravenbool
3011232950Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3012232950Stheraven{
3013232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3014232950Stheraven    return less<_P1>()(__x.get(), nullptr);
3015232950Stheraven}
3016232950Stheraven
3017232950Stheraventemplate <class _T1, class _D1>
3018232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3019232950Stheravenbool
3020232950Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3021232950Stheraven{
3022232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3023232950Stheraven    return less<_P1>()(nullptr, __x.get());
3024232950Stheraven}
3025232950Stheraven
3026232950Stheraventemplate <class _T1, class _D1>
3027232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3028232950Stheravenbool
3029232950Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3030232950Stheraven{
3031232950Stheraven    return nullptr < __x;
3032232950Stheraven}
3033232950Stheraven
3034232950Stheraventemplate <class _T1, class _D1>
3035232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3036232950Stheravenbool
3037232950Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3038232950Stheraven{
3039232950Stheraven    return __x < nullptr;
3040232950Stheraven}
3041232950Stheraven
3042232950Stheraventemplate <class _T1, class _D1>
3043232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3044232950Stheravenbool
3045232950Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3046232950Stheraven{
3047232950Stheraven    return !(nullptr < __x);
3048232950Stheraven}
3049232950Stheraven
3050232950Stheraventemplate <class _T1, class _D1>
3051232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3052232950Stheravenbool
3053232950Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3054232950Stheraven{
3055232950Stheraven    return !(__x < nullptr);
3056232950Stheraven}
3057232950Stheraven
3058232950Stheraventemplate <class _T1, class _D1>
3059232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3060232950Stheravenbool
3061232950Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3062232950Stheraven{
3063232950Stheraven    return !(__x < nullptr);
3064232950Stheraven}
3065232950Stheraven
3066232950Stheraventemplate <class _T1, class _D1>
3067232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3068232950Stheravenbool
3069232950Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3070232950Stheraven{
3071232950Stheraven    return !(nullptr < __x);
3072232950Stheraven}
3073232950Stheraven
3074234976Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3075234976Stheraven
3076234976Stheraventemplate <class _Tp, class _Dp>
3077234976Stheraveninline _LIBCPP_INLINE_VISIBILITY
3078234976Stheravenunique_ptr<_Tp, _Dp>
3079234976Stheravenmove(unique_ptr<_Tp, _Dp>& __t)
3080234976Stheraven{
3081234976Stheraven    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3082234976Stheraven}
3083234976Stheraven
3084234976Stheraven#endif
3085234976Stheraven
3086253159Stheraven#if _LIBCPP_STD_VER > 11
3087253159Stheraven
3088253159Stheraventemplate<class _Tp>
3089253159Stheravenstruct __unique_if
3090253159Stheraven{
3091253159Stheraven    typedef unique_ptr<_Tp> __unique_single;
3092253159Stheraven};
3093253159Stheraven
3094253159Stheraventemplate<class _Tp>
3095253159Stheravenstruct __unique_if<_Tp[]>
3096253159Stheraven{
3097253159Stheraven    typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3098253159Stheraven};
3099253159Stheraven
3100253159Stheraventemplate<class _Tp, size_t _Np>
3101253159Stheravenstruct __unique_if<_Tp[_Np]>
3102253159Stheraven{
3103253159Stheraven    typedef void __unique_array_known_bound;
3104253159Stheraven};
3105253159Stheraven
3106253159Stheraventemplate<class _Tp, class... _Args>
3107253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3108253159Stheraventypename __unique_if<_Tp>::__unique_single
3109253159Stheravenmake_unique(_Args&&... __args)
3110253159Stheraven{
3111253159Stheraven    return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3112253159Stheraven}
3113253159Stheraven
3114253159Stheraventemplate<class _Tp>
3115253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3116253159Stheraventypename __unique_if<_Tp>::__unique_array_unknown_bound
3117253159Stheravenmake_unique(size_t __n)
3118253159Stheraven{
3119253159Stheraven    typedef typename remove_extent<_Tp>::type _Up;
3120253159Stheraven    return unique_ptr<_Tp>(new _Up[__n]());
3121253159Stheraven}
3122253159Stheraven
3123253159Stheraventemplate<class _Tp, class... _Args>
3124253159Stheraven    typename __unique_if<_Tp>::__unique_array_known_bound
3125253159Stheraven    make_unique(_Args&&...) = delete;
3126253159Stheraven
3127253159Stheraven#endif  // _LIBCPP_STD_VER > 11
3128253159Stheraven
3129227825Stheraventemplate <class _Tp> struct hash;
3130227825Stheraven
3131253159Stheraventemplate <class _Size>
3132253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3133253159Stheraven_Size
3134253159Stheraven__loadword(const void* __p)
3135253159Stheraven{
3136253159Stheraven    _Size __r;
3137253159Stheraven    std::memcpy(&__r, __p, sizeof(__r));
3138253159Stheraven    return __r;
3139253159Stheraven}
3140253159Stheraven
3141232950Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3142232950Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3143232950Stheraven// multiplication, which can be very slow on 32-bit systems.
3144232950Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3145232950Stheravenstruct __murmur2_or_cityhash;
3146232950Stheraven
3147232950Stheraventemplate <class _Size>
3148232950Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3149227825Stheraven{
3150232950Stheraven    _Size operator()(const void* __key, _Size __len);
3151232950Stheraven};
3152232950Stheraven
3153232950Stheraven// murmur2
3154232950Stheraventemplate <class _Size>
3155232950Stheraven_Size
3156232950Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3157232950Stheraven{
3158232950Stheraven    const _Size __m = 0x5bd1e995;
3159232950Stheraven    const _Size __r = 24;
3160232950Stheraven    _Size __h = __len;
3161232950Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3162232950Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3163232950Stheraven    {
3164253159Stheraven        _Size __k = __loadword<_Size>(__data);
3165232950Stheraven        __k *= __m;
3166232950Stheraven        __k ^= __k >> __r;
3167232950Stheraven        __k *= __m;
3168232950Stheraven        __h *= __m;
3169232950Stheraven        __h ^= __k;
3170232950Stheraven    }
3171232950Stheraven    switch (__len)
3172232950Stheraven    {
3173232950Stheraven    case 3:
3174232950Stheraven        __h ^= __data[2] << 16;
3175232950Stheraven    case 2:
3176232950Stheraven        __h ^= __data[1] << 8;
3177232950Stheraven    case 1:
3178232950Stheraven        __h ^= __data[0];
3179232950Stheraven        __h *= __m;
3180232950Stheraven    }
3181232950Stheraven    __h ^= __h >> 13;
3182232950Stheraven    __h *= __m;
3183232950Stheraven    __h ^= __h >> 15;
3184232950Stheraven    return __h;
3185232950Stheraven}
3186232950Stheraven
3187232950Stheraventemplate <class _Size>
3188232950Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3189232950Stheraven{
3190232950Stheraven    _Size operator()(const void* __key, _Size __len);
3191232950Stheraven
3192232950Stheraven private:
3193232950Stheraven  // Some primes between 2^63 and 2^64.
3194232950Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3195232950Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3196232950Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3197232950Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3198232950Stheraven
3199232950Stheraven  static _Size __rotate(_Size __val, int __shift) {
3200232950Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3201232950Stheraven  }
3202232950Stheraven
3203232950Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3204232950Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3205232950Stheraven  }
3206232950Stheraven
3207232950Stheraven  static _Size __shift_mix(_Size __val) {
3208232950Stheraven    return __val ^ (__val >> 47);
3209232950Stheraven  }
3210232950Stheraven
3211232950Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3212232950Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3213232950Stheraven    _Size __a = (__u ^ __v) * __mul;
3214232950Stheraven    __a ^= (__a >> 47);
3215232950Stheraven    _Size __b = (__v ^ __a) * __mul;
3216232950Stheraven    __b ^= (__b >> 47);
3217232950Stheraven    __b *= __mul;
3218232950Stheraven    return __b;
3219232950Stheraven  }
3220232950Stheraven
3221232950Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3222232950Stheraven    if (__len > 8) {
3223253159Stheraven      const _Size __a = __loadword<_Size>(__s);
3224253159Stheraven      const _Size __b = __loadword<_Size>(__s + __len - 8);
3225232950Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3226232950Stheraven    }
3227232950Stheraven    if (__len >= 4) {
3228253159Stheraven      const uint32_t __a = __loadword<uint32_t>(__s);
3229253159Stheraven      const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3230232950Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3231232950Stheraven    }
3232232950Stheraven    if (__len > 0) {
3233232950Stheraven      const unsigned char __a = __s[0];
3234232950Stheraven      const unsigned char __b = __s[__len >> 1];
3235232950Stheraven      const unsigned char __c = __s[__len - 1];
3236232950Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3237232950Stheraven                           (static_cast<uint32_t>(__b) << 8);
3238232950Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3239232950Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3240232950Stheraven    }
3241232950Stheraven    return __k2;
3242232950Stheraven  }
3243232950Stheraven
3244232950Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3245253159Stheraven    const _Size __a = __loadword<_Size>(__s) * __k1;
3246253159Stheraven    const _Size __b = __loadword<_Size>(__s + 8);
3247253159Stheraven    const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3248253159Stheraven    const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3249232950Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3250232950Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3251232950Stheraven  }
3252232950Stheraven
3253232950Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3254232950Stheraven  // Callers do best to use "random-looking" values for a and b.
3255232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3256232950Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3257232950Stheraven    __a += __w;
3258232950Stheraven    __b = __rotate(__b + __a + __z, 21);
3259232950Stheraven    const _Size __c = __a;
3260232950Stheraven    __a += __x;
3261232950Stheraven    __a += __y;
3262232950Stheraven    __b += __rotate(__a, 44);
3263232950Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3264232950Stheraven  }
3265232950Stheraven
3266232950Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3267232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3268232950Stheraven      const char* __s, _Size __a, _Size __b) {
3269253159Stheraven    return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3270253159Stheraven                                         __loadword<_Size>(__s + 8),
3271253159Stheraven                                         __loadword<_Size>(__s + 16),
3272253159Stheraven                                         __loadword<_Size>(__s + 24),
3273232950Stheraven                                         __a,
3274232950Stheraven                                         __b);
3275232950Stheraven  }
3276232950Stheraven
3277232950Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3278232950Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3279253159Stheraven    _Size __z = __loadword<_Size>(__s + 24);
3280253159Stheraven    _Size __a = __loadword<_Size>(__s) +
3281253159Stheraven                (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3282232950Stheraven    _Size __b = __rotate(__a + __z, 52);
3283232950Stheraven    _Size __c = __rotate(__a, 37);
3284253159Stheraven    __a += __loadword<_Size>(__s + 8);
3285232950Stheraven    __c += __rotate(__a, 7);
3286253159Stheraven    __a += __loadword<_Size>(__s + 16);
3287232950Stheraven    _Size __vf = __a + __z;
3288232950Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3289253159Stheraven    __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3290253159Stheraven    __z += __loadword<_Size>(__s + __len - 8);
3291232950Stheraven    __b = __rotate(__a + __z, 52);
3292232950Stheraven    __c = __rotate(__a, 37);
3293253159Stheraven    __a += __loadword<_Size>(__s + __len - 24);
3294232950Stheraven    __c += __rotate(__a, 7);
3295253159Stheraven    __a += __loadword<_Size>(__s + __len - 16);
3296232950Stheraven    _Size __wf = __a + __z;
3297232950Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3298232950Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3299232950Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3300232950Stheraven  }
3301232950Stheraven};
3302232950Stheraven
3303232950Stheraven// cityhash64
3304232950Stheraventemplate <class _Size>
3305232950Stheraven_Size
3306232950Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3307232950Stheraven{
3308232950Stheraven  const char* __s = static_cast<const char*>(__key);
3309232950Stheraven  if (__len <= 32) {
3310232950Stheraven    if (__len <= 16) {
3311232950Stheraven      return __hash_len_0_to_16(__s, __len);
3312232950Stheraven    } else {
3313232950Stheraven      return __hash_len_17_to_32(__s, __len);
3314232950Stheraven    }
3315232950Stheraven  } else if (__len <= 64) {
3316232950Stheraven    return __hash_len_33_to_64(__s, __len);
3317232950Stheraven  }
3318232950Stheraven
3319232950Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3320232950Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3321253159Stheraven  _Size __x = __loadword<_Size>(__s + __len - 40);
3322253159Stheraven  _Size __y = __loadword<_Size>(__s + __len - 16) +
3323253159Stheraven              __loadword<_Size>(__s + __len - 56);
3324253159Stheraven  _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3325253159Stheraven                          __loadword<_Size>(__s + __len - 24));
3326232950Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3327232950Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3328253159Stheraven  __x = __x * __k1 + __loadword<_Size>(__s);
3329232950Stheraven
3330232950Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3331232950Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3332232950Stheraven  do {
3333253159Stheraven    __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3334253159Stheraven    __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3335232950Stheraven    __x ^= __w.second;
3336253159Stheraven    __y += __v.first + __loadword<_Size>(__s + 40);
3337232950Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3338232950Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3339232950Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3340253159Stheraven                                        __y + __loadword<_Size>(__s + 16));
3341232950Stheraven    std::swap(__z, __x);
3342232950Stheraven    __s += 64;
3343232950Stheraven    __len -= 64;
3344232950Stheraven  } while (__len != 0);
3345232950Stheraven  return __hash_len_16(
3346232950Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3347232950Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3348232950Stheraven}
3349232950Stheraven
3350232950Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3351232950Stheravenstruct __scalar_hash;
3352232950Stheraven
3353232950Stheraventemplate <class _Tp>
3354232950Stheravenstruct __scalar_hash<_Tp, 0>
3355232950Stheraven    : public unary_function<_Tp, size_t>
3356232950Stheraven{
3357227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3358232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3359227825Stheraven    {
3360232950Stheraven        union
3361232950Stheraven        {
3362232950Stheraven            _Tp    __t;
3363232950Stheraven            size_t __a;
3364232950Stheraven        } __u;
3365232950Stheraven        __u.__a = 0;
3366232950Stheraven        __u.__t = __v;
3367232950Stheraven        return __u.__a;
3368227825Stheraven    }
3369227825Stheraven};
3370227825Stheraven
3371232950Stheraventemplate <class _Tp>
3372232950Stheravenstruct __scalar_hash<_Tp, 1>
3373232950Stheraven    : public unary_function<_Tp, size_t>
3374232950Stheraven{
3375232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3376232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3377232950Stheraven    {
3378232950Stheraven        union
3379232950Stheraven        {
3380232950Stheraven            _Tp    __t;
3381232950Stheraven            size_t __a;
3382232950Stheraven        } __u;
3383232950Stheraven        __u.__t = __v;
3384232950Stheraven        return __u.__a;
3385232950Stheraven    }
3386232950Stheraven};
3387232950Stheraven
3388232950Stheraventemplate <class _Tp>
3389232950Stheravenstruct __scalar_hash<_Tp, 2>
3390232950Stheraven    : public unary_function<_Tp, size_t>
3391232950Stheraven{
3392232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3393232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3394232950Stheraven    {
3395232950Stheraven        union
3396232950Stheraven        {
3397232950Stheraven            _Tp __t;
3398232950Stheraven            struct
3399232950Stheraven            {
3400232950Stheraven                size_t __a;
3401232950Stheraven                size_t __b;
3402232950Stheraven            };
3403232950Stheraven        } __u;
3404232950Stheraven        __u.__t = __v;
3405232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3406232950Stheraven    }
3407232950Stheraven};
3408232950Stheraven
3409232950Stheraventemplate <class _Tp>
3410232950Stheravenstruct __scalar_hash<_Tp, 3>
3411232950Stheraven    : public unary_function<_Tp, size_t>
3412232950Stheraven{
3413232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3414232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3415232950Stheraven    {
3416232950Stheraven        union
3417232950Stheraven        {
3418232950Stheraven            _Tp __t;
3419232950Stheraven            struct
3420232950Stheraven            {
3421232950Stheraven                size_t __a;
3422232950Stheraven                size_t __b;
3423232950Stheraven                size_t __c;
3424232950Stheraven            };
3425232950Stheraven        } __u;
3426232950Stheraven        __u.__t = __v;
3427232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3428232950Stheraven    }
3429232950Stheraven};
3430232950Stheraven
3431232950Stheraventemplate <class _Tp>
3432232950Stheravenstruct __scalar_hash<_Tp, 4>
3433232950Stheraven    : public unary_function<_Tp, size_t>
3434232950Stheraven{
3435232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3436232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3437232950Stheraven    {
3438232950Stheraven        union
3439232950Stheraven        {
3440232950Stheraven            _Tp __t;
3441232950Stheraven            struct
3442232950Stheraven            {
3443232950Stheraven                size_t __a;
3444232950Stheraven                size_t __b;
3445232950Stheraven                size_t __c;
3446232950Stheraven                size_t __d;
3447232950Stheraven            };
3448232950Stheraven        } __u;
3449232950Stheraven        __u.__t = __v;
3450232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3451232950Stheraven    }
3452232950Stheraven};
3453232950Stheraven
3454232950Stheraventemplate<class _Tp>
3455249998Sdimstruct _LIBCPP_TYPE_VIS hash<_Tp*>
3456241903Sdim    : public unary_function<_Tp*, size_t>
3457232950Stheraven{
3458241903Sdim    _LIBCPP_INLINE_VISIBILITY
3459241903Sdim    size_t operator()(_Tp* __v) const _NOEXCEPT
3460241903Sdim    {
3461241903Sdim        union
3462241903Sdim        {
3463241903Sdim            _Tp* __t;
3464241903Sdim            size_t __a;
3465241903Sdim        } __u;
3466241903Sdim        __u.__t = __v;
3467241903Sdim        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3468241903Sdim    }
3469232950Stheraven};
3470232950Stheraven
3471227825Stheraventemplate <class _Tp, class _Dp>
3472249998Sdimstruct _LIBCPP_TYPE_VIS hash<unique_ptr<_Tp, _Dp> >
3473227825Stheraven{
3474227825Stheraven    typedef unique_ptr<_Tp, _Dp> argument_type;
3475227825Stheraven    typedef size_t               result_type;
3476227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3477227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3478227825Stheraven    {
3479227825Stheraven        typedef typename argument_type::pointer pointer;
3480227825Stheraven        return hash<pointer>()(__ptr.get());
3481227825Stheraven    }
3482227825Stheraven};
3483227825Stheraven
3484227825Stheravenstruct __destruct_n
3485227825Stheraven{
3486227825Stheravenprivate:
3487227825Stheraven    size_t size;
3488227825Stheraven
3489227825Stheraven    template <class _Tp>
3490227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3491227825Stheraven        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3492227825Stheraven
3493227825Stheraven    template <class _Tp>
3494227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3495227825Stheraven        {}
3496227825Stheraven
3497227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3498227825Stheraven        {++size;}
3499227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3500227825Stheraven        {}
3501227825Stheraven
3502227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3503227825Stheraven        {size = __s;}
3504227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3505227825Stheraven        {}
3506227825Stheravenpublic:
3507227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3508227825Stheraven        : size(__s) {}
3509227825Stheraven
3510227825Stheraven    template <class _Tp>
3511227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3512227825Stheraven        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3513227825Stheraven
3514227825Stheraven    template <class _Tp>
3515227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3516227825Stheraven        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3517227825Stheraven
3518227825Stheraven    template <class _Tp>
3519227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3520227825Stheraven        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3521227825Stheraven};
3522227825Stheraven
3523227825Stheraventemplate <class _Alloc>
3524227825Stheravenclass __allocator_destructor
3525227825Stheraven{
3526227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
3527227825Stheravenpublic:
3528227825Stheraven    typedef typename __alloc_traits::pointer pointer;
3529227825Stheraven    typedef typename __alloc_traits::size_type size_type;
3530227825Stheravenprivate:
3531227825Stheraven    _Alloc& __alloc_;
3532227825Stheraven    size_type __s_;
3533227825Stheravenpublic:
3534227825Stheraven    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3535227825Stheraven             _NOEXCEPT
3536227825Stheraven        : __alloc_(__a), __s_(__s) {}
3537227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3538227825Stheraven    void operator()(pointer __p) _NOEXCEPT
3539227825Stheraven        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3540227825Stheraven};
3541227825Stheraven
3542227825Stheraventemplate <class _InputIterator, class _ForwardIterator>
3543227825Stheraven_ForwardIterator
3544227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3545227825Stheraven{
3546227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3547232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3548232950Stheraven    _ForwardIterator __s = __r;
3549232950Stheraven    try
3550232950Stheraven    {
3551232950Stheraven#endif
3552232950Stheraven        for (; __f != __l; ++__f, ++__r)
3553232950Stheraven            ::new(&*__r) value_type(*__f);
3554232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3555232950Stheraven    }
3556232950Stheraven    catch (...)
3557232950Stheraven    {
3558232950Stheraven        for (; __s != __r; ++__s)
3559232950Stheraven            __s->~value_type();
3560232950Stheraven        throw;
3561232950Stheraven    }
3562232950Stheraven#endif
3563227825Stheraven    return __r;
3564227825Stheraven}
3565227825Stheraven
3566227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator>
3567227825Stheraven_ForwardIterator
3568227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3569227825Stheraven{
3570227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3571232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3572232950Stheraven    _ForwardIterator __s = __r;
3573232950Stheraven    try
3574232950Stheraven    {
3575232950Stheraven#endif
3576232950Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3577232950Stheraven            ::new(&*__r) value_type(*__f);
3578232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3579232950Stheraven    }
3580232950Stheraven    catch (...)
3581232950Stheraven    {
3582232950Stheraven        for (; __s != __r; ++__s)
3583232950Stheraven            __s->~value_type();
3584232950Stheraven        throw;
3585232950Stheraven    }
3586232950Stheraven#endif
3587227825Stheraven    return __r;
3588227825Stheraven}
3589227825Stheraven
3590227825Stheraventemplate <class _ForwardIterator, class _Tp>
3591227825Stheravenvoid
3592227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3593227825Stheraven{
3594227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3595232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3596232950Stheraven    _ForwardIterator __s = __f;
3597232950Stheraven    try
3598232950Stheraven    {
3599232950Stheraven#endif
3600232950Stheraven        for (; __f != __l; ++__f)
3601232950Stheraven            ::new(&*__f) value_type(__x);
3602232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3603232950Stheraven    }
3604232950Stheraven    catch (...)
3605232950Stheraven    {
3606232950Stheraven        for (; __s != __f; ++__s)
3607232950Stheraven            __s->~value_type();
3608232950Stheraven        throw;
3609232950Stheraven    }
3610232950Stheraven#endif
3611227825Stheraven}
3612227825Stheraven
3613227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp>
3614227825Stheraven_ForwardIterator
3615227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3616227825Stheraven{
3617227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3618232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3619232950Stheraven    _ForwardIterator __s = __f;
3620232950Stheraven    try
3621232950Stheraven    {
3622232950Stheraven#endif
3623232950Stheraven        for (; __n > 0; ++__f, --__n)
3624232950Stheraven            ::new(&*__f) value_type(__x);
3625232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3626232950Stheraven    }
3627232950Stheraven    catch (...)
3628232950Stheraven    {
3629232950Stheraven        for (; __s != __f; ++__s)
3630232950Stheraven            __s->~value_type();
3631232950Stheraven        throw;
3632232950Stheraven    }
3633232950Stheraven#endif
3634227825Stheraven    return __f;
3635227825Stheraven}
3636227825Stheraven
3637227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3638227825Stheraven    : public std::exception
3639227825Stheraven{
3640227825Stheravenpublic:
3641227825Stheraven    virtual ~bad_weak_ptr() _NOEXCEPT;
3642227825Stheraven    virtual const char* what() const  _NOEXCEPT;
3643227825Stheraven};
3644227825Stheraven
3645249998Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS weak_ptr;
3646227825Stheraven
3647227825Stheravenclass __shared_count
3648227825Stheraven{
3649227825Stheraven    __shared_count(const __shared_count&);
3650227825Stheraven    __shared_count& operator=(const __shared_count&);
3651227825Stheraven
3652227825Stheravenprotected:
3653227825Stheraven    long __shared_owners_;
3654227825Stheraven    virtual ~__shared_count();
3655227825Stheravenprivate:
3656227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT = 0;
3657227825Stheraven
3658227825Stheravenpublic:
3659227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3660227825Stheraven    explicit __shared_count(long __refs = 0) _NOEXCEPT
3661227825Stheraven        : __shared_owners_(__refs) {}
3662227825Stheraven
3663227825Stheraven    void __add_shared() _NOEXCEPT;
3664227825Stheraven    bool __release_shared() _NOEXCEPT;
3665227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3666227825Stheraven    long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3667227825Stheraven};
3668227825Stheraven
3669227825Stheravenclass __shared_weak_count
3670227825Stheraven    : private __shared_count
3671227825Stheraven{
3672227825Stheraven    long __shared_weak_owners_;
3673227825Stheraven
3674227825Stheravenpublic:
3675227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3676227825Stheraven    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3677227825Stheraven        : __shared_count(__refs),
3678227825Stheraven          __shared_weak_owners_(__refs) {}
3679227825Stheravenprotected:
3680227825Stheraven    virtual ~__shared_weak_count();
3681227825Stheraven
3682227825Stheravenpublic:
3683227825Stheraven    void __add_shared() _NOEXCEPT;
3684227825Stheraven    void __add_weak() _NOEXCEPT;
3685227825Stheraven    void __release_shared() _NOEXCEPT;
3686227825Stheraven    void __release_weak() _NOEXCEPT;
3687227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3688227825Stheraven    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3689227825Stheraven    __shared_weak_count* lock() _NOEXCEPT;
3690227825Stheraven
3691249998Sdim    // Define the function out only if we build static libc++ without RTTI.
3692249998Sdim    // Otherwise we may break clients who need to compile their projects with
3693249998Sdim    // -fno-rtti and yet link against a libc++.dylib compiled
3694249998Sdim    // without -fno-rtti.
3695249998Sdim#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3696227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3697249998Sdim#endif
3698227825Stheravenprivate:
3699227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3700227825Stheraven};
3701227825Stheraven
3702227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3703227825Stheravenclass __shared_ptr_pointer
3704227825Stheraven    : public __shared_weak_count
3705227825Stheraven{
3706227825Stheraven    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3707227825Stheravenpublic:
3708227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3709227825Stheraven    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3710227825Stheraven        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3711227825Stheraven
3712227825Stheraven#ifndef _LIBCPP_NO_RTTI
3713227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3714227825Stheraven#endif
3715227825Stheraven
3716227825Stheravenprivate:
3717227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3718227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3719227825Stheraven};
3720227825Stheraven
3721227825Stheraven#ifndef _LIBCPP_NO_RTTI
3722227825Stheraven
3723227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3724227825Stheravenconst void*
3725227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3726227825Stheraven{
3727227825Stheraven    return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3728227825Stheraven}
3729227825Stheraven
3730227825Stheraven#endif  // _LIBCPP_NO_RTTI
3731227825Stheraven
3732227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3733227825Stheravenvoid
3734227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3735227825Stheraven{
3736227825Stheraven    __data_.first().second()(__data_.first().first());
3737227825Stheraven    __data_.first().second().~_Dp();
3738227825Stheraven}
3739227825Stheraven
3740227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3741227825Stheravenvoid
3742227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3743227825Stheraven{
3744227825Stheraven    typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3745227825Stheraven    __data_.second().~_Alloc();
3746227825Stheraven    __a.deallocate(this, 1);
3747227825Stheraven}
3748227825Stheraven
3749227825Stheraventemplate <class _Tp, class _Alloc>
3750227825Stheravenclass __shared_ptr_emplace
3751227825Stheraven    : public __shared_weak_count
3752227825Stheraven{
3753227825Stheraven    __compressed_pair<_Alloc, _Tp> __data_;
3754227825Stheravenpublic:
3755227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3756227825Stheraven
3757227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3758227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3759227825Stheraven        :  __data_(_VSTD::move(__a)) {}
3760227825Stheraven
3761227825Stheraven    template <class ..._Args>
3762227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3763227825Stheraven        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3764232950Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3765232950Stheraven                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3766227825Stheraven
3767227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3768227825Stheraven
3769227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3770227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3771227825Stheraven        :  __data_(__a) {}
3772227825Stheraven
3773227825Stheraven    template <class _A0>
3774227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3775227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3776227825Stheraven            :  __data_(__a, _Tp(__a0)) {}
3777227825Stheraven
3778227825Stheraven    template <class _A0, class _A1>
3779227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3780227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3781227825Stheraven            :  __data_(__a, _Tp(__a0, __a1)) {}
3782227825Stheraven
3783227825Stheraven    template <class _A0, class _A1, class _A2>
3784227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3785227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3786227825Stheraven            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3787227825Stheraven
3788227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3789227825Stheraven
3790227825Stheravenprivate:
3791227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3792227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3793227825Stheravenpublic:
3794227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3795227825Stheraven    _Tp* get() _NOEXCEPT {return &__data_.second();}
3796227825Stheraven};
3797227825Stheraven
3798227825Stheraventemplate <class _Tp, class _Alloc>
3799227825Stheravenvoid
3800227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3801227825Stheraven{
3802227825Stheraven    __data_.second().~_Tp();
3803227825Stheraven}
3804227825Stheraven
3805227825Stheraventemplate <class _Tp, class _Alloc>
3806227825Stheravenvoid
3807227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3808227825Stheraven{
3809227825Stheraven    typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3810227825Stheraven    __data_.first().~_Alloc();
3811227825Stheraven    __a.deallocate(this, 1);
3812227825Stheraven}
3813227825Stheraven
3814249998Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS enable_shared_from_this;
3815227825Stheraven
3816227825Stheraventemplate<class _Tp>
3817249998Sdimclass _LIBCPP_TYPE_VIS shared_ptr
3818227825Stheraven{
3819227825Stheravenpublic:
3820227825Stheraven    typedef _Tp element_type;
3821227825Stheravenprivate:
3822227825Stheraven    element_type*      __ptr_;
3823227825Stheraven    __shared_weak_count* __cntrl_;
3824227825Stheraven
3825227825Stheraven    struct __nat {int __for_bool_;};
3826227825Stheravenpublic:
3827241903Sdim    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3828241903Sdim    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3829232950Stheraven    template<class _Yp,
3830232950Stheraven             class = typename enable_if
3831232950Stheraven                     <
3832232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3833232950Stheraven                     >::type
3834232950Stheraven            >
3835232950Stheraven        explicit shared_ptr(_Yp* __p);
3836232950Stheraven    template<class _Yp, class _Dp,
3837232950Stheraven             class = typename enable_if
3838232950Stheraven                     <
3839232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3840232950Stheraven                     >::type
3841232950Stheraven            >
3842232950Stheraven        shared_ptr(_Yp* __p, _Dp __d);
3843232950Stheraven    template<class _Yp, class _Dp, class _Alloc,
3844232950Stheraven             class = typename enable_if
3845232950Stheraven                     <
3846232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3847232950Stheraven                     >::type
3848232950Stheraven            >
3849232950Stheraven        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3850227825Stheraven    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3851227825Stheraven    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3852227825Stheraven    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3853227825Stheraven    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3854227825Stheraven    template<class _Yp>
3855227825Stheraven        shared_ptr(const shared_ptr<_Yp>& __r,
3856227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3857227825Stheraven                       _NOEXCEPT;
3858227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3859227825Stheraven    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3860227825Stheraven    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3861227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3862227825Stheraven                       _NOEXCEPT;
3863227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3864227825Stheraven    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3865227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3866227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3867232950Stheraven    template<class _Yp,
3868232950Stheraven             class = typename enable_if
3869232950Stheraven                     <
3870232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3871232950Stheraven                     >::type
3872232950Stheraven            >
3873232950Stheraven        shared_ptr(auto_ptr<_Yp>&& __r);
3874227825Stheraven#else
3875232950Stheraven    template<class _Yp,
3876232950Stheraven             class = typename enable_if
3877232950Stheraven                     <
3878232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3879232950Stheraven                     >::type
3880232950Stheraven            >
3881232950Stheraven        shared_ptr(auto_ptr<_Yp> __r);
3882227825Stheraven#endif
3883227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3884232950Stheraven    template <class _Yp, class _Dp,
3885232950Stheraven                 class = typename enable_if
3886232950Stheraven                 <
3887232950Stheraven                    !is_array<_Yp>::value &&
3888232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3889232950Stheraven                 >::type
3890232950Stheraven             >
3891232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3892227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3893232950Stheraven    template <class _Yp, class _Dp,
3894232950Stheraven                 class = typename enable_if
3895232950Stheraven                 <
3896232950Stheraven                    !is_array<_Yp>::value &&
3897232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3898232950Stheraven                 >::type
3899232950Stheraven             >
3900232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3901227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3902227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3903232950Stheraven    template <class _Yp, class _Dp,
3904232950Stheraven                 class = typename enable_if
3905232950Stheraven                 <
3906232950Stheraven                    !is_array<_Yp>::value &&
3907232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3908232950Stheraven                 >::type
3909232950Stheraven             > shared_ptr(unique_ptr<_Yp, _Dp>,
3910227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3911232950Stheraven    template <class _Yp, class _Dp,
3912232950Stheraven                 class = typename enable_if
3913232950Stheraven                 <
3914232950Stheraven                    !is_array<_Yp>::value &&
3915232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3916232950Stheraven                 >::type
3917232950Stheraven             >
3918232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>,
3919227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3920227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3921227825Stheraven
3922227825Stheraven    ~shared_ptr();
3923227825Stheraven
3924227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3925232950Stheraven    template<class _Yp>
3926232950Stheraven        typename enable_if
3927232950Stheraven        <
3928232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3929232950Stheraven            shared_ptr&
3930232950Stheraven        >::type
3931232950Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3932227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3933227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3934232950Stheraven    template<class _Yp>
3935232950Stheraven        typename enable_if
3936232950Stheraven        <
3937232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3938232950Stheraven            shared_ptr<_Tp>&
3939232950Stheraven        >::type
3940232950Stheraven        operator=(shared_ptr<_Yp>&& __r);
3941232950Stheraven    template<class _Yp>
3942232950Stheraven        typename enable_if
3943232950Stheraven        <
3944232950Stheraven            !is_array<_Yp>::value &&
3945232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3946232950Stheraven            shared_ptr&
3947232950Stheraven        >::type
3948232950Stheraven        operator=(auto_ptr<_Yp>&& __r);
3949227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3950232950Stheraven    template<class _Yp>
3951232950Stheraven        typename enable_if
3952232950Stheraven        <
3953232950Stheraven            !is_array<_Yp>::value &&
3954232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3955232950Stheraven            shared_ptr&
3956232950Stheraven        >::type
3957232950Stheraven        operator=(auto_ptr<_Yp> __r);
3958227825Stheraven#endif
3959232950Stheraven    template <class _Yp, class _Dp>
3960232950Stheraven        typename enable_if
3961232950Stheraven        <
3962232950Stheraven            !is_array<_Yp>::value &&
3963232950Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3964232950Stheraven            shared_ptr&
3965232950Stheraven        >::type
3966227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3967232950Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3968227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3969232950Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3970227825Stheraven#endif
3971227825Stheraven
3972227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3973227825Stheraven    void reset() _NOEXCEPT;
3974232950Stheraven    template<class _Yp>
3975232950Stheraven        typename enable_if
3976232950Stheraven        <
3977232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3978232950Stheraven            void
3979232950Stheraven        >::type
3980232950Stheraven        reset(_Yp* __p);
3981232950Stheraven    template<class _Yp, class _Dp>
3982232950Stheraven        typename enable_if
3983232950Stheraven        <
3984232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3985232950Stheraven            void
3986232950Stheraven        >::type
3987232950Stheraven        reset(_Yp* __p, _Dp __d);
3988232950Stheraven    template<class _Yp, class _Dp, class _Alloc>
3989232950Stheraven        typename enable_if
3990232950Stheraven        <
3991232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3992232950Stheraven            void
3993232950Stheraven        >::type
3994232950Stheraven        reset(_Yp* __p, _Dp __d, _Alloc __a);
3995227825Stheraven
3996227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3997227825Stheraven    element_type* get() const _NOEXCEPT {return __ptr_;}
3998227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3999227825Stheraven    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4000227825Stheraven        {return *__ptr_;}
4001227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4002227825Stheraven    element_type* operator->() const _NOEXCEPT {return __ptr_;}
4003227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4004227825Stheraven    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
4005227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4006227825Stheraven    bool unique() const _NOEXCEPT {return use_count() == 1;}
4007227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4008232950Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
4009232950Stheraven    template <class _Up>
4010227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4011232950Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
4012227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
4013232950Stheraven    template <class _Up>
4014227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4015232950Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
4016227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
4017241903Sdim    _LIBCPP_INLINE_VISIBILITY
4018241903Sdim    bool
4019241903Sdim    __owner_equivalent(const shared_ptr& __p) const
4020241903Sdim        {return __cntrl_ == __p.__cntrl_;}
4021227825Stheraven
4022227825Stheraven#ifndef _LIBCPP_NO_RTTI
4023227825Stheraven    template <class _Dp>
4024227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4025227825Stheraven        _Dp* __get_deleter() const _NOEXCEPT
4026227825Stheraven            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
4027227825Stheraven#endif  // _LIBCPP_NO_RTTI
4028227825Stheraven
4029227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4030227825Stheraven
4031227825Stheraven    template<class ..._Args>
4032227825Stheraven        static
4033227825Stheraven        shared_ptr<_Tp>
4034227825Stheraven        make_shared(_Args&& ...__args);
4035227825Stheraven
4036227825Stheraven    template<class _Alloc, class ..._Args>
4037227825Stheraven        static
4038227825Stheraven        shared_ptr<_Tp>
4039227825Stheraven        allocate_shared(const _Alloc& __a, _Args&& ...__args);
4040227825Stheraven
4041227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4042227825Stheraven
4043227825Stheraven    static shared_ptr<_Tp> make_shared();
4044227825Stheraven
4045227825Stheraven    template<class _A0>
4046227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&);
4047227825Stheraven
4048227825Stheraven    template<class _A0, class _A1>
4049227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4050227825Stheraven
4051227825Stheraven    template<class _A0, class _A1, class _A2>
4052227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4053227825Stheraven
4054227825Stheraven    template<class _Alloc>
4055227825Stheraven        static shared_ptr<_Tp>
4056227825Stheraven        allocate_shared(const _Alloc& __a);
4057227825Stheraven
4058227825Stheraven    template<class _Alloc, class _A0>
4059227825Stheraven        static shared_ptr<_Tp>
4060227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0);
4061227825Stheraven
4062227825Stheraven    template<class _Alloc, class _A0, class _A1>
4063227825Stheraven        static shared_ptr<_Tp>
4064227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4065227825Stheraven
4066227825Stheraven    template<class _Alloc, class _A0, class _A1, class _A2>
4067227825Stheraven        static shared_ptr<_Tp>
4068227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4069227825Stheraven
4070227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4071227825Stheraven
4072227825Stheravenprivate:
4073227825Stheraven
4074227825Stheraven    template <class _Yp>
4075227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4076227825Stheraven        void
4077227825Stheraven        __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4078227825Stheraven        {
4079227825Stheraven            if (__e)
4080227825Stheraven                __e->__weak_this_ = *this;
4081227825Stheraven        }
4082227825Stheraven
4083227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4084227825Stheraven    void __enable_weak_this(const void*) _NOEXCEPT {}
4085227825Stheraven
4086249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
4087249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
4088227825Stheraven};
4089227825Stheraven
4090227825Stheraventemplate<class _Tp>
4091227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4092241903Sdim_LIBCPP_CONSTEXPR
4093227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4094227825Stheraven    : __ptr_(0),
4095227825Stheraven      __cntrl_(0)
4096227825Stheraven{
4097227825Stheraven}
4098227825Stheraven
4099227825Stheraventemplate<class _Tp>
4100227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4101241903Sdim_LIBCPP_CONSTEXPR
4102227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4103227825Stheraven    : __ptr_(0),
4104227825Stheraven      __cntrl_(0)
4105227825Stheraven{
4106227825Stheraven}
4107227825Stheraven
4108227825Stheraventemplate<class _Tp>
4109232950Stheraventemplate<class _Yp, class>
4110227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p)
4111227825Stheraven    : __ptr_(__p)
4112227825Stheraven{
4113227825Stheraven    unique_ptr<_Yp> __hold(__p);
4114227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4115227825Stheraven    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4116227825Stheraven    __hold.release();
4117227825Stheraven    __enable_weak_this(__p);
4118227825Stheraven}
4119227825Stheraven
4120227825Stheraventemplate<class _Tp>
4121232950Stheraventemplate<class _Yp, class _Dp, class>
4122227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4123227825Stheraven    : __ptr_(__p)
4124227825Stheraven{
4125227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4126227825Stheraven    try
4127227825Stheraven    {
4128227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4129227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4130227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4131227825Stheraven        __enable_weak_this(__p);
4132227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4133227825Stheraven    }
4134227825Stheraven    catch (...)
4135227825Stheraven    {
4136227825Stheraven        __d(__p);
4137227825Stheraven        throw;
4138227825Stheraven    }
4139227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4140227825Stheraven}
4141227825Stheraven
4142227825Stheraventemplate<class _Tp>
4143227825Stheraventemplate<class _Dp>
4144227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4145227825Stheraven    : __ptr_(0)
4146227825Stheraven{
4147227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4148227825Stheraven    try
4149227825Stheraven    {
4150227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4151227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4152227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4153227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4154227825Stheraven    }
4155227825Stheraven    catch (...)
4156227825Stheraven    {
4157227825Stheraven        __d(__p);
4158227825Stheraven        throw;
4159227825Stheraven    }
4160227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4161227825Stheraven}
4162227825Stheraven
4163227825Stheraventemplate<class _Tp>
4164232950Stheraventemplate<class _Yp, class _Dp, class _Alloc, class>
4165227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4166227825Stheraven    : __ptr_(__p)
4167227825Stheraven{
4168227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4169227825Stheraven    try
4170227825Stheraven    {
4171227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4172227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4173227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4174227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4175227825Stheraven        _A2 __a2(__a);
4176227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4177227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4178227825Stheraven        __cntrl_ = __hold2.release();
4179227825Stheraven        __enable_weak_this(__p);
4180227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4181227825Stheraven    }
4182227825Stheraven    catch (...)
4183227825Stheraven    {
4184227825Stheraven        __d(__p);
4185227825Stheraven        throw;
4186227825Stheraven    }
4187227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4188227825Stheraven}
4189227825Stheraven
4190227825Stheraventemplate<class _Tp>
4191227825Stheraventemplate<class _Dp, class _Alloc>
4192227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4193227825Stheraven    : __ptr_(0)
4194227825Stheraven{
4195227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4196227825Stheraven    try
4197227825Stheraven    {
4198227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4199227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4200227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4201227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4202227825Stheraven        _A2 __a2(__a);
4203227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4204227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4205227825Stheraven        __cntrl_ = __hold2.release();
4206227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4207227825Stheraven    }
4208227825Stheraven    catch (...)
4209227825Stheraven    {
4210227825Stheraven        __d(__p);
4211227825Stheraven        throw;
4212227825Stheraven    }
4213227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4214227825Stheraven}
4215227825Stheraven
4216227825Stheraventemplate<class _Tp>
4217227825Stheraventemplate<class _Yp>
4218227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4219227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4220227825Stheraven    : __ptr_(__p),
4221227825Stheraven      __cntrl_(__r.__cntrl_)
4222227825Stheraven{
4223227825Stheraven    if (__cntrl_)
4224227825Stheraven        __cntrl_->__add_shared();
4225227825Stheraven}
4226227825Stheraven
4227227825Stheraventemplate<class _Tp>
4228227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4229227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4230227825Stheraven    : __ptr_(__r.__ptr_),
4231227825Stheraven      __cntrl_(__r.__cntrl_)
4232227825Stheraven{
4233227825Stheraven    if (__cntrl_)
4234227825Stheraven        __cntrl_->__add_shared();
4235227825Stheraven}
4236227825Stheraven
4237227825Stheraventemplate<class _Tp>
4238227825Stheraventemplate<class _Yp>
4239227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4240227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4241227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4242227825Stheraven         _NOEXCEPT
4243227825Stheraven    : __ptr_(__r.__ptr_),
4244227825Stheraven      __cntrl_(__r.__cntrl_)
4245227825Stheraven{
4246227825Stheraven    if (__cntrl_)
4247227825Stheraven        __cntrl_->__add_shared();
4248227825Stheraven}
4249227825Stheraven
4250227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4251227825Stheraven
4252227825Stheraventemplate<class _Tp>
4253227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4254227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4255227825Stheraven    : __ptr_(__r.__ptr_),
4256227825Stheraven      __cntrl_(__r.__cntrl_)
4257227825Stheraven{
4258227825Stheraven    __r.__ptr_ = 0;
4259227825Stheraven    __r.__cntrl_ = 0;
4260227825Stheraven}
4261227825Stheraven
4262227825Stheraventemplate<class _Tp>
4263227825Stheraventemplate<class _Yp>
4264227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4265227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4266227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4267227825Stheraven         _NOEXCEPT
4268227825Stheraven    : __ptr_(__r.__ptr_),
4269227825Stheraven      __cntrl_(__r.__cntrl_)
4270227825Stheraven{
4271227825Stheraven    __r.__ptr_ = 0;
4272227825Stheraven    __r.__cntrl_ = 0;
4273227825Stheraven}
4274227825Stheraven
4275227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4276227825Stheraven
4277227825Stheraventemplate<class _Tp>
4278232950Stheraventemplate<class _Yp, class>
4279227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4280227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4281227825Stheraven#else
4282227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4283227825Stheraven#endif
4284227825Stheraven    : __ptr_(__r.get())
4285227825Stheraven{
4286227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4287227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4288227825Stheraven    __enable_weak_this(__r.get());
4289227825Stheraven    __r.release();
4290227825Stheraven}
4291227825Stheraven
4292227825Stheraventemplate<class _Tp>
4293232950Stheraventemplate <class _Yp, class _Dp, class>
4294227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4295227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4296227825Stheraven#else
4297227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4298227825Stheraven#endif
4299227825Stheraven           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4300227825Stheraven    : __ptr_(__r.get())
4301227825Stheraven{
4302227825Stheraven    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4303227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4304227825Stheraven    __enable_weak_this(__r.get());
4305227825Stheraven    __r.release();
4306227825Stheraven}
4307227825Stheraven
4308227825Stheraventemplate<class _Tp>
4309232950Stheraventemplate <class _Yp, class _Dp, class>
4310227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4311227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4312227825Stheraven#else
4313227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4314227825Stheraven#endif
4315227825Stheraven           typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4316227825Stheraven    : __ptr_(__r.get())
4317227825Stheraven{
4318227825Stheraven    typedef __shared_ptr_pointer<_Yp*,
4319227825Stheraven                                 reference_wrapper<typename remove_reference<_Dp>::type>,
4320227825Stheraven                                 allocator<_Yp> > _CntrlBlk;
4321227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4322227825Stheraven    __enable_weak_this(__r.get());
4323227825Stheraven    __r.release();
4324227825Stheraven}
4325227825Stheraven
4326227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4327227825Stheraven
4328227825Stheraventemplate<class _Tp>
4329227825Stheraventemplate<class ..._Args>
4330227825Stheravenshared_ptr<_Tp>
4331227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args)
4332227825Stheraven{
4333227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4334227825Stheraven    typedef allocator<_CntrlBlk> _A2;
4335227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4336227825Stheraven    _A2 __a2;
4337227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4338227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4339227825Stheraven    shared_ptr<_Tp> __r;
4340227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4341227825Stheraven    __r.__cntrl_ = __hold2.release();
4342227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4343227825Stheraven    return __r;
4344227825Stheraven}
4345227825Stheraven
4346227825Stheraventemplate<class _Tp>
4347227825Stheraventemplate<class _Alloc, class ..._Args>
4348227825Stheravenshared_ptr<_Tp>
4349227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4350227825Stheraven{
4351227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4352227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4353227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4354227825Stheraven    _A2 __a2(__a);
4355227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4356227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4357227825Stheraven    shared_ptr<_Tp> __r;
4358227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4359227825Stheraven    __r.__cntrl_ = __hold2.release();
4360227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4361227825Stheraven    return __r;
4362227825Stheraven}
4363227825Stheraven
4364227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4365227825Stheraven
4366227825Stheraventemplate<class _Tp>
4367227825Stheravenshared_ptr<_Tp>
4368227825Stheravenshared_ptr<_Tp>::make_shared()
4369227825Stheraven{
4370227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4371227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4372227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4373227825Stheraven    _Alloc2 __alloc2;
4374227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4375227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2);
4376227825Stheraven    shared_ptr<_Tp> __r;
4377227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4378227825Stheraven    __r.__cntrl_ = __hold2.release();
4379227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4380227825Stheraven    return __r;
4381227825Stheraven}
4382227825Stheraven
4383227825Stheraventemplate<class _Tp>
4384227825Stheraventemplate<class _A0>
4385227825Stheravenshared_ptr<_Tp>
4386227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0)
4387227825Stheraven{
4388227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4389227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4390227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4391227825Stheraven    _Alloc2 __alloc2;
4392227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4393227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4394227825Stheraven    shared_ptr<_Tp> __r;
4395227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4396227825Stheraven    __r.__cntrl_ = __hold2.release();
4397227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4398227825Stheraven    return __r;
4399227825Stheraven}
4400227825Stheraven
4401227825Stheraventemplate<class _Tp>
4402227825Stheraventemplate<class _A0, class _A1>
4403227825Stheravenshared_ptr<_Tp>
4404227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4405227825Stheraven{
4406227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4407227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4408227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4409227825Stheraven    _Alloc2 __alloc2;
4410227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4411227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4412227825Stheraven    shared_ptr<_Tp> __r;
4413227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4414227825Stheraven    __r.__cntrl_ = __hold2.release();
4415227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4416227825Stheraven    return __r;
4417227825Stheraven}
4418227825Stheraven
4419227825Stheraventemplate<class _Tp>
4420227825Stheraventemplate<class _A0, class _A1, class _A2>
4421227825Stheravenshared_ptr<_Tp>
4422227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4423227825Stheraven{
4424227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4425227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4426227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4427227825Stheraven    _Alloc2 __alloc2;
4428227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4429227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4430227825Stheraven    shared_ptr<_Tp> __r;
4431227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4432227825Stheraven    __r.__cntrl_ = __hold2.release();
4433227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4434227825Stheraven    return __r;
4435227825Stheraven}
4436227825Stheraven
4437227825Stheraventemplate<class _Tp>
4438227825Stheraventemplate<class _Alloc>
4439227825Stheravenshared_ptr<_Tp>
4440227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4441227825Stheraven{
4442227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4443227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4444227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4445227825Stheraven    _Alloc2 __alloc2(__a);
4446227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4447227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a);
4448227825Stheraven    shared_ptr<_Tp> __r;
4449227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4450227825Stheraven    __r.__cntrl_ = __hold2.release();
4451227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4452227825Stheraven    return __r;
4453227825Stheraven}
4454227825Stheraven
4455227825Stheraventemplate<class _Tp>
4456227825Stheraventemplate<class _Alloc, class _A0>
4457227825Stheravenshared_ptr<_Tp>
4458227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4459227825Stheraven{
4460227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4461227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4462227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4463227825Stheraven    _Alloc2 __alloc2(__a);
4464227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4465227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4466227825Stheraven    shared_ptr<_Tp> __r;
4467227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4468227825Stheraven    __r.__cntrl_ = __hold2.release();
4469227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4470227825Stheraven    return __r;
4471227825Stheraven}
4472227825Stheraven
4473227825Stheraventemplate<class _Tp>
4474227825Stheraventemplate<class _Alloc, class _A0, class _A1>
4475227825Stheravenshared_ptr<_Tp>
4476227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4477227825Stheraven{
4478227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4479227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4480227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4481227825Stheraven    _Alloc2 __alloc2(__a);
4482227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4483227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4484227825Stheraven    shared_ptr<_Tp> __r;
4485227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4486227825Stheraven    __r.__cntrl_ = __hold2.release();
4487227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4488227825Stheraven    return __r;
4489227825Stheraven}
4490227825Stheraven
4491227825Stheraventemplate<class _Tp>
4492227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2>
4493227825Stheravenshared_ptr<_Tp>
4494227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4495227825Stheraven{
4496227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4497227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4498227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4499227825Stheraven    _Alloc2 __alloc2(__a);
4500227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4501227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4502227825Stheraven    shared_ptr<_Tp> __r;
4503227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4504227825Stheraven    __r.__cntrl_ = __hold2.release();
4505227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4506227825Stheraven    return __r;
4507227825Stheraven}
4508227825Stheraven
4509227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4510227825Stheraven
4511227825Stheraventemplate<class _Tp>
4512227825Stheravenshared_ptr<_Tp>::~shared_ptr()
4513227825Stheraven{
4514227825Stheraven    if (__cntrl_)
4515227825Stheraven        __cntrl_->__release_shared();
4516227825Stheraven}
4517227825Stheraven
4518227825Stheraventemplate<class _Tp>
4519227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4520227825Stheravenshared_ptr<_Tp>&
4521227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4522227825Stheraven{
4523227825Stheraven    shared_ptr(__r).swap(*this);
4524227825Stheraven    return *this;
4525227825Stheraven}
4526227825Stheraven
4527227825Stheraventemplate<class _Tp>
4528227825Stheraventemplate<class _Yp>
4529227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4530232950Stheraventypename enable_if
4531232950Stheraven<
4532232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4533232950Stheraven    shared_ptr<_Tp>&
4534232950Stheraven>::type
4535227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4536227825Stheraven{
4537227825Stheraven    shared_ptr(__r).swap(*this);
4538227825Stheraven    return *this;
4539227825Stheraven}
4540227825Stheraven
4541227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4542227825Stheraven
4543227825Stheraventemplate<class _Tp>
4544227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4545227825Stheravenshared_ptr<_Tp>&
4546227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4547227825Stheraven{
4548227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4549227825Stheraven    return *this;
4550227825Stheraven}
4551227825Stheraven
4552227825Stheraventemplate<class _Tp>
4553227825Stheraventemplate<class _Yp>
4554227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4555232950Stheraventypename enable_if
4556232950Stheraven<
4557232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4558232950Stheraven    shared_ptr<_Tp>&
4559232950Stheraven>::type
4560227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4561227825Stheraven{
4562227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4563227825Stheraven    return *this;
4564227825Stheraven}
4565227825Stheraven
4566227825Stheraventemplate<class _Tp>
4567227825Stheraventemplate<class _Yp>
4568227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4569232950Stheraventypename enable_if
4570232950Stheraven<
4571232950Stheraven    !is_array<_Yp>::value &&
4572232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4573232950Stheraven    shared_ptr<_Tp>&
4574232950Stheraven>::type
4575227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4576227825Stheraven{
4577227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4578227825Stheraven    return *this;
4579227825Stheraven}
4580227825Stheraven
4581227825Stheraventemplate<class _Tp>
4582227825Stheraventemplate <class _Yp, class _Dp>
4583227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4584232950Stheraventypename enable_if
4585232950Stheraven<
4586232950Stheraven    !is_array<_Yp>::value &&
4587232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4588232950Stheraven    shared_ptr<_Tp>&
4589232950Stheraven>::type
4590227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4591227825Stheraven{
4592227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4593227825Stheraven    return *this;
4594227825Stheraven}
4595227825Stheraven
4596227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4597227825Stheraven
4598227825Stheraventemplate<class _Tp>
4599227825Stheraventemplate<class _Yp>
4600227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4601232950Stheraventypename enable_if
4602232950Stheraven<
4603232950Stheraven    !is_array<_Yp>::value &&
4604232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4605232950Stheraven    shared_ptr<_Tp>&
4606232950Stheraven>::type
4607227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4608227825Stheraven{
4609227825Stheraven    shared_ptr(__r).swap(*this);
4610227825Stheraven    return *this;
4611227825Stheraven}
4612227825Stheraven
4613227825Stheraventemplate<class _Tp>
4614227825Stheraventemplate <class _Yp, class _Dp>
4615227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4616232950Stheraventypename enable_if
4617232950Stheraven<
4618232950Stheraven    !is_array<_Yp>::value &&
4619232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4620232950Stheraven    shared_ptr<_Tp>&
4621232950Stheraven>::type
4622227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4623227825Stheraven{
4624227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4625227825Stheraven    return *this;
4626227825Stheraven}
4627227825Stheraven
4628227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4629227825Stheraven
4630227825Stheraventemplate<class _Tp>
4631227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4632227825Stheravenvoid
4633227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4634227825Stheraven{
4635227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
4636227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
4637227825Stheraven}
4638227825Stheraven
4639227825Stheraventemplate<class _Tp>
4640227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4641227825Stheravenvoid
4642227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT
4643227825Stheraven{
4644227825Stheraven    shared_ptr().swap(*this);
4645227825Stheraven}
4646227825Stheraven
4647227825Stheraventemplate<class _Tp>
4648227825Stheraventemplate<class _Yp>
4649227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4650232950Stheraventypename enable_if
4651232950Stheraven<
4652232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4653232950Stheraven    void
4654232950Stheraven>::type
4655227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p)
4656227825Stheraven{
4657227825Stheraven    shared_ptr(__p).swap(*this);
4658227825Stheraven}
4659227825Stheraven
4660227825Stheraventemplate<class _Tp>
4661227825Stheraventemplate<class _Yp, class _Dp>
4662227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4663232950Stheraventypename enable_if
4664232950Stheraven<
4665232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4666232950Stheraven    void
4667232950Stheraven>::type
4668227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4669227825Stheraven{
4670227825Stheraven    shared_ptr(__p, __d).swap(*this);
4671227825Stheraven}
4672227825Stheraven
4673227825Stheraventemplate<class _Tp>
4674227825Stheraventemplate<class _Yp, class _Dp, class _Alloc>
4675227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4676232950Stheraventypename enable_if
4677232950Stheraven<
4678232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4679232950Stheraven    void
4680232950Stheraven>::type
4681227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4682227825Stheraven{
4683227825Stheraven    shared_ptr(__p, __d, __a).swap(*this);
4684227825Stheraven}
4685227825Stheraven
4686227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4687227825Stheraven
4688227825Stheraventemplate<class _Tp, class ..._Args>
4689227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4690232950Stheraventypename enable_if
4691232950Stheraven<
4692232950Stheraven    !is_array<_Tp>::value,
4693232950Stheraven    shared_ptr<_Tp>
4694232950Stheraven>::type
4695227825Stheravenmake_shared(_Args&& ...__args)
4696227825Stheraven{
4697227825Stheraven    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4698227825Stheraven}
4699227825Stheraven
4700227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args>
4701227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4702232950Stheraventypename enable_if
4703232950Stheraven<
4704232950Stheraven    !is_array<_Tp>::value,
4705232950Stheraven    shared_ptr<_Tp>
4706232950Stheraven>::type
4707227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args)
4708227825Stheraven{
4709227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4710227825Stheraven}
4711227825Stheraven
4712227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4713227825Stheraven
4714227825Stheraventemplate<class _Tp>
4715227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4716227825Stheravenshared_ptr<_Tp>
4717227825Stheravenmake_shared()
4718227825Stheraven{
4719227825Stheraven    return shared_ptr<_Tp>::make_shared();
4720227825Stheraven}
4721227825Stheraven
4722227825Stheraventemplate<class _Tp, class _A0>
4723227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4724227825Stheravenshared_ptr<_Tp>
4725227825Stheravenmake_shared(_A0& __a0)
4726227825Stheraven{
4727227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0);
4728227825Stheraven}
4729227825Stheraven
4730227825Stheraventemplate<class _Tp, class _A0, class _A1>
4731227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4732227825Stheravenshared_ptr<_Tp>
4733227825Stheravenmake_shared(_A0& __a0, _A1& __a1)
4734227825Stheraven{
4735227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4736227825Stheraven}
4737227825Stheraven
4738227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2>
4739227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4740227825Stheravenshared_ptr<_Tp>
4741227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4742227825Stheraven{
4743227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4744227825Stheraven}
4745227825Stheraven
4746227825Stheraventemplate<class _Tp, class _Alloc>
4747227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4748227825Stheravenshared_ptr<_Tp>
4749227825Stheravenallocate_shared(const _Alloc& __a)
4750227825Stheraven{
4751227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a);
4752227825Stheraven}
4753227825Stheraven
4754227825Stheraventemplate<class _Tp, class _Alloc, class _A0>
4755227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4756227825Stheravenshared_ptr<_Tp>
4757227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0)
4758227825Stheraven{
4759227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4760227825Stheraven}
4761227825Stheraven
4762227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1>
4763227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4764227825Stheravenshared_ptr<_Tp>
4765227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4766227825Stheraven{
4767227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4768227825Stheraven}
4769227825Stheraven
4770227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4771227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4772227825Stheravenshared_ptr<_Tp>
4773227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4774227825Stheraven{
4775227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4776227825Stheraven}
4777227825Stheraven
4778227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4779227825Stheraven
4780227825Stheraventemplate<class _Tp, class _Up>
4781227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4782227825Stheravenbool
4783227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4784227825Stheraven{
4785227825Stheraven    return __x.get() == __y.get();
4786227825Stheraven}
4787227825Stheraven
4788227825Stheraventemplate<class _Tp, class _Up>
4789227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4790227825Stheravenbool
4791227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4792227825Stheraven{
4793227825Stheraven    return !(__x == __y);
4794227825Stheraven}
4795227825Stheraven
4796227825Stheraventemplate<class _Tp, class _Up>
4797227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4798227825Stheravenbool
4799227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4800227825Stheraven{
4801232950Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4802232950Stheraven    return less<_V>()(__x.get(), __y.get());
4803227825Stheraven}
4804227825Stheraven
4805232950Stheraventemplate<class _Tp, class _Up>
4806232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4807232950Stheravenbool
4808232950Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4809232950Stheraven{
4810232950Stheraven    return __y < __x;
4811232950Stheraven}
4812232950Stheraven
4813232950Stheraventemplate<class _Tp, class _Up>
4814232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4815232950Stheravenbool
4816232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4817232950Stheraven{
4818232950Stheraven    return !(__y < __x);
4819232950Stheraven}
4820232950Stheraven
4821232950Stheraventemplate<class _Tp, class _Up>
4822232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4823232950Stheravenbool
4824232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4825232950Stheraven{
4826232950Stheraven    return !(__x < __y);
4827232950Stheraven}
4828232950Stheraven
4829227825Stheraventemplate<class _Tp>
4830227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4831232950Stheravenbool
4832232950Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4833232950Stheraven{
4834232950Stheraven    return !__x;
4835232950Stheraven}
4836232950Stheraven
4837232950Stheraventemplate<class _Tp>
4838232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4839232950Stheravenbool
4840232950Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4841232950Stheraven{
4842232950Stheraven    return !__x;
4843232950Stheraven}
4844232950Stheraven
4845232950Stheraventemplate<class _Tp>
4846232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4847232950Stheravenbool
4848232950Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4849232950Stheraven{
4850232950Stheraven    return static_cast<bool>(__x);
4851232950Stheraven}
4852232950Stheraven
4853232950Stheraventemplate<class _Tp>
4854232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4855232950Stheravenbool
4856232950Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4857232950Stheraven{
4858232950Stheraven    return static_cast<bool>(__x);
4859232950Stheraven}
4860232950Stheraven
4861232950Stheraventemplate<class _Tp>
4862232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4863232950Stheravenbool
4864232950Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4865232950Stheraven{
4866232950Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4867232950Stheraven}
4868232950Stheraven
4869232950Stheraventemplate<class _Tp>
4870232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4871232950Stheravenbool
4872232950Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4873232950Stheraven{
4874232950Stheraven    return less<_Tp*>()(nullptr, __x.get());
4875232950Stheraven}
4876232950Stheraven
4877232950Stheraventemplate<class _Tp>
4878232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4879232950Stheravenbool
4880232950Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4881232950Stheraven{
4882232950Stheraven    return nullptr < __x;
4883232950Stheraven}
4884232950Stheraven
4885232950Stheraventemplate<class _Tp>
4886232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4887232950Stheravenbool
4888232950Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4889232950Stheraven{
4890232950Stheraven    return __x < nullptr;
4891232950Stheraven}
4892232950Stheraven
4893232950Stheraventemplate<class _Tp>
4894232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4895232950Stheravenbool
4896232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4897232950Stheraven{
4898232950Stheraven    return !(nullptr < __x);
4899232950Stheraven}
4900232950Stheraven
4901232950Stheraventemplate<class _Tp>
4902232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4903232950Stheravenbool
4904232950Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4905232950Stheraven{
4906232950Stheraven    return !(__x < nullptr);
4907232950Stheraven}
4908232950Stheraven
4909232950Stheraventemplate<class _Tp>
4910232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4911232950Stheravenbool
4912232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4913232950Stheraven{
4914232950Stheraven    return !(__x < nullptr);
4915232950Stheraven}
4916232950Stheraven
4917232950Stheraventemplate<class _Tp>
4918232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4919232950Stheravenbool
4920232950Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4921232950Stheraven{
4922232950Stheraven    return !(nullptr < __x);
4923232950Stheraven}
4924232950Stheraven
4925232950Stheraventemplate<class _Tp>
4926232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4927227825Stheravenvoid
4928227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4929227825Stheraven{
4930227825Stheraven    __x.swap(__y);
4931227825Stheraven}
4932227825Stheraven
4933227825Stheraventemplate<class _Tp, class _Up>
4934227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4935232950Stheraventypename enable_if
4936232950Stheraven<
4937232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4938232950Stheraven    shared_ptr<_Tp>
4939232950Stheraven>::type
4940227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4941227825Stheraven{
4942227825Stheraven    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4943227825Stheraven}
4944227825Stheraven
4945227825Stheraventemplate<class _Tp, class _Up>
4946227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4947232950Stheraventypename enable_if
4948232950Stheraven<
4949232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4950232950Stheraven    shared_ptr<_Tp>
4951232950Stheraven>::type
4952227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4953227825Stheraven{
4954227825Stheraven    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4955227825Stheraven    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4956227825Stheraven}
4957227825Stheraven
4958227825Stheraventemplate<class _Tp, class _Up>
4959232950Stheraventypename enable_if
4960232950Stheraven<
4961232950Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4962232950Stheraven    shared_ptr<_Tp>
4963232950Stheraven>::type
4964227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4965227825Stheraven{
4966232950Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4967232950Stheraven    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4968227825Stheraven}
4969227825Stheraven
4970227825Stheraven#ifndef _LIBCPP_NO_RTTI
4971227825Stheraven
4972227825Stheraventemplate<class _Dp, class _Tp>
4973227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4974227825Stheraven_Dp*
4975227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4976227825Stheraven{
4977227825Stheraven    return __p.template __get_deleter<_Dp>();
4978227825Stheraven}
4979227825Stheraven
4980227825Stheraven#endif  // _LIBCPP_NO_RTTI
4981227825Stheraven
4982227825Stheraventemplate<class _Tp>
4983249998Sdimclass _LIBCPP_TYPE_VIS weak_ptr
4984227825Stheraven{
4985227825Stheravenpublic:
4986227825Stheraven    typedef _Tp element_type;
4987227825Stheravenprivate:
4988227825Stheraven    element_type*        __ptr_;
4989227825Stheraven    __shared_weak_count* __cntrl_;
4990227825Stheraven
4991227825Stheravenpublic:
4992241903Sdim    _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4993227825Stheraven    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4994227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4995227825Stheraven                        _NOEXCEPT;
4996227825Stheraven    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4997227825Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4998227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4999227825Stheraven                         _NOEXCEPT;
5000227825Stheraven
5001232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5002232950Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5003232950Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
5004232950Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5005232950Stheraven                         _NOEXCEPT;
5006232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5007227825Stheraven    ~weak_ptr();
5008227825Stheraven
5009227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5010232950Stheraven    template<class _Yp>
5011232950Stheraven        typename enable_if
5012232950Stheraven        <
5013232950Stheraven            is_convertible<_Yp*, element_type*>::value,
5014232950Stheraven            weak_ptr&
5015232950Stheraven        >::type
5016232950Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5017227825Stheraven
5018232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5019232950Stheraven
5020232950Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5021232950Stheraven    template<class _Yp>
5022232950Stheraven        typename enable_if
5023232950Stheraven        <
5024232950Stheraven            is_convertible<_Yp*, element_type*>::value,
5025232950Stheraven            weak_ptr&
5026232950Stheraven        >::type
5027232950Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5028232950Stheraven
5029232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5030232950Stheraven
5031232950Stheraven    template<class _Yp>
5032232950Stheraven        typename enable_if
5033232950Stheraven        <
5034232950Stheraven            is_convertible<_Yp*, element_type*>::value,
5035232950Stheraven            weak_ptr&
5036232950Stheraven        >::type
5037232950Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5038232950Stheraven
5039227825Stheraven    void swap(weak_ptr& __r) _NOEXCEPT;
5040227825Stheraven    void reset() _NOEXCEPT;
5041227825Stheraven
5042227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5043227825Stheraven    long use_count() const _NOEXCEPT
5044227825Stheraven        {return __cntrl_ ? __cntrl_->use_count() : 0;}
5045227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5046227825Stheraven    bool expired() const _NOEXCEPT
5047227825Stheraven        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5048227825Stheraven    shared_ptr<_Tp> lock() const _NOEXCEPT;
5049227825Stheraven    template<class _Up>
5050227825Stheraven        _LIBCPP_INLINE_VISIBILITY
5051227825Stheraven        bool owner_before(const shared_ptr<_Up>& __r) const
5052227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
5053227825Stheraven    template<class _Up>
5054227825Stheraven        _LIBCPP_INLINE_VISIBILITY
5055227825Stheraven        bool owner_before(const weak_ptr<_Up>& __r) const
5056227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
5057227825Stheraven
5058249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
5059249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
5060227825Stheraven};
5061227825Stheraven
5062227825Stheraventemplate<class _Tp>
5063227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5064241903Sdim_LIBCPP_CONSTEXPR
5065227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5066227825Stheraven    : __ptr_(0),
5067227825Stheraven      __cntrl_(0)
5068227825Stheraven{
5069227825Stheraven}
5070227825Stheraven
5071227825Stheraventemplate<class _Tp>
5072227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5073227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5074227825Stheraven    : __ptr_(__r.__ptr_),
5075227825Stheraven      __cntrl_(__r.__cntrl_)
5076227825Stheraven{
5077227825Stheraven    if (__cntrl_)
5078227825Stheraven        __cntrl_->__add_weak();
5079227825Stheraven}
5080227825Stheraven
5081227825Stheraventemplate<class _Tp>
5082227825Stheraventemplate<class _Yp>
5083227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5084227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5085227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5086227825Stheraven                         _NOEXCEPT
5087227825Stheraven    : __ptr_(__r.__ptr_),
5088227825Stheraven      __cntrl_(__r.__cntrl_)
5089227825Stheraven{
5090227825Stheraven    if (__cntrl_)
5091227825Stheraven        __cntrl_->__add_weak();
5092227825Stheraven}
5093227825Stheraven
5094227825Stheraventemplate<class _Tp>
5095227825Stheraventemplate<class _Yp>
5096227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5097227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5098227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5099227825Stheraven         _NOEXCEPT
5100227825Stheraven    : __ptr_(__r.__ptr_),
5101227825Stheraven      __cntrl_(__r.__cntrl_)
5102227825Stheraven{
5103227825Stheraven    if (__cntrl_)
5104227825Stheraven        __cntrl_->__add_weak();
5105227825Stheraven}
5106227825Stheraven
5107232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5108232950Stheraven
5109227825Stheraventemplate<class _Tp>
5110232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5111232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5112232950Stheraven    : __ptr_(__r.__ptr_),
5113232950Stheraven      __cntrl_(__r.__cntrl_)
5114232950Stheraven{
5115232950Stheraven    __r.__ptr_ = 0;
5116232950Stheraven    __r.__cntrl_ = 0;
5117232950Stheraven}
5118232950Stheraven
5119232950Stheraventemplate<class _Tp>
5120232950Stheraventemplate<class _Yp>
5121232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5122232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5123232950Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5124232950Stheraven         _NOEXCEPT
5125232950Stheraven    : __ptr_(__r.__ptr_),
5126232950Stheraven      __cntrl_(__r.__cntrl_)
5127232950Stheraven{
5128232950Stheraven    __r.__ptr_ = 0;
5129232950Stheraven    __r.__cntrl_ = 0;
5130232950Stheraven}
5131232950Stheraven
5132232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5133232950Stheraven
5134232950Stheraventemplate<class _Tp>
5135227825Stheravenweak_ptr<_Tp>::~weak_ptr()
5136227825Stheraven{
5137227825Stheraven    if (__cntrl_)
5138227825Stheraven        __cntrl_->__release_weak();
5139227825Stheraven}
5140227825Stheraven
5141227825Stheraventemplate<class _Tp>
5142227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5143227825Stheravenweak_ptr<_Tp>&
5144227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5145227825Stheraven{
5146227825Stheraven    weak_ptr(__r).swap(*this);
5147227825Stheraven    return *this;
5148227825Stheraven}
5149227825Stheraven
5150227825Stheraventemplate<class _Tp>
5151227825Stheraventemplate<class _Yp>
5152227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5153232950Stheraventypename enable_if
5154232950Stheraven<
5155232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5156232950Stheraven    weak_ptr<_Tp>&
5157232950Stheraven>::type
5158227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5159227825Stheraven{
5160227825Stheraven    weak_ptr(__r).swap(*this);
5161227825Stheraven    return *this;
5162227825Stheraven}
5163227825Stheraven
5164232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5165232950Stheraven
5166227825Stheraventemplate<class _Tp>
5167232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5168232950Stheravenweak_ptr<_Tp>&
5169232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5170232950Stheraven{
5171232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5172232950Stheraven    return *this;
5173232950Stheraven}
5174232950Stheraven
5175232950Stheraventemplate<class _Tp>
5176227825Stheraventemplate<class _Yp>
5177227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5178232950Stheraventypename enable_if
5179232950Stheraven<
5180232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5181232950Stheraven    weak_ptr<_Tp>&
5182232950Stheraven>::type
5183232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5184232950Stheraven{
5185232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5186232950Stheraven    return *this;
5187232950Stheraven}
5188232950Stheraven
5189232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5190232950Stheraven
5191232950Stheraventemplate<class _Tp>
5192232950Stheraventemplate<class _Yp>
5193232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5194232950Stheraventypename enable_if
5195232950Stheraven<
5196232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5197232950Stheraven    weak_ptr<_Tp>&
5198232950Stheraven>::type
5199227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5200227825Stheraven{
5201227825Stheraven    weak_ptr(__r).swap(*this);
5202227825Stheraven    return *this;
5203227825Stheraven}
5204227825Stheraven
5205227825Stheraventemplate<class _Tp>
5206227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5207227825Stheravenvoid
5208227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5209227825Stheraven{
5210227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
5211227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
5212227825Stheraven}
5213227825Stheraven
5214227825Stheraventemplate<class _Tp>
5215227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5216227825Stheravenvoid
5217227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5218227825Stheraven{
5219227825Stheraven    __x.swap(__y);
5220227825Stheraven}
5221227825Stheraven
5222227825Stheraventemplate<class _Tp>
5223227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5224227825Stheravenvoid
5225227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT
5226227825Stheraven{
5227227825Stheraven    weak_ptr().swap(*this);
5228227825Stheraven}
5229227825Stheraven
5230227825Stheraventemplate<class _Tp>
5231227825Stheraventemplate<class _Yp>
5232227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5233227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5234227825Stheraven    : __ptr_(__r.__ptr_),
5235227825Stheraven      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5236227825Stheraven{
5237227825Stheraven    if (__cntrl_ == 0)
5238227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
5239227825Stheraven        throw bad_weak_ptr();
5240227825Stheraven#else
5241227825Stheraven        assert(!"bad_weak_ptr");
5242227825Stheraven#endif
5243227825Stheraven}
5244227825Stheraven
5245227825Stheraventemplate<class _Tp>
5246227825Stheravenshared_ptr<_Tp>
5247227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT
5248227825Stheraven{
5249227825Stheraven    shared_ptr<_Tp> __r;
5250227825Stheraven    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5251227825Stheraven    if (__r.__cntrl_)
5252227825Stheraven        __r.__ptr_ = __ptr_;
5253227825Stheraven    return __r;
5254227825Stheraven}
5255227825Stheraven
5256227825Stheraventemplate <class _Tp> struct owner_less;
5257227825Stheraven
5258227825Stheraventemplate <class _Tp>
5259249998Sdimstruct _LIBCPP_TYPE_VIS owner_less<shared_ptr<_Tp> >
5260227825Stheraven    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5261227825Stheraven{
5262227825Stheraven    typedef bool result_type;
5263227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5264227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5265227825Stheraven        {return __x.owner_before(__y);}
5266227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5267227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5268227825Stheraven        {return __x.owner_before(__y);}
5269227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5270227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5271227825Stheraven        {return __x.owner_before(__y);}
5272227825Stheraven};
5273227825Stheraven
5274227825Stheraventemplate <class _Tp>
5275249998Sdimstruct _LIBCPP_TYPE_VIS owner_less<weak_ptr<_Tp> >
5276227825Stheraven    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5277227825Stheraven{
5278227825Stheraven    typedef bool result_type;
5279227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5280227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5281227825Stheraven        {return __x.owner_before(__y);}
5282227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5283227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5284227825Stheraven        {return __x.owner_before(__y);}
5285227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5286227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5287227825Stheraven        {return __x.owner_before(__y);}
5288227825Stheraven};
5289227825Stheraven
5290227825Stheraventemplate<class _Tp>
5291249998Sdimclass _LIBCPP_TYPE_VIS enable_shared_from_this
5292227825Stheraven{
5293227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5294227825Stheravenprotected:
5295241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5296227825Stheraven    enable_shared_from_this() _NOEXCEPT {}
5297227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5298227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5299227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5300227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5301227825Stheraven        {return *this;}
5302227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5303227825Stheraven    ~enable_shared_from_this() {}
5304227825Stheravenpublic:
5305227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5306227825Stheraven    shared_ptr<_Tp> shared_from_this()
5307227825Stheraven        {return shared_ptr<_Tp>(__weak_this_);}
5308227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5309227825Stheraven    shared_ptr<_Tp const> shared_from_this() const
5310227825Stheraven        {return shared_ptr<const _Tp>(__weak_this_);}
5311227825Stheraven
5312227825Stheraven    template <class _Up> friend class shared_ptr;
5313227825Stheraven};
5314227825Stheraven
5315227825Stheraventemplate <class _Tp>
5316249998Sdimstruct _LIBCPP_TYPE_VIS hash<shared_ptr<_Tp> >
5317227825Stheraven{
5318227825Stheraven    typedef shared_ptr<_Tp>      argument_type;
5319227825Stheraven    typedef size_t               result_type;
5320227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5321227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5322227825Stheraven    {
5323227825Stheraven        return hash<_Tp*>()(__ptr.get());
5324227825Stheraven    }
5325227825Stheraven};
5326227825Stheraven
5327232950Stheraventemplate<class _CharT, class _Traits, class _Yp>
5328227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5329227825Stheravenbasic_ostream<_CharT, _Traits>&
5330232950Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5331227825Stheraven
5332241903Sdim#if __has_feature(cxx_atomic)
5333241903Sdim
5334241903Sdimclass __sp_mut
5335241903Sdim{
5336242945Stheraven    void* __lx;
5337241903Sdimpublic:
5338241903Sdim    void lock() _NOEXCEPT;
5339241903Sdim    void unlock() _NOEXCEPT;
5340241903Sdim
5341241903Sdimprivate:
5342241903Sdim    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5343241903Sdim    __sp_mut(const __sp_mut&);
5344241903Sdim    __sp_mut& operator=(const __sp_mut&);
5345241903Sdim
5346249998Sdim    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5347241903Sdim};
5348241903Sdim
5349249998Sdim_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5350241903Sdim
5351241903Sdimtemplate <class _Tp>
5352241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5353241903Sdimbool
5354241903Sdimatomic_is_lock_free(const shared_ptr<_Tp>*)
5355241903Sdim{
5356241903Sdim    return false;
5357241903Sdim}
5358241903Sdim
5359241903Sdimtemplate <class _Tp>
5360241903Sdimshared_ptr<_Tp>
5361241903Sdimatomic_load(const shared_ptr<_Tp>* __p)
5362241903Sdim{
5363241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5364241903Sdim    __m.lock();
5365241903Sdim    shared_ptr<_Tp> __q = *__p;
5366241903Sdim    __m.unlock();
5367241903Sdim    return __q;
5368241903Sdim}
5369241903Sdim  
5370241903Sdimtemplate <class _Tp>
5371241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5372241903Sdimshared_ptr<_Tp>
5373241903Sdimatomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5374241903Sdim{
5375241903Sdim    return atomic_load(__p);
5376241903Sdim}
5377241903Sdim
5378241903Sdimtemplate <class _Tp>
5379241903Sdimvoid
5380241903Sdimatomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5381241903Sdim{
5382241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5383241903Sdim    __m.lock();
5384241903Sdim    __p->swap(__r);
5385241903Sdim    __m.unlock();
5386241903Sdim}
5387241903Sdim
5388241903Sdimtemplate <class _Tp>
5389241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5390241903Sdimvoid
5391241903Sdimatomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5392241903Sdim{
5393241903Sdim    atomic_store(__p, __r);
5394241903Sdim}
5395241903Sdim
5396241903Sdimtemplate <class _Tp>
5397241903Sdimshared_ptr<_Tp>
5398241903Sdimatomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5399241903Sdim{
5400241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5401241903Sdim    __m.lock();
5402241903Sdim    __p->swap(__r);
5403241903Sdim    __m.unlock();
5404241903Sdim    return __r;
5405241903Sdim}
5406241903Sdim  
5407241903Sdimtemplate <class _Tp>
5408241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5409241903Sdimshared_ptr<_Tp>
5410241903Sdimatomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5411241903Sdim{
5412241903Sdim    return atomic_exchange(__p, __r);
5413241903Sdim}
5414241903Sdim
5415241903Sdimtemplate <class _Tp>
5416241903Sdimbool
5417241903Sdimatomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5418241903Sdim{
5419241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5420241903Sdim    __m.lock();
5421241903Sdim    if (__p->__owner_equivalent(*__v))
5422241903Sdim    {
5423241903Sdim        *__p = __w;
5424241903Sdim        __m.unlock();
5425241903Sdim        return true;
5426241903Sdim    }
5427241903Sdim    *__v = *__p;
5428241903Sdim    __m.unlock();
5429241903Sdim    return false;
5430241903Sdim}
5431241903Sdim
5432241903Sdimtemplate <class _Tp>
5433241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5434241903Sdimbool
5435241903Sdimatomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5436241903Sdim{
5437241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5438241903Sdim}
5439241903Sdim
5440241903Sdimtemplate <class _Tp>
5441241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5442241903Sdimbool
5443241903Sdimatomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5444241903Sdim                                        shared_ptr<_Tp> __w, memory_order, memory_order)
5445241903Sdim{
5446241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5447241903Sdim}
5448241903Sdim
5449241903Sdimtemplate <class _Tp>
5450241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5451241903Sdimbool
5452241903Sdimatomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5453241903Sdim                                      shared_ptr<_Tp> __w, memory_order, memory_order)
5454241903Sdim{
5455241903Sdim    return atomic_compare_exchange_weak(__p, __v, __w);
5456241903Sdim}
5457241903Sdim
5458241903Sdim#endif  // __has_feature(cxx_atomic)
5459241903Sdim
5460227825Stheraven//enum class
5461249998Sdimstruct _LIBCPP_TYPE_VIS pointer_safety
5462227825Stheraven{
5463242945Stheraven    enum __lx
5464227825Stheraven    {
5465227825Stheraven        relaxed,
5466227825Stheraven        preferred,
5467227825Stheraven        strict
5468227825Stheraven    };
5469227825Stheraven
5470242945Stheraven    __lx __v_;
5471227825Stheraven
5472227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5473242945Stheraven    pointer_safety(__lx __v) : __v_(__v) {}
5474227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5475227825Stheraven    operator int() const {return __v_;}
5476227825Stheraven};
5477227825Stheraven
5478227825Stheravenvoid declare_reachable(void* __p);
5479227825Stheravenvoid declare_no_pointers(char* __p, size_t __n);
5480227825Stheravenvoid undeclare_no_pointers(char* __p, size_t __n);
5481227825Stheravenpointer_safety get_pointer_safety() _NOEXCEPT;
5482227825Stheravenvoid* __undeclare_reachable(void* __p);
5483227825Stheraven
5484227825Stheraventemplate <class _Tp>
5485227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5486227825Stheraven_Tp*
5487227825Stheravenundeclare_reachable(_Tp* __p)
5488227825Stheraven{
5489227825Stheraven    return static_cast<_Tp*>(__undeclare_reachable(__p));
5490227825Stheraven}
5491227825Stheraven
5492227825Stheravenvoid* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5493227825Stheraven
5494227825Stheraven_LIBCPP_END_NAMESPACE_STD
5495227825Stheraven
5496227825Stheraven#endif  // _LIBCPP_MEMORY
5497