memory revision 276792
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
93261272Sdim    static size_type max_size(const allocator_type& a); // noexcept in C++14
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
353253146Stheraventemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);     // C++14
354253146Stheraventemplate<class T>                unique_ptr<T> make_unique(size_t n);           // C++14
355253146Stheraventemplate<class T, class... Args> unspecified   make_unique(Args&&...) = delete; // C++14, T == U[N]
356253146Stheraven
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;
482276792Sdim    weak_ptr(weak_ptr&& r) noexcept;                      // C++14
483276792Sdim    template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
484227825Stheraven
485227825Stheraven    // destructor
486227825Stheraven    ~weak_ptr();
487227825Stheraven
488227825Stheraven    // assignment
489227825Stheraven    weak_ptr& operator=(weak_ptr const& r) noexcept;
490227825Stheraven    template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
491227825Stheraven    template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
492276792Sdim    weak_ptr& operator=(weak_ptr&& r) noexcept;                      // C++14
493276792Sdim    template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
494227825Stheraven
495227825Stheraven    // modifiers
496227825Stheraven    void swap(weak_ptr& r) noexcept;
497227825Stheraven    void reset() noexcept;
498227825Stheraven
499227825Stheraven    // observers
500227825Stheraven    long use_count() const noexcept;
501227825Stheraven    bool expired() const noexcept;
502227825Stheraven    shared_ptr<T> lock() const noexcept;
503261272Sdim    template<class U> bool owner_before(shared_ptr<U> const& b) const;
504261272Sdim    template<class U> bool owner_before(weak_ptr<U> const& b) const;
505227825Stheraven};
506227825Stheraven
507227825Stheraven// weak_ptr specialized algorithms:
508227825Stheraventemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
509227825Stheraven
510227825Stheraven// class owner_less:
511227825Stheraventemplate<class T> struct owner_less;
512227825Stheraven
513227825Stheraventemplate<class T>
514227825Stheravenstruct owner_less<shared_ptr<T>>
515227825Stheraven    : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
516227825Stheraven{
517227825Stheraven    typedef bool result_type;
518227825Stheraven    bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
519227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
520227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
521227825Stheraven};
522227825Stheraven
523227825Stheraventemplate<class T>
524227825Stheravenstruct owner_less<weak_ptr<T>>
525227825Stheraven    : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
526227825Stheraven{
527227825Stheraven    typedef bool result_type;
528227825Stheraven    bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
529227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
530227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
531227825Stheraven};
532227825Stheraven
533227825Stheraventemplate<class T>
534227825Stheravenclass enable_shared_from_this
535227825Stheraven{
536227825Stheravenprotected:
537227825Stheraven    constexpr enable_shared_from_this() noexcept;
538227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) noexcept;
539227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
540227825Stheraven    ~enable_shared_from_this();
541227825Stheravenpublic:
542227825Stheraven    shared_ptr<T> shared_from_this();
543227825Stheraven    shared_ptr<T const> shared_from_this() const;
544227825Stheraven};
545227825Stheraven
546227825Stheraventemplate<class T>
547227825Stheraven    bool atomic_is_lock_free(const shared_ptr<T>* p);
548227825Stheraventemplate<class T>
549227825Stheraven    shared_ptr<T> atomic_load(const shared_ptr<T>* p);
550227825Stheraventemplate<class T>
551227825Stheraven    shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
552227825Stheraventemplate<class T>
553227825Stheraven    void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
554227825Stheraventemplate<class T>
555227825Stheraven    void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
556227825Stheraventemplate<class T>
557227825Stheraven    shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
558227825Stheraventemplate<class T>
559227825Stheraven    shared_ptr<T>
560227825Stheraven    atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
561227825Stheraventemplate<class T>
562227825Stheraven    bool
563227825Stheraven    atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
564227825Stheraventemplate<class T>
565227825Stheraven    bool
566227825Stheraven    atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
567227825Stheraventemplate<class T>
568227825Stheraven    bool
569227825Stheraven    atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
570227825Stheraven                                          shared_ptr<T> w, memory_order success,
571227825Stheraven                                          memory_order failure);
572227825Stheraventemplate<class T>
573227825Stheraven    bool
574227825Stheraven    atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
575227825Stheraven                                            shared_ptr<T> w, memory_order success,
576227825Stheraven                                            memory_order failure);
577227825Stheraven// Hash support
578227825Stheraventemplate <class T> struct hash;
579227825Stheraventemplate <class T, class D> struct hash<unique_ptr<T, D> >;
580227825Stheraventemplate <class T> struct hash<shared_ptr<T> >;
581227825Stheraven
582227825Stheraven// Pointer safety
583227825Stheravenenum class pointer_safety { relaxed, preferred, strict };
584227825Stheravenvoid declare_reachable(void *p);
585227825Stheraventemplate <class T> T *undeclare_reachable(T *p);
586227825Stheravenvoid declare_no_pointers(char *p, size_t n);
587227825Stheravenvoid undeclare_no_pointers(char *p, size_t n);
588227825Stheravenpointer_safety get_pointer_safety() noexcept;
589227825Stheraven
590227825Stheravenvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space);
591227825Stheraven
592227825Stheraven}  // std
593227825Stheraven
594227825Stheraven*/
595227825Stheraven
596227825Stheraven#include <__config>
597227825Stheraven#include <type_traits>
598227825Stheraven#include <typeinfo>
599227825Stheraven#include <cstddef>
600227825Stheraven#include <cstdint>
601227825Stheraven#include <new>
602227825Stheraven#include <utility>
603227825Stheraven#include <limits>
604227825Stheraven#include <iterator>
605227825Stheraven#include <__functional_base>
606227825Stheraven#include <iosfwd>
607232924Stheraven#include <tuple>
608232924Stheraven#include <cstring>
609227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS)
610227825Stheraven    #include <cassert>
611227825Stheraven#endif
612227825Stheraven
613276792Sdim#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
614241900Sdim#  include <atomic>
615241900Sdim#endif
616241900Sdim
617232924Stheraven#include <__undef_min_max>
618232924Stheraven
619227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
620227825Stheraven#pragma GCC system_header
621227825Stheraven#endif
622227825Stheraven
623227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
624227825Stheraven
625261272Sdim// addressof moved to <__functional_base>
626227825Stheraven
627227825Stheraventemplate <class _Tp> class allocator;
628227825Stheraven
629227825Stheraventemplate <>
630261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<void>
631227825Stheraven{
632227825Stheravenpublic:
633227825Stheraven    typedef void*             pointer;
634227825Stheraven    typedef const void*       const_pointer;
635227825Stheraven    typedef void              value_type;
636227825Stheraven
637227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
638227825Stheraven};
639227825Stheraven
640232924Stheraventemplate <>
641261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const void>
642232924Stheraven{
643232924Stheravenpublic:
644232924Stheraven    typedef const void*       pointer;
645232924Stheraven    typedef const void*       const_pointer;
646232924Stheraven    typedef const void        value_type;
647232924Stheraven
648232924Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
649232924Stheraven};
650232924Stheraven
651227825Stheraven// pointer_traits
652227825Stheraven
653227825Stheraventemplate <class _Tp>
654227825Stheravenstruct __has_element_type
655227825Stheraven{
656227825Stheravenprivate:
657242939Stheraven    struct __two {char __lx; char __lxx;};
658227825Stheraven    template <class _Up> static __two __test(...);
659227825Stheraven    template <class _Up> static char __test(typename _Up::element_type* = 0);
660227825Stheravenpublic:
661227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
662227825Stheraven};
663227825Stheraven
664227825Stheraventemplate <class _Ptr, bool = __has_element_type<_Ptr>::value>
665227825Stheravenstruct __pointer_traits_element_type;
666227825Stheraven
667227825Stheraventemplate <class _Ptr>
668227825Stheravenstruct __pointer_traits_element_type<_Ptr, true>
669227825Stheraven{
670227825Stheraven    typedef typename _Ptr::element_type type;
671227825Stheraven};
672227825Stheraven
673227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
674227825Stheraven
675227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
676227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
677227825Stheraven{
678227825Stheraven    typedef typename _Sp<_Tp, _Args...>::element_type type;
679227825Stheraven};
680227825Stheraven
681227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
682227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
683227825Stheraven{
684227825Stheraven    typedef _Tp type;
685227825Stheraven};
686227825Stheraven
687227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
688227825Stheraven
689227825Stheraventemplate <template <class> class _Sp, class _Tp>
690227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, true>
691227825Stheraven{
692227825Stheraven    typedef typename _Sp<_Tp>::element_type type;
693227825Stheraven};
694227825Stheraven
695227825Stheraventemplate <template <class> class _Sp, class _Tp>
696227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, false>
697227825Stheraven{
698227825Stheraven    typedef _Tp type;
699227825Stheraven};
700227825Stheraven
701227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
702227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
703227825Stheraven{
704227825Stheraven    typedef typename _Sp<_Tp, _A0>::element_type type;
705227825Stheraven};
706227825Stheraven
707227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
708227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
709227825Stheraven{
710227825Stheraven    typedef _Tp type;
711227825Stheraven};
712227825Stheraven
713227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
714227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
715227825Stheraven{
716227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
717227825Stheraven};
718227825Stheraven
719227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
720227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
721227825Stheraven{
722227825Stheraven    typedef _Tp type;
723227825Stheraven};
724227825Stheraven
725227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
726227825Stheraven                                                           class _A1, class _A2>
727227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
728227825Stheraven{
729227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
730227825Stheraven};
731227825Stheraven
732227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
733227825Stheraven                                                           class _A1, class _A2>
734227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
735227825Stheraven{
736227825Stheraven    typedef _Tp type;
737227825Stheraven};
738227825Stheraven
739227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
740227825Stheraven
741227825Stheraventemplate <class _Tp>
742227825Stheravenstruct __has_difference_type
743227825Stheraven{
744227825Stheravenprivate:
745242939Stheraven    struct __two {char __lx; char __lxx;};
746227825Stheraven    template <class _Up> static __two __test(...);
747227825Stheraven    template <class _Up> static char __test(typename _Up::difference_type* = 0);
748227825Stheravenpublic:
749227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
750227825Stheraven};
751227825Stheraven
752227825Stheraventemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value>
753227825Stheravenstruct __pointer_traits_difference_type
754227825Stheraven{
755227825Stheraven    typedef ptrdiff_t type;
756227825Stheraven};
757227825Stheraven
758227825Stheraventemplate <class _Ptr>
759227825Stheravenstruct __pointer_traits_difference_type<_Ptr, true>
760227825Stheraven{
761227825Stheraven    typedef typename _Ptr::difference_type type;
762227825Stheraven};
763227825Stheraven
764227825Stheraventemplate <class _Tp, class _Up>
765227825Stheravenstruct __has_rebind
766227825Stheraven{
767227825Stheravenprivate:
768242939Stheraven    struct __two {char __lx; char __lxx;};
769227825Stheraven    template <class _Xp> static __two __test(...);
770227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
771227825Stheravenpublic:
772227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
773227825Stheraven};
774227825Stheraven
775227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
776227825Stheravenstruct __pointer_traits_rebind
777227825Stheraven{
778227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
779227825Stheraven    typedef typename _Tp::template rebind<_Up> type;
780227825Stheraven#else
781227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
782227825Stheraven#endif
783227825Stheraven};
784227825Stheraven
785227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
786227825Stheraven
787227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
788227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
789227825Stheraven{
790227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
791227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
792227825Stheraven#else
793227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
794227825Stheraven#endif
795227825Stheraven};
796227825Stheraven
797227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
798227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
799227825Stheraven{
800227825Stheraven    typedef _Sp<_Up, _Args...> type;
801227825Stheraven};
802227825Stheraven
803227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
804227825Stheraven
805227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
806227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
807227825Stheraven{
808227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
809227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up> type;
810227825Stheraven#else
811227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
812227825Stheraven#endif
813227825Stheraven};
814227825Stheraven
815227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
816227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
817227825Stheraven{
818227825Stheraven    typedef _Sp<_Up> type;
819227825Stheraven};
820227825Stheraven
821227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
822227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
823227825Stheraven{
824227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
825227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
826227825Stheraven#else
827227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
828227825Stheraven#endif
829227825Stheraven};
830227825Stheraven
831227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
832227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
833227825Stheraven{
834227825Stheraven    typedef _Sp<_Up, _A0> type;
835227825Stheraven};
836227825Stheraven
837227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
838227825Stheraven                                         class _A1, class _Up>
839227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
840227825Stheraven{
841227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
842227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
843227825Stheraven#else
844227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
845227825Stheraven#endif
846227825Stheraven};
847227825Stheraven
848227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
849227825Stheraven                                         class _A1, class _Up>
850227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
851227825Stheraven{
852227825Stheraven    typedef _Sp<_Up, _A0, _A1> type;
853227825Stheraven};
854227825Stheraven
855227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
856227825Stheraven                                                class _A1, class _A2, class _Up>
857227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
858227825Stheraven{
859227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
860227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
861227825Stheraven#else
862227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
863227825Stheraven#endif
864227825Stheraven};
865227825Stheraven
866227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
867227825Stheraven                                                class _A1, class _A2, class _Up>
868227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
869227825Stheraven{
870227825Stheraven    typedef _Sp<_Up, _A0, _A1, _A2> type;
871227825Stheraven};
872227825Stheraven
873227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
874227825Stheraven
875227825Stheraventemplate <class _Ptr>
876261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY pointer_traits
877227825Stheraven{
878227825Stheraven    typedef _Ptr                                                     pointer;
879227825Stheraven    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
880227825Stheraven    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
881227825Stheraven
882227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
883227825Stheraven    template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
884227825Stheraven#else
885227825Stheraven    template <class _Up> struct rebind
886227825Stheraven        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
887227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
888227825Stheraven
889227825Stheravenprivate:
890227825Stheraven    struct __nat {};
891227825Stheravenpublic:
892227825Stheraven    _LIBCPP_INLINE_VISIBILITY
893227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
894227825Stheraven                                           __nat, element_type>::type& __r)
895227825Stheraven        {return pointer::pointer_to(__r);}
896227825Stheraven};
897227825Stheraven
898227825Stheraventemplate <class _Tp>
899261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
900227825Stheraven{
901227825Stheraven    typedef _Tp*      pointer;
902227825Stheraven    typedef _Tp       element_type;
903227825Stheraven    typedef ptrdiff_t difference_type;
904227825Stheraven
905227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
906227825Stheraven    template <class _Up> using rebind = _Up*;
907227825Stheraven#else
908227825Stheraven    template <class _Up> struct rebind {typedef _Up* other;};
909227825Stheraven#endif
910227825Stheraven
911227825Stheravenprivate:
912227825Stheraven    struct __nat {};
913227825Stheravenpublic:
914227825Stheraven    _LIBCPP_INLINE_VISIBILITY
915227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
916227825Stheraven                                      __nat, element_type>::type& __r) _NOEXCEPT
917227825Stheraven        {return _VSTD::addressof(__r);}
918227825Stheraven};
919227825Stheraven
920227825Stheraven// allocator_traits
921227825Stheraven
922227825Stheravennamespace __has_pointer_type_imp
923227825Stheraven{
924261272Sdim    template <class _Up> static __two __test(...);
925261272Sdim    template <class _Up> static char __test(typename _Up::pointer* = 0);
926227825Stheraven}
927227825Stheraven
928227825Stheraventemplate <class _Tp>
929227825Stheravenstruct __has_pointer_type
930261272Sdim    : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
931227825Stheraven{
932227825Stheraven};
933227825Stheraven
934227825Stheravennamespace __pointer_type_imp
935227825Stheraven{
936227825Stheraven
937227825Stheraventemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
938227825Stheravenstruct __pointer_type
939227825Stheraven{
940227825Stheraven    typedef typename _Dp::pointer type;
941227825Stheraven};
942227825Stheraven
943227825Stheraventemplate <class _Tp, class _Dp>
944227825Stheravenstruct __pointer_type<_Tp, _Dp, false>
945227825Stheraven{
946227825Stheraven    typedef _Tp* type;
947227825Stheraven};
948227825Stheraven
949227825Stheraven}  // __pointer_type_imp
950227825Stheraven
951227825Stheraventemplate <class _Tp, class _Dp>
952227825Stheravenstruct __pointer_type
953227825Stheraven{
954227825Stheraven    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
955227825Stheraven};
956227825Stheraven
957227825Stheraventemplate <class _Tp>
958227825Stheravenstruct __has_const_pointer
959227825Stheraven{
960227825Stheravenprivate:
961242939Stheraven    struct __two {char __lx; char __lxx;};
962227825Stheraven    template <class _Up> static __two __test(...);
963227825Stheraven    template <class _Up> static char __test(typename _Up::const_pointer* = 0);
964227825Stheravenpublic:
965227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
966227825Stheraven};
967227825Stheraven
968227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
969227825Stheravenstruct __const_pointer
970227825Stheraven{
971227825Stheraven    typedef typename _Alloc::const_pointer type;
972227825Stheraven};
973227825Stheraven
974227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc>
975227825Stheravenstruct __const_pointer<_Tp, _Ptr, _Alloc, false>
976227825Stheraven{
977227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
978227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
979227825Stheraven#else
980227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
981227825Stheraven#endif
982227825Stheraven};
983227825Stheraven
984227825Stheraventemplate <class _Tp>
985227825Stheravenstruct __has_void_pointer
986227825Stheraven{
987227825Stheravenprivate:
988242939Stheraven    struct __two {char __lx; char __lxx;};
989227825Stheraven    template <class _Up> static __two __test(...);
990227825Stheraven    template <class _Up> static char __test(typename _Up::void_pointer* = 0);
991227825Stheravenpublic:
992227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
993227825Stheraven};
994227825Stheraven
995227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
996227825Stheravenstruct __void_pointer
997227825Stheraven{
998227825Stheraven    typedef typename _Alloc::void_pointer type;
999227825Stheraven};
1000227825Stheraven
1001227825Stheraventemplate <class _Ptr, class _Alloc>
1002227825Stheravenstruct __void_pointer<_Ptr, _Alloc, false>
1003227825Stheraven{
1004227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1005227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1006227825Stheraven#else
1007227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1008227825Stheraven#endif
1009227825Stheraven};
1010227825Stheraven
1011227825Stheraventemplate <class _Tp>
1012227825Stheravenstruct __has_const_void_pointer
1013227825Stheraven{
1014227825Stheravenprivate:
1015242939Stheraven    struct __two {char __lx; char __lxx;};
1016227825Stheraven    template <class _Up> static __two __test(...);
1017227825Stheraven    template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1018227825Stheravenpublic:
1019227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1020227825Stheraven};
1021227825Stheraven
1022227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1023227825Stheravenstruct __const_void_pointer
1024227825Stheraven{
1025227825Stheraven    typedef typename _Alloc::const_void_pointer type;
1026227825Stheraven};
1027227825Stheraven
1028227825Stheraventemplate <class _Ptr, class _Alloc>
1029227825Stheravenstruct __const_void_pointer<_Ptr, _Alloc, false>
1030227825Stheraven{
1031227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1032227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1033227825Stheraven#else
1034227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1035227825Stheraven#endif
1036227825Stheraven};
1037227825Stheraven
1038232924Stheraventemplate <class _Tp>
1039227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1040232924Stheraven_Tp*
1041232924Stheraven__to_raw_pointer(_Tp* __p) _NOEXCEPT
1042227825Stheraven{
1043227825Stheraven    return __p;
1044227825Stheraven}
1045227825Stheraven
1046227825Stheraventemplate <class _Pointer>
1047227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1048227825Stheraventypename pointer_traits<_Pointer>::element_type*
1049227825Stheraven__to_raw_pointer(_Pointer __p) _NOEXCEPT
1050227825Stheraven{
1051227825Stheraven    return _VSTD::__to_raw_pointer(__p.operator->());
1052227825Stheraven}
1053227825Stheraven
1054227825Stheraventemplate <class _Tp>
1055227825Stheravenstruct __has_size_type
1056227825Stheraven{
1057227825Stheravenprivate:
1058242939Stheraven    struct __two {char __lx; char __lxx;};
1059227825Stheraven    template <class _Up> static __two __test(...);
1060227825Stheraven    template <class _Up> static char __test(typename _Up::size_type* = 0);
1061227825Stheravenpublic:
1062227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1063227825Stheraven};
1064227825Stheraven
1065227825Stheraventemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1066227825Stheravenstruct __size_type
1067227825Stheraven{
1068227825Stheraven    typedef typename make_unsigned<_DiffType>::type type;
1069227825Stheraven};
1070227825Stheraven
1071227825Stheraventemplate <class _Alloc, class _DiffType>
1072227825Stheravenstruct __size_type<_Alloc, _DiffType, true>
1073227825Stheraven{
1074227825Stheraven    typedef typename _Alloc::size_type type;
1075227825Stheraven};
1076227825Stheraven
1077227825Stheraventemplate <class _Tp>
1078227825Stheravenstruct __has_propagate_on_container_copy_assignment
1079227825Stheraven{
1080227825Stheravenprivate:
1081242939Stheraven    struct __two {char __lx; char __lxx;};
1082227825Stheraven    template <class _Up> static __two __test(...);
1083227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1084227825Stheravenpublic:
1085227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1086227825Stheraven};
1087227825Stheraven
1088227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1089227825Stheravenstruct __propagate_on_container_copy_assignment
1090227825Stheraven{
1091227825Stheraven    typedef false_type type;
1092227825Stheraven};
1093227825Stheraven
1094227825Stheraventemplate <class _Alloc>
1095227825Stheravenstruct __propagate_on_container_copy_assignment<_Alloc, true>
1096227825Stheraven{
1097227825Stheraven    typedef typename _Alloc::propagate_on_container_copy_assignment type;
1098227825Stheraven};
1099227825Stheraven
1100227825Stheraventemplate <class _Tp>
1101227825Stheravenstruct __has_propagate_on_container_move_assignment
1102227825Stheraven{
1103227825Stheravenprivate:
1104242939Stheraven    struct __two {char __lx; char __lxx;};
1105227825Stheraven    template <class _Up> static __two __test(...);
1106227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1107227825Stheravenpublic:
1108227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1109227825Stheraven};
1110227825Stheraven
1111227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1112227825Stheravenstruct __propagate_on_container_move_assignment
1113227825Stheraven{
1114227825Stheraven    typedef false_type type;
1115227825Stheraven};
1116227825Stheraven
1117227825Stheraventemplate <class _Alloc>
1118227825Stheravenstruct __propagate_on_container_move_assignment<_Alloc, true>
1119227825Stheraven{
1120227825Stheraven    typedef typename _Alloc::propagate_on_container_move_assignment type;
1121227825Stheraven};
1122227825Stheraven
1123227825Stheraventemplate <class _Tp>
1124227825Stheravenstruct __has_propagate_on_container_swap
1125227825Stheraven{
1126227825Stheravenprivate:
1127242939Stheraven    struct __two {char __lx; char __lxx;};
1128227825Stheraven    template <class _Up> static __two __test(...);
1129227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1130227825Stheravenpublic:
1131227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1132227825Stheraven};
1133227825Stheraven
1134227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1135227825Stheravenstruct __propagate_on_container_swap
1136227825Stheraven{
1137227825Stheraven    typedef false_type type;
1138227825Stheraven};
1139227825Stheraven
1140227825Stheraventemplate <class _Alloc>
1141227825Stheravenstruct __propagate_on_container_swap<_Alloc, true>
1142227825Stheraven{
1143227825Stheraven    typedef typename _Alloc::propagate_on_container_swap type;
1144227825Stheraven};
1145227825Stheraven
1146227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1147227825Stheravenstruct __has_rebind_other
1148227825Stheraven{
1149227825Stheravenprivate:
1150242939Stheraven    struct __two {char __lx; char __lxx;};
1151227825Stheraven    template <class _Xp> static __two __test(...);
1152227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1153227825Stheravenpublic:
1154227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1155227825Stheraven};
1156227825Stheraven
1157227825Stheraventemplate <class _Tp, class _Up>
1158227825Stheravenstruct __has_rebind_other<_Tp, _Up, false>
1159227825Stheraven{
1160227825Stheraven    static const bool value = false;
1161227825Stheraven};
1162227825Stheraven
1163227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1164227825Stheravenstruct __allocator_traits_rebind
1165227825Stheraven{
1166227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
1167227825Stheraven};
1168227825Stheraven
1169227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1170227825Stheraven
1171227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1172227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1173227825Stheraven{
1174227825Stheraven    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1175227825Stheraven};
1176227825Stheraven
1177227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1178227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1179227825Stheraven{
1180227825Stheraven    typedef _Alloc<_Up, _Args...> type;
1181227825Stheraven};
1182227825Stheraven
1183227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1184227825Stheraven
1185227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1186227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1187227825Stheraven{
1188227825Stheraven    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1189227825Stheraven};
1190227825Stheraven
1191227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1192227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1193227825Stheraven{
1194227825Stheraven    typedef _Alloc<_Up> type;
1195227825Stheraven};
1196227825Stheraven
1197227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1198227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1199227825Stheraven{
1200227825Stheraven    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1201227825Stheraven};
1202227825Stheraven
1203227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1204227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1205227825Stheraven{
1206227825Stheraven    typedef _Alloc<_Up, _A0> type;
1207227825Stheraven};
1208227825Stheraven
1209227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1210227825Stheraven                                         class _A1, class _Up>
1211227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1212227825Stheraven{
1213227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1214227825Stheraven};
1215227825Stheraven
1216227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1217227825Stheraven                                         class _A1, class _Up>
1218227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1219227825Stheraven{
1220227825Stheraven    typedef _Alloc<_Up, _A0, _A1> type;
1221227825Stheraven};
1222227825Stheraven
1223227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1224227825Stheraven                                                class _A1, class _A2, class _Up>
1225227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1226227825Stheraven{
1227227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1228227825Stheraven};
1229227825Stheraven
1230227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1231227825Stheraven                                                class _A1, class _A2, class _Up>
1232227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1233227825Stheraven{
1234227825Stheraven    typedef _Alloc<_Up, _A0, _A1, _A2> type;
1235227825Stheraven};
1236227825Stheraven
1237227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1238227825Stheraven
1239227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1240227825Stheraven
1241227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1242227825Stheravenauto
1243227825Stheraven__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1244227825Stheraven    -> decltype(__a.allocate(__sz, __p), true_type());
1245227825Stheraven
1246227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1247227825Stheravenauto
1248227825Stheraven__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1249227825Stheraven    -> false_type;
1250227825Stheraven
1251227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1252227825Stheravenstruct __has_allocate_hint
1253227825Stheraven    : integral_constant<bool,
1254227825Stheraven        is_same<
1255227825Stheraven            decltype(__has_allocate_hint_test(declval<_Alloc>(),
1256227825Stheraven                                          declval<_SizeType>(),
1257227825Stheraven                                          declval<_ConstVoidPtr>())),
1258227825Stheraven            true_type>::value>
1259227825Stheraven{
1260227825Stheraven};
1261227825Stheraven
1262227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1263227825Stheraven
1264227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1265227825Stheravenstruct __has_allocate_hint
1266227825Stheraven    : true_type
1267227825Stheraven{
1268227825Stheraven};
1269227825Stheraven
1270227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1271227825Stheraven
1272227825Stheraven#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1273227825Stheraven
1274227825Stheraventemplate <class _Alloc, class _Tp, class ..._Args>
1275227825Stheravendecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1276227825Stheraven                                           _VSTD::declval<_Args>()...),
1277227825Stheraven                                           true_type())
1278227825Stheraven__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1279227825Stheraven
1280227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1281227825Stheravenfalse_type
1282227825Stheraven__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1283227825Stheraven
1284227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1285227825Stheravenstruct __has_construct
1286227825Stheraven    : integral_constant<bool,
1287227825Stheraven        is_same<
1288227825Stheraven            decltype(__has_construct_test(declval<_Alloc>(),
1289227825Stheraven                                          declval<_Pointer>(),
1290227825Stheraven                                          declval<_Args>()...)),
1291227825Stheraven            true_type>::value>
1292227825Stheraven{
1293227825Stheraven};
1294227825Stheraven
1295227825Stheraventemplate <class _Alloc, class _Pointer>
1296227825Stheravenauto
1297227825Stheraven__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1298227825Stheraven    -> decltype(__a.destroy(__p), true_type());
1299227825Stheraven
1300227825Stheraventemplate <class _Alloc, class _Pointer>
1301227825Stheravenauto
1302227825Stheraven__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1303227825Stheraven    -> false_type;
1304227825Stheraven
1305227825Stheraventemplate <class _Alloc, class _Pointer>
1306227825Stheravenstruct __has_destroy
1307227825Stheraven    : integral_constant<bool,
1308227825Stheraven        is_same<
1309227825Stheraven            decltype(__has_destroy_test(declval<_Alloc>(),
1310227825Stheraven                                        declval<_Pointer>())),
1311227825Stheraven            true_type>::value>
1312227825Stheraven{
1313227825Stheraven};
1314227825Stheraven
1315227825Stheraventemplate <class _Alloc>
1316227825Stheravenauto
1317227825Stheraven__has_max_size_test(_Alloc&& __a)
1318227825Stheraven    -> decltype(__a.max_size(), true_type());
1319227825Stheraven
1320227825Stheraventemplate <class _Alloc>
1321227825Stheravenauto
1322227825Stheraven__has_max_size_test(const volatile _Alloc& __a)
1323227825Stheraven    -> false_type;
1324227825Stheraven
1325227825Stheraventemplate <class _Alloc>
1326227825Stheravenstruct __has_max_size
1327227825Stheraven    : integral_constant<bool,
1328227825Stheraven        is_same<
1329227825Stheraven            decltype(__has_max_size_test(declval<_Alloc&>())),
1330227825Stheraven            true_type>::value>
1331227825Stheraven{
1332227825Stheraven};
1333227825Stheraven
1334227825Stheraventemplate <class _Alloc>
1335227825Stheravenauto
1336227825Stheraven__has_select_on_container_copy_construction_test(_Alloc&& __a)
1337227825Stheraven    -> decltype(__a.select_on_container_copy_construction(), true_type());
1338227825Stheraven
1339227825Stheraventemplate <class _Alloc>
1340227825Stheravenauto
1341227825Stheraven__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1342227825Stheraven    -> false_type;
1343227825Stheraven
1344227825Stheraventemplate <class _Alloc>
1345227825Stheravenstruct __has_select_on_container_copy_construction
1346227825Stheraven    : integral_constant<bool,
1347227825Stheraven        is_same<
1348227825Stheraven            decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1349227825Stheraven            true_type>::value>
1350227825Stheraven{
1351227825Stheraven};
1352227825Stheraven
1353227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1354227825Stheraven
1355227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1356227825Stheraven
1357227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1358227825Stheravenstruct __has_construct
1359227825Stheraven    : false_type
1360227825Stheraven{
1361227825Stheraven};
1362227825Stheraven
1363232924Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1364232924Stheraven
1365232924Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1366232924Stheravenstruct __has_construct
1367232924Stheraven    : false_type
1368232924Stheraven{
1369232924Stheraven};
1370232924Stheraven
1371227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1372227825Stheraven
1373227825Stheraventemplate <class _Alloc, class _Pointer>
1374227825Stheravenstruct __has_destroy
1375227825Stheraven    : false_type
1376227825Stheraven{
1377227825Stheraven};
1378227825Stheraven
1379227825Stheraventemplate <class _Alloc>
1380227825Stheravenstruct __has_max_size
1381227825Stheraven    : true_type
1382227825Stheraven{
1383227825Stheraven};
1384227825Stheraven
1385227825Stheraventemplate <class _Alloc>
1386227825Stheravenstruct __has_select_on_container_copy_construction
1387227825Stheraven    : false_type
1388227825Stheraven{
1389227825Stheraven};
1390227825Stheraven
1391227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1392227825Stheraven
1393227825Stheraventemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1394227825Stheravenstruct __alloc_traits_difference_type
1395227825Stheraven{
1396227825Stheraven    typedef typename pointer_traits<_Ptr>::difference_type type;
1397227825Stheraven};
1398227825Stheraven
1399227825Stheraventemplate <class _Alloc, class _Ptr>
1400227825Stheravenstruct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1401227825Stheraven{
1402227825Stheraven    typedef typename _Alloc::difference_type type;
1403227825Stheraven};
1404227825Stheraven
1405227825Stheraventemplate <class _Alloc>
1406261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY allocator_traits
1407227825Stheraven{
1408227825Stheraven    typedef _Alloc                              allocator_type;
1409227825Stheraven    typedef typename allocator_type::value_type value_type;
1410227825Stheraven
1411227825Stheraven    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1412227825Stheraven    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1413227825Stheraven    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1414227825Stheraven    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1415227825Stheraven
1416227825Stheraven    typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1417227825Stheraven    typedef typename __size_type<allocator_type, difference_type>::type size_type;
1418227825Stheraven
1419227825Stheraven    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1420227825Stheraven                     propagate_on_container_copy_assignment;
1421227825Stheraven    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1422227825Stheraven                     propagate_on_container_move_assignment;
1423227825Stheraven    typedef typename __propagate_on_container_swap<allocator_type>::type
1424227825Stheraven                     propagate_on_container_swap;
1425227825Stheraven
1426227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1427227825Stheraven    template <class _Tp> using rebind_alloc =
1428227825Stheraven                  typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1429227825Stheraven    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1430227825Stheraven#else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1431227825Stheraven    template <class _Tp> struct rebind_alloc
1432227825Stheraven        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1433227825Stheraven    template <class _Tp> struct rebind_traits
1434227825Stheraven        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1435227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1436227825Stheraven
1437227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1438227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n)
1439227825Stheraven        {return __a.allocate(__n);}
1440227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1441227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1442227825Stheraven        {return allocate(__a, __n, __hint,
1443227825Stheraven            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1444227825Stheraven
1445227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1446227825Stheraven    static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1447227825Stheraven        {__a.deallocate(__p, __n);}
1448227825Stheraven
1449227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1450227825Stheraven    template <class _Tp, class... _Args>
1451227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1452227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1453276792Sdim            {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1454227825Stheraven                         __a, __p, _VSTD::forward<_Args>(__args)...);}
1455227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1456227825Stheraven    template <class _Tp>
1457227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1458227825Stheraven        static void construct(allocator_type& __a, _Tp* __p)
1459227825Stheraven            {
1460227825Stheraven                ::new ((void*)__p) _Tp();
1461227825Stheraven            }
1462227825Stheraven    template <class _Tp, class _A0>
1463227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1464227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1465227825Stheraven            {
1466227825Stheraven                ::new ((void*)__p) _Tp(__a0);
1467227825Stheraven            }
1468227825Stheraven    template <class _Tp, class _A0, class _A1>
1469227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1470227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1471227825Stheraven                              const _A1& __a1)
1472227825Stheraven            {
1473227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1);
1474227825Stheraven            }
1475227825Stheraven    template <class _Tp, class _A0, class _A1, class _A2>
1476227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1477227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1478227825Stheraven                              const _A1& __a1, const _A2& __a2)
1479227825Stheraven            {
1480227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1481227825Stheraven            }
1482227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1483227825Stheraven
1484227825Stheraven    template <class _Tp>
1485227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1486227825Stheraven        static void destroy(allocator_type& __a, _Tp* __p)
1487227825Stheraven            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1488227825Stheraven
1489227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1490261272Sdim    static size_type max_size(const allocator_type& __a) _NOEXCEPT
1491227825Stheraven        {return __max_size(__has_max_size<const allocator_type>(), __a);}
1492227825Stheraven
1493227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1494227825Stheraven    static allocator_type
1495227825Stheraven        select_on_container_copy_construction(const allocator_type& __a)
1496227825Stheraven            {return select_on_container_copy_construction(
1497227825Stheraven                __has_select_on_container_copy_construction<const allocator_type>(),
1498227825Stheraven                __a);}
1499227825Stheraven
1500232924Stheraven    template <class _Ptr>
1501232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1502232924Stheraven        static
1503232924Stheraven        void
1504232924Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1505232924Stheraven        {
1506232924Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1507232924Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1508232924Stheraven        }
1509232924Stheraven
1510232924Stheraven    template <class _Tp>
1511232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1512232924Stheraven        static
1513232924Stheraven        typename enable_if
1514232924Stheraven        <
1515232924Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1516232924Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1517232924Stheraven             is_trivially_move_constructible<_Tp>::value,
1518232924Stheraven            void
1519232924Stheraven        >::type
1520232924Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1521232924Stheraven        {
1522232924Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1523232924Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1524232924Stheraven            __begin2 += _Np;
1525232924Stheraven        }
1526232924Stheraven
1527232924Stheraven    template <class _Ptr>
1528232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1529232924Stheraven        static
1530232924Stheraven        void
1531232924Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1532232924Stheraven        {
1533232924Stheraven            while (__end1 != __begin1)
1534246468Stheraven            {
1535246468Stheraven                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1536246468Stheraven                --__end2;
1537246468Stheraven            }
1538232924Stheraven        }
1539232924Stheraven
1540232924Stheraven    template <class _Tp>
1541232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1542232924Stheraven        static
1543232924Stheraven        typename enable_if
1544232924Stheraven        <
1545232924Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1546232924Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1547232924Stheraven             is_trivially_move_constructible<_Tp>::value,
1548232924Stheraven            void
1549232924Stheraven        >::type
1550232924Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1551232924Stheraven        {
1552232924Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1553232924Stheraven            __end2 -= _Np;
1554232924Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1555232924Stheraven        }
1556232924Stheraven
1557227825Stheravenprivate:
1558227825Stheraven
1559227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1560227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1561227825Stheraven        const_void_pointer __hint, true_type)
1562227825Stheraven        {return __a.allocate(__n, __hint);}
1563227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1564227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1565232924Stheraven        const_void_pointer, false_type)
1566227825Stheraven        {return __a.allocate(__n);}
1567227825Stheraven
1568227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1569227825Stheraven    template <class _Tp, class... _Args>
1570227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1571227825Stheraven        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1572227825Stheraven            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1573227825Stheraven    template <class _Tp, class... _Args>
1574227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1575227825Stheraven        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1576227825Stheraven            {
1577227825Stheraven                ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1578227825Stheraven            }
1579227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1580227825Stheraven
1581227825Stheraven    template <class _Tp>
1582227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1583227825Stheraven        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1584227825Stheraven            {__a.destroy(__p);}
1585227825Stheraven    template <class _Tp>
1586227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1587227825Stheraven        static void __destroy(false_type, allocator_type&, _Tp* __p)
1588227825Stheraven            {
1589227825Stheraven                __p->~_Tp();
1590227825Stheraven            }
1591227825Stheraven
1592227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1593227825Stheraven    static size_type __max_size(true_type, const allocator_type& __a)
1594227825Stheraven            {return __a.max_size();}
1595227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1596227825Stheraven    static size_type __max_size(false_type, const allocator_type&)
1597227825Stheraven            {return numeric_limits<size_type>::max();}
1598227825Stheraven
1599227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1600227825Stheraven    static allocator_type
1601227825Stheraven        select_on_container_copy_construction(true_type, const allocator_type& __a)
1602227825Stheraven            {return __a.select_on_container_copy_construction();}
1603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1604227825Stheraven    static allocator_type
1605227825Stheraven        select_on_container_copy_construction(false_type, const allocator_type& __a)
1606227825Stheraven            {return __a;}
1607227825Stheraven};
1608227825Stheraven
1609232924Stheraven// allocator
1610227825Stheraven
1611227825Stheraventemplate <class _Tp>
1612261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator
1613227825Stheraven{
1614227825Stheravenpublic:
1615232924Stheraven    typedef size_t            size_type;
1616232924Stheraven    typedef ptrdiff_t         difference_type;
1617232924Stheraven    typedef _Tp*              pointer;
1618232924Stheraven    typedef const _Tp*        const_pointer;
1619232924Stheraven    typedef _Tp&              reference;
1620232924Stheraven    typedef const _Tp&        const_reference;
1621232924Stheraven    typedef _Tp               value_type;
1622227825Stheraven
1623232924Stheraven    typedef true_type propagate_on_container_move_assignment;
1624227825Stheraven
1625232924Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1626227825Stheraven
1627232924Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1628232924Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1629232924Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1630232924Stheraven        {return _VSTD::addressof(__x);}
1631232924Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1632232924Stheraven        {return _VSTD::addressof(__x);}
1633232924Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1634276792Sdim        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1635232924Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1636276792Sdim        {_VSTD::__deallocate((void*)__p);}
1637232924Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1638232924Stheraven        {return size_type(~0) / sizeof(_Tp);}
1639232924Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1640232924Stheraven    template <class _Up, class... _Args>
1641232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1642232924Stheraven        void
1643232924Stheraven        construct(_Up* __p, _Args&&... __args)
1644232924Stheraven        {
1645232924Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1646232924Stheraven        }
1647232924Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1648232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1649232924Stheraven        void
1650232924Stheraven        construct(pointer __p)
1651232924Stheraven        {
1652232924Stheraven            ::new((void*)__p) _Tp();
1653232924Stheraven        }
1654232924Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1655234959Stheraven
1656232924Stheraven    template <class _A0>
1657232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1658234959Stheraven        void
1659232924Stheraven        construct(pointer __p, _A0& __a0)
1660232924Stheraven        {
1661232924Stheraven            ::new((void*)__p) _Tp(__a0);
1662232924Stheraven        }
1663232924Stheraven    template <class _A0>
1664232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1665234959Stheraven        void
1666232924Stheraven        construct(pointer __p, const _A0& __a0)
1667232924Stheraven        {
1668232924Stheraven            ::new((void*)__p) _Tp(__a0);
1669232924Stheraven        }
1670232924Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1671232924Stheraven    template <class _A0, class _A1>
1672232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1673232924Stheraven        void
1674232924Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1675232924Stheraven        {
1676232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1677232924Stheraven        }
1678232924Stheraven    template <class _A0, class _A1>
1679232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1680232924Stheraven        void
1681232924Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1682232924Stheraven        {
1683232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1684232924Stheraven        }
1685232924Stheraven    template <class _A0, class _A1>
1686232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1687232924Stheraven        void
1688232924Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1689232924Stheraven        {
1690232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1691232924Stheraven        }
1692232924Stheraven    template <class _A0, class _A1>
1693232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1694232924Stheraven        void
1695232924Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1696232924Stheraven        {
1697232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1698232924Stheraven        }
1699232924Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1700232924Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1701227825Stheraven};
1702227825Stheraven
1703227825Stheraventemplate <class _Tp>
1704261272Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1705227825Stheraven{
1706227825Stheravenpublic:
1707227825Stheraven    typedef size_t            size_type;
1708227825Stheraven    typedef ptrdiff_t         difference_type;
1709232924Stheraven    typedef const _Tp*        pointer;
1710227825Stheraven    typedef const _Tp*        const_pointer;
1711232924Stheraven    typedef const _Tp&        reference;
1712227825Stheraven    typedef const _Tp&        const_reference;
1713253146Stheraven    typedef const _Tp         value_type;
1714227825Stheraven
1715227825Stheraven    typedef true_type propagate_on_container_move_assignment;
1716227825Stheraven
1717227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1718227825Stheraven
1719227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1720227825Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1721227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1722227825Stheraven        {return _VSTD::addressof(__x);}
1723227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1724276792Sdim        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1725227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1726276792Sdim        {_VSTD::__deallocate((void*)__p);}
1727227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1728227825Stheraven        {return size_type(~0) / sizeof(_Tp);}
1729227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1730227825Stheraven    template <class _Up, class... _Args>
1731227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1732227825Stheraven        void
1733227825Stheraven        construct(_Up* __p, _Args&&... __args)
1734227825Stheraven        {
1735227825Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1736227825Stheraven        }
1737227825Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1738227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1739227825Stheraven        void
1740227825Stheraven        construct(pointer __p)
1741227825Stheraven        {
1742227825Stheraven            ::new((void*)__p) _Tp();
1743227825Stheraven        }
1744227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1745234959Stheraven
1746227825Stheraven    template <class _A0>
1747227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1748234959Stheraven        void
1749227825Stheraven        construct(pointer __p, _A0& __a0)
1750227825Stheraven        {
1751227825Stheraven            ::new((void*)__p) _Tp(__a0);
1752227825Stheraven        }
1753227825Stheraven    template <class _A0>
1754227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1755234959Stheraven        void
1756227825Stheraven        construct(pointer __p, const _A0& __a0)
1757227825Stheraven        {
1758227825Stheraven            ::new((void*)__p) _Tp(__a0);
1759227825Stheraven        }
1760227825Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1761227825Stheraven    template <class _A0, class _A1>
1762227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1763227825Stheraven        void
1764227825Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1765227825Stheraven        {
1766227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1767227825Stheraven        }
1768227825Stheraven    template <class _A0, class _A1>
1769227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1770227825Stheraven        void
1771227825Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1772227825Stheraven        {
1773227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1774227825Stheraven        }
1775227825Stheraven    template <class _A0, class _A1>
1776227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1777227825Stheraven        void
1778227825Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1779227825Stheraven        {
1780227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1781227825Stheraven        }
1782227825Stheraven    template <class _A0, class _A1>
1783227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1784227825Stheraven        void
1785227825Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1786227825Stheraven        {
1787227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1788227825Stheraven        }
1789227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1790227825Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1791227825Stheraven};
1792227825Stheraven
1793227825Stheraventemplate <class _Tp, class _Up>
1794227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1795227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1796227825Stheraven
1797227825Stheraventemplate <class _Tp, class _Up>
1798227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1799227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1800227825Stheraven
1801227825Stheraventemplate <class _OutputIterator, class _Tp>
1802261272Sdimclass _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
1803227825Stheraven    : public iterator<output_iterator_tag,
1804227825Stheraven                      _Tp,                                         // purposefully not C++03
1805227825Stheraven                      ptrdiff_t,                                   // purposefully not C++03
1806227825Stheraven                      _Tp*,                                        // purposefully not C++03
1807227825Stheraven                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1808227825Stheraven{
1809227825Stheravenprivate:
1810227825Stheraven    _OutputIterator __x_;
1811227825Stheravenpublic:
1812227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1813227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1814227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1815227825Stheraven        {::new(&*__x_) _Tp(__element); return *this;}
1816227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1817227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
1818227825Stheraven        {raw_storage_iterator __t(*this); ++__x_; return __t;}
1819227825Stheraven};
1820227825Stheraven
1821227825Stheraventemplate <class _Tp>
1822227825Stheravenpair<_Tp*, ptrdiff_t>
1823227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1824227825Stheraven{
1825227825Stheraven    pair<_Tp*, ptrdiff_t> __r(0, 0);
1826227825Stheraven    const ptrdiff_t __m = (~ptrdiff_t(0) ^
1827227825Stheraven                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1828227825Stheraven                           / sizeof(_Tp);
1829227825Stheraven    if (__n > __m)
1830227825Stheraven        __n = __m;
1831227825Stheraven    while (__n > 0)
1832227825Stheraven    {
1833227825Stheraven        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1834227825Stheraven        if (__r.first)
1835227825Stheraven        {
1836227825Stheraven            __r.second = __n;
1837227825Stheraven            break;
1838227825Stheraven        }
1839227825Stheraven        __n /= 2;
1840227825Stheraven    }
1841227825Stheraven    return __r;
1842227825Stheraven}
1843227825Stheraven
1844227825Stheraventemplate <class _Tp>
1845227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1846227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1847227825Stheraven
1848227825Stheraventemplate <class _Tp>
1849227825Stheravenstruct auto_ptr_ref
1850227825Stheraven{
1851227825Stheraven    _Tp* __ptr_;
1852227825Stheraven};
1853227825Stheraven
1854227825Stheraventemplate<class _Tp>
1855261272Sdimclass _LIBCPP_TYPE_VIS_ONLY auto_ptr
1856227825Stheraven{
1857227825Stheravenprivate:
1858227825Stheraven    _Tp* __ptr_;
1859227825Stheravenpublic:
1860227825Stheraven    typedef _Tp element_type;
1861227825Stheraven
1862227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1863227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1864227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1865227825Stheraven        : __ptr_(__p.release()) {}
1866227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1867227825Stheraven        {reset(__p.release()); return *this;}
1868227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1869227825Stheraven        {reset(__p.release()); return *this;}
1870227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1871227825Stheraven        {reset(__p.__ptr_); return *this;}
1872227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1873227825Stheraven
1874227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1875227825Stheraven        {return *__ptr_;}
1876227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1877227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1878227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1879227825Stheraven    {
1880227825Stheraven        _Tp* __t = __ptr_;
1881227825Stheraven        __ptr_ = 0;
1882227825Stheraven        return __t;
1883227825Stheraven    }
1884227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1885227825Stheraven    {
1886227825Stheraven        if (__ptr_ != __p)
1887227825Stheraven            delete __ptr_;
1888227825Stheraven        __ptr_ = __p;
1889227825Stheraven    }
1890227825Stheraven
1891227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1892227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1893227825Stheraven        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1894227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1895227825Stheraven        {return auto_ptr<_Up>(release());}
1896227825Stheraven};
1897227825Stheraven
1898227825Stheraventemplate <>
1899261272Sdimclass _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
1900227825Stheraven{
1901227825Stheravenpublic:
1902227825Stheraven    typedef void element_type;
1903227825Stheraven};
1904227825Stheraven
1905227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1906227825Stheraven                                                     typename remove_cv<_T2>::type>::value,
1907232924Stheraven                                bool = is_empty<_T1>::value
1908232924Stheraven#if __has_feature(is_final)
1909232924Stheraven                                       && !__is_final(_T1)
1910232924Stheraven#endif
1911232924Stheraven                                ,
1912232924Stheraven                                bool = is_empty<_T2>::value
1913232924Stheraven#if __has_feature(is_final)
1914232924Stheraven                                       && !__is_final(_T2)
1915232924Stheraven#endif
1916232924Stheraven         >
1917227825Stheravenstruct __libcpp_compressed_pair_switch;
1918227825Stheraven
1919227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1920227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1921227825Stheraven
1922227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1923227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
1924227825Stheraven
1925227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1926227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
1927227825Stheraven
1928227825Stheraventemplate <class _T1, class _T2>
1929227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
1930227825Stheraven
1931227825Stheraventemplate <class _T1, class _T2>
1932227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
1933227825Stheraven
1934227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1935227825Stheravenclass __libcpp_compressed_pair_imp;
1936227825Stheraven
1937227825Stheraventemplate <class _T1, class _T2>
1938227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0>
1939227825Stheraven{
1940227825Stheravenprivate:
1941227825Stheraven    _T1 __first_;
1942227825Stheraven    _T2 __second_;
1943227825Stheravenpublic:
1944227825Stheraven    typedef _T1 _T1_param;
1945227825Stheraven    typedef _T2 _T2_param;
1946227825Stheraven
1947227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
1948227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
1949227825Stheraven
1950227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1951227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1952227825Stheraven
1953227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1954232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1955227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1956232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
1957227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
1958227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
1959227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
1960227825Stheraven
1961261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1962227825Stheraven
1963227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1964227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
1965227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
1966227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
1967227825Stheraven        : __first_(__p.first()),
1968227825Stheraven          __second_(__p.second()) {}
1969227825Stheraven
1970227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1971227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
1972227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
1973227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
1974227825Stheraven        {
1975227825Stheraven            __first_ = __p.first();
1976227825Stheraven            __second_ = __p.second();
1977227825Stheraven            return *this;
1978227825Stheraven        }
1979227825Stheraven
1980227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1981227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
1982227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
1983227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
1984227825Stheraven        : __first_(_VSTD::forward<_T1>(__p.first())),
1985227825Stheraven          __second_(_VSTD::forward<_T2>(__p.second())) {}
1986227825Stheraven
1987227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1988227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
1989227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
1990227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
1991227825Stheraven        {
1992227825Stheraven            __first_ = _VSTD::forward<_T1>(__p.first());
1993227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
1994227825Stheraven            return *this;
1995227825Stheraven        }
1996227825Stheraven
1997261272Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1998253146Stheraven
1999232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2000232924Stheraven
2001232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2002232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2003232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2004232924Stheraven                                     tuple<_Args1...> __first_args,
2005232924Stheraven                                     tuple<_Args2...> __second_args,
2006232924Stheraven                                     __tuple_indices<_I1...>,
2007232924Stheraven                                     __tuple_indices<_I2...>)
2008276792Sdim            : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2009276792Sdim              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2010232924Stheraven            {}
2011232924Stheraven
2012232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2013232924Stheraven
2014227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2015227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2016227825Stheraven
2017227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2018227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2019227825Stheraven
2020227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2021227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2022276792Sdim                   __is_nothrow_swappable<_T2>::value)
2023227825Stheraven    {
2024227825Stheraven        using _VSTD::swap;
2025227825Stheraven        swap(__first_, __x.__first_);
2026227825Stheraven        swap(__second_, __x.__second_);
2027227825Stheraven    }
2028227825Stheraven};
2029227825Stheraven
2030227825Stheraventemplate <class _T1, class _T2>
2031227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1>
2032227825Stheraven    : private _T1
2033227825Stheraven{
2034227825Stheravenprivate:
2035227825Stheraven    _T2 __second_;
2036227825Stheravenpublic:
2037227825Stheraven    typedef _T1 _T1_param;
2038227825Stheraven    typedef _T2 _T2_param;
2039227825Stheraven
2040227825Stheraven    typedef _T1&                                        _T1_reference;
2041227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2042227825Stheraven
2043227825Stheraven    typedef const _T1&                                        _T1_const_reference;
2044227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2045227825Stheraven
2046227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2047232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2048227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2049232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2050227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2051227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2052227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2053227825Stheraven
2054261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2055227825Stheraven
2056227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2057227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2058227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2059227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2060227825Stheraven        : _T1(__p.first()), __second_(__p.second()) {}
2061227825Stheraven
2062227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2063227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2064227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2065227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2066227825Stheraven        {
2067227825Stheraven            _T1::operator=(__p.first());
2068227825Stheraven            __second_ = __p.second();
2069227825Stheraven            return *this;
2070227825Stheraven        }
2071227825Stheraven
2072227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2073227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2074227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2075227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2076227825Stheraven        : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2077227825Stheraven
2078227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2079227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2080227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2081227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2082227825Stheraven        {
2083227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2084227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2085227825Stheraven            return *this;
2086227825Stheraven        }
2087227825Stheraven
2088261272Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2089253146Stheraven
2090232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2091232924Stheraven
2092232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2093232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2094232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2095232924Stheraven                                     tuple<_Args1...> __first_args,
2096232924Stheraven                                     tuple<_Args2...> __second_args,
2097232924Stheraven                                     __tuple_indices<_I1...>,
2098232924Stheraven                                     __tuple_indices<_I2...>)
2099276792Sdim            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2100276792Sdim              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2101232924Stheraven            {}
2102232924Stheraven
2103232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2104232924Stheraven
2105227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2106227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2107227825Stheraven
2108227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2109227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2110227825Stheraven
2111227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2112227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2113276792Sdim                   __is_nothrow_swappable<_T2>::value)
2114227825Stheraven    {
2115227825Stheraven        using _VSTD::swap;
2116227825Stheraven        swap(__second_, __x.__second_);
2117227825Stheraven    }
2118227825Stheraven};
2119227825Stheraven
2120227825Stheraventemplate <class _T1, class _T2>
2121227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2>
2122227825Stheraven    : private _T2
2123227825Stheraven{
2124227825Stheravenprivate:
2125227825Stheraven    _T1 __first_;
2126227825Stheravenpublic:
2127227825Stheraven    typedef _T1 _T1_param;
2128227825Stheraven    typedef _T2 _T2_param;
2129227825Stheraven
2130227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2131227825Stheraven    typedef _T2&                                        _T2_reference;
2132227825Stheraven
2133227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2134227825Stheraven    typedef const _T2&                                        _T2_const_reference;
2135227825Stheraven
2136227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2137227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2138227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2139227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2140227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2141227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2142227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2143227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2144227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2145227825Stheraven
2146261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2147227825Stheraven
2148227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2149227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2150227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2151227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2152227825Stheraven        : _T2(__p.second()), __first_(__p.first()) {}
2153227825Stheraven
2154227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2155227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2156227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2157227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2158227825Stheraven        {
2159227825Stheraven            _T2::operator=(__p.second());
2160227825Stheraven            __first_ = __p.first();
2161227825Stheraven            return *this;
2162227825Stheraven        }
2163227825Stheraven
2164227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2165227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2166227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2167227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2168227825Stheraven        : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2169227825Stheraven
2170227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2171227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2172227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2173227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2174227825Stheraven        {
2175227825Stheraven            _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2176227825Stheraven            __first_ = _VSTD::move(__p.first());
2177227825Stheraven            return *this;
2178227825Stheraven        }
2179227825Stheraven
2180261272Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2181253146Stheraven
2182232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2183232924Stheraven
2184232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2185232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2186232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2187232924Stheraven                                     tuple<_Args1...> __first_args,
2188232924Stheraven                                     tuple<_Args2...> __second_args,
2189232924Stheraven                                     __tuple_indices<_I1...>,
2190232924Stheraven                                     __tuple_indices<_I2...>)
2191276792Sdim            : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2192276792Sdim              __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2193232924Stheraven              
2194232924Stheraven            {}
2195232924Stheraven
2196232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2197232924Stheraven
2198227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2199227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2200227825Stheraven
2201227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2202227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2203227825Stheraven
2204227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2205227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2206276792Sdim                   __is_nothrow_swappable<_T2>::value)
2207227825Stheraven    {
2208227825Stheraven        using _VSTD::swap;
2209227825Stheraven        swap(__first_, __x.__first_);
2210227825Stheraven    }
2211227825Stheraven};
2212227825Stheraven
2213227825Stheraventemplate <class _T1, class _T2>
2214227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3>
2215227825Stheraven    : private _T1,
2216227825Stheraven      private _T2
2217227825Stheraven{
2218227825Stheravenpublic:
2219227825Stheraven    typedef _T1 _T1_param;
2220227825Stheraven    typedef _T2 _T2_param;
2221227825Stheraven
2222227825Stheraven    typedef _T1& _T1_reference;
2223227825Stheraven    typedef _T2& _T2_reference;
2224227825Stheraven
2225227825Stheraven    typedef const _T1& _T1_const_reference;
2226227825Stheraven    typedef const _T2& _T2_const_reference;
2227227825Stheraven
2228227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2229227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2230227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2231227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2232227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2233227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2234227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2235227825Stheraven
2236261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2237227825Stheraven
2238227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2239227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2240227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2241227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2242227825Stheraven        : _T1(__p.first()), _T2(__p.second()) {}
2243227825Stheraven
2244227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2245227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2246227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2247227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2248227825Stheraven        {
2249227825Stheraven            _T1::operator=(__p.first());
2250227825Stheraven            _T2::operator=(__p.second());
2251227825Stheraven            return *this;
2252227825Stheraven        }
2253227825Stheraven
2254227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2255227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2256227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2257227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2258227825Stheraven        : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2259227825Stheraven
2260227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2261227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2262227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2263227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2264227825Stheraven        {
2265227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2266227825Stheraven            _T2::operator=(_VSTD::move(__p.second()));
2267227825Stheraven            return *this;
2268227825Stheraven        }
2269227825Stheraven
2270261272Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2271253146Stheraven
2272232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2273232924Stheraven
2274232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2275232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2276232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2277232924Stheraven                                     tuple<_Args1...> __first_args,
2278232924Stheraven                                     tuple<_Args2...> __second_args,
2279232924Stheraven                                     __tuple_indices<_I1...>,
2280232924Stheraven                                     __tuple_indices<_I2...>)
2281276792Sdim            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2282276792Sdim              _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2283232924Stheraven            {}
2284232924Stheraven
2285232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2286232924Stheraven
2287227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2288227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2289227825Stheraven
2290227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2291227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2292227825Stheraven
2293232924Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2294227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2295276792Sdim                   __is_nothrow_swappable<_T2>::value)
2296227825Stheraven    {
2297227825Stheraven    }
2298227825Stheraven};
2299227825Stheraven
2300227825Stheraventemplate <class _T1, class _T2>
2301227825Stheravenclass __compressed_pair
2302227825Stheraven    : private __libcpp_compressed_pair_imp<_T1, _T2>
2303227825Stheraven{
2304227825Stheraven    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2305227825Stheravenpublic:
2306227825Stheraven    typedef typename base::_T1_param _T1_param;
2307227825Stheraven    typedef typename base::_T2_param _T2_param;
2308227825Stheraven
2309227825Stheraven    typedef typename base::_T1_reference _T1_reference;
2310227825Stheraven    typedef typename base::_T2_reference _T2_reference;
2311227825Stheraven
2312227825Stheraven    typedef typename base::_T1_const_reference _T1_const_reference;
2313227825Stheraven    typedef typename base::_T2_const_reference _T2_const_reference;
2314227825Stheraven
2315227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2316232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2317227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2318232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2319227825Stheraven        : base(_VSTD::forward<_T2_param>(__t2)) {}
2320227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2321227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2322227825Stheraven
2323261272Sdim#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2324227825Stheraven
2325227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2326227825Stheraven    __compressed_pair(const __compressed_pair& __p)
2327227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2328227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2329227825Stheraven        : base(__p) {}
2330227825Stheraven
2331227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2332227825Stheraven    __compressed_pair& operator=(const __compressed_pair& __p)
2333227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2334227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2335227825Stheraven        {
2336227825Stheraven            base::operator=(__p);
2337227825Stheraven            return *this;
2338227825Stheraven        }
2339227825Stheraven
2340227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2341227825Stheraven    __compressed_pair(__compressed_pair&& __p)
2342227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2343227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2344227825Stheraven        : base(_VSTD::move(__p)) {}
2345227825Stheraven
2346227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2347227825Stheraven    __compressed_pair& operator=(__compressed_pair&& __p)
2348227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2349227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2350227825Stheraven        {
2351227825Stheraven            base::operator=(_VSTD::move(__p));
2352227825Stheraven            return *this;
2353227825Stheraven        }
2354232924Stheraven
2355261272Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2356253146Stheraven
2357232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2358232924Stheraven
2359232924Stheraven    template <class... _Args1, class... _Args2>
2360232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2361232924Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2362232924Stheraven                                                      tuple<_Args2...> __second_args)
2363232924Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2364232924Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2365232924Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2366232924Stheraven            {}
2367232924Stheraven
2368232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2369232924Stheraven
2370227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
2371227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2372227825Stheraven
2373227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return base::second();}
2374227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2375227825Stheraven
2376227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2377227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2378276792Sdim                   __is_nothrow_swappable<_T2>::value)
2379227825Stheraven        {base::swap(__x);}
2380227825Stheraven};
2381227825Stheraven
2382227825Stheraventemplate <class _T1, class _T2>
2383227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2384227825Stheravenvoid
2385227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2386227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2387276792Sdim                   __is_nothrow_swappable<_T2>::value)
2388227825Stheraven    {__x.swap(__y);}
2389227825Stheraven
2390232924Stheraven// __same_or_less_cv_qualified
2391232924Stheraven
2392232924Stheraventemplate <class _Ptr1, class _Ptr2,
2393232924Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2394232924Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2395232924Stheraven                        >::value
2396232924Stheraven         >
2397232924Stheravenstruct __same_or_less_cv_qualified_imp
2398232924Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2399232924Stheraven
2400232924Stheraventemplate <class _Ptr1, class _Ptr2>
2401232924Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2402232924Stheraven    : false_type {};
2403232924Stheraven
2404276792Sdimtemplate <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2405276792Sdim                                           is_same<_Ptr1, _Ptr2>::value ||
2406276792Sdim                                           __has_element_type<_Ptr1>::value>
2407232924Stheravenstruct __same_or_less_cv_qualified
2408232924Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2409232924Stheraven
2410232924Stheraventemplate <class _Ptr1, class _Ptr2>
2411276792Sdimstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2412232924Stheraven    : false_type {};
2413232924Stheraven
2414232924Stheraven// default_delete
2415232924Stheraven
2416227825Stheraventemplate <class _Tp>
2417261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete
2418227825Stheraven{
2419241900Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2420241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2421241900Sdim#else
2422241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2423241900Sdim#endif
2424227825Stheraven    template <class _Up>
2425227825Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2426227825Stheraven             typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2427227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2428227825Stheraven        {
2429227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2430249989Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2431227825Stheraven            delete __ptr;
2432227825Stheraven        }
2433227825Stheraven};
2434227825Stheraven
2435227825Stheraventemplate <class _Tp>
2436261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2437227825Stheraven{
2438232924Stheravenpublic:
2439241900Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2440241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2441241900Sdim#else
2442241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2443241900Sdim#endif
2444232924Stheraven    template <class _Up>
2445232924Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2446232924Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2447232924Stheraven    template <class _Up>
2448232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2449232924Stheraven        void operator() (_Up* __ptr,
2450232924Stheraven                         typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2451227825Stheraven        {
2452227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2453249989Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2454227825Stheraven            delete [] __ptr;
2455227825Stheraven        }
2456227825Stheraven};
2457227825Stheraven
2458227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> >
2459261272Sdimclass _LIBCPP_TYPE_VIS_ONLY unique_ptr
2460227825Stheraven{
2461227825Stheravenpublic:
2462227825Stheraven    typedef _Tp element_type;
2463227825Stheraven    typedef _Dp deleter_type;
2464227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2465227825Stheravenprivate:
2466227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2467227825Stheraven
2468232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2469227825Stheraven    unique_ptr(unique_ptr&);
2470227825Stheraven    template <class _Up, class _Ep>
2471227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&);
2472227825Stheraven    unique_ptr& operator=(unique_ptr&);
2473227825Stheraven    template <class _Up, class _Ep>
2474227825Stheraven        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2475227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2476227825Stheraven
2477227825Stheraven    struct __nat {int __for_bool_;};
2478227825Stheraven
2479227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2480227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2481227825Stheravenpublic:
2482241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2483227825Stheraven        : __ptr_(pointer())
2484227825Stheraven        {
2485227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2486227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2487227825Stheraven        }
2488241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2489227825Stheraven        : __ptr_(pointer())
2490227825Stheraven        {
2491227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2492227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2493227825Stheraven        }
2494227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2495227825Stheraven        : __ptr_(_VSTD::move(__p))
2496227825Stheraven        {
2497227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2498227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2499227825Stheraven        }
2500227825Stheraven
2501227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2502227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2503227825Stheraven                                        is_reference<deleter_type>::value,
2504227825Stheraven                                        deleter_type,
2505227825Stheraven                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
2506227825Stheraven             _NOEXCEPT
2507227825Stheraven        : __ptr_(__p, __d) {}
2508227825Stheraven
2509227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2510227825Stheraven             _NOEXCEPT
2511227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2512227825Stheraven        {
2513227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2514227825Stheraven        }
2515227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2516227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2517227825Stheraven    template <class _Up, class _Ep>
2518227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2519227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2520227825Stheraven                   typename enable_if
2521227825Stheraven                      <
2522227825Stheraven                        !is_array<_Up>::value &&
2523227825Stheraven                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2524227825Stheraven                         is_convertible<_Ep, deleter_type>::value &&
2525227825Stheraven                         (
2526227825Stheraven                            !is_reference<deleter_type>::value ||
2527227825Stheraven                            is_same<deleter_type, _Ep>::value
2528227825Stheraven                         ),
2529227825Stheraven                         __nat
2530227825Stheraven                      >::type = __nat()) _NOEXCEPT
2531227825Stheraven            : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2532227825Stheraven
2533227825Stheraven    template <class _Up>
2534227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2535227825Stheraven                typename enable_if<
2536227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2537227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2538227825Stheraven                                      __nat
2539227825Stheraven                                  >::type = __nat()) _NOEXCEPT
2540227825Stheraven            : __ptr_(__p.release())
2541227825Stheraven            {
2542227825Stheraven            }
2543227825Stheraven
2544227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2545227825Stheraven            {
2546227825Stheraven                reset(__u.release());
2547227825Stheraven                __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2548227825Stheraven                return *this;
2549227825Stheraven            }
2550227825Stheraven
2551227825Stheraven        template <class _Up, class _Ep>
2552227825Stheraven            _LIBCPP_INLINE_VISIBILITY
2553227825Stheraven            typename enable_if
2554227825Stheraven            <
2555232924Stheraven                !is_array<_Up>::value &&
2556232924Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2557232924Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2558227825Stheraven                unique_ptr&
2559227825Stheraven            >::type
2560227825Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2561227825Stheraven            {
2562227825Stheraven                reset(__u.release());
2563227825Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2564227825Stheraven                return *this;
2565227825Stheraven            }
2566227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2567227825Stheraven
2568227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2569227825Stheraven    {
2570227825Stheraven        return __rv<unique_ptr>(*this);
2571227825Stheraven    }
2572227825Stheraven
2573227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2574227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2575227825Stheraven
2576227825Stheraven    template <class _Up, class _Ep>
2577227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2578227825Stheraven    {
2579227825Stheraven        reset(__u.release());
2580227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2581227825Stheraven        return *this;
2582227825Stheraven    }
2583227825Stheraven
2584227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2585227825Stheraven        : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2586227825Stheraven
2587227825Stheraven    template <class _Up>
2588227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2589227825Stheraven                typename enable_if<
2590227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2591227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2592227825Stheraven                                      unique_ptr&
2593227825Stheraven                                  >::type
2594227825Stheraven        operator=(auto_ptr<_Up> __p)
2595227825Stheraven            {reset(__p.release()); return *this;}
2596227825Stheraven
2597227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2598227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2599227825Stheraven
2600227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2601227825Stheraven    {
2602227825Stheraven        reset();
2603227825Stheraven        return *this;
2604227825Stheraven    }
2605227825Stheraven
2606227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2607227825Stheraven        {return *__ptr_.first();}
2608227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2609227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2610227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2611227825Stheraven        {return __ptr_.second();}
2612227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2613227825Stheraven        {return __ptr_.second();}
2614232924Stheraven    _LIBCPP_INLINE_VISIBILITY
2615232924Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2616232924Stheraven        {return __ptr_.first() != nullptr;}
2617227825Stheraven
2618227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2619227825Stheraven    {
2620227825Stheraven        pointer __t = __ptr_.first();
2621227825Stheraven        __ptr_.first() = pointer();
2622227825Stheraven        return __t;
2623227825Stheraven    }
2624227825Stheraven
2625227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2626227825Stheraven    {
2627227825Stheraven        pointer __tmp = __ptr_.first();
2628227825Stheraven        __ptr_.first() = __p;
2629227825Stheraven        if (__tmp)
2630227825Stheraven            __ptr_.second()(__tmp);
2631227825Stheraven    }
2632227825Stheraven
2633227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2634227825Stheraven        {__ptr_.swap(__u.__ptr_);}
2635227825Stheraven};
2636227825Stheraven
2637227825Stheraventemplate <class _Tp, class _Dp>
2638261272Sdimclass _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
2639227825Stheraven{
2640227825Stheravenpublic:
2641227825Stheraven    typedef _Tp element_type;
2642227825Stheraven    typedef _Dp deleter_type;
2643227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2644227825Stheravenprivate:
2645227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2646227825Stheraven
2647232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2648227825Stheraven    unique_ptr(unique_ptr&);
2649227825Stheraven    template <class _Up>
2650227825Stheraven        unique_ptr(unique_ptr<_Up>&);
2651227825Stheraven    unique_ptr& operator=(unique_ptr&);
2652227825Stheraven    template <class _Up>
2653227825Stheraven        unique_ptr& operator=(unique_ptr<_Up>&);
2654227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2655227825Stheraven
2656227825Stheraven    struct __nat {int __for_bool_;};
2657227825Stheraven
2658227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2659227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2660227825Stheravenpublic:
2661241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2662227825Stheraven        : __ptr_(pointer())
2663227825Stheraven        {
2664227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2665227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2666227825Stheraven        }
2667241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2668227825Stheraven        : __ptr_(pointer())
2669227825Stheraven        {
2670227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2671227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2672227825Stheraven        }
2673227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2674276792Sdim    template <class _Pp>
2675276792Sdim    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2676276792Sdim            typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
2677227825Stheraven        : __ptr_(__p)
2678227825Stheraven        {
2679227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2680227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2681227825Stheraven        }
2682227825Stheraven
2683276792Sdim    template <class _Pp>
2684232924Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2685227825Stheraven                                       is_reference<deleter_type>::value,
2686227825Stheraven                                       deleter_type,
2687276792Sdim                                       typename add_lvalue_reference<const deleter_type>::type>::type __d,
2688276792Sdim                                       typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2689227825Stheraven             _NOEXCEPT
2690227825Stheraven        : __ptr_(__p, __d) {}
2691227825Stheraven
2692227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2693227825Stheraven                                       is_reference<deleter_type>::value,
2694227825Stheraven                                       deleter_type,
2695227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2696227825Stheraven             _NOEXCEPT
2697227825Stheraven        : __ptr_(pointer(), __d) {}
2698227825Stheraven
2699276792Sdim    template <class _Pp>
2700276792Sdim    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2701276792Sdim                                         typename remove_reference<deleter_type>::type&& __d,
2702276792Sdim                                         typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
2703227825Stheraven             _NOEXCEPT
2704227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2705227825Stheraven        {
2706227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2707227825Stheraven        }
2708227825Stheraven
2709227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2710227825Stheraven             _NOEXCEPT
2711227825Stheraven        : __ptr_(pointer(), _VSTD::move(__d))
2712227825Stheraven        {
2713227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2714227825Stheraven        }
2715227825Stheraven
2716227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2717227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2718227825Stheraven
2719227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2720227825Stheraven        {
2721227825Stheraven            reset(__u.release());
2722227825Stheraven            __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2723227825Stheraven            return *this;
2724227825Stheraven        }
2725232924Stheraven
2726232924Stheraven    template <class _Up, class _Ep>
2727232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2728232924Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2729232924Stheraven                   typename enable_if
2730232924Stheraven                            <
2731232924Stheraven                                is_array<_Up>::value &&
2732232924Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2733232924Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2734232924Stheraven                                (
2735232924Stheraven                                    !is_reference<deleter_type>::value ||
2736232924Stheraven                                    is_same<deleter_type, _Ep>::value
2737232924Stheraven                                ),
2738232924Stheraven                                __nat
2739232924Stheraven                            >::type = __nat()
2740232924Stheraven                  ) _NOEXCEPT
2741232924Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2742232924Stheraven
2743232924Stheraven
2744232924Stheraven        template <class _Up, class _Ep>
2745232924Stheraven            _LIBCPP_INLINE_VISIBILITY
2746232924Stheraven            typename enable_if
2747232924Stheraven            <
2748232924Stheraven                is_array<_Up>::value &&
2749232924Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2750232924Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2751232924Stheraven                unique_ptr&
2752232924Stheraven            >::type
2753232924Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2754232924Stheraven            {
2755232924Stheraven                reset(__u.release());
2756232924Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2757232924Stheraven                return *this;
2758232924Stheraven            }
2759227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2760227825Stheraven
2761227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2762227825Stheraven        : __ptr_(__p)
2763227825Stheraven        {
2764227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2765227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2766227825Stheraven        }
2767227825Stheraven
2768227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2769227825Stheraven        : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2770227825Stheraven
2771227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2772227825Stheraven        : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2773227825Stheraven
2774227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2775227825Stheraven    {
2776227825Stheraven        return __rv<unique_ptr>(*this);
2777227825Stheraven    }
2778227825Stheraven
2779227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2780227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2781227825Stheraven
2782227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2783227825Stheraven    {
2784227825Stheraven        reset(__u->release());
2785227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2786227825Stheraven        return *this;
2787227825Stheraven    }
2788227825Stheraven
2789227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2790227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2791227825Stheraven
2792227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2793227825Stheraven    {
2794227825Stheraven        reset();
2795227825Stheraven        return *this;
2796227825Stheraven    }
2797227825Stheraven
2798227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2799227825Stheraven        {return __ptr_.first()[__i];}
2800227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2801227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2802227825Stheraven        {return __ptr_.second();}
2803227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2804227825Stheraven        {return __ptr_.second();}
2805232924Stheraven    _LIBCPP_INLINE_VISIBILITY
2806232924Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2807232924Stheraven        {return __ptr_.first() != nullptr;}
2808227825Stheraven
2809227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2810227825Stheraven    {
2811227825Stheraven        pointer __t = __ptr_.first();
2812227825Stheraven        __ptr_.first() = pointer();
2813227825Stheraven        return __t;
2814227825Stheraven    }
2815227825Stheraven
2816227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2817276792Sdim    template <class _Pp>
2818276792Sdim    _LIBCPP_INLINE_VISIBILITY
2819276792Sdim    typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2820276792Sdim    reset(_Pp __p) _NOEXCEPT
2821227825Stheraven    {
2822227825Stheraven        pointer __tmp = __ptr_.first();
2823227825Stheraven        __ptr_.first() = __p;
2824227825Stheraven        if (__tmp)
2825227825Stheraven            __ptr_.second()(__tmp);
2826227825Stheraven    }
2827227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2828227825Stheraven    {
2829227825Stheraven        pointer __tmp = __ptr_.first();
2830227825Stheraven        __ptr_.first() = nullptr;
2831227825Stheraven        if (__tmp)
2832227825Stheraven            __ptr_.second()(__tmp);
2833227825Stheraven    }
2834227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2835227825Stheraven    {
2836227825Stheraven        pointer __tmp = __ptr_.first();
2837227825Stheraven        __ptr_.first() = nullptr;
2838227825Stheraven        if (__tmp)
2839227825Stheraven            __ptr_.second()(__tmp);
2840227825Stheraven    }
2841227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2842227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2843227825Stheraven    {
2844227825Stheraven        pointer __tmp = __ptr_.first();
2845227825Stheraven        __ptr_.first() = __p;
2846227825Stheraven        if (__tmp)
2847227825Stheraven            __ptr_.second()(__tmp);
2848227825Stheraven    }
2849227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2850227825Stheraven
2851227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2852227825Stheravenprivate:
2853227825Stheraven
2854227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2855227825Stheraven    template <class _Up>
2856227825Stheraven        explicit unique_ptr(_Up);
2857227825Stheraven    template <class _Up>
2858227825Stheraven        unique_ptr(_Up __u,
2859227825Stheraven                   typename conditional<
2860227825Stheraven                                       is_reference<deleter_type>::value,
2861227825Stheraven                                       deleter_type,
2862227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type,
2863227825Stheraven                   typename enable_if
2864227825Stheraven                      <
2865227825Stheraven                         is_convertible<_Up, pointer>::value,
2866227825Stheraven                         __nat
2867227825Stheraven                      >::type = __nat());
2868227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2869227825Stheraven};
2870227825Stheraven
2871227825Stheraventemplate <class _Tp, class _Dp>
2872227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2873227825Stheravenvoid
2874227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2875227825Stheraven
2876227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2877227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2878227825Stheravenbool
2879227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2880227825Stheraven
2881227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2882227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2883227825Stheravenbool
2884227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2885227825Stheraven
2886227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2887227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2888227825Stheravenbool
2889232924Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2890232924Stheraven{
2891232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2892232924Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2893232924Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2894232924Stheraven    return less<_V>()(__x.get(), __y.get());
2895232924Stheraven}
2896227825Stheraven
2897227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2898227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2899227825Stheravenbool
2900227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2901227825Stheraven
2902227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2903227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2904227825Stheravenbool
2905227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2906227825Stheraven
2907227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2908227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2909227825Stheravenbool
2910227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2911227825Stheraven
2912232924Stheraventemplate <class _T1, class _D1>
2913232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2914232924Stheravenbool
2915241900Sdimoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2916232924Stheraven{
2917232924Stheraven    return !__x;
2918232924Stheraven}
2919232924Stheraven
2920232924Stheraventemplate <class _T1, class _D1>
2921232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2922232924Stheravenbool
2923241900Sdimoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2924232924Stheraven{
2925232924Stheraven    return !__x;
2926232924Stheraven}
2927232924Stheraven
2928232924Stheraventemplate <class _T1, class _D1>
2929232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2930232924Stheravenbool
2931241900Sdimoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2932232924Stheraven{
2933232924Stheraven    return static_cast<bool>(__x);
2934232924Stheraven}
2935232924Stheraven
2936232924Stheraventemplate <class _T1, class _D1>
2937232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2938232924Stheravenbool
2939241900Sdimoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2940232924Stheraven{
2941232924Stheraven    return static_cast<bool>(__x);
2942232924Stheraven}
2943232924Stheraven
2944232924Stheraventemplate <class _T1, class _D1>
2945232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2946232924Stheravenbool
2947232924Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2948232924Stheraven{
2949232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2950232924Stheraven    return less<_P1>()(__x.get(), nullptr);
2951232924Stheraven}
2952232924Stheraven
2953232924Stheraventemplate <class _T1, class _D1>
2954232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2955232924Stheravenbool
2956232924Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2957232924Stheraven{
2958232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2959232924Stheraven    return less<_P1>()(nullptr, __x.get());
2960232924Stheraven}
2961232924Stheraven
2962232924Stheraventemplate <class _T1, class _D1>
2963232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2964232924Stheravenbool
2965232924Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2966232924Stheraven{
2967232924Stheraven    return nullptr < __x;
2968232924Stheraven}
2969232924Stheraven
2970232924Stheraventemplate <class _T1, class _D1>
2971232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2972232924Stheravenbool
2973232924Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2974232924Stheraven{
2975232924Stheraven    return __x < nullptr;
2976232924Stheraven}
2977232924Stheraven
2978232924Stheraventemplate <class _T1, class _D1>
2979232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2980232924Stheravenbool
2981232924Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2982232924Stheraven{
2983232924Stheraven    return !(nullptr < __x);
2984232924Stheraven}
2985232924Stheraven
2986232924Stheraventemplate <class _T1, class _D1>
2987232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2988232924Stheravenbool
2989232924Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2990232924Stheraven{
2991232924Stheraven    return !(__x < nullptr);
2992232924Stheraven}
2993232924Stheraven
2994232924Stheraventemplate <class _T1, class _D1>
2995232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2996232924Stheravenbool
2997232924Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2998232924Stheraven{
2999232924Stheraven    return !(__x < nullptr);
3000232924Stheraven}
3001232924Stheraven
3002232924Stheraventemplate <class _T1, class _D1>
3003232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3004232924Stheravenbool
3005232924Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3006232924Stheraven{
3007232924Stheraven    return !(nullptr < __x);
3008232924Stheraven}
3009232924Stheraven
3010234959Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3011234959Stheraven
3012234959Stheraventemplate <class _Tp, class _Dp>
3013234959Stheraveninline _LIBCPP_INLINE_VISIBILITY
3014234959Stheravenunique_ptr<_Tp, _Dp>
3015234959Stheravenmove(unique_ptr<_Tp, _Dp>& __t)
3016234959Stheraven{
3017234959Stheraven    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3018234959Stheraven}
3019234959Stheraven
3020234959Stheraven#endif
3021234959Stheraven
3022253146Stheraven#if _LIBCPP_STD_VER > 11
3023253146Stheraven
3024253146Stheraventemplate<class _Tp>
3025253146Stheravenstruct __unique_if
3026253146Stheraven{
3027253146Stheraven    typedef unique_ptr<_Tp> __unique_single;
3028253146Stheraven};
3029253146Stheraven
3030253146Stheraventemplate<class _Tp>
3031253146Stheravenstruct __unique_if<_Tp[]>
3032253146Stheraven{
3033253146Stheraven    typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3034253146Stheraven};
3035253146Stheraven
3036253146Stheraventemplate<class _Tp, size_t _Np>
3037253146Stheravenstruct __unique_if<_Tp[_Np]>
3038253146Stheraven{
3039253146Stheraven    typedef void __unique_array_known_bound;
3040253146Stheraven};
3041253146Stheraven
3042253146Stheraventemplate<class _Tp, class... _Args>
3043253146Stheraveninline _LIBCPP_INLINE_VISIBILITY
3044253146Stheraventypename __unique_if<_Tp>::__unique_single
3045253146Stheravenmake_unique(_Args&&... __args)
3046253146Stheraven{
3047253146Stheraven    return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3048253146Stheraven}
3049253146Stheraven
3050253146Stheraventemplate<class _Tp>
3051253146Stheraveninline _LIBCPP_INLINE_VISIBILITY
3052253146Stheraventypename __unique_if<_Tp>::__unique_array_unknown_bound
3053253146Stheravenmake_unique(size_t __n)
3054253146Stheraven{
3055253146Stheraven    typedef typename remove_extent<_Tp>::type _Up;
3056253146Stheraven    return unique_ptr<_Tp>(new _Up[__n]());
3057253146Stheraven}
3058253146Stheraven
3059253146Stheraventemplate<class _Tp, class... _Args>
3060253146Stheraven    typename __unique_if<_Tp>::__unique_array_known_bound
3061253146Stheraven    make_unique(_Args&&...) = delete;
3062253146Stheraven
3063253146Stheraven#endif  // _LIBCPP_STD_VER > 11
3064253146Stheraven
3065227825Stheraventemplate <class _Tp> struct hash;
3066227825Stheraven
3067253146Stheraventemplate <class _Size>
3068253146Stheraveninline _LIBCPP_INLINE_VISIBILITY
3069253146Stheraven_Size
3070253146Stheraven__loadword(const void* __p)
3071253146Stheraven{
3072253146Stheraven    _Size __r;
3073253146Stheraven    std::memcpy(&__r, __p, sizeof(__r));
3074253146Stheraven    return __r;
3075253146Stheraven}
3076253146Stheraven
3077232924Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3078232924Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3079232924Stheraven// multiplication, which can be very slow on 32-bit systems.
3080232924Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3081232924Stheravenstruct __murmur2_or_cityhash;
3082232924Stheraven
3083232924Stheraventemplate <class _Size>
3084232924Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3085227825Stheraven{
3086232924Stheraven    _Size operator()(const void* __key, _Size __len);
3087232924Stheraven};
3088232924Stheraven
3089232924Stheraven// murmur2
3090232924Stheraventemplate <class _Size>
3091232924Stheraven_Size
3092232924Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3093232924Stheraven{
3094232924Stheraven    const _Size __m = 0x5bd1e995;
3095232924Stheraven    const _Size __r = 24;
3096232924Stheraven    _Size __h = __len;
3097232924Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3098232924Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3099232924Stheraven    {
3100253146Stheraven        _Size __k = __loadword<_Size>(__data);
3101232924Stheraven        __k *= __m;
3102232924Stheraven        __k ^= __k >> __r;
3103232924Stheraven        __k *= __m;
3104232924Stheraven        __h *= __m;
3105232924Stheraven        __h ^= __k;
3106232924Stheraven    }
3107232924Stheraven    switch (__len)
3108232924Stheraven    {
3109232924Stheraven    case 3:
3110232924Stheraven        __h ^= __data[2] << 16;
3111232924Stheraven    case 2:
3112232924Stheraven        __h ^= __data[1] << 8;
3113232924Stheraven    case 1:
3114232924Stheraven        __h ^= __data[0];
3115232924Stheraven        __h *= __m;
3116232924Stheraven    }
3117232924Stheraven    __h ^= __h >> 13;
3118232924Stheraven    __h *= __m;
3119232924Stheraven    __h ^= __h >> 15;
3120232924Stheraven    return __h;
3121232924Stheraven}
3122232924Stheraven
3123232924Stheraventemplate <class _Size>
3124232924Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3125232924Stheraven{
3126232924Stheraven    _Size operator()(const void* __key, _Size __len);
3127232924Stheraven
3128232924Stheraven private:
3129232924Stheraven  // Some primes between 2^63 and 2^64.
3130232924Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3131232924Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3132232924Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3133232924Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3134232924Stheraven
3135232924Stheraven  static _Size __rotate(_Size __val, int __shift) {
3136232924Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3137232924Stheraven  }
3138232924Stheraven
3139232924Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3140232924Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3141232924Stheraven  }
3142232924Stheraven
3143232924Stheraven  static _Size __shift_mix(_Size __val) {
3144232924Stheraven    return __val ^ (__val >> 47);
3145232924Stheraven  }
3146232924Stheraven
3147232924Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3148232924Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3149232924Stheraven    _Size __a = (__u ^ __v) * __mul;
3150232924Stheraven    __a ^= (__a >> 47);
3151232924Stheraven    _Size __b = (__v ^ __a) * __mul;
3152232924Stheraven    __b ^= (__b >> 47);
3153232924Stheraven    __b *= __mul;
3154232924Stheraven    return __b;
3155232924Stheraven  }
3156232924Stheraven
3157232924Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3158232924Stheraven    if (__len > 8) {
3159253146Stheraven      const _Size __a = __loadword<_Size>(__s);
3160253146Stheraven      const _Size __b = __loadword<_Size>(__s + __len - 8);
3161232924Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3162232924Stheraven    }
3163232924Stheraven    if (__len >= 4) {
3164253146Stheraven      const uint32_t __a = __loadword<uint32_t>(__s);
3165253146Stheraven      const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3166232924Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3167232924Stheraven    }
3168232924Stheraven    if (__len > 0) {
3169232924Stheraven      const unsigned char __a = __s[0];
3170232924Stheraven      const unsigned char __b = __s[__len >> 1];
3171232924Stheraven      const unsigned char __c = __s[__len - 1];
3172232924Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3173232924Stheraven                           (static_cast<uint32_t>(__b) << 8);
3174232924Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3175232924Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3176232924Stheraven    }
3177232924Stheraven    return __k2;
3178232924Stheraven  }
3179232924Stheraven
3180232924Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3181253146Stheraven    const _Size __a = __loadword<_Size>(__s) * __k1;
3182253146Stheraven    const _Size __b = __loadword<_Size>(__s + 8);
3183253146Stheraven    const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3184253146Stheraven    const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3185232924Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3186232924Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3187232924Stheraven  }
3188232924Stheraven
3189232924Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3190232924Stheraven  // Callers do best to use "random-looking" values for a and b.
3191232924Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3192232924Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3193232924Stheraven    __a += __w;
3194232924Stheraven    __b = __rotate(__b + __a + __z, 21);
3195232924Stheraven    const _Size __c = __a;
3196232924Stheraven    __a += __x;
3197232924Stheraven    __a += __y;
3198232924Stheraven    __b += __rotate(__a, 44);
3199232924Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3200232924Stheraven  }
3201232924Stheraven
3202232924Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3203232924Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3204232924Stheraven      const char* __s, _Size __a, _Size __b) {
3205253146Stheraven    return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3206253146Stheraven                                         __loadword<_Size>(__s + 8),
3207253146Stheraven                                         __loadword<_Size>(__s + 16),
3208253146Stheraven                                         __loadword<_Size>(__s + 24),
3209232924Stheraven                                         __a,
3210232924Stheraven                                         __b);
3211232924Stheraven  }
3212232924Stheraven
3213232924Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3214232924Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3215253146Stheraven    _Size __z = __loadword<_Size>(__s + 24);
3216253146Stheraven    _Size __a = __loadword<_Size>(__s) +
3217253146Stheraven                (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3218232924Stheraven    _Size __b = __rotate(__a + __z, 52);
3219232924Stheraven    _Size __c = __rotate(__a, 37);
3220253146Stheraven    __a += __loadword<_Size>(__s + 8);
3221232924Stheraven    __c += __rotate(__a, 7);
3222253146Stheraven    __a += __loadword<_Size>(__s + 16);
3223232924Stheraven    _Size __vf = __a + __z;
3224232924Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3225253146Stheraven    __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3226253146Stheraven    __z += __loadword<_Size>(__s + __len - 8);
3227232924Stheraven    __b = __rotate(__a + __z, 52);
3228232924Stheraven    __c = __rotate(__a, 37);
3229253146Stheraven    __a += __loadword<_Size>(__s + __len - 24);
3230232924Stheraven    __c += __rotate(__a, 7);
3231253146Stheraven    __a += __loadword<_Size>(__s + __len - 16);
3232232924Stheraven    _Size __wf = __a + __z;
3233232924Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3234232924Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3235232924Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3236232924Stheraven  }
3237232924Stheraven};
3238232924Stheraven
3239232924Stheraven// cityhash64
3240232924Stheraventemplate <class _Size>
3241232924Stheraven_Size
3242232924Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3243232924Stheraven{
3244232924Stheraven  const char* __s = static_cast<const char*>(__key);
3245232924Stheraven  if (__len <= 32) {
3246232924Stheraven    if (__len <= 16) {
3247232924Stheraven      return __hash_len_0_to_16(__s, __len);
3248232924Stheraven    } else {
3249232924Stheraven      return __hash_len_17_to_32(__s, __len);
3250232924Stheraven    }
3251232924Stheraven  } else if (__len <= 64) {
3252232924Stheraven    return __hash_len_33_to_64(__s, __len);
3253232924Stheraven  }
3254232924Stheraven
3255232924Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3256232924Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3257253146Stheraven  _Size __x = __loadword<_Size>(__s + __len - 40);
3258253146Stheraven  _Size __y = __loadword<_Size>(__s + __len - 16) +
3259253146Stheraven              __loadword<_Size>(__s + __len - 56);
3260253146Stheraven  _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3261253146Stheraven                          __loadword<_Size>(__s + __len - 24));
3262232924Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3263232924Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3264253146Stheraven  __x = __x * __k1 + __loadword<_Size>(__s);
3265232924Stheraven
3266232924Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3267232924Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3268232924Stheraven  do {
3269253146Stheraven    __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3270253146Stheraven    __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3271232924Stheraven    __x ^= __w.second;
3272253146Stheraven    __y += __v.first + __loadword<_Size>(__s + 40);
3273232924Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3274232924Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3275232924Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3276253146Stheraven                                        __y + __loadword<_Size>(__s + 16));
3277232924Stheraven    std::swap(__z, __x);
3278232924Stheraven    __s += 64;
3279232924Stheraven    __len -= 64;
3280232924Stheraven  } while (__len != 0);
3281232924Stheraven  return __hash_len_16(
3282232924Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3283232924Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3284232924Stheraven}
3285232924Stheraven
3286232924Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3287232924Stheravenstruct __scalar_hash;
3288232924Stheraven
3289232924Stheraventemplate <class _Tp>
3290232924Stheravenstruct __scalar_hash<_Tp, 0>
3291232924Stheraven    : public unary_function<_Tp, size_t>
3292232924Stheraven{
3293227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3294232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3295227825Stheraven    {
3296232924Stheraven        union
3297232924Stheraven        {
3298232924Stheraven            _Tp    __t;
3299232924Stheraven            size_t __a;
3300232924Stheraven        } __u;
3301232924Stheraven        __u.__a = 0;
3302232924Stheraven        __u.__t = __v;
3303232924Stheraven        return __u.__a;
3304227825Stheraven    }
3305227825Stheraven};
3306227825Stheraven
3307232924Stheraventemplate <class _Tp>
3308232924Stheravenstruct __scalar_hash<_Tp, 1>
3309232924Stheraven    : public unary_function<_Tp, size_t>
3310232924Stheraven{
3311232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3312232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3313232924Stheraven    {
3314232924Stheraven        union
3315232924Stheraven        {
3316232924Stheraven            _Tp    __t;
3317232924Stheraven            size_t __a;
3318232924Stheraven        } __u;
3319232924Stheraven        __u.__t = __v;
3320232924Stheraven        return __u.__a;
3321232924Stheraven    }
3322232924Stheraven};
3323232924Stheraven
3324232924Stheraventemplate <class _Tp>
3325232924Stheravenstruct __scalar_hash<_Tp, 2>
3326232924Stheraven    : public unary_function<_Tp, size_t>
3327232924Stheraven{
3328232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3329232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3330232924Stheraven    {
3331232924Stheraven        union
3332232924Stheraven        {
3333232924Stheraven            _Tp __t;
3334232924Stheraven            struct
3335232924Stheraven            {
3336232924Stheraven                size_t __a;
3337232924Stheraven                size_t __b;
3338232924Stheraven            };
3339232924Stheraven        } __u;
3340232924Stheraven        __u.__t = __v;
3341232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3342232924Stheraven    }
3343232924Stheraven};
3344232924Stheraven
3345232924Stheraventemplate <class _Tp>
3346232924Stheravenstruct __scalar_hash<_Tp, 3>
3347232924Stheraven    : public unary_function<_Tp, size_t>
3348232924Stheraven{
3349232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3350232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3351232924Stheraven    {
3352232924Stheraven        union
3353232924Stheraven        {
3354232924Stheraven            _Tp __t;
3355232924Stheraven            struct
3356232924Stheraven            {
3357232924Stheraven                size_t __a;
3358232924Stheraven                size_t __b;
3359232924Stheraven                size_t __c;
3360232924Stheraven            };
3361232924Stheraven        } __u;
3362232924Stheraven        __u.__t = __v;
3363232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3364232924Stheraven    }
3365232924Stheraven};
3366232924Stheraven
3367232924Stheraventemplate <class _Tp>
3368232924Stheravenstruct __scalar_hash<_Tp, 4>
3369232924Stheraven    : public unary_function<_Tp, size_t>
3370232924Stheraven{
3371232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3372232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3373232924Stheraven    {
3374232924Stheraven        union
3375232924Stheraven        {
3376232924Stheraven            _Tp __t;
3377232924Stheraven            struct
3378232924Stheraven            {
3379232924Stheraven                size_t __a;
3380232924Stheraven                size_t __b;
3381232924Stheraven                size_t __c;
3382232924Stheraven                size_t __d;
3383232924Stheraven            };
3384232924Stheraven        } __u;
3385232924Stheraven        __u.__t = __v;
3386232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3387232924Stheraven    }
3388232924Stheraven};
3389232924Stheraven
3390232924Stheraventemplate<class _Tp>
3391261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3392241900Sdim    : public unary_function<_Tp*, size_t>
3393232924Stheraven{
3394241900Sdim    _LIBCPP_INLINE_VISIBILITY
3395241900Sdim    size_t operator()(_Tp* __v) const _NOEXCEPT
3396241900Sdim    {
3397241900Sdim        union
3398241900Sdim        {
3399241900Sdim            _Tp* __t;
3400241900Sdim            size_t __a;
3401241900Sdim        } __u;
3402241900Sdim        __u.__t = __v;
3403241900Sdim        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3404241900Sdim    }
3405232924Stheraven};
3406232924Stheraven
3407227825Stheraventemplate <class _Tp, class _Dp>
3408261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
3409227825Stheraven{
3410227825Stheraven    typedef unique_ptr<_Tp, _Dp> argument_type;
3411227825Stheraven    typedef size_t               result_type;
3412227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3413227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3414227825Stheraven    {
3415227825Stheraven        typedef typename argument_type::pointer pointer;
3416227825Stheraven        return hash<pointer>()(__ptr.get());
3417227825Stheraven    }
3418227825Stheraven};
3419227825Stheraven
3420227825Stheravenstruct __destruct_n
3421227825Stheraven{
3422227825Stheravenprivate:
3423227825Stheraven    size_t size;
3424227825Stheraven
3425227825Stheraven    template <class _Tp>
3426227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3427227825Stheraven        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3428227825Stheraven
3429227825Stheraven    template <class _Tp>
3430227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3431227825Stheraven        {}
3432227825Stheraven
3433227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3434227825Stheraven        {++size;}
3435227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3436227825Stheraven        {}
3437227825Stheraven
3438227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3439227825Stheraven        {size = __s;}
3440227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3441227825Stheraven        {}
3442227825Stheravenpublic:
3443227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3444227825Stheraven        : size(__s) {}
3445227825Stheraven
3446227825Stheraven    template <class _Tp>
3447227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3448227825Stheraven        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3449227825Stheraven
3450227825Stheraven    template <class _Tp>
3451227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3452227825Stheraven        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3453227825Stheraven
3454227825Stheraven    template <class _Tp>
3455227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3456227825Stheraven        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3457227825Stheraven};
3458227825Stheraven
3459227825Stheraventemplate <class _Alloc>
3460227825Stheravenclass __allocator_destructor
3461227825Stheraven{
3462227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
3463227825Stheravenpublic:
3464227825Stheraven    typedef typename __alloc_traits::pointer pointer;
3465227825Stheraven    typedef typename __alloc_traits::size_type size_type;
3466227825Stheravenprivate:
3467227825Stheraven    _Alloc& __alloc_;
3468227825Stheraven    size_type __s_;
3469227825Stheravenpublic:
3470227825Stheraven    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3471227825Stheraven             _NOEXCEPT
3472227825Stheraven        : __alloc_(__a), __s_(__s) {}
3473227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3474227825Stheraven    void operator()(pointer __p) _NOEXCEPT
3475227825Stheraven        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3476227825Stheraven};
3477227825Stheraven
3478227825Stheraventemplate <class _InputIterator, class _ForwardIterator>
3479227825Stheraven_ForwardIterator
3480227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3481227825Stheraven{
3482227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3483232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3484232924Stheraven    _ForwardIterator __s = __r;
3485232924Stheraven    try
3486232924Stheraven    {
3487232924Stheraven#endif
3488232924Stheraven        for (; __f != __l; ++__f, ++__r)
3489232924Stheraven            ::new(&*__r) value_type(*__f);
3490232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3491232924Stheraven    }
3492232924Stheraven    catch (...)
3493232924Stheraven    {
3494232924Stheraven        for (; __s != __r; ++__s)
3495232924Stheraven            __s->~value_type();
3496232924Stheraven        throw;
3497232924Stheraven    }
3498232924Stheraven#endif
3499227825Stheraven    return __r;
3500227825Stheraven}
3501227825Stheraven
3502227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator>
3503227825Stheraven_ForwardIterator
3504227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3505227825Stheraven{
3506227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3507232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3508232924Stheraven    _ForwardIterator __s = __r;
3509232924Stheraven    try
3510232924Stheraven    {
3511232924Stheraven#endif
3512232924Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3513232924Stheraven            ::new(&*__r) value_type(*__f);
3514232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3515232924Stheraven    }
3516232924Stheraven    catch (...)
3517232924Stheraven    {
3518232924Stheraven        for (; __s != __r; ++__s)
3519232924Stheraven            __s->~value_type();
3520232924Stheraven        throw;
3521232924Stheraven    }
3522232924Stheraven#endif
3523227825Stheraven    return __r;
3524227825Stheraven}
3525227825Stheraven
3526227825Stheraventemplate <class _ForwardIterator, class _Tp>
3527227825Stheravenvoid
3528227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3529227825Stheraven{
3530227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3531232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3532232924Stheraven    _ForwardIterator __s = __f;
3533232924Stheraven    try
3534232924Stheraven    {
3535232924Stheraven#endif
3536232924Stheraven        for (; __f != __l; ++__f)
3537232924Stheraven            ::new(&*__f) value_type(__x);
3538232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3539232924Stheraven    }
3540232924Stheraven    catch (...)
3541232924Stheraven    {
3542232924Stheraven        for (; __s != __f; ++__s)
3543232924Stheraven            __s->~value_type();
3544232924Stheraven        throw;
3545232924Stheraven    }
3546232924Stheraven#endif
3547227825Stheraven}
3548227825Stheraven
3549227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp>
3550227825Stheraven_ForwardIterator
3551227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3552227825Stheraven{
3553227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3554232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3555232924Stheraven    _ForwardIterator __s = __f;
3556232924Stheraven    try
3557232924Stheraven    {
3558232924Stheraven#endif
3559232924Stheraven        for (; __n > 0; ++__f, --__n)
3560232924Stheraven            ::new(&*__f) value_type(__x);
3561232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3562232924Stheraven    }
3563232924Stheraven    catch (...)
3564232924Stheraven    {
3565232924Stheraven        for (; __s != __f; ++__s)
3566232924Stheraven            __s->~value_type();
3567232924Stheraven        throw;
3568232924Stheraven    }
3569232924Stheraven#endif
3570227825Stheraven    return __f;
3571227825Stheraven}
3572227825Stheraven
3573227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3574227825Stheraven    : public std::exception
3575227825Stheraven{
3576227825Stheravenpublic:
3577227825Stheraven    virtual ~bad_weak_ptr() _NOEXCEPT;
3578227825Stheraven    virtual const char* what() const  _NOEXCEPT;
3579227825Stheraven};
3580227825Stheraven
3581261272Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3582227825Stheraven
3583261272Sdimclass _LIBCPP_TYPE_VIS __shared_count
3584227825Stheraven{
3585227825Stheraven    __shared_count(const __shared_count&);
3586227825Stheraven    __shared_count& operator=(const __shared_count&);
3587227825Stheraven
3588227825Stheravenprotected:
3589227825Stheraven    long __shared_owners_;
3590227825Stheraven    virtual ~__shared_count();
3591227825Stheravenprivate:
3592227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT = 0;
3593227825Stheraven
3594227825Stheravenpublic:
3595227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3596227825Stheraven    explicit __shared_count(long __refs = 0) _NOEXCEPT
3597227825Stheraven        : __shared_owners_(__refs) {}
3598227825Stheraven
3599227825Stheraven    void __add_shared() _NOEXCEPT;
3600227825Stheraven    bool __release_shared() _NOEXCEPT;
3601227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3602227825Stheraven    long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3603227825Stheraven};
3604227825Stheraven
3605261272Sdimclass _LIBCPP_TYPE_VIS __shared_weak_count
3606227825Stheraven    : private __shared_count
3607227825Stheraven{
3608227825Stheraven    long __shared_weak_owners_;
3609227825Stheraven
3610227825Stheravenpublic:
3611227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3612227825Stheraven    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3613227825Stheraven        : __shared_count(__refs),
3614227825Stheraven          __shared_weak_owners_(__refs) {}
3615227825Stheravenprotected:
3616227825Stheraven    virtual ~__shared_weak_count();
3617227825Stheraven
3618227825Stheravenpublic:
3619227825Stheraven    void __add_shared() _NOEXCEPT;
3620227825Stheraven    void __add_weak() _NOEXCEPT;
3621227825Stheraven    void __release_shared() _NOEXCEPT;
3622227825Stheraven    void __release_weak() _NOEXCEPT;
3623227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3624227825Stheraven    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3625227825Stheraven    __shared_weak_count* lock() _NOEXCEPT;
3626227825Stheraven
3627249989Sdim    // Define the function out only if we build static libc++ without RTTI.
3628249989Sdim    // Otherwise we may break clients who need to compile their projects with
3629249989Sdim    // -fno-rtti and yet link against a libc++.dylib compiled
3630249989Sdim    // without -fno-rtti.
3631249989Sdim#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3632227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3633249989Sdim#endif
3634227825Stheravenprivate:
3635227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3636227825Stheraven};
3637227825Stheraven
3638227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3639227825Stheravenclass __shared_ptr_pointer
3640227825Stheraven    : public __shared_weak_count
3641227825Stheraven{
3642227825Stheraven    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3643227825Stheravenpublic:
3644227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3645227825Stheraven    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3646227825Stheraven        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3647227825Stheraven
3648227825Stheraven#ifndef _LIBCPP_NO_RTTI
3649227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3650227825Stheraven#endif
3651227825Stheraven
3652227825Stheravenprivate:
3653227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3654227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3655227825Stheraven};
3656227825Stheraven
3657227825Stheraven#ifndef _LIBCPP_NO_RTTI
3658227825Stheraven
3659227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3660227825Stheravenconst void*
3661227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3662227825Stheraven{
3663276792Sdim    return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
3664227825Stheraven}
3665227825Stheraven
3666227825Stheraven#endif  // _LIBCPP_NO_RTTI
3667227825Stheraven
3668227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3669227825Stheravenvoid
3670227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3671227825Stheraven{
3672227825Stheraven    __data_.first().second()(__data_.first().first());
3673227825Stheraven    __data_.first().second().~_Dp();
3674227825Stheraven}
3675227825Stheraven
3676227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3677227825Stheravenvoid
3678227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3679227825Stheraven{
3680276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _A;
3681276792Sdim    typedef allocator_traits<_A> _ATraits;
3682276792Sdim    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3683276792Sdim
3684276792Sdim    _A __a(__data_.second());
3685227825Stheraven    __data_.second().~_Alloc();
3686276792Sdim    __a.deallocate(_PTraits::pointer_to(*this), 1);
3687227825Stheraven}
3688227825Stheraven
3689227825Stheraventemplate <class _Tp, class _Alloc>
3690227825Stheravenclass __shared_ptr_emplace
3691227825Stheraven    : public __shared_weak_count
3692227825Stheraven{
3693227825Stheraven    __compressed_pair<_Alloc, _Tp> __data_;
3694227825Stheravenpublic:
3695227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3696227825Stheraven
3697227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3698227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3699227825Stheraven        :  __data_(_VSTD::move(__a)) {}
3700227825Stheraven
3701227825Stheraven    template <class ..._Args>
3702227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3703227825Stheraven        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3704232924Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3705232924Stheraven                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3706227825Stheraven
3707227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3708227825Stheraven
3709227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3710227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3711227825Stheraven        :  __data_(__a) {}
3712227825Stheraven
3713227825Stheraven    template <class _A0>
3714227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3715227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3716227825Stheraven            :  __data_(__a, _Tp(__a0)) {}
3717227825Stheraven
3718227825Stheraven    template <class _A0, class _A1>
3719227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3720227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3721227825Stheraven            :  __data_(__a, _Tp(__a0, __a1)) {}
3722227825Stheraven
3723227825Stheraven    template <class _A0, class _A1, class _A2>
3724227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3725227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3726227825Stheraven            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3727227825Stheraven
3728227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3729227825Stheraven
3730227825Stheravenprivate:
3731227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3732227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3733227825Stheravenpublic:
3734227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3735227825Stheraven    _Tp* get() _NOEXCEPT {return &__data_.second();}
3736227825Stheraven};
3737227825Stheraven
3738227825Stheraventemplate <class _Tp, class _Alloc>
3739227825Stheravenvoid
3740227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3741227825Stheraven{
3742227825Stheraven    __data_.second().~_Tp();
3743227825Stheraven}
3744227825Stheraven
3745227825Stheraventemplate <class _Tp, class _Alloc>
3746227825Stheravenvoid
3747227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3748227825Stheraven{
3749276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _A;
3750276792Sdim    typedef allocator_traits<_A> _ATraits;
3751276792Sdim    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3752276792Sdim    _A __a(__data_.first());
3753227825Stheraven    __data_.first().~_Alloc();
3754276792Sdim    __a.deallocate(_PTraits::pointer_to(*this), 1);
3755227825Stheraven}
3756227825Stheraven
3757261272Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3758227825Stheraven
3759227825Stheraventemplate<class _Tp>
3760261272Sdimclass _LIBCPP_TYPE_VIS_ONLY shared_ptr
3761227825Stheraven{
3762227825Stheravenpublic:
3763227825Stheraven    typedef _Tp element_type;
3764227825Stheravenprivate:
3765227825Stheraven    element_type*      __ptr_;
3766227825Stheraven    __shared_weak_count* __cntrl_;
3767227825Stheraven
3768227825Stheraven    struct __nat {int __for_bool_;};
3769227825Stheravenpublic:
3770241900Sdim    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3771241900Sdim    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3772276792Sdim    template<class _Yp>
3773276792Sdim        explicit shared_ptr(_Yp* __p,
3774276792Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3775276792Sdim    template<class _Yp, class _Dp>
3776276792Sdim        shared_ptr(_Yp* __p, _Dp __d,
3777276792Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3778276792Sdim    template<class _Yp, class _Dp, class _Alloc>
3779276792Sdim        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3780276792Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3781227825Stheraven    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3782227825Stheraven    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3783227825Stheraven    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3784227825Stheraven    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3785227825Stheraven    template<class _Yp>
3786227825Stheraven        shared_ptr(const shared_ptr<_Yp>& __r,
3787227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3788227825Stheraven                       _NOEXCEPT;
3789227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3790227825Stheraven    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3791227825Stheraven    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3792227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3793227825Stheraven                       _NOEXCEPT;
3794227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3795227825Stheraven    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3796227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3797227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3798276792Sdim    template<class _Yp>
3799276792Sdim        shared_ptr(auto_ptr<_Yp>&& __r,
3800276792Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3801227825Stheraven#else
3802276792Sdim    template<class _Yp>
3803276792Sdim        shared_ptr(auto_ptr<_Yp> __r,
3804276792Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3805227825Stheraven#endif
3806227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3807276792Sdim    template <class _Yp, class _Dp>
3808276792Sdim        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3809276792Sdim                   typename enable_if
3810276792Sdim                   <
3811276792Sdim                       !is_lvalue_reference<_Dp>::value &&
3812276792Sdim                       !is_array<_Yp>::value &&
3813276792Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3814276792Sdim                       __nat
3815276792Sdim                   >::type = __nat());
3816276792Sdim    template <class _Yp, class _Dp>
3817276792Sdim        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3818276792Sdim                   typename enable_if
3819276792Sdim                   <
3820276792Sdim                       is_lvalue_reference<_Dp>::value &&
3821276792Sdim                       !is_array<_Yp>::value &&
3822276792Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3823276792Sdim                       __nat
3824276792Sdim                   >::type = __nat());
3825227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3826276792Sdim    template <class _Yp, class _Dp>
3827276792Sdim        shared_ptr(unique_ptr<_Yp, _Dp>,
3828276792Sdim                   typename enable_if
3829276792Sdim                   <
3830276792Sdim                       !is_lvalue_reference<_Dp>::value &&
3831276792Sdim                       !is_array<_Yp>::value &&
3832276792Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3833276792Sdim                       __nat
3834276792Sdim                   >::type = __nat());
3835276792Sdim    template <class _Yp, class _Dp>
3836276792Sdim        shared_ptr(unique_ptr<_Yp, _Dp>,
3837276792Sdim                   typename enable_if
3838276792Sdim                   <
3839276792Sdim                       is_lvalue_reference<_Dp>::value &&
3840276792Sdim                       !is_array<_Yp>::value &&
3841276792Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3842276792Sdim                       __nat
3843276792Sdim                   >::type = __nat());
3844227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3845227825Stheraven
3846227825Stheraven    ~shared_ptr();
3847227825Stheraven
3848227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3849232924Stheraven    template<class _Yp>
3850232924Stheraven        typename enable_if
3851232924Stheraven        <
3852232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3853232924Stheraven            shared_ptr&
3854232924Stheraven        >::type
3855232924Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3856227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3857227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3858232924Stheraven    template<class _Yp>
3859232924Stheraven        typename enable_if
3860232924Stheraven        <
3861232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3862232924Stheraven            shared_ptr<_Tp>&
3863232924Stheraven        >::type
3864232924Stheraven        operator=(shared_ptr<_Yp>&& __r);
3865232924Stheraven    template<class _Yp>
3866232924Stheraven        typename enable_if
3867232924Stheraven        <
3868232924Stheraven            !is_array<_Yp>::value &&
3869232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3870261272Sdim            shared_ptr
3871261272Sdim        >::type&
3872232924Stheraven        operator=(auto_ptr<_Yp>&& __r);
3873227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3874232924Stheraven    template<class _Yp>
3875232924Stheraven        typename enable_if
3876232924Stheraven        <
3877232924Stheraven            !is_array<_Yp>::value &&
3878232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3879232924Stheraven            shared_ptr&
3880232924Stheraven        >::type
3881232924Stheraven        operator=(auto_ptr<_Yp> __r);
3882227825Stheraven#endif
3883232924Stheraven    template <class _Yp, class _Dp>
3884232924Stheraven        typename enable_if
3885232924Stheraven        <
3886232924Stheraven            !is_array<_Yp>::value &&
3887232924Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3888232924Stheraven            shared_ptr&
3889232924Stheraven        >::type
3890227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3891232924Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3892227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3893232924Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3894227825Stheraven#endif
3895227825Stheraven
3896227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3897227825Stheraven    void reset() _NOEXCEPT;
3898232924Stheraven    template<class _Yp>
3899232924Stheraven        typename enable_if
3900232924Stheraven        <
3901232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3902232924Stheraven            void
3903232924Stheraven        >::type
3904232924Stheraven        reset(_Yp* __p);
3905232924Stheraven    template<class _Yp, class _Dp>
3906232924Stheraven        typename enable_if
3907232924Stheraven        <
3908232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3909232924Stheraven            void
3910232924Stheraven        >::type
3911232924Stheraven        reset(_Yp* __p, _Dp __d);
3912232924Stheraven    template<class _Yp, class _Dp, class _Alloc>
3913232924Stheraven        typename enable_if
3914232924Stheraven        <
3915232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3916232924Stheraven            void
3917232924Stheraven        >::type
3918232924Stheraven        reset(_Yp* __p, _Dp __d, _Alloc __a);
3919227825Stheraven
3920227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3921227825Stheraven    element_type* get() const _NOEXCEPT {return __ptr_;}
3922227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3923227825Stheraven    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3924227825Stheraven        {return *__ptr_;}
3925227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3926227825Stheraven    element_type* operator->() const _NOEXCEPT {return __ptr_;}
3927227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3928227825Stheraven    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3929227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3930227825Stheraven    bool unique() const _NOEXCEPT {return use_count() == 1;}
3931227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3932232924Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3933232924Stheraven    template <class _Up>
3934227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3935232924Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
3936227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3937232924Stheraven    template <class _Up>
3938227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3939232924Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
3940227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3941241900Sdim    _LIBCPP_INLINE_VISIBILITY
3942241900Sdim    bool
3943241900Sdim    __owner_equivalent(const shared_ptr& __p) const
3944241900Sdim        {return __cntrl_ == __p.__cntrl_;}
3945227825Stheraven
3946227825Stheraven#ifndef _LIBCPP_NO_RTTI
3947227825Stheraven    template <class _Dp>
3948227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3949227825Stheraven        _Dp* __get_deleter() const _NOEXCEPT
3950227825Stheraven            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3951227825Stheraven#endif  // _LIBCPP_NO_RTTI
3952227825Stheraven
3953227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3954227825Stheraven
3955227825Stheraven    template<class ..._Args>
3956227825Stheraven        static
3957227825Stheraven        shared_ptr<_Tp>
3958227825Stheraven        make_shared(_Args&& ...__args);
3959227825Stheraven
3960227825Stheraven    template<class _Alloc, class ..._Args>
3961227825Stheraven        static
3962227825Stheraven        shared_ptr<_Tp>
3963227825Stheraven        allocate_shared(const _Alloc& __a, _Args&& ...__args);
3964227825Stheraven
3965227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3966227825Stheraven
3967227825Stheraven    static shared_ptr<_Tp> make_shared();
3968227825Stheraven
3969227825Stheraven    template<class _A0>
3970227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&);
3971227825Stheraven
3972227825Stheraven    template<class _A0, class _A1>
3973227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3974227825Stheraven
3975227825Stheraven    template<class _A0, class _A1, class _A2>
3976227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3977227825Stheraven
3978227825Stheraven    template<class _Alloc>
3979227825Stheraven        static shared_ptr<_Tp>
3980227825Stheraven        allocate_shared(const _Alloc& __a);
3981227825Stheraven
3982227825Stheraven    template<class _Alloc, class _A0>
3983227825Stheraven        static shared_ptr<_Tp>
3984227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0);
3985227825Stheraven
3986227825Stheraven    template<class _Alloc, class _A0, class _A1>
3987227825Stheraven        static shared_ptr<_Tp>
3988227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3989227825Stheraven
3990227825Stheraven    template<class _Alloc, class _A0, class _A1, class _A2>
3991227825Stheraven        static shared_ptr<_Tp>
3992227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3993227825Stheraven
3994227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3995227825Stheraven
3996227825Stheravenprivate:
3997227825Stheraven
3998227825Stheraven    template <class _Yp>
3999227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4000227825Stheraven        void
4001227825Stheraven        __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4002227825Stheraven        {
4003227825Stheraven            if (__e)
4004227825Stheraven                __e->__weak_this_ = *this;
4005227825Stheraven        }
4006227825Stheraven
4007227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4008227825Stheraven    void __enable_weak_this(const void*) _NOEXCEPT {}
4009227825Stheraven
4010261272Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4011261272Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4012227825Stheraven};
4013227825Stheraven
4014227825Stheraventemplate<class _Tp>
4015227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4016241900Sdim_LIBCPP_CONSTEXPR
4017227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4018227825Stheraven    : __ptr_(0),
4019227825Stheraven      __cntrl_(0)
4020227825Stheraven{
4021227825Stheraven}
4022227825Stheraven
4023227825Stheraventemplate<class _Tp>
4024227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4025241900Sdim_LIBCPP_CONSTEXPR
4026227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4027227825Stheraven    : __ptr_(0),
4028227825Stheraven      __cntrl_(0)
4029227825Stheraven{
4030227825Stheraven}
4031227825Stheraven
4032227825Stheraventemplate<class _Tp>
4033276792Sdimtemplate<class _Yp>
4034276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p,
4035276792Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4036227825Stheraven    : __ptr_(__p)
4037227825Stheraven{
4038227825Stheraven    unique_ptr<_Yp> __hold(__p);
4039227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4040227825Stheraven    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4041227825Stheraven    __hold.release();
4042227825Stheraven    __enable_weak_this(__p);
4043227825Stheraven}
4044227825Stheraven
4045227825Stheraventemplate<class _Tp>
4046276792Sdimtemplate<class _Yp, class _Dp>
4047276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4048276792Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4049227825Stheraven    : __ptr_(__p)
4050227825Stheraven{
4051227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4052227825Stheraven    try
4053227825Stheraven    {
4054227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4055227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4056227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4057227825Stheraven        __enable_weak_this(__p);
4058227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4059227825Stheraven    }
4060227825Stheraven    catch (...)
4061227825Stheraven    {
4062227825Stheraven        __d(__p);
4063227825Stheraven        throw;
4064227825Stheraven    }
4065227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4066227825Stheraven}
4067227825Stheraven
4068227825Stheraventemplate<class _Tp>
4069227825Stheraventemplate<class _Dp>
4070227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4071227825Stheraven    : __ptr_(0)
4072227825Stheraven{
4073227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4074227825Stheraven    try
4075227825Stheraven    {
4076227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4077227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4078227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4079227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4080227825Stheraven    }
4081227825Stheraven    catch (...)
4082227825Stheraven    {
4083227825Stheraven        __d(__p);
4084227825Stheraven        throw;
4085227825Stheraven    }
4086227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4087227825Stheraven}
4088227825Stheraven
4089227825Stheraventemplate<class _Tp>
4090276792Sdimtemplate<class _Yp, class _Dp, class _Alloc>
4091276792Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4092276792Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4093227825Stheraven    : __ptr_(__p)
4094227825Stheraven{
4095227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4096227825Stheraven    try
4097227825Stheraven    {
4098227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4099227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4100276792Sdim        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4101227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4102227825Stheraven        _A2 __a2(__a);
4103227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4104276792Sdim        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4105276792Sdim            _CntrlBlk(__p, __d, __a);
4106276792Sdim        __cntrl_ = _VSTD::addressof(*__hold2.release());
4107227825Stheraven        __enable_weak_this(__p);
4108227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4109227825Stheraven    }
4110227825Stheraven    catch (...)
4111227825Stheraven    {
4112227825Stheraven        __d(__p);
4113227825Stheraven        throw;
4114227825Stheraven    }
4115227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4116227825Stheraven}
4117227825Stheraven
4118227825Stheraventemplate<class _Tp>
4119227825Stheraventemplate<class _Dp, class _Alloc>
4120227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4121227825Stheraven    : __ptr_(0)
4122227825Stheraven{
4123227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4124227825Stheraven    try
4125227825Stheraven    {
4126227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4127227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4128276792Sdim        typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4129227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4130227825Stheraven        _A2 __a2(__a);
4131227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4132276792Sdim        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4133276792Sdim            _CntrlBlk(__p, __d, __a);
4134276792Sdim        __cntrl_ = _VSTD::addressof(*__hold2.release());
4135227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4136227825Stheraven    }
4137227825Stheraven    catch (...)
4138227825Stheraven    {
4139227825Stheraven        __d(__p);
4140227825Stheraven        throw;
4141227825Stheraven    }
4142227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4143227825Stheraven}
4144227825Stheraven
4145227825Stheraventemplate<class _Tp>
4146227825Stheraventemplate<class _Yp>
4147227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4148227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4149227825Stheraven    : __ptr_(__p),
4150227825Stheraven      __cntrl_(__r.__cntrl_)
4151227825Stheraven{
4152227825Stheraven    if (__cntrl_)
4153227825Stheraven        __cntrl_->__add_shared();
4154227825Stheraven}
4155227825Stheraven
4156227825Stheraventemplate<class _Tp>
4157227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4158227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4159227825Stheraven    : __ptr_(__r.__ptr_),
4160227825Stheraven      __cntrl_(__r.__cntrl_)
4161227825Stheraven{
4162227825Stheraven    if (__cntrl_)
4163227825Stheraven        __cntrl_->__add_shared();
4164227825Stheraven}
4165227825Stheraven
4166227825Stheraventemplate<class _Tp>
4167227825Stheraventemplate<class _Yp>
4168227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4169227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4170227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4171227825Stheraven         _NOEXCEPT
4172227825Stheraven    : __ptr_(__r.__ptr_),
4173227825Stheraven      __cntrl_(__r.__cntrl_)
4174227825Stheraven{
4175227825Stheraven    if (__cntrl_)
4176227825Stheraven        __cntrl_->__add_shared();
4177227825Stheraven}
4178227825Stheraven
4179227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4180227825Stheraven
4181227825Stheraventemplate<class _Tp>
4182227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4183227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4184227825Stheraven    : __ptr_(__r.__ptr_),
4185227825Stheraven      __cntrl_(__r.__cntrl_)
4186227825Stheraven{
4187227825Stheraven    __r.__ptr_ = 0;
4188227825Stheraven    __r.__cntrl_ = 0;
4189227825Stheraven}
4190227825Stheraven
4191227825Stheraventemplate<class _Tp>
4192227825Stheraventemplate<class _Yp>
4193227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4194227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4195227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4196227825Stheraven         _NOEXCEPT
4197227825Stheraven    : __ptr_(__r.__ptr_),
4198227825Stheraven      __cntrl_(__r.__cntrl_)
4199227825Stheraven{
4200227825Stheraven    __r.__ptr_ = 0;
4201227825Stheraven    __r.__cntrl_ = 0;
4202227825Stheraven}
4203227825Stheraven
4204227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4205227825Stheraven
4206227825Stheraventemplate<class _Tp>
4207276792Sdimtemplate<class _Yp>
4208227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4209276792Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4210227825Stheraven#else
4211276792Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4212227825Stheraven#endif
4213276792Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4214227825Stheraven    : __ptr_(__r.get())
4215227825Stheraven{
4216227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4217227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4218227825Stheraven    __enable_weak_this(__r.get());
4219227825Stheraven    __r.release();
4220227825Stheraven}
4221227825Stheraven
4222227825Stheraventemplate<class _Tp>
4223276792Sdimtemplate <class _Yp, class _Dp>
4224227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4225227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4226227825Stheraven#else
4227227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4228227825Stheraven#endif
4229276792Sdim                            typename enable_if
4230276792Sdim                            <
4231276792Sdim                                !is_lvalue_reference<_Dp>::value &&
4232276792Sdim                                !is_array<_Yp>::value &&
4233276792Sdim                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4234276792Sdim                                __nat
4235276792Sdim                            >::type)
4236227825Stheraven    : __ptr_(__r.get())
4237227825Stheraven{
4238227825Stheraven    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4239227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4240227825Stheraven    __enable_weak_this(__r.get());
4241227825Stheraven    __r.release();
4242227825Stheraven}
4243227825Stheraven
4244227825Stheraventemplate<class _Tp>
4245276792Sdimtemplate <class _Yp, class _Dp>
4246227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4247227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4248227825Stheraven#else
4249227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4250227825Stheraven#endif
4251276792Sdim                            typename enable_if
4252276792Sdim                            <
4253276792Sdim                                is_lvalue_reference<_Dp>::value &&
4254276792Sdim                                !is_array<_Yp>::value &&
4255276792Sdim                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4256276792Sdim                                __nat
4257276792Sdim                            >::type)
4258227825Stheraven    : __ptr_(__r.get())
4259227825Stheraven{
4260227825Stheraven    typedef __shared_ptr_pointer<_Yp*,
4261227825Stheraven                                 reference_wrapper<typename remove_reference<_Dp>::type>,
4262227825Stheraven                                 allocator<_Yp> > _CntrlBlk;
4263227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4264227825Stheraven    __enable_weak_this(__r.get());
4265227825Stheraven    __r.release();
4266227825Stheraven}
4267227825Stheraven
4268227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4269227825Stheraven
4270227825Stheraventemplate<class _Tp>
4271227825Stheraventemplate<class ..._Args>
4272227825Stheravenshared_ptr<_Tp>
4273227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args)
4274227825Stheraven{
4275227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4276227825Stheraven    typedef allocator<_CntrlBlk> _A2;
4277227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4278227825Stheraven    _A2 __a2;
4279227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4280227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4281227825Stheraven    shared_ptr<_Tp> __r;
4282227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4283227825Stheraven    __r.__cntrl_ = __hold2.release();
4284227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4285227825Stheraven    return __r;
4286227825Stheraven}
4287227825Stheraven
4288227825Stheraventemplate<class _Tp>
4289227825Stheraventemplate<class _Alloc, class ..._Args>
4290227825Stheravenshared_ptr<_Tp>
4291227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4292227825Stheraven{
4293227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4294276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4295227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4296227825Stheraven    _A2 __a2(__a);
4297227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4298276792Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4299276792Sdim        _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4300227825Stheraven    shared_ptr<_Tp> __r;
4301227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4302276792Sdim    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4303227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4304227825Stheraven    return __r;
4305227825Stheraven}
4306227825Stheraven
4307227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4308227825Stheraven
4309227825Stheraventemplate<class _Tp>
4310227825Stheravenshared_ptr<_Tp>
4311227825Stheravenshared_ptr<_Tp>::make_shared()
4312227825Stheraven{
4313227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4314227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4315227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4316227825Stheraven    _Alloc2 __alloc2;
4317227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4318227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2);
4319227825Stheraven    shared_ptr<_Tp> __r;
4320227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4321227825Stheraven    __r.__cntrl_ = __hold2.release();
4322227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4323227825Stheraven    return __r;
4324227825Stheraven}
4325227825Stheraven
4326227825Stheraventemplate<class _Tp>
4327227825Stheraventemplate<class _A0>
4328227825Stheravenshared_ptr<_Tp>
4329227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0)
4330227825Stheraven{
4331227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4332227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4333227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4334227825Stheraven    _Alloc2 __alloc2;
4335227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4336227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4337227825Stheraven    shared_ptr<_Tp> __r;
4338227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4339227825Stheraven    __r.__cntrl_ = __hold2.release();
4340227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4341227825Stheraven    return __r;
4342227825Stheraven}
4343227825Stheraven
4344227825Stheraventemplate<class _Tp>
4345227825Stheraventemplate<class _A0, class _A1>
4346227825Stheravenshared_ptr<_Tp>
4347227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4348227825Stheraven{
4349227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4350227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4351227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4352227825Stheraven    _Alloc2 __alloc2;
4353227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4354227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4355227825Stheraven    shared_ptr<_Tp> __r;
4356227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4357227825Stheraven    __r.__cntrl_ = __hold2.release();
4358227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4359227825Stheraven    return __r;
4360227825Stheraven}
4361227825Stheraven
4362227825Stheraventemplate<class _Tp>
4363227825Stheraventemplate<class _A0, class _A1, class _A2>
4364227825Stheravenshared_ptr<_Tp>
4365227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4366227825Stheraven{
4367227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4368227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4369227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4370227825Stheraven    _Alloc2 __alloc2;
4371227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4372227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4373227825Stheraven    shared_ptr<_Tp> __r;
4374227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4375227825Stheraven    __r.__cntrl_ = __hold2.release();
4376227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4377227825Stheraven    return __r;
4378227825Stheraven}
4379227825Stheraven
4380227825Stheraventemplate<class _Tp>
4381227825Stheraventemplate<class _Alloc>
4382227825Stheravenshared_ptr<_Tp>
4383227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4384227825Stheraven{
4385227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4386276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4387227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4388227825Stheraven    _Alloc2 __alloc2(__a);
4389227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4390276792Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4391276792Sdim        _CntrlBlk(__a);
4392227825Stheraven    shared_ptr<_Tp> __r;
4393227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4394276792Sdim    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4395227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4396227825Stheraven    return __r;
4397227825Stheraven}
4398227825Stheraven
4399227825Stheraventemplate<class _Tp>
4400227825Stheraventemplate<class _Alloc, class _A0>
4401227825Stheravenshared_ptr<_Tp>
4402227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4403227825Stheraven{
4404227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4405276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4406227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4407227825Stheraven    _Alloc2 __alloc2(__a);
4408227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4409276792Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4410276792Sdim        _CntrlBlk(__a, __a0);
4411227825Stheraven    shared_ptr<_Tp> __r;
4412227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4413276792Sdim    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4414227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4415227825Stheraven    return __r;
4416227825Stheraven}
4417227825Stheraven
4418227825Stheraventemplate<class _Tp>
4419227825Stheraventemplate<class _Alloc, class _A0, class _A1>
4420227825Stheravenshared_ptr<_Tp>
4421227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4422227825Stheraven{
4423227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4424276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4425227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4426227825Stheraven    _Alloc2 __alloc2(__a);
4427227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4428276792Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4429276792Sdim        _CntrlBlk(__a, __a0, __a1);
4430227825Stheraven    shared_ptr<_Tp> __r;
4431227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4432276792Sdim    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4433227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4434227825Stheraven    return __r;
4435227825Stheraven}
4436227825Stheraven
4437227825Stheraventemplate<class _Tp>
4438227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2>
4439227825Stheravenshared_ptr<_Tp>
4440227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4441227825Stheraven{
4442227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4443276792Sdim    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4444227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4445227825Stheraven    _Alloc2 __alloc2(__a);
4446227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4447276792Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4448276792Sdim        _CntrlBlk(__a, __a0, __a1, __a2);
4449227825Stheraven    shared_ptr<_Tp> __r;
4450227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4451276792Sdim    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4452227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4453227825Stheraven    return __r;
4454227825Stheraven}
4455227825Stheraven
4456227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4457227825Stheraven
4458227825Stheraventemplate<class _Tp>
4459227825Stheravenshared_ptr<_Tp>::~shared_ptr()
4460227825Stheraven{
4461227825Stheraven    if (__cntrl_)
4462227825Stheraven        __cntrl_->__release_shared();
4463227825Stheraven}
4464227825Stheraven
4465227825Stheraventemplate<class _Tp>
4466227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4467227825Stheravenshared_ptr<_Tp>&
4468227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4469227825Stheraven{
4470227825Stheraven    shared_ptr(__r).swap(*this);
4471227825Stheraven    return *this;
4472227825Stheraven}
4473227825Stheraven
4474227825Stheraventemplate<class _Tp>
4475227825Stheraventemplate<class _Yp>
4476227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4477232924Stheraventypename enable_if
4478232924Stheraven<
4479232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4480232924Stheraven    shared_ptr<_Tp>&
4481232924Stheraven>::type
4482227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4483227825Stheraven{
4484227825Stheraven    shared_ptr(__r).swap(*this);
4485227825Stheraven    return *this;
4486227825Stheraven}
4487227825Stheraven
4488227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4489227825Stheraven
4490227825Stheraventemplate<class _Tp>
4491227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4492227825Stheravenshared_ptr<_Tp>&
4493227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4494227825Stheraven{
4495227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4496227825Stheraven    return *this;
4497227825Stheraven}
4498227825Stheraven
4499227825Stheraventemplate<class _Tp>
4500227825Stheraventemplate<class _Yp>
4501227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4502232924Stheraventypename enable_if
4503232924Stheraven<
4504232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4505232924Stheraven    shared_ptr<_Tp>&
4506232924Stheraven>::type
4507227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4508227825Stheraven{
4509227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4510227825Stheraven    return *this;
4511227825Stheraven}
4512227825Stheraven
4513227825Stheraventemplate<class _Tp>
4514227825Stheraventemplate<class _Yp>
4515227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4516232924Stheraventypename enable_if
4517232924Stheraven<
4518232924Stheraven    !is_array<_Yp>::value &&
4519232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4520261272Sdim    shared_ptr<_Tp>
4521261272Sdim>::type&
4522227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4523227825Stheraven{
4524227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4525227825Stheraven    return *this;
4526227825Stheraven}
4527227825Stheraven
4528227825Stheraventemplate<class _Tp>
4529227825Stheraventemplate <class _Yp, class _Dp>
4530227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4531232924Stheraventypename enable_if
4532232924Stheraven<
4533232924Stheraven    !is_array<_Yp>::value &&
4534232924Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4535232924Stheraven    shared_ptr<_Tp>&
4536232924Stheraven>::type
4537227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4538227825Stheraven{
4539227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4540227825Stheraven    return *this;
4541227825Stheraven}
4542227825Stheraven
4543227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4544227825Stheraven
4545227825Stheraventemplate<class _Tp>
4546227825Stheraventemplate<class _Yp>
4547227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4548232924Stheraventypename enable_if
4549232924Stheraven<
4550232924Stheraven    !is_array<_Yp>::value &&
4551232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4552232924Stheraven    shared_ptr<_Tp>&
4553232924Stheraven>::type
4554227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4555227825Stheraven{
4556227825Stheraven    shared_ptr(__r).swap(*this);
4557227825Stheraven    return *this;
4558227825Stheraven}
4559227825Stheraven
4560227825Stheraventemplate<class _Tp>
4561227825Stheraventemplate <class _Yp, class _Dp>
4562227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4563232924Stheraventypename enable_if
4564232924Stheraven<
4565232924Stheraven    !is_array<_Yp>::value &&
4566232924Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4567232924Stheraven    shared_ptr<_Tp>&
4568232924Stheraven>::type
4569227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4570227825Stheraven{
4571227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4572227825Stheraven    return *this;
4573227825Stheraven}
4574227825Stheraven
4575227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4576227825Stheraven
4577227825Stheraventemplate<class _Tp>
4578227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4579227825Stheravenvoid
4580227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4581227825Stheraven{
4582227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
4583227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
4584227825Stheraven}
4585227825Stheraven
4586227825Stheraventemplate<class _Tp>
4587227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4588227825Stheravenvoid
4589227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT
4590227825Stheraven{
4591227825Stheraven    shared_ptr().swap(*this);
4592227825Stheraven}
4593227825Stheraven
4594227825Stheraventemplate<class _Tp>
4595227825Stheraventemplate<class _Yp>
4596227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4597232924Stheraventypename enable_if
4598232924Stheraven<
4599232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4600232924Stheraven    void
4601232924Stheraven>::type
4602227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p)
4603227825Stheraven{
4604227825Stheraven    shared_ptr(__p).swap(*this);
4605227825Stheraven}
4606227825Stheraven
4607227825Stheraventemplate<class _Tp>
4608227825Stheraventemplate<class _Yp, class _Dp>
4609227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4610232924Stheraventypename enable_if
4611232924Stheraven<
4612232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4613232924Stheraven    void
4614232924Stheraven>::type
4615227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4616227825Stheraven{
4617227825Stheraven    shared_ptr(__p, __d).swap(*this);
4618227825Stheraven}
4619227825Stheraven
4620227825Stheraventemplate<class _Tp>
4621227825Stheraventemplate<class _Yp, class _Dp, class _Alloc>
4622227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4623232924Stheraventypename enable_if
4624232924Stheraven<
4625232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4626232924Stheraven    void
4627232924Stheraven>::type
4628227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4629227825Stheraven{
4630227825Stheraven    shared_ptr(__p, __d, __a).swap(*this);
4631227825Stheraven}
4632227825Stheraven
4633227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4634227825Stheraven
4635227825Stheraventemplate<class _Tp, class ..._Args>
4636227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4637232924Stheraventypename enable_if
4638232924Stheraven<
4639232924Stheraven    !is_array<_Tp>::value,
4640232924Stheraven    shared_ptr<_Tp>
4641232924Stheraven>::type
4642227825Stheravenmake_shared(_Args&& ...__args)
4643227825Stheraven{
4644227825Stheraven    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4645227825Stheraven}
4646227825Stheraven
4647227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args>
4648227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4649232924Stheraventypename enable_if
4650232924Stheraven<
4651232924Stheraven    !is_array<_Tp>::value,
4652232924Stheraven    shared_ptr<_Tp>
4653232924Stheraven>::type
4654227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args)
4655227825Stheraven{
4656227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4657227825Stheraven}
4658227825Stheraven
4659227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4660227825Stheraven
4661227825Stheraventemplate<class _Tp>
4662227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4663227825Stheravenshared_ptr<_Tp>
4664227825Stheravenmake_shared()
4665227825Stheraven{
4666227825Stheraven    return shared_ptr<_Tp>::make_shared();
4667227825Stheraven}
4668227825Stheraven
4669227825Stheraventemplate<class _Tp, class _A0>
4670227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4671227825Stheravenshared_ptr<_Tp>
4672227825Stheravenmake_shared(_A0& __a0)
4673227825Stheraven{
4674227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0);
4675227825Stheraven}
4676227825Stheraven
4677227825Stheraventemplate<class _Tp, class _A0, class _A1>
4678227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4679227825Stheravenshared_ptr<_Tp>
4680227825Stheravenmake_shared(_A0& __a0, _A1& __a1)
4681227825Stheraven{
4682227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4683227825Stheraven}
4684227825Stheraven
4685227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2>
4686227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4687227825Stheravenshared_ptr<_Tp>
4688227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4689227825Stheraven{
4690227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4691227825Stheraven}
4692227825Stheraven
4693227825Stheraventemplate<class _Tp, class _Alloc>
4694227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4695227825Stheravenshared_ptr<_Tp>
4696227825Stheravenallocate_shared(const _Alloc& __a)
4697227825Stheraven{
4698227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a);
4699227825Stheraven}
4700227825Stheraven
4701227825Stheraventemplate<class _Tp, class _Alloc, class _A0>
4702227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4703227825Stheravenshared_ptr<_Tp>
4704227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0)
4705227825Stheraven{
4706227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4707227825Stheraven}
4708227825Stheraven
4709227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1>
4710227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4711227825Stheravenshared_ptr<_Tp>
4712227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4713227825Stheraven{
4714227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4715227825Stheraven}
4716227825Stheraven
4717227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4718227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4719227825Stheravenshared_ptr<_Tp>
4720227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4721227825Stheraven{
4722227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4723227825Stheraven}
4724227825Stheraven
4725227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4726227825Stheraven
4727227825Stheraventemplate<class _Tp, class _Up>
4728227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4729227825Stheravenbool
4730227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4731227825Stheraven{
4732227825Stheraven    return __x.get() == __y.get();
4733227825Stheraven}
4734227825Stheraven
4735227825Stheraventemplate<class _Tp, class _Up>
4736227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4737227825Stheravenbool
4738227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4739227825Stheraven{
4740227825Stheraven    return !(__x == __y);
4741227825Stheraven}
4742227825Stheraven
4743227825Stheraventemplate<class _Tp, class _Up>
4744227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4745227825Stheravenbool
4746227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4747227825Stheraven{
4748232924Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4749232924Stheraven    return less<_V>()(__x.get(), __y.get());
4750227825Stheraven}
4751227825Stheraven
4752232924Stheraventemplate<class _Tp, class _Up>
4753232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4754232924Stheravenbool
4755232924Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4756232924Stheraven{
4757232924Stheraven    return __y < __x;
4758232924Stheraven}
4759232924Stheraven
4760232924Stheraventemplate<class _Tp, class _Up>
4761232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4762232924Stheravenbool
4763232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4764232924Stheraven{
4765232924Stheraven    return !(__y < __x);
4766232924Stheraven}
4767232924Stheraven
4768232924Stheraventemplate<class _Tp, class _Up>
4769232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4770232924Stheravenbool
4771232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4772232924Stheraven{
4773232924Stheraven    return !(__x < __y);
4774232924Stheraven}
4775232924Stheraven
4776227825Stheraventemplate<class _Tp>
4777227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4778232924Stheravenbool
4779232924Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4780232924Stheraven{
4781232924Stheraven    return !__x;
4782232924Stheraven}
4783232924Stheraven
4784232924Stheraventemplate<class _Tp>
4785232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4786232924Stheravenbool
4787232924Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4788232924Stheraven{
4789232924Stheraven    return !__x;
4790232924Stheraven}
4791232924Stheraven
4792232924Stheraventemplate<class _Tp>
4793232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4794232924Stheravenbool
4795232924Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4796232924Stheraven{
4797232924Stheraven    return static_cast<bool>(__x);
4798232924Stheraven}
4799232924Stheraven
4800232924Stheraventemplate<class _Tp>
4801232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4802232924Stheravenbool
4803232924Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4804232924Stheraven{
4805232924Stheraven    return static_cast<bool>(__x);
4806232924Stheraven}
4807232924Stheraven
4808232924Stheraventemplate<class _Tp>
4809232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4810232924Stheravenbool
4811232924Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4812232924Stheraven{
4813232924Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4814232924Stheraven}
4815232924Stheraven
4816232924Stheraventemplate<class _Tp>
4817232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4818232924Stheravenbool
4819232924Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4820232924Stheraven{
4821232924Stheraven    return less<_Tp*>()(nullptr, __x.get());
4822232924Stheraven}
4823232924Stheraven
4824232924Stheraventemplate<class _Tp>
4825232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4826232924Stheravenbool
4827232924Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4828232924Stheraven{
4829232924Stheraven    return nullptr < __x;
4830232924Stheraven}
4831232924Stheraven
4832232924Stheraventemplate<class _Tp>
4833232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4834232924Stheravenbool
4835232924Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4836232924Stheraven{
4837232924Stheraven    return __x < nullptr;
4838232924Stheraven}
4839232924Stheraven
4840232924Stheraventemplate<class _Tp>
4841232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4842232924Stheravenbool
4843232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4844232924Stheraven{
4845232924Stheraven    return !(nullptr < __x);
4846232924Stheraven}
4847232924Stheraven
4848232924Stheraventemplate<class _Tp>
4849232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4850232924Stheravenbool
4851232924Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4852232924Stheraven{
4853232924Stheraven    return !(__x < nullptr);
4854232924Stheraven}
4855232924Stheraven
4856232924Stheraventemplate<class _Tp>
4857232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4858232924Stheravenbool
4859232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4860232924Stheraven{
4861232924Stheraven    return !(__x < nullptr);
4862232924Stheraven}
4863232924Stheraven
4864232924Stheraventemplate<class _Tp>
4865232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4866232924Stheravenbool
4867232924Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4868232924Stheraven{
4869232924Stheraven    return !(nullptr < __x);
4870232924Stheraven}
4871232924Stheraven
4872232924Stheraventemplate<class _Tp>
4873232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4874227825Stheravenvoid
4875227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4876227825Stheraven{
4877227825Stheraven    __x.swap(__y);
4878227825Stheraven}
4879227825Stheraven
4880227825Stheraventemplate<class _Tp, class _Up>
4881227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4882232924Stheraventypename enable_if
4883232924Stheraven<
4884232924Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4885232924Stheraven    shared_ptr<_Tp>
4886232924Stheraven>::type
4887227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4888227825Stheraven{
4889227825Stheraven    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4890227825Stheraven}
4891227825Stheraven
4892227825Stheraventemplate<class _Tp, class _Up>
4893227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4894232924Stheraventypename enable_if
4895232924Stheraven<
4896232924Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4897232924Stheraven    shared_ptr<_Tp>
4898232924Stheraven>::type
4899227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4900227825Stheraven{
4901227825Stheraven    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4902227825Stheraven    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4903227825Stheraven}
4904227825Stheraven
4905227825Stheraventemplate<class _Tp, class _Up>
4906232924Stheraventypename enable_if
4907232924Stheraven<
4908232924Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4909232924Stheraven    shared_ptr<_Tp>
4910232924Stheraven>::type
4911227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4912227825Stheraven{
4913232924Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4914232924Stheraven    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4915227825Stheraven}
4916227825Stheraven
4917227825Stheraven#ifndef _LIBCPP_NO_RTTI
4918227825Stheraven
4919227825Stheraventemplate<class _Dp, class _Tp>
4920227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4921227825Stheraven_Dp*
4922227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4923227825Stheraven{
4924227825Stheraven    return __p.template __get_deleter<_Dp>();
4925227825Stheraven}
4926227825Stheraven
4927227825Stheraven#endif  // _LIBCPP_NO_RTTI
4928227825Stheraven
4929227825Stheraventemplate<class _Tp>
4930261272Sdimclass _LIBCPP_TYPE_VIS_ONLY weak_ptr
4931227825Stheraven{
4932227825Stheravenpublic:
4933227825Stheraven    typedef _Tp element_type;
4934227825Stheravenprivate:
4935227825Stheraven    element_type*        __ptr_;
4936227825Stheraven    __shared_weak_count* __cntrl_;
4937227825Stheraven
4938227825Stheravenpublic:
4939241900Sdim    _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4940227825Stheraven    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4941227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4942227825Stheraven                        _NOEXCEPT;
4943227825Stheraven    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4944227825Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4945227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4946227825Stheraven                         _NOEXCEPT;
4947227825Stheraven
4948232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4949232924Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4950232924Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4951232924Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4952232924Stheraven                         _NOEXCEPT;
4953232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4954227825Stheraven    ~weak_ptr();
4955227825Stheraven
4956227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4957232924Stheraven    template<class _Yp>
4958232924Stheraven        typename enable_if
4959232924Stheraven        <
4960232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4961232924Stheraven            weak_ptr&
4962232924Stheraven        >::type
4963232924Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4964227825Stheraven
4965232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4966232924Stheraven
4967232924Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4968232924Stheraven    template<class _Yp>
4969232924Stheraven        typename enable_if
4970232924Stheraven        <
4971232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4972232924Stheraven            weak_ptr&
4973232924Stheraven        >::type
4974232924Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4975232924Stheraven
4976232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4977232924Stheraven
4978232924Stheraven    template<class _Yp>
4979232924Stheraven        typename enable_if
4980232924Stheraven        <
4981232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4982232924Stheraven            weak_ptr&
4983232924Stheraven        >::type
4984232924Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4985232924Stheraven
4986227825Stheraven    void swap(weak_ptr& __r) _NOEXCEPT;
4987227825Stheraven    void reset() _NOEXCEPT;
4988227825Stheraven
4989227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4990227825Stheraven    long use_count() const _NOEXCEPT
4991227825Stheraven        {return __cntrl_ ? __cntrl_->use_count() : 0;}
4992227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4993227825Stheraven    bool expired() const _NOEXCEPT
4994227825Stheraven        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4995227825Stheraven    shared_ptr<_Tp> lock() const _NOEXCEPT;
4996227825Stheraven    template<class _Up>
4997227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4998227825Stheraven        bool owner_before(const shared_ptr<_Up>& __r) const
4999227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
5000227825Stheraven    template<class _Up>
5001227825Stheraven        _LIBCPP_INLINE_VISIBILITY
5002227825Stheraven        bool owner_before(const weak_ptr<_Up>& __r) const
5003227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
5004227825Stheraven
5005261272Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5006261272Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
5007227825Stheraven};
5008227825Stheraven
5009227825Stheraventemplate<class _Tp>
5010227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5011241900Sdim_LIBCPP_CONSTEXPR
5012227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5013227825Stheraven    : __ptr_(0),
5014227825Stheraven      __cntrl_(0)
5015227825Stheraven{
5016227825Stheraven}
5017227825Stheraven
5018227825Stheraventemplate<class _Tp>
5019227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5020227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5021227825Stheraven    : __ptr_(__r.__ptr_),
5022227825Stheraven      __cntrl_(__r.__cntrl_)
5023227825Stheraven{
5024227825Stheraven    if (__cntrl_)
5025227825Stheraven        __cntrl_->__add_weak();
5026227825Stheraven}
5027227825Stheraven
5028227825Stheraventemplate<class _Tp>
5029227825Stheraventemplate<class _Yp>
5030227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5031227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5032227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5033227825Stheraven                         _NOEXCEPT
5034227825Stheraven    : __ptr_(__r.__ptr_),
5035227825Stheraven      __cntrl_(__r.__cntrl_)
5036227825Stheraven{
5037227825Stheraven    if (__cntrl_)
5038227825Stheraven        __cntrl_->__add_weak();
5039227825Stheraven}
5040227825Stheraven
5041227825Stheraventemplate<class _Tp>
5042227825Stheraventemplate<class _Yp>
5043227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5044227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5045227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5046227825Stheraven         _NOEXCEPT
5047227825Stheraven    : __ptr_(__r.__ptr_),
5048227825Stheraven      __cntrl_(__r.__cntrl_)
5049227825Stheraven{
5050227825Stheraven    if (__cntrl_)
5051227825Stheraven        __cntrl_->__add_weak();
5052227825Stheraven}
5053227825Stheraven
5054232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5055232924Stheraven
5056227825Stheraventemplate<class _Tp>
5057232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5058232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5059232924Stheraven    : __ptr_(__r.__ptr_),
5060232924Stheraven      __cntrl_(__r.__cntrl_)
5061232924Stheraven{
5062232924Stheraven    __r.__ptr_ = 0;
5063232924Stheraven    __r.__cntrl_ = 0;
5064232924Stheraven}
5065232924Stheraven
5066232924Stheraventemplate<class _Tp>
5067232924Stheraventemplate<class _Yp>
5068232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5069232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5070232924Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5071232924Stheraven         _NOEXCEPT
5072232924Stheraven    : __ptr_(__r.__ptr_),
5073232924Stheraven      __cntrl_(__r.__cntrl_)
5074232924Stheraven{
5075232924Stheraven    __r.__ptr_ = 0;
5076232924Stheraven    __r.__cntrl_ = 0;
5077232924Stheraven}
5078232924Stheraven
5079232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5080232924Stheraven
5081232924Stheraventemplate<class _Tp>
5082227825Stheravenweak_ptr<_Tp>::~weak_ptr()
5083227825Stheraven{
5084227825Stheraven    if (__cntrl_)
5085227825Stheraven        __cntrl_->__release_weak();
5086227825Stheraven}
5087227825Stheraven
5088227825Stheraventemplate<class _Tp>
5089227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5090227825Stheravenweak_ptr<_Tp>&
5091227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5092227825Stheraven{
5093227825Stheraven    weak_ptr(__r).swap(*this);
5094227825Stheraven    return *this;
5095227825Stheraven}
5096227825Stheraven
5097227825Stheraventemplate<class _Tp>
5098227825Stheraventemplate<class _Yp>
5099227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5100232924Stheraventypename enable_if
5101232924Stheraven<
5102232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5103232924Stheraven    weak_ptr<_Tp>&
5104232924Stheraven>::type
5105227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5106227825Stheraven{
5107227825Stheraven    weak_ptr(__r).swap(*this);
5108227825Stheraven    return *this;
5109227825Stheraven}
5110227825Stheraven
5111232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5112232924Stheraven
5113227825Stheraventemplate<class _Tp>
5114232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5115232924Stheravenweak_ptr<_Tp>&
5116232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5117232924Stheraven{
5118232924Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5119232924Stheraven    return *this;
5120232924Stheraven}
5121232924Stheraven
5122232924Stheraventemplate<class _Tp>
5123227825Stheraventemplate<class _Yp>
5124227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5125232924Stheraventypename enable_if
5126232924Stheraven<
5127232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5128232924Stheraven    weak_ptr<_Tp>&
5129232924Stheraven>::type
5130232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5131232924Stheraven{
5132232924Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5133232924Stheraven    return *this;
5134232924Stheraven}
5135232924Stheraven
5136232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5137232924Stheraven
5138232924Stheraventemplate<class _Tp>
5139232924Stheraventemplate<class _Yp>
5140232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5141232924Stheraventypename enable_if
5142232924Stheraven<
5143232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5144232924Stheraven    weak_ptr<_Tp>&
5145232924Stheraven>::type
5146227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5147227825Stheraven{
5148227825Stheraven    weak_ptr(__r).swap(*this);
5149227825Stheraven    return *this;
5150227825Stheraven}
5151227825Stheraven
5152227825Stheraventemplate<class _Tp>
5153227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5154227825Stheravenvoid
5155227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5156227825Stheraven{
5157227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
5158227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
5159227825Stheraven}
5160227825Stheraven
5161227825Stheraventemplate<class _Tp>
5162227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5163227825Stheravenvoid
5164227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5165227825Stheraven{
5166227825Stheraven    __x.swap(__y);
5167227825Stheraven}
5168227825Stheraven
5169227825Stheraventemplate<class _Tp>
5170227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5171227825Stheravenvoid
5172227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT
5173227825Stheraven{
5174227825Stheraven    weak_ptr().swap(*this);
5175227825Stheraven}
5176227825Stheraven
5177227825Stheraventemplate<class _Tp>
5178227825Stheraventemplate<class _Yp>
5179227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5180227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5181227825Stheraven    : __ptr_(__r.__ptr_),
5182227825Stheraven      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5183227825Stheraven{
5184227825Stheraven    if (__cntrl_ == 0)
5185227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
5186227825Stheraven        throw bad_weak_ptr();
5187227825Stheraven#else
5188227825Stheraven        assert(!"bad_weak_ptr");
5189227825Stheraven#endif
5190227825Stheraven}
5191227825Stheraven
5192227825Stheraventemplate<class _Tp>
5193227825Stheravenshared_ptr<_Tp>
5194227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT
5195227825Stheraven{
5196227825Stheraven    shared_ptr<_Tp> __r;
5197227825Stheraven    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5198227825Stheraven    if (__r.__cntrl_)
5199227825Stheraven        __r.__ptr_ = __ptr_;
5200227825Stheraven    return __r;
5201227825Stheraven}
5202227825Stheraven
5203227825Stheraventemplate <class _Tp> struct owner_less;
5204227825Stheraven
5205227825Stheraventemplate <class _Tp>
5206261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
5207227825Stheraven    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5208227825Stheraven{
5209227825Stheraven    typedef bool result_type;
5210227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5211227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5212227825Stheraven        {return __x.owner_before(__y);}
5213227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5214227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5215227825Stheraven        {return __x.owner_before(__y);}
5216227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5217227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5218227825Stheraven        {return __x.owner_before(__y);}
5219227825Stheraven};
5220227825Stheraven
5221227825Stheraventemplate <class _Tp>
5222261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
5223227825Stheraven    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5224227825Stheraven{
5225227825Stheraven    typedef bool result_type;
5226227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5227227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5228227825Stheraven        {return __x.owner_before(__y);}
5229227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5230227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5231227825Stheraven        {return __x.owner_before(__y);}
5232227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5233227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5234227825Stheraven        {return __x.owner_before(__y);}
5235227825Stheraven};
5236227825Stheraven
5237227825Stheraventemplate<class _Tp>
5238261272Sdimclass _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5239227825Stheraven{
5240227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5241227825Stheravenprotected:
5242241900Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5243227825Stheraven    enable_shared_from_this() _NOEXCEPT {}
5244227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5245227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5246227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5247227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5248227825Stheraven        {return *this;}
5249227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5250227825Stheraven    ~enable_shared_from_this() {}
5251227825Stheravenpublic:
5252227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5253227825Stheraven    shared_ptr<_Tp> shared_from_this()
5254227825Stheraven        {return shared_ptr<_Tp>(__weak_this_);}
5255227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5256227825Stheraven    shared_ptr<_Tp const> shared_from_this() const
5257227825Stheraven        {return shared_ptr<const _Tp>(__weak_this_);}
5258227825Stheraven
5259227825Stheraven    template <class _Up> friend class shared_ptr;
5260227825Stheraven};
5261227825Stheraven
5262227825Stheraventemplate <class _Tp>
5263261272Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
5264227825Stheraven{
5265227825Stheraven    typedef shared_ptr<_Tp>      argument_type;
5266227825Stheraven    typedef size_t               result_type;
5267227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5268227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5269227825Stheraven    {
5270227825Stheraven        return hash<_Tp*>()(__ptr.get());
5271227825Stheraven    }
5272227825Stheraven};
5273227825Stheraven
5274232924Stheraventemplate<class _CharT, class _Traits, class _Yp>
5275227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5276227825Stheravenbasic_ostream<_CharT, _Traits>&
5277232924Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5278227825Stheraven
5279276792Sdim#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
5280241900Sdim
5281261272Sdimclass _LIBCPP_TYPE_VIS __sp_mut
5282241900Sdim{
5283242939Stheraven    void* __lx;
5284241900Sdimpublic:
5285241900Sdim    void lock() _NOEXCEPT;
5286241900Sdim    void unlock() _NOEXCEPT;
5287241900Sdim
5288241900Sdimprivate:
5289241900Sdim    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5290241900Sdim    __sp_mut(const __sp_mut&);
5291241900Sdim    __sp_mut& operator=(const __sp_mut&);
5292241900Sdim
5293249989Sdim    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5294241900Sdim};
5295241900Sdim
5296249989Sdim_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5297241900Sdim
5298241900Sdimtemplate <class _Tp>
5299241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5300241900Sdimbool
5301241900Sdimatomic_is_lock_free(const shared_ptr<_Tp>*)
5302241900Sdim{
5303241900Sdim    return false;
5304241900Sdim}
5305241900Sdim
5306241900Sdimtemplate <class _Tp>
5307241900Sdimshared_ptr<_Tp>
5308241900Sdimatomic_load(const shared_ptr<_Tp>* __p)
5309241900Sdim{
5310241900Sdim    __sp_mut& __m = __get_sp_mut(__p);
5311241900Sdim    __m.lock();
5312241900Sdim    shared_ptr<_Tp> __q = *__p;
5313241900Sdim    __m.unlock();
5314241900Sdim    return __q;
5315241900Sdim}
5316241900Sdim  
5317241900Sdimtemplate <class _Tp>
5318241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5319241900Sdimshared_ptr<_Tp>
5320241900Sdimatomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5321241900Sdim{
5322241900Sdim    return atomic_load(__p);
5323241900Sdim}
5324241900Sdim
5325241900Sdimtemplate <class _Tp>
5326241900Sdimvoid
5327241900Sdimatomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5328241900Sdim{
5329241900Sdim    __sp_mut& __m = __get_sp_mut(__p);
5330241900Sdim    __m.lock();
5331241900Sdim    __p->swap(__r);
5332241900Sdim    __m.unlock();
5333241900Sdim}
5334241900Sdim
5335241900Sdimtemplate <class _Tp>
5336241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5337241900Sdimvoid
5338241900Sdimatomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5339241900Sdim{
5340241900Sdim    atomic_store(__p, __r);
5341241900Sdim}
5342241900Sdim
5343241900Sdimtemplate <class _Tp>
5344241900Sdimshared_ptr<_Tp>
5345241900Sdimatomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5346241900Sdim{
5347241900Sdim    __sp_mut& __m = __get_sp_mut(__p);
5348241900Sdim    __m.lock();
5349241900Sdim    __p->swap(__r);
5350241900Sdim    __m.unlock();
5351241900Sdim    return __r;
5352241900Sdim}
5353241900Sdim  
5354241900Sdimtemplate <class _Tp>
5355241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5356241900Sdimshared_ptr<_Tp>
5357241900Sdimatomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5358241900Sdim{
5359241900Sdim    return atomic_exchange(__p, __r);
5360241900Sdim}
5361241900Sdim
5362241900Sdimtemplate <class _Tp>
5363241900Sdimbool
5364241900Sdimatomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5365241900Sdim{
5366241900Sdim    __sp_mut& __m = __get_sp_mut(__p);
5367241900Sdim    __m.lock();
5368241900Sdim    if (__p->__owner_equivalent(*__v))
5369241900Sdim    {
5370241900Sdim        *__p = __w;
5371241900Sdim        __m.unlock();
5372241900Sdim        return true;
5373241900Sdim    }
5374241900Sdim    *__v = *__p;
5375241900Sdim    __m.unlock();
5376241900Sdim    return false;
5377241900Sdim}
5378241900Sdim
5379241900Sdimtemplate <class _Tp>
5380241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5381241900Sdimbool
5382241900Sdimatomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5383241900Sdim{
5384241900Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5385241900Sdim}
5386241900Sdim
5387241900Sdimtemplate <class _Tp>
5388241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5389241900Sdimbool
5390241900Sdimatomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5391241900Sdim                                        shared_ptr<_Tp> __w, memory_order, memory_order)
5392241900Sdim{
5393241900Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5394241900Sdim}
5395241900Sdim
5396241900Sdimtemplate <class _Tp>
5397241900Sdiminline _LIBCPP_INLINE_VISIBILITY
5398241900Sdimbool
5399241900Sdimatomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5400241900Sdim                                      shared_ptr<_Tp> __w, memory_order, memory_order)
5401241900Sdim{
5402241900Sdim    return atomic_compare_exchange_weak(__p, __v, __w);
5403241900Sdim}
5404241900Sdim
5405276792Sdim#endif  // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
5406241900Sdim
5407227825Stheraven//enum class
5408249989Sdimstruct _LIBCPP_TYPE_VIS pointer_safety
5409227825Stheraven{
5410242939Stheraven    enum __lx
5411227825Stheraven    {
5412227825Stheraven        relaxed,
5413227825Stheraven        preferred,
5414227825Stheraven        strict
5415227825Stheraven    };
5416227825Stheraven
5417242939Stheraven    __lx __v_;
5418227825Stheraven
5419227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5420242939Stheraven    pointer_safety(__lx __v) : __v_(__v) {}
5421227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5422227825Stheraven    operator int() const {return __v_;}
5423227825Stheraven};
5424227825Stheraven
5425261272Sdim_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5426261272Sdim_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5427261272Sdim_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5428261272Sdim_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5429261272Sdim_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5430227825Stheraven
5431227825Stheraventemplate <class _Tp>
5432227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5433227825Stheraven_Tp*
5434227825Stheravenundeclare_reachable(_Tp* __p)
5435227825Stheraven{
5436227825Stheraven    return static_cast<_Tp*>(__undeclare_reachable(__p));
5437227825Stheraven}
5438227825Stheraven
5439261272Sdim_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5440227825Stheraven
5441227825Stheraven_LIBCPP_END_NAMESPACE_STD
5442227825Stheraven
5443227825Stheraven#endif  // _LIBCPP_MEMORY
5444