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
93262801Sdim    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
353253159Stheraventemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);     // C++14
354253159Stheraventemplate<class T>                unique_ptr<T> make_unique(size_t n);           // C++14
355253159Stheraventemplate<class T, class... Args> unspecified   make_unique(Args&&...) = delete; // C++14, T == U[N]
356253159Stheraven
357227825Stheraventemplate<class T>
358227825Stheravenclass shared_ptr
359227825Stheraven{
360227825Stheravenpublic:
361227825Stheraven    typedef T element_type;
362227825Stheraven
363227825Stheraven    // constructors:
364227825Stheraven    constexpr shared_ptr() noexcept;
365227825Stheraven    template<class Y> explicit shared_ptr(Y* p);
366227825Stheraven    template<class Y, class D> shared_ptr(Y* p, D d);
367227825Stheraven    template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
368227825Stheraven    template <class D> shared_ptr(nullptr_t p, D d);
369227825Stheraven    template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
370227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
371227825Stheraven    shared_ptr(const shared_ptr& r) noexcept;
372227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
373227825Stheraven    shared_ptr(shared_ptr&& r) noexcept;
374227825Stheraven    template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
375227825Stheraven    template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
376227825Stheraven    template<class Y> shared_ptr(auto_ptr<Y>&& r);
377227825Stheraven    template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
378227825Stheraven    shared_ptr(nullptr_t) : shared_ptr() { }
379227825Stheraven
380227825Stheraven    // destructor:
381227825Stheraven    ~shared_ptr();
382227825Stheraven
383227825Stheraven    // assignment:
384227825Stheraven    shared_ptr& operator=(const shared_ptr& r) noexcept;
385227825Stheraven    template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
386227825Stheraven    shared_ptr& operator=(shared_ptr&& r) noexcept;
387227825Stheraven    template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
388227825Stheraven    template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
389227825Stheraven    template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
390227825Stheraven
391227825Stheraven    // modifiers:
392227825Stheraven    void swap(shared_ptr& r) noexcept;
393227825Stheraven    void reset() noexcept;
394227825Stheraven    template<class Y> void reset(Y* p);
395227825Stheraven    template<class Y, class D> void reset(Y* p, D d);
396227825Stheraven    template<class Y, class D, class A> void reset(Y* p, D d, A a);
397227825Stheraven
398227825Stheraven    // observers:
399227825Stheraven    T* get() const noexcept;
400227825Stheraven    T& operator*() const noexcept;
401227825Stheraven    T* operator->() const noexcept;
402227825Stheraven    long use_count() const noexcept;
403227825Stheraven    bool unique() const noexcept;
404227825Stheraven    explicit operator bool() const noexcept;
405227825Stheraven    template<class U> bool owner_before(shared_ptr<U> const& b) const;
406227825Stheraven    template<class U> bool owner_before(weak_ptr<U> const& b) const;
407227825Stheraven};
408227825Stheraven
409227825Stheraven// shared_ptr comparisons:
410227825Stheraventemplate<class T, class U>
411227825Stheraven    bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
412227825Stheraventemplate<class T, class U>
413227825Stheraven    bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
414227825Stheraventemplate<class T, class U>
415227825Stheraven    bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
416227825Stheraventemplate<class T, class U>
417227825Stheraven    bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
418227825Stheraventemplate<class T, class U>
419227825Stheraven    bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
420227825Stheraventemplate<class T, class U>
421227825Stheraven    bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
422227825Stheraven
423227825Stheraventemplate <class T>
424227825Stheraven    bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
425227825Stheraventemplate <class T>
426227825Stheraven    bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
427227825Stheraventemplate <class T>
428227825Stheraven    bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
429227825Stheraventemplate <class T>
430227825Stheraven    bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
431227825Stheraventemplate <class T>
432227825Stheraven    bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
433227825Stheraventemplate <class T>
434227825Stheravenbool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
435227825Stheraventemplate <class T>
436227825Stheraven    bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
437227825Stheraventemplate <class T>
438227825Stheraven    bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
439227825Stheraventemplate <class T>
440227825Stheraven    bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
441227825Stheraventemplate <class T>
442227825Stheraven    bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
443227825Stheraventemplate <class T>
444227825Stheraven    bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
445227825Stheraventemplate <class T>
446227825Stheraven    bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
447227825Stheraven
448227825Stheraven// shared_ptr specialized algorithms:
449227825Stheraventemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
450227825Stheraven
451227825Stheraven// shared_ptr casts:
452227825Stheraventemplate<class T, class U>
453227825Stheraven    shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
454227825Stheraventemplate<class T, class U>
455227825Stheraven    shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
456227825Stheraventemplate<class T, class U>
457227825Stheraven    shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
458227825Stheraven
459227825Stheraven// shared_ptr I/O:
460227825Stheraventemplate<class E, class T, class Y>
461227825Stheraven    basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
462227825Stheraven
463227825Stheraven// shared_ptr get_deleter:
464227825Stheraventemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
465227825Stheraven
466227825Stheraventemplate<class T, class... Args>
467227825Stheraven    shared_ptr<T> make_shared(Args&&... args);
468227825Stheraventemplate<class T, class A, class... Args>
469227825Stheraven    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
470227825Stheraven
471227825Stheraventemplate<class T>
472227825Stheravenclass weak_ptr
473227825Stheraven{
474227825Stheravenpublic:
475227825Stheraven    typedef T element_type;
476227825Stheraven
477227825Stheraven    // constructors
478227825Stheraven    constexpr weak_ptr() noexcept;
479227825Stheraven    template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
480227825Stheraven    weak_ptr(weak_ptr const& r) noexcept;
481227825Stheraven    template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
482278724Sdim    weak_ptr(weak_ptr&& r) noexcept;                      // C++14
483278724Sdim    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;
492278724Sdim    weak_ptr& operator=(weak_ptr&& r) noexcept;                      // C++14
493278724Sdim    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;
503262801Sdim    template<class U> bool owner_before(shared_ptr<U> const& b) const;
504262801Sdim    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>
607232950Stheraven#include <tuple>
608232950Stheraven#include <cstring>
609227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS)
610227825Stheraven    #include <cassert>
611227825Stheraven#endif
612227825Stheraven
613278724Sdim#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
614241903Sdim#  include <atomic>
615241903Sdim#endif
616241903Sdim
617232950Stheraven#include <__undef_min_max>
618232950Stheraven
619227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
620227825Stheraven#pragma GCC system_header
621227825Stheraven#endif
622227825Stheraven
623227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
624227825Stheraven
625262801Sdim// addressof moved to <__functional_base>
626227825Stheraven
627227825Stheraventemplate <class _Tp> class allocator;
628227825Stheraven
629227825Stheraventemplate <>
630262801Sdimclass _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
640232950Stheraventemplate <>
641262801Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const void>
642232950Stheraven{
643232950Stheravenpublic:
644232950Stheraven    typedef const void*       pointer;
645232950Stheraven    typedef const void*       const_pointer;
646232950Stheraven    typedef const void        value_type;
647232950Stheraven
648232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
649232950Stheraven};
650232950Stheraven
651227825Stheraven// pointer_traits
652227825Stheraven
653227825Stheraventemplate <class _Tp>
654227825Stheravenstruct __has_element_type
655227825Stheraven{
656227825Stheravenprivate:
657242945Stheraven    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:
745242945Stheraven    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:
768242945Stheraven    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>
876262801Sdimstruct _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>
899262801Sdimstruct _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{
924256082Sdecke    template <class _Up> static __two __test(...);
925256082Sdecke    template <class _Up> static char __test(typename _Up::pointer* = 0);
926227825Stheraven}
927227825Stheraven
928227825Stheraventemplate <class _Tp>
929227825Stheravenstruct __has_pointer_type
930256082Sdecke    : 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:
961242945Stheraven    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:
988242945Stheraven    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:
1015242945Stheraven    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
1038232950Stheraventemplate <class _Tp>
1039227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1040232950Stheraven_Tp*
1041232950Stheraven__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:
1058242945Stheraven    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:
1081242945Stheraven    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:
1104242945Stheraven    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:
1127242945Stheraven    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:
1150242945Stheraven    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
1363232950Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1364232950Stheraven
1365232950Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1366232950Stheravenstruct __has_construct
1367232950Stheraven    : false_type
1368232950Stheraven{
1369232950Stheraven};
1370232950Stheraven
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>
1406262801Sdimstruct _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)
1453278724Sdim            {__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
1490262801Sdim    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
1500232950Stheraven    template <class _Ptr>
1501232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1502232950Stheraven        static
1503232950Stheraven        void
1504232950Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1505232950Stheraven        {
1506232950Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1507232950Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1508232950Stheraven        }
1509232950Stheraven
1510232950Stheraven    template <class _Tp>
1511232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1512232950Stheraven        static
1513232950Stheraven        typename enable_if
1514232950Stheraven        <
1515232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1516232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1517232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1518232950Stheraven            void
1519232950Stheraven        >::type
1520232950Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1521232950Stheraven        {
1522232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1523232950Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1524232950Stheraven            __begin2 += _Np;
1525232950Stheraven        }
1526232950Stheraven
1527232950Stheraven    template <class _Ptr>
1528232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1529232950Stheraven        static
1530232950Stheraven        void
1531232950Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1532232950Stheraven        {
1533232950Stheraven            while (__end1 != __begin1)
1534246487Stheraven            {
1535246487Stheraven                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1536246487Stheraven                --__end2;
1537246487Stheraven            }
1538232950Stheraven        }
1539232950Stheraven
1540232950Stheraven    template <class _Tp>
1541232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1542232950Stheraven        static
1543232950Stheraven        typename enable_if
1544232950Stheraven        <
1545232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1546232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1547232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1548232950Stheraven            void
1549232950Stheraven        >::type
1550232950Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1551232950Stheraven        {
1552232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1553232950Stheraven            __end2 -= _Np;
1554232950Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1555232950Stheraven        }
1556232950Stheraven
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,
1565232950Stheraven        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
1609232950Stheraven// allocator
1610227825Stheraven
1611227825Stheraventemplate <class _Tp>
1612262801Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator
1613227825Stheraven{
1614227825Stheravenpublic:
1615232950Stheraven    typedef size_t            size_type;
1616232950Stheraven    typedef ptrdiff_t         difference_type;
1617232950Stheraven    typedef _Tp*              pointer;
1618232950Stheraven    typedef const _Tp*        const_pointer;
1619232950Stheraven    typedef _Tp&              reference;
1620232950Stheraven    typedef const _Tp&        const_reference;
1621232950Stheraven    typedef _Tp               value_type;
1622227825Stheraven
1623232950Stheraven    typedef true_type propagate_on_container_move_assignment;
1624227825Stheraven
1625232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1626227825Stheraven
1627232950Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1628232950Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1629232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1630232950Stheraven        {return _VSTD::addressof(__x);}
1631232950Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1632232950Stheraven        {return _VSTD::addressof(__x);}
1633232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1634278724Sdim        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1635232950Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1636278724Sdim        {_VSTD::__deallocate((void*)__p);}
1637232950Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1638232950Stheraven        {return size_type(~0) / sizeof(_Tp);}
1639232950Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1640232950Stheraven    template <class _Up, class... _Args>
1641232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1642232950Stheraven        void
1643232950Stheraven        construct(_Up* __p, _Args&&... __args)
1644232950Stheraven        {
1645232950Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1646232950Stheraven        }
1647232950Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1648232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1649232950Stheraven        void
1650232950Stheraven        construct(pointer __p)
1651232950Stheraven        {
1652232950Stheraven            ::new((void*)__p) _Tp();
1653232950Stheraven        }
1654232950Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1655234976Stheraven
1656232950Stheraven    template <class _A0>
1657232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1658234976Stheraven        void
1659232950Stheraven        construct(pointer __p, _A0& __a0)
1660232950Stheraven        {
1661232950Stheraven            ::new((void*)__p) _Tp(__a0);
1662232950Stheraven        }
1663232950Stheraven    template <class _A0>
1664232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1665234976Stheraven        void
1666232950Stheraven        construct(pointer __p, const _A0& __a0)
1667232950Stheraven        {
1668232950Stheraven            ::new((void*)__p) _Tp(__a0);
1669232950Stheraven        }
1670232950Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1671232950Stheraven    template <class _A0, class _A1>
1672232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1673232950Stheraven        void
1674232950Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1675232950Stheraven        {
1676232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1677232950Stheraven        }
1678232950Stheraven    template <class _A0, class _A1>
1679232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1680232950Stheraven        void
1681232950Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1682232950Stheraven        {
1683232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1684232950Stheraven        }
1685232950Stheraven    template <class _A0, class _A1>
1686232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1687232950Stheraven        void
1688232950Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1689232950Stheraven        {
1690232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1691232950Stheraven        }
1692232950Stheraven    template <class _A0, class _A1>
1693232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1694232950Stheraven        void
1695232950Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1696232950Stheraven        {
1697232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1698232950Stheraven        }
1699232950Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1700232950Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1701227825Stheraven};
1702227825Stheraven
1703227825Stheraventemplate <class _Tp>
1704262801Sdimclass _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
1705227825Stheraven{
1706227825Stheravenpublic:
1707227825Stheraven    typedef size_t            size_type;
1708227825Stheraven    typedef ptrdiff_t         difference_type;
1709232950Stheraven    typedef const _Tp*        pointer;
1710227825Stheraven    typedef const _Tp*        const_pointer;
1711232950Stheraven    typedef const _Tp&        reference;
1712227825Stheraven    typedef const _Tp&        const_reference;
1713253159Stheraven    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)
1724278724Sdim        {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
1725227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1726278724Sdim        {_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)
1745234976Stheraven
1746227825Stheraven    template <class _A0>
1747227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1748234976Stheraven        void
1749227825Stheraven        construct(pointer __p, _A0& __a0)
1750227825Stheraven        {
1751227825Stheraven            ::new((void*)__p) _Tp(__a0);
1752227825Stheraven        }
1753227825Stheraven    template <class _A0>
1754227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1755234976Stheraven        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>
1802262801Sdimclass _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>
1855262801Sdimclass _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 <>
1899262801Sdimclass _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,
1907232950Stheraven                                bool = is_empty<_T1>::value
1908232950Stheraven#if __has_feature(is_final)
1909232950Stheraven                                       && !__is_final(_T1)
1910232950Stheraven#endif
1911232950Stheraven                                ,
1912232950Stheraven                                bool = is_empty<_T2>::value
1913232950Stheraven#if __has_feature(is_final)
1914232950Stheraven                                       && !__is_final(_T2)
1915232950Stheraven#endif
1916232950Stheraven         >
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() {}
1954232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1955227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1956232950Stheraven    _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
1961262801Sdim#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
1997262801Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1998253159Stheraven
1999232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2000232950Stheraven
2001232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2002232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2003232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2004232950Stheraven                                     tuple<_Args1...> __first_args,
2005232950Stheraven                                     tuple<_Args2...> __second_args,
2006232950Stheraven                                     __tuple_indices<_I1...>,
2007232950Stheraven                                     __tuple_indices<_I2...>)
2008278724Sdim            : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2009278724Sdim              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2010232950Stheraven            {}
2011232950Stheraven
2012232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2013232950Stheraven
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 &&
2022278724Sdim                   __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() {}
2047232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2048227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2049232950Stheraven    _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
2054262801Sdim#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
2088262801Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2089253159Stheraven
2090232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2091232950Stheraven
2092232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2093232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2094232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2095232950Stheraven                                     tuple<_Args1...> __first_args,
2096232950Stheraven                                     tuple<_Args2...> __second_args,
2097232950Stheraven                                     __tuple_indices<_I1...>,
2098232950Stheraven                                     __tuple_indices<_I2...>)
2099278724Sdim            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2100278724Sdim              __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2101232950Stheraven            {}
2102232950Stheraven
2103232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2104232950Stheraven
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 &&
2113278724Sdim                   __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
2146262801Sdim#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
2180262801Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2181253159Stheraven
2182232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2183232950Stheraven
2184232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2185232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2186232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2187232950Stheraven                                     tuple<_Args1...> __first_args,
2188232950Stheraven                                     tuple<_Args2...> __second_args,
2189232950Stheraven                                     __tuple_indices<_I1...>,
2190232950Stheraven                                     __tuple_indices<_I2...>)
2191278724Sdim            : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2192278724Sdim              __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
2193232950Stheraven              
2194232950Stheraven            {}
2195232950Stheraven
2196232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2197232950Stheraven
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 &&
2206278724Sdim                   __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
2236262801Sdim#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
2270262801Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2271253159Stheraven
2272232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2273232950Stheraven
2274232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2275232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2276232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2277232950Stheraven                                     tuple<_Args1...> __first_args,
2278232950Stheraven                                     tuple<_Args2...> __second_args,
2279232950Stheraven                                     __tuple_indices<_I1...>,
2280232950Stheraven                                     __tuple_indices<_I2...>)
2281278724Sdim            : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2282278724Sdim              _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
2283232950Stheraven            {}
2284232950Stheraven
2285232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2286232950Stheraven
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
2293232950Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2294227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2295278724Sdim                   __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() {}
2316232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2317227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2318232950Stheraven    _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
2323262801Sdim#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        }
2354232950Stheraven
2355262801Sdim#endif  // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2356253159Stheraven
2357232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2358232950Stheraven
2359232950Stheraven    template <class... _Args1, class... _Args2>
2360232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2361232950Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2362232950Stheraven                                                      tuple<_Args2...> __second_args)
2363232950Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2364232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2365232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2366232950Stheraven            {}
2367232950Stheraven
2368232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2369232950Stheraven
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 &&
2378278724Sdim                   __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 &&
2387278724Sdim                   __is_nothrow_swappable<_T2>::value)
2388227825Stheraven    {__x.swap(__y);}
2389227825Stheraven
2390232950Stheraven// __same_or_less_cv_qualified
2391232950Stheraven
2392232950Stheraventemplate <class _Ptr1, class _Ptr2,
2393232950Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2394232950Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2395232950Stheraven                        >::value
2396232950Stheraven         >
2397232950Stheravenstruct __same_or_less_cv_qualified_imp
2398232950Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2399232950Stheraven
2400232950Stheraventemplate <class _Ptr1, class _Ptr2>
2401232950Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2402232950Stheraven    : false_type {};
2403232950Stheraven
2404278724Sdimtemplate <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2405278724Sdim                                           is_same<_Ptr1, _Ptr2>::value ||
2406278724Sdim                                           __has_element_type<_Ptr1>::value>
2407232950Stheravenstruct __same_or_less_cv_qualified
2408232950Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2409232950Stheraven
2410232950Stheraventemplate <class _Ptr1, class _Ptr2>
2411278724Sdimstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
2412232950Stheraven    : false_type {};
2413232950Stheraven
2414232950Stheraven// default_delete
2415232950Stheraven
2416227825Stheraventemplate <class _Tp>
2417262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete
2418227825Stheraven{
2419241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2420241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2421241903Sdim#else
2422241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2423241903Sdim#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");
2430249998Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2431227825Stheraven            delete __ptr;
2432227825Stheraven        }
2433227825Stheraven};
2434227825Stheraven
2435227825Stheraventemplate <class _Tp>
2436262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
2437227825Stheraven{
2438232950Stheravenpublic:
2439241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2440241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2441241903Sdim#else
2442241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2443241903Sdim#endif
2444232950Stheraven    template <class _Up>
2445232950Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2446232950Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2447232950Stheraven    template <class _Up>
2448232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2449232950Stheraven        void operator() (_Up* __ptr,
2450232950Stheraven                         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");
2453249998Sdim            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> >
2459262801Sdimclass _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
2468232950Stheraven#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:
2482241903Sdim    _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        }
2488241903Sdim    _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            <
2555232950Stheraven                !is_array<_Up>::value &&
2556232950Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2557232950Stheraven                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();}
2614232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2615232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2616232950Stheraven        {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>
2638262801Sdimclass _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
2647232950Stheraven#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:
2661241903Sdim    _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        }
2667241903Sdim    _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
2674278724Sdim    template <class _Pp>
2675278724Sdim    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2676278724Sdim            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
2683278724Sdim    template <class _Pp>
2684232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2685227825Stheraven                                       is_reference<deleter_type>::value,
2686227825Stheraven                                       deleter_type,
2687278724Sdim                                       typename add_lvalue_reference<const deleter_type>::type>::type __d,
2688278724Sdim                                       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
2699278724Sdim    template <class _Pp>
2700278724Sdim    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2701278724Sdim                                         typename remove_reference<deleter_type>::type&& __d,
2702278724Sdim                                         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        }
2725232950Stheraven
2726232950Stheraven    template <class _Up, class _Ep>
2727232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2728232950Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2729232950Stheraven                   typename enable_if
2730232950Stheraven                            <
2731232950Stheraven                                is_array<_Up>::value &&
2732232950Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2733232950Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2734232950Stheraven                                (
2735232950Stheraven                                    !is_reference<deleter_type>::value ||
2736232950Stheraven                                    is_same<deleter_type, _Ep>::value
2737232950Stheraven                                ),
2738232950Stheraven                                __nat
2739232950Stheraven                            >::type = __nat()
2740232950Stheraven                  ) _NOEXCEPT
2741232950Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2742232950Stheraven
2743232950Stheraven
2744232950Stheraven        template <class _Up, class _Ep>
2745232950Stheraven            _LIBCPP_INLINE_VISIBILITY
2746232950Stheraven            typename enable_if
2747232950Stheraven            <
2748232950Stheraven                is_array<_Up>::value &&
2749232950Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2750232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2751232950Stheraven                unique_ptr&
2752232950Stheraven            >::type
2753232950Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2754232950Stheraven            {
2755232950Stheraven                reset(__u.release());
2756232950Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2757232950Stheraven                return *this;
2758232950Stheraven            }
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();}
2805232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2806232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2807232950Stheraven        {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
2817278724Sdim    template <class _Pp>
2818278724Sdim    _LIBCPP_INLINE_VISIBILITY
2819278724Sdim    typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2820278724Sdim    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
2889232950Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2890232950Stheraven{
2891232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2892232950Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2893232950Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2894232950Stheraven    return less<_V>()(__x.get(), __y.get());
2895232950Stheraven}
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
2912232950Stheraventemplate <class _T1, class _D1>
2913232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2914232950Stheravenbool
2915241903Sdimoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2916232950Stheraven{
2917232950Stheraven    return !__x;
2918232950Stheraven}
2919232950Stheraven
2920232950Stheraventemplate <class _T1, class _D1>
2921232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2922232950Stheravenbool
2923241903Sdimoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2924232950Stheraven{
2925232950Stheraven    return !__x;
2926232950Stheraven}
2927232950Stheraven
2928232950Stheraventemplate <class _T1, class _D1>
2929232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2930232950Stheravenbool
2931241903Sdimoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2932232950Stheraven{
2933232950Stheraven    return static_cast<bool>(__x);
2934232950Stheraven}
2935232950Stheraven
2936232950Stheraventemplate <class _T1, class _D1>
2937232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2938232950Stheravenbool
2939241903Sdimoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2940232950Stheraven{
2941232950Stheraven    return static_cast<bool>(__x);
2942232950Stheraven}
2943232950Stheraven
2944232950Stheraventemplate <class _T1, class _D1>
2945232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2946232950Stheravenbool
2947232950Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2948232950Stheraven{
2949232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2950232950Stheraven    return less<_P1>()(__x.get(), nullptr);
2951232950Stheraven}
2952232950Stheraven
2953232950Stheraventemplate <class _T1, class _D1>
2954232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2955232950Stheravenbool
2956232950Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2957232950Stheraven{
2958232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2959232950Stheraven    return less<_P1>()(nullptr, __x.get());
2960232950Stheraven}
2961232950Stheraven
2962232950Stheraventemplate <class _T1, class _D1>
2963232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2964232950Stheravenbool
2965232950Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2966232950Stheraven{
2967232950Stheraven    return nullptr < __x;
2968232950Stheraven}
2969232950Stheraven
2970232950Stheraventemplate <class _T1, class _D1>
2971232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2972232950Stheravenbool
2973232950Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2974232950Stheraven{
2975232950Stheraven    return __x < nullptr;
2976232950Stheraven}
2977232950Stheraven
2978232950Stheraventemplate <class _T1, class _D1>
2979232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2980232950Stheravenbool
2981232950Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2982232950Stheraven{
2983232950Stheraven    return !(nullptr < __x);
2984232950Stheraven}
2985232950Stheraven
2986232950Stheraventemplate <class _T1, class _D1>
2987232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2988232950Stheravenbool
2989232950Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2990232950Stheraven{
2991232950Stheraven    return !(__x < nullptr);
2992232950Stheraven}
2993232950Stheraven
2994232950Stheraventemplate <class _T1, class _D1>
2995232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2996232950Stheravenbool
2997232950Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2998232950Stheraven{
2999232950Stheraven    return !(__x < nullptr);
3000232950Stheraven}
3001232950Stheraven
3002232950Stheraventemplate <class _T1, class _D1>
3003232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3004232950Stheravenbool
3005232950Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3006232950Stheraven{
3007232950Stheraven    return !(nullptr < __x);
3008232950Stheraven}
3009232950Stheraven
3010234976Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3011234976Stheraven
3012234976Stheraventemplate <class _Tp, class _Dp>
3013234976Stheraveninline _LIBCPP_INLINE_VISIBILITY
3014234976Stheravenunique_ptr<_Tp, _Dp>
3015234976Stheravenmove(unique_ptr<_Tp, _Dp>& __t)
3016234976Stheraven{
3017234976Stheraven    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3018234976Stheraven}
3019234976Stheraven
3020234976Stheraven#endif
3021234976Stheraven
3022253159Stheraven#if _LIBCPP_STD_VER > 11
3023253159Stheraven
3024253159Stheraventemplate<class _Tp>
3025253159Stheravenstruct __unique_if
3026253159Stheraven{
3027253159Stheraven    typedef unique_ptr<_Tp> __unique_single;
3028253159Stheraven};
3029253159Stheraven
3030253159Stheraventemplate<class _Tp>
3031253159Stheravenstruct __unique_if<_Tp[]>
3032253159Stheraven{
3033253159Stheraven    typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3034253159Stheraven};
3035253159Stheraven
3036253159Stheraventemplate<class _Tp, size_t _Np>
3037253159Stheravenstruct __unique_if<_Tp[_Np]>
3038253159Stheraven{
3039253159Stheraven    typedef void __unique_array_known_bound;
3040253159Stheraven};
3041253159Stheraven
3042253159Stheraventemplate<class _Tp, class... _Args>
3043253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3044253159Stheraventypename __unique_if<_Tp>::__unique_single
3045253159Stheravenmake_unique(_Args&&... __args)
3046253159Stheraven{
3047253159Stheraven    return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3048253159Stheraven}
3049253159Stheraven
3050253159Stheraventemplate<class _Tp>
3051253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3052253159Stheraventypename __unique_if<_Tp>::__unique_array_unknown_bound
3053253159Stheravenmake_unique(size_t __n)
3054253159Stheraven{
3055253159Stheraven    typedef typename remove_extent<_Tp>::type _Up;
3056253159Stheraven    return unique_ptr<_Tp>(new _Up[__n]());
3057253159Stheraven}
3058253159Stheraven
3059253159Stheraventemplate<class _Tp, class... _Args>
3060253159Stheraven    typename __unique_if<_Tp>::__unique_array_known_bound
3061253159Stheraven    make_unique(_Args&&...) = delete;
3062253159Stheraven
3063253159Stheraven#endif  // _LIBCPP_STD_VER > 11
3064253159Stheraven
3065227825Stheraventemplate <class _Tp> struct hash;
3066227825Stheraven
3067253159Stheraventemplate <class _Size>
3068253159Stheraveninline _LIBCPP_INLINE_VISIBILITY
3069253159Stheraven_Size
3070253159Stheraven__loadword(const void* __p)
3071253159Stheraven{
3072253159Stheraven    _Size __r;
3073253159Stheraven    std::memcpy(&__r, __p, sizeof(__r));
3074253159Stheraven    return __r;
3075253159Stheraven}
3076253159Stheraven
3077232950Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3078232950Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3079232950Stheraven// multiplication, which can be very slow on 32-bit systems.
3080232950Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3081232950Stheravenstruct __murmur2_or_cityhash;
3082232950Stheraven
3083232950Stheraventemplate <class _Size>
3084232950Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3085227825Stheraven{
3086232950Stheraven    _Size operator()(const void* __key, _Size __len);
3087232950Stheraven};
3088232950Stheraven
3089232950Stheraven// murmur2
3090232950Stheraventemplate <class _Size>
3091232950Stheraven_Size
3092232950Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3093232950Stheraven{
3094232950Stheraven    const _Size __m = 0x5bd1e995;
3095232950Stheraven    const _Size __r = 24;
3096232950Stheraven    _Size __h = __len;
3097232950Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3098232950Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3099232950Stheraven    {
3100253159Stheraven        _Size __k = __loadword<_Size>(__data);
3101232950Stheraven        __k *= __m;
3102232950Stheraven        __k ^= __k >> __r;
3103232950Stheraven        __k *= __m;
3104232950Stheraven        __h *= __m;
3105232950Stheraven        __h ^= __k;
3106232950Stheraven    }
3107232950Stheraven    switch (__len)
3108232950Stheraven    {
3109232950Stheraven    case 3:
3110232950Stheraven        __h ^= __data[2] << 16;
3111232950Stheraven    case 2:
3112232950Stheraven        __h ^= __data[1] << 8;
3113232950Stheraven    case 1:
3114232950Stheraven        __h ^= __data[0];
3115232950Stheraven        __h *= __m;
3116232950Stheraven    }
3117232950Stheraven    __h ^= __h >> 13;
3118232950Stheraven    __h *= __m;
3119232950Stheraven    __h ^= __h >> 15;
3120232950Stheraven    return __h;
3121232950Stheraven}
3122232950Stheraven
3123232950Stheraventemplate <class _Size>
3124232950Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3125232950Stheraven{
3126232950Stheraven    _Size operator()(const void* __key, _Size __len);
3127232950Stheraven
3128232950Stheraven private:
3129232950Stheraven  // Some primes between 2^63 and 2^64.
3130232950Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3131232950Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3132232950Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3133232950Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3134232950Stheraven
3135232950Stheraven  static _Size __rotate(_Size __val, int __shift) {
3136232950Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3137232950Stheraven  }
3138232950Stheraven
3139232950Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3140232950Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3141232950Stheraven  }
3142232950Stheraven
3143232950Stheraven  static _Size __shift_mix(_Size __val) {
3144232950Stheraven    return __val ^ (__val >> 47);
3145232950Stheraven  }
3146232950Stheraven
3147232950Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3148232950Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3149232950Stheraven    _Size __a = (__u ^ __v) * __mul;
3150232950Stheraven    __a ^= (__a >> 47);
3151232950Stheraven    _Size __b = (__v ^ __a) * __mul;
3152232950Stheraven    __b ^= (__b >> 47);
3153232950Stheraven    __b *= __mul;
3154232950Stheraven    return __b;
3155232950Stheraven  }
3156232950Stheraven
3157232950Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3158232950Stheraven    if (__len > 8) {
3159253159Stheraven      const _Size __a = __loadword<_Size>(__s);
3160253159Stheraven      const _Size __b = __loadword<_Size>(__s + __len - 8);
3161232950Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3162232950Stheraven    }
3163232950Stheraven    if (__len >= 4) {
3164253159Stheraven      const uint32_t __a = __loadword<uint32_t>(__s);
3165253159Stheraven      const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
3166232950Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3167232950Stheraven    }
3168232950Stheraven    if (__len > 0) {
3169232950Stheraven      const unsigned char __a = __s[0];
3170232950Stheraven      const unsigned char __b = __s[__len >> 1];
3171232950Stheraven      const unsigned char __c = __s[__len - 1];
3172232950Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3173232950Stheraven                           (static_cast<uint32_t>(__b) << 8);
3174232950Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3175232950Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3176232950Stheraven    }
3177232950Stheraven    return __k2;
3178232950Stheraven  }
3179232950Stheraven
3180232950Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3181253159Stheraven    const _Size __a = __loadword<_Size>(__s) * __k1;
3182253159Stheraven    const _Size __b = __loadword<_Size>(__s + 8);
3183253159Stheraven    const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3184253159Stheraven    const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
3185232950Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3186232950Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3187232950Stheraven  }
3188232950Stheraven
3189232950Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3190232950Stheraven  // Callers do best to use "random-looking" values for a and b.
3191232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3192232950Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3193232950Stheraven    __a += __w;
3194232950Stheraven    __b = __rotate(__b + __a + __z, 21);
3195232950Stheraven    const _Size __c = __a;
3196232950Stheraven    __a += __x;
3197232950Stheraven    __a += __y;
3198232950Stheraven    __b += __rotate(__a, 44);
3199232950Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3200232950Stheraven  }
3201232950Stheraven
3202232950Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3203232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3204232950Stheraven      const char* __s, _Size __a, _Size __b) {
3205253159Stheraven    return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3206253159Stheraven                                         __loadword<_Size>(__s + 8),
3207253159Stheraven                                         __loadword<_Size>(__s + 16),
3208253159Stheraven                                         __loadword<_Size>(__s + 24),
3209232950Stheraven                                         __a,
3210232950Stheraven                                         __b);
3211232950Stheraven  }
3212232950Stheraven
3213232950Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3214232950Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3215253159Stheraven    _Size __z = __loadword<_Size>(__s + 24);
3216253159Stheraven    _Size __a = __loadword<_Size>(__s) +
3217253159Stheraven                (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
3218232950Stheraven    _Size __b = __rotate(__a + __z, 52);
3219232950Stheraven    _Size __c = __rotate(__a, 37);
3220253159Stheraven    __a += __loadword<_Size>(__s + 8);
3221232950Stheraven    __c += __rotate(__a, 7);
3222253159Stheraven    __a += __loadword<_Size>(__s + 16);
3223232950Stheraven    _Size __vf = __a + __z;
3224232950Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3225253159Stheraven    __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3226253159Stheraven    __z += __loadword<_Size>(__s + __len - 8);
3227232950Stheraven    __b = __rotate(__a + __z, 52);
3228232950Stheraven    __c = __rotate(__a, 37);
3229253159Stheraven    __a += __loadword<_Size>(__s + __len - 24);
3230232950Stheraven    __c += __rotate(__a, 7);
3231253159Stheraven    __a += __loadword<_Size>(__s + __len - 16);
3232232950Stheraven    _Size __wf = __a + __z;
3233232950Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3234232950Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3235232950Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3236232950Stheraven  }
3237232950Stheraven};
3238232950Stheraven
3239232950Stheraven// cityhash64
3240232950Stheraventemplate <class _Size>
3241232950Stheraven_Size
3242232950Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3243232950Stheraven{
3244232950Stheraven  const char* __s = static_cast<const char*>(__key);
3245232950Stheraven  if (__len <= 32) {
3246232950Stheraven    if (__len <= 16) {
3247232950Stheraven      return __hash_len_0_to_16(__s, __len);
3248232950Stheraven    } else {
3249232950Stheraven      return __hash_len_17_to_32(__s, __len);
3250232950Stheraven    }
3251232950Stheraven  } else if (__len <= 64) {
3252232950Stheraven    return __hash_len_33_to_64(__s, __len);
3253232950Stheraven  }
3254232950Stheraven
3255232950Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3256232950Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3257253159Stheraven  _Size __x = __loadword<_Size>(__s + __len - 40);
3258253159Stheraven  _Size __y = __loadword<_Size>(__s + __len - 16) +
3259253159Stheraven              __loadword<_Size>(__s + __len - 56);
3260253159Stheraven  _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3261253159Stheraven                          __loadword<_Size>(__s + __len - 24));
3262232950Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3263232950Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3264253159Stheraven  __x = __x * __k1 + __loadword<_Size>(__s);
3265232950Stheraven
3266232950Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3267232950Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3268232950Stheraven  do {
3269253159Stheraven    __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3270253159Stheraven    __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
3271232950Stheraven    __x ^= __w.second;
3272253159Stheraven    __y += __v.first + __loadword<_Size>(__s + 40);
3273232950Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3274232950Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3275232950Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3276253159Stheraven                                        __y + __loadword<_Size>(__s + 16));
3277232950Stheraven    std::swap(__z, __x);
3278232950Stheraven    __s += 64;
3279232950Stheraven    __len -= 64;
3280232950Stheraven  } while (__len != 0);
3281232950Stheraven  return __hash_len_16(
3282232950Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3283232950Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3284232950Stheraven}
3285232950Stheraven
3286232950Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3287232950Stheravenstruct __scalar_hash;
3288232950Stheraven
3289232950Stheraventemplate <class _Tp>
3290232950Stheravenstruct __scalar_hash<_Tp, 0>
3291232950Stheraven    : public unary_function<_Tp, size_t>
3292232950Stheraven{
3293227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3294232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3295227825Stheraven    {
3296232950Stheraven        union
3297232950Stheraven        {
3298232950Stheraven            _Tp    __t;
3299232950Stheraven            size_t __a;
3300232950Stheraven        } __u;
3301232950Stheraven        __u.__a = 0;
3302232950Stheraven        __u.__t = __v;
3303232950Stheraven        return __u.__a;
3304227825Stheraven    }
3305227825Stheraven};
3306227825Stheraven
3307232950Stheraventemplate <class _Tp>
3308232950Stheravenstruct __scalar_hash<_Tp, 1>
3309232950Stheraven    : public unary_function<_Tp, size_t>
3310232950Stheraven{
3311232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3312232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3313232950Stheraven    {
3314232950Stheraven        union
3315232950Stheraven        {
3316232950Stheraven            _Tp    __t;
3317232950Stheraven            size_t __a;
3318232950Stheraven        } __u;
3319232950Stheraven        __u.__t = __v;
3320232950Stheraven        return __u.__a;
3321232950Stheraven    }
3322232950Stheraven};
3323232950Stheraven
3324232950Stheraventemplate <class _Tp>
3325232950Stheravenstruct __scalar_hash<_Tp, 2>
3326232950Stheraven    : public unary_function<_Tp, size_t>
3327232950Stheraven{
3328232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3329232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3330232950Stheraven    {
3331232950Stheraven        union
3332232950Stheraven        {
3333232950Stheraven            _Tp __t;
3334232950Stheraven            struct
3335232950Stheraven            {
3336232950Stheraven                size_t __a;
3337232950Stheraven                size_t __b;
3338232950Stheraven            };
3339232950Stheraven        } __u;
3340232950Stheraven        __u.__t = __v;
3341232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3342232950Stheraven    }
3343232950Stheraven};
3344232950Stheraven
3345232950Stheraventemplate <class _Tp>
3346232950Stheravenstruct __scalar_hash<_Tp, 3>
3347232950Stheraven    : public unary_function<_Tp, size_t>
3348232950Stheraven{
3349232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3350232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3351232950Stheraven    {
3352232950Stheraven        union
3353232950Stheraven        {
3354232950Stheraven            _Tp __t;
3355232950Stheraven            struct
3356232950Stheraven            {
3357232950Stheraven                size_t __a;
3358232950Stheraven                size_t __b;
3359232950Stheraven                size_t __c;
3360232950Stheraven            };
3361232950Stheraven        } __u;
3362232950Stheraven        __u.__t = __v;
3363232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3364232950Stheraven    }
3365232950Stheraven};
3366232950Stheraven
3367232950Stheraventemplate <class _Tp>
3368232950Stheravenstruct __scalar_hash<_Tp, 4>
3369232950Stheraven    : public unary_function<_Tp, size_t>
3370232950Stheraven{
3371232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3372232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3373232950Stheraven    {
3374232950Stheraven        union
3375232950Stheraven        {
3376232950Stheraven            _Tp __t;
3377232950Stheraven            struct
3378232950Stheraven            {
3379232950Stheraven                size_t __a;
3380232950Stheraven                size_t __b;
3381232950Stheraven                size_t __c;
3382232950Stheraven                size_t __d;
3383232950Stheraven            };
3384232950Stheraven        } __u;
3385232950Stheraven        __u.__t = __v;
3386232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3387232950Stheraven    }
3388232950Stheraven};
3389232950Stheraven
3390232950Stheraventemplate<class _Tp>
3391262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
3392241903Sdim    : public unary_function<_Tp*, size_t>
3393232950Stheraven{
3394241903Sdim    _LIBCPP_INLINE_VISIBILITY
3395241903Sdim    size_t operator()(_Tp* __v) const _NOEXCEPT
3396241903Sdim    {
3397241903Sdim        union
3398241903Sdim        {
3399241903Sdim            _Tp* __t;
3400241903Sdim            size_t __a;
3401241903Sdim        } __u;
3402241903Sdim        __u.__t = __v;
3403241903Sdim        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3404241903Sdim    }
3405232950Stheraven};
3406232950Stheraven
3407227825Stheraventemplate <class _Tp, class _Dp>
3408262801Sdimstruct _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;
3483232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3484232950Stheraven    _ForwardIterator __s = __r;
3485232950Stheraven    try
3486232950Stheraven    {
3487232950Stheraven#endif
3488232950Stheraven        for (; __f != __l; ++__f, ++__r)
3489232950Stheraven            ::new(&*__r) value_type(*__f);
3490232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3491232950Stheraven    }
3492232950Stheraven    catch (...)
3493232950Stheraven    {
3494232950Stheraven        for (; __s != __r; ++__s)
3495232950Stheraven            __s->~value_type();
3496232950Stheraven        throw;
3497232950Stheraven    }
3498232950Stheraven#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;
3507232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3508232950Stheraven    _ForwardIterator __s = __r;
3509232950Stheraven    try
3510232950Stheraven    {
3511232950Stheraven#endif
3512232950Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3513232950Stheraven            ::new(&*__r) value_type(*__f);
3514232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3515232950Stheraven    }
3516232950Stheraven    catch (...)
3517232950Stheraven    {
3518232950Stheraven        for (; __s != __r; ++__s)
3519232950Stheraven            __s->~value_type();
3520232950Stheraven        throw;
3521232950Stheraven    }
3522232950Stheraven#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;
3531232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3532232950Stheraven    _ForwardIterator __s = __f;
3533232950Stheraven    try
3534232950Stheraven    {
3535232950Stheraven#endif
3536232950Stheraven        for (; __f != __l; ++__f)
3537232950Stheraven            ::new(&*__f) value_type(__x);
3538232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3539232950Stheraven    }
3540232950Stheraven    catch (...)
3541232950Stheraven    {
3542232950Stheraven        for (; __s != __f; ++__s)
3543232950Stheraven            __s->~value_type();
3544232950Stheraven        throw;
3545232950Stheraven    }
3546232950Stheraven#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;
3554232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3555232950Stheraven    _ForwardIterator __s = __f;
3556232950Stheraven    try
3557232950Stheraven    {
3558232950Stheraven#endif
3559232950Stheraven        for (; __n > 0; ++__f, --__n)
3560232950Stheraven            ::new(&*__f) value_type(__x);
3561232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3562232950Stheraven    }
3563232950Stheraven    catch (...)
3564232950Stheraven    {
3565232950Stheraven        for (; __s != __f; ++__s)
3566232950Stheraven            __s->~value_type();
3567232950Stheraven        throw;
3568232950Stheraven    }
3569232950Stheraven#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
3581262801Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
3582227825Stheraven
3583262801Sdimclass _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
3605262801Sdimclass _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
3627249998Sdim    // Define the function out only if we build static libc++ without RTTI.
3628249998Sdim    // Otherwise we may break clients who need to compile their projects with
3629249998Sdim    // -fno-rtti and yet link against a libc++.dylib compiled
3630249998Sdim    // without -fno-rtti.
3631249998Sdim#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3632227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3633249998Sdim#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{
3663278724Sdim    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{
3680278724Sdim    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _A;
3681278724Sdim    typedef allocator_traits<_A> _ATraits;
3682278724Sdim    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3683278724Sdim
3684278724Sdim    _A __a(__data_.second());
3685227825Stheraven    __data_.second().~_Alloc();
3686278724Sdim    __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)
3704232950Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3705232950Stheraven                   _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{
3749278724Sdim    typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _A;
3750278724Sdim    typedef allocator_traits<_A> _ATraits;
3751278724Sdim    typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3752278724Sdim    _A __a(__data_.first());
3753227825Stheraven    __data_.first().~_Alloc();
3754278724Sdim    __a.deallocate(_PTraits::pointer_to(*this), 1);
3755227825Stheraven}
3756227825Stheraven
3757262801Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
3758227825Stheraven
3759227825Stheraventemplate<class _Tp>
3760262801Sdimclass _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:
3770241903Sdim    _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3771241903Sdim    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3772278724Sdim    template<class _Yp>
3773278724Sdim        explicit shared_ptr(_Yp* __p,
3774278724Sdim                            typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3775278724Sdim    template<class _Yp, class _Dp>
3776278724Sdim        shared_ptr(_Yp* __p, _Dp __d,
3777278724Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3778278724Sdim    template<class _Yp, class _Dp, class _Alloc>
3779278724Sdim        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3780278724Sdim                   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
3798278724Sdim    template<class _Yp>
3799278724Sdim        shared_ptr(auto_ptr<_Yp>&& __r,
3800278724Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3801227825Stheraven#else
3802278724Sdim    template<class _Yp>
3803278724Sdim        shared_ptr(auto_ptr<_Yp> __r,
3804278724Sdim                   typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3805227825Stheraven#endif
3806227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3807278724Sdim    template <class _Yp, class _Dp>
3808278724Sdim        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3809278724Sdim                   typename enable_if
3810278724Sdim                   <
3811278724Sdim                       !is_lvalue_reference<_Dp>::value &&
3812278724Sdim                       !is_array<_Yp>::value &&
3813278724Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3814278724Sdim                       __nat
3815278724Sdim                   >::type = __nat());
3816278724Sdim    template <class _Yp, class _Dp>
3817278724Sdim        shared_ptr(unique_ptr<_Yp, _Dp>&&,
3818278724Sdim                   typename enable_if
3819278724Sdim                   <
3820278724Sdim                       is_lvalue_reference<_Dp>::value &&
3821278724Sdim                       !is_array<_Yp>::value &&
3822278724Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3823278724Sdim                       __nat
3824278724Sdim                   >::type = __nat());
3825227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3826278724Sdim    template <class _Yp, class _Dp>
3827278724Sdim        shared_ptr(unique_ptr<_Yp, _Dp>,
3828278724Sdim                   typename enable_if
3829278724Sdim                   <
3830278724Sdim                       !is_lvalue_reference<_Dp>::value &&
3831278724Sdim                       !is_array<_Yp>::value &&
3832278724Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3833278724Sdim                       __nat
3834278724Sdim                   >::type = __nat());
3835278724Sdim    template <class _Yp, class _Dp>
3836278724Sdim        shared_ptr(unique_ptr<_Yp, _Dp>,
3837278724Sdim                   typename enable_if
3838278724Sdim                   <
3839278724Sdim                       is_lvalue_reference<_Dp>::value &&
3840278724Sdim                       !is_array<_Yp>::value &&
3841278724Sdim                       is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3842278724Sdim                       __nat
3843278724Sdim                   >::type = __nat());
3844227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3845227825Stheraven
3846227825Stheraven    ~shared_ptr();
3847227825Stheraven
3848227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3849232950Stheraven    template<class _Yp>
3850232950Stheraven        typename enable_if
3851232950Stheraven        <
3852232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3853232950Stheraven            shared_ptr&
3854232950Stheraven        >::type
3855232950Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3856227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3857227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3858232950Stheraven    template<class _Yp>
3859232950Stheraven        typename enable_if
3860232950Stheraven        <
3861232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3862232950Stheraven            shared_ptr<_Tp>&
3863232950Stheraven        >::type
3864232950Stheraven        operator=(shared_ptr<_Yp>&& __r);
3865232950Stheraven    template<class _Yp>
3866232950Stheraven        typename enable_if
3867232950Stheraven        <
3868232950Stheraven            !is_array<_Yp>::value &&
3869232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3870262801Sdim            shared_ptr
3871262801Sdim        >::type&
3872232950Stheraven        operator=(auto_ptr<_Yp>&& __r);
3873227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3874232950Stheraven    template<class _Yp>
3875232950Stheraven        typename enable_if
3876232950Stheraven        <
3877232950Stheraven            !is_array<_Yp>::value &&
3878232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3879232950Stheraven            shared_ptr&
3880232950Stheraven        >::type
3881232950Stheraven        operator=(auto_ptr<_Yp> __r);
3882227825Stheraven#endif
3883232950Stheraven    template <class _Yp, class _Dp>
3884232950Stheraven        typename enable_if
3885232950Stheraven        <
3886232950Stheraven            !is_array<_Yp>::value &&
3887232950Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3888232950Stheraven            shared_ptr&
3889232950Stheraven        >::type
3890227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3891232950Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3892227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3893232950Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3894227825Stheraven#endif
3895227825Stheraven
3896227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3897227825Stheraven    void reset() _NOEXCEPT;
3898232950Stheraven    template<class _Yp>
3899232950Stheraven        typename enable_if
3900232950Stheraven        <
3901232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3902232950Stheraven            void
3903232950Stheraven        >::type
3904232950Stheraven        reset(_Yp* __p);
3905232950Stheraven    template<class _Yp, class _Dp>
3906232950Stheraven        typename enable_if
3907232950Stheraven        <
3908232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3909232950Stheraven            void
3910232950Stheraven        >::type
3911232950Stheraven        reset(_Yp* __p, _Dp __d);
3912232950Stheraven    template<class _Yp, class _Dp, class _Alloc>
3913232950Stheraven        typename enable_if
3914232950Stheraven        <
3915232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3916232950Stheraven            void
3917232950Stheraven        >::type
3918232950Stheraven        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
3932232950Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3933232950Stheraven    template <class _Up>
3934227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3935232950Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
3936227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3937232950Stheraven    template <class _Up>
3938227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3939232950Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
3940227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3941241903Sdim    _LIBCPP_INLINE_VISIBILITY
3942241903Sdim    bool
3943241903Sdim    __owner_equivalent(const shared_ptr& __p) const
3944241903Sdim        {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
4010262801Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4011262801Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
4012227825Stheraven};
4013227825Stheraven
4014227825Stheraventemplate<class _Tp>
4015227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4016241903Sdim_LIBCPP_CONSTEXPR
4017227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4018227825Stheraven    : __ptr_(0),
4019227825Stheraven      __cntrl_(0)
4020227825Stheraven{
4021227825Stheraven}
4022227825Stheraven
4023227825Stheraventemplate<class _Tp>
4024227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4025241903Sdim_LIBCPP_CONSTEXPR
4026227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4027227825Stheraven    : __ptr_(0),
4028227825Stheraven      __cntrl_(0)
4029227825Stheraven{
4030227825Stheraven}
4031227825Stheraven
4032227825Stheraventemplate<class _Tp>
4033278724Sdimtemplate<class _Yp>
4034278724Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p,
4035278724Sdim                            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>
4046278724Sdimtemplate<class _Yp, class _Dp>
4047278724Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4048278724Sdim                            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>
4090278724Sdimtemplate<class _Yp, class _Dp, class _Alloc>
4091278724Sdimshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4092278724Sdim                            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;
4100278724Sdim        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));
4104278724Sdim        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4105278724Sdim            _CntrlBlk(__p, __d, __a);
4106278724Sdim        __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;
4128278724Sdim        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));
4132278724Sdim        ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4133278724Sdim            _CntrlBlk(__p, __d, __a);
4134278724Sdim        __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>
4207278724Sdimtemplate<class _Yp>
4208227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4209278724Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4210227825Stheraven#else
4211278724Sdimshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4212227825Stheraven#endif
4213278724Sdim                            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>
4223278724Sdimtemplate <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
4229278724Sdim                            typename enable_if
4230278724Sdim                            <
4231278724Sdim                                !is_lvalue_reference<_Dp>::value &&
4232278724Sdim                                !is_array<_Yp>::value &&
4233278724Sdim                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4234278724Sdim                                __nat
4235278724Sdim                            >::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>
4245278724Sdimtemplate <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
4251278724Sdim                            typename enable_if
4252278724Sdim                            <
4253278724Sdim                                is_lvalue_reference<_Dp>::value &&
4254278724Sdim                                !is_array<_Yp>::value &&
4255278724Sdim                                is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4256278724Sdim                                __nat
4257278724Sdim                            >::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;
4294278724Sdim    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));
4298278724Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4299278724Sdim        _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4300227825Stheraven    shared_ptr<_Tp> __r;
4301227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4302278724Sdim    __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;
4386278724Sdim    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));
4390278724Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4391278724Sdim        _CntrlBlk(__a);
4392227825Stheraven    shared_ptr<_Tp> __r;
4393227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4394278724Sdim    __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;
4405278724Sdim    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));
4409278724Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4410278724Sdim        _CntrlBlk(__a, __a0);
4411227825Stheraven    shared_ptr<_Tp> __r;
4412227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4413278724Sdim    __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;
4424278724Sdim    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));
4428278724Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4429278724Sdim        _CntrlBlk(__a, __a0, __a1);
4430227825Stheraven    shared_ptr<_Tp> __r;
4431227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4432278724Sdim    __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;
4443278724Sdim    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));
4447278724Sdim    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4448278724Sdim        _CntrlBlk(__a, __a0, __a1, __a2);
4449227825Stheraven    shared_ptr<_Tp> __r;
4450227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4451278724Sdim    __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
4477232950Stheraventypename enable_if
4478232950Stheraven<
4479232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4480232950Stheraven    shared_ptr<_Tp>&
4481232950Stheraven>::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
4502232950Stheraventypename enable_if
4503232950Stheraven<
4504232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4505232950Stheraven    shared_ptr<_Tp>&
4506232950Stheraven>::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
4516232950Stheraventypename enable_if
4517232950Stheraven<
4518232950Stheraven    !is_array<_Yp>::value &&
4519232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4520262801Sdim    shared_ptr<_Tp>
4521262801Sdim>::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
4531232950Stheraventypename enable_if
4532232950Stheraven<
4533232950Stheraven    !is_array<_Yp>::value &&
4534232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4535232950Stheraven    shared_ptr<_Tp>&
4536232950Stheraven>::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
4548232950Stheraventypename enable_if
4549232950Stheraven<
4550232950Stheraven    !is_array<_Yp>::value &&
4551232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4552232950Stheraven    shared_ptr<_Tp>&
4553232950Stheraven>::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
4563232950Stheraventypename enable_if
4564232950Stheraven<
4565232950Stheraven    !is_array<_Yp>::value &&
4566232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4567232950Stheraven    shared_ptr<_Tp>&
4568232950Stheraven>::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
4597232950Stheraventypename enable_if
4598232950Stheraven<
4599232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4600232950Stheraven    void
4601232950Stheraven>::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
4610232950Stheraventypename enable_if
4611232950Stheraven<
4612232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4613232950Stheraven    void
4614232950Stheraven>::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
4623232950Stheraventypename enable_if
4624232950Stheraven<
4625232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4626232950Stheraven    void
4627232950Stheraven>::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
4637232950Stheraventypename enable_if
4638232950Stheraven<
4639232950Stheraven    !is_array<_Tp>::value,
4640232950Stheraven    shared_ptr<_Tp>
4641232950Stheraven>::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
4649232950Stheraventypename enable_if
4650232950Stheraven<
4651232950Stheraven    !is_array<_Tp>::value,
4652232950Stheraven    shared_ptr<_Tp>
4653232950Stheraven>::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{
4748232950Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4749232950Stheraven    return less<_V>()(__x.get(), __y.get());
4750227825Stheraven}
4751227825Stheraven
4752232950Stheraventemplate<class _Tp, class _Up>
4753232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4754232950Stheravenbool
4755232950Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4756232950Stheraven{
4757232950Stheraven    return __y < __x;
4758232950Stheraven}
4759232950Stheraven
4760232950Stheraventemplate<class _Tp, class _Up>
4761232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4762232950Stheravenbool
4763232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4764232950Stheraven{
4765232950Stheraven    return !(__y < __x);
4766232950Stheraven}
4767232950Stheraven
4768232950Stheraventemplate<class _Tp, class _Up>
4769232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4770232950Stheravenbool
4771232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4772232950Stheraven{
4773232950Stheraven    return !(__x < __y);
4774232950Stheraven}
4775232950Stheraven
4776227825Stheraventemplate<class _Tp>
4777227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4778232950Stheravenbool
4779232950Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4780232950Stheraven{
4781232950Stheraven    return !__x;
4782232950Stheraven}
4783232950Stheraven
4784232950Stheraventemplate<class _Tp>
4785232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4786232950Stheravenbool
4787232950Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4788232950Stheraven{
4789232950Stheraven    return !__x;
4790232950Stheraven}
4791232950Stheraven
4792232950Stheraventemplate<class _Tp>
4793232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4794232950Stheravenbool
4795232950Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4796232950Stheraven{
4797232950Stheraven    return static_cast<bool>(__x);
4798232950Stheraven}
4799232950Stheraven
4800232950Stheraventemplate<class _Tp>
4801232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4802232950Stheravenbool
4803232950Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4804232950Stheraven{
4805232950Stheraven    return static_cast<bool>(__x);
4806232950Stheraven}
4807232950Stheraven
4808232950Stheraventemplate<class _Tp>
4809232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4810232950Stheravenbool
4811232950Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4812232950Stheraven{
4813232950Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4814232950Stheraven}
4815232950Stheraven
4816232950Stheraventemplate<class _Tp>
4817232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4818232950Stheravenbool
4819232950Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4820232950Stheraven{
4821232950Stheraven    return less<_Tp*>()(nullptr, __x.get());
4822232950Stheraven}
4823232950Stheraven
4824232950Stheraventemplate<class _Tp>
4825232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4826232950Stheravenbool
4827232950Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4828232950Stheraven{
4829232950Stheraven    return nullptr < __x;
4830232950Stheraven}
4831232950Stheraven
4832232950Stheraventemplate<class _Tp>
4833232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4834232950Stheravenbool
4835232950Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4836232950Stheraven{
4837232950Stheraven    return __x < nullptr;
4838232950Stheraven}
4839232950Stheraven
4840232950Stheraventemplate<class _Tp>
4841232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4842232950Stheravenbool
4843232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4844232950Stheraven{
4845232950Stheraven    return !(nullptr < __x);
4846232950Stheraven}
4847232950Stheraven
4848232950Stheraventemplate<class _Tp>
4849232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4850232950Stheravenbool
4851232950Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4852232950Stheraven{
4853232950Stheraven    return !(__x < nullptr);
4854232950Stheraven}
4855232950Stheraven
4856232950Stheraventemplate<class _Tp>
4857232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4858232950Stheravenbool
4859232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4860232950Stheraven{
4861232950Stheraven    return !(__x < nullptr);
4862232950Stheraven}
4863232950Stheraven
4864232950Stheraventemplate<class _Tp>
4865232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4866232950Stheravenbool
4867232950Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4868232950Stheraven{
4869232950Stheraven    return !(nullptr < __x);
4870232950Stheraven}
4871232950Stheraven
4872232950Stheraventemplate<class _Tp>
4873232950Stheraveninline _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
4882232950Stheraventypename enable_if
4883232950Stheraven<
4884232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4885232950Stheraven    shared_ptr<_Tp>
4886232950Stheraven>::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
4894232950Stheraventypename enable_if
4895232950Stheraven<
4896232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4897232950Stheraven    shared_ptr<_Tp>
4898232950Stheraven>::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>
4906232950Stheraventypename enable_if
4907232950Stheraven<
4908232950Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4909232950Stheraven    shared_ptr<_Tp>
4910232950Stheraven>::type
4911227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4912227825Stheraven{
4913232950Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4914232950Stheraven    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>
4930262801Sdimclass _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:
4939241903Sdim    _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
4948232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4949232950Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4950232950Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4951232950Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4952232950Stheraven                         _NOEXCEPT;
4953232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4954227825Stheraven    ~weak_ptr();
4955227825Stheraven
4956227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4957232950Stheraven    template<class _Yp>
4958232950Stheraven        typename enable_if
4959232950Stheraven        <
4960232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4961232950Stheraven            weak_ptr&
4962232950Stheraven        >::type
4963232950Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4964227825Stheraven
4965232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4966232950Stheraven
4967232950Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4968232950Stheraven    template<class _Yp>
4969232950Stheraven        typename enable_if
4970232950Stheraven        <
4971232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4972232950Stheraven            weak_ptr&
4973232950Stheraven        >::type
4974232950Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4975232950Stheraven
4976232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4977232950Stheraven
4978232950Stheraven    template<class _Yp>
4979232950Stheraven        typename enable_if
4980232950Stheraven        <
4981232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4982232950Stheraven            weak_ptr&
4983232950Stheraven        >::type
4984232950Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4985232950Stheraven
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
5005262801Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5006262801Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
5007227825Stheraven};
5008227825Stheraven
5009227825Stheraventemplate<class _Tp>
5010227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5011241903Sdim_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
5054232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5055232950Stheraven
5056227825Stheraventemplate<class _Tp>
5057232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5058232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5059232950Stheraven    : __ptr_(__r.__ptr_),
5060232950Stheraven      __cntrl_(__r.__cntrl_)
5061232950Stheraven{
5062232950Stheraven    __r.__ptr_ = 0;
5063232950Stheraven    __r.__cntrl_ = 0;
5064232950Stheraven}
5065232950Stheraven
5066232950Stheraventemplate<class _Tp>
5067232950Stheraventemplate<class _Yp>
5068232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5069232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5070232950Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5071232950Stheraven         _NOEXCEPT
5072232950Stheraven    : __ptr_(__r.__ptr_),
5073232950Stheraven      __cntrl_(__r.__cntrl_)
5074232950Stheraven{
5075232950Stheraven    __r.__ptr_ = 0;
5076232950Stheraven    __r.__cntrl_ = 0;
5077232950Stheraven}
5078232950Stheraven
5079232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5080232950Stheraven
5081232950Stheraventemplate<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
5100232950Stheraventypename enable_if
5101232950Stheraven<
5102232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5103232950Stheraven    weak_ptr<_Tp>&
5104232950Stheraven>::type
5105227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5106227825Stheraven{
5107227825Stheraven    weak_ptr(__r).swap(*this);
5108227825Stheraven    return *this;
5109227825Stheraven}
5110227825Stheraven
5111232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5112232950Stheraven
5113227825Stheraventemplate<class _Tp>
5114232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5115232950Stheravenweak_ptr<_Tp>&
5116232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5117232950Stheraven{
5118232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5119232950Stheraven    return *this;
5120232950Stheraven}
5121232950Stheraven
5122232950Stheraventemplate<class _Tp>
5123227825Stheraventemplate<class _Yp>
5124227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5125232950Stheraventypename enable_if
5126232950Stheraven<
5127232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5128232950Stheraven    weak_ptr<_Tp>&
5129232950Stheraven>::type
5130232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5131232950Stheraven{
5132232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5133232950Stheraven    return *this;
5134232950Stheraven}
5135232950Stheraven
5136232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5137232950Stheraven
5138232950Stheraventemplate<class _Tp>
5139232950Stheraventemplate<class _Yp>
5140232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5141232950Stheraventypename enable_if
5142232950Stheraven<
5143232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5144232950Stheraven    weak_ptr<_Tp>&
5145232950Stheraven>::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>
5206262801Sdimstruct _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>
5222262801Sdimstruct _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>
5238262801Sdimclass _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
5239227825Stheraven{
5240227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5241227825Stheravenprotected:
5242241903Sdim    _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>
5263262801Sdimstruct _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
5274232950Stheraventemplate<class _CharT, class _Traits, class _Yp>
5275227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5276227825Stheravenbasic_ostream<_CharT, _Traits>&
5277232950Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5278227825Stheraven
5279278724Sdim#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
5280241903Sdim
5281262801Sdimclass _LIBCPP_TYPE_VIS __sp_mut
5282241903Sdim{
5283242945Stheraven    void* __lx;
5284241903Sdimpublic:
5285241903Sdim    void lock() _NOEXCEPT;
5286241903Sdim    void unlock() _NOEXCEPT;
5287241903Sdim
5288241903Sdimprivate:
5289241903Sdim    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5290241903Sdim    __sp_mut(const __sp_mut&);
5291241903Sdim    __sp_mut& operator=(const __sp_mut&);
5292241903Sdim
5293249998Sdim    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5294241903Sdim};
5295241903Sdim
5296249998Sdim_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5297241903Sdim
5298241903Sdimtemplate <class _Tp>
5299241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5300241903Sdimbool
5301241903Sdimatomic_is_lock_free(const shared_ptr<_Tp>*)
5302241903Sdim{
5303241903Sdim    return false;
5304241903Sdim}
5305241903Sdim
5306241903Sdimtemplate <class _Tp>
5307241903Sdimshared_ptr<_Tp>
5308241903Sdimatomic_load(const shared_ptr<_Tp>* __p)
5309241903Sdim{
5310241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5311241903Sdim    __m.lock();
5312241903Sdim    shared_ptr<_Tp> __q = *__p;
5313241903Sdim    __m.unlock();
5314241903Sdim    return __q;
5315241903Sdim}
5316241903Sdim  
5317241903Sdimtemplate <class _Tp>
5318241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5319241903Sdimshared_ptr<_Tp>
5320241903Sdimatomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5321241903Sdim{
5322241903Sdim    return atomic_load(__p);
5323241903Sdim}
5324241903Sdim
5325241903Sdimtemplate <class _Tp>
5326241903Sdimvoid
5327241903Sdimatomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5328241903Sdim{
5329241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5330241903Sdim    __m.lock();
5331241903Sdim    __p->swap(__r);
5332241903Sdim    __m.unlock();
5333241903Sdim}
5334241903Sdim
5335241903Sdimtemplate <class _Tp>
5336241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5337241903Sdimvoid
5338241903Sdimatomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5339241903Sdim{
5340241903Sdim    atomic_store(__p, __r);
5341241903Sdim}
5342241903Sdim
5343241903Sdimtemplate <class _Tp>
5344241903Sdimshared_ptr<_Tp>
5345241903Sdimatomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5346241903Sdim{
5347241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5348241903Sdim    __m.lock();
5349241903Sdim    __p->swap(__r);
5350241903Sdim    __m.unlock();
5351241903Sdim    return __r;
5352241903Sdim}
5353241903Sdim  
5354241903Sdimtemplate <class _Tp>
5355241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5356241903Sdimshared_ptr<_Tp>
5357241903Sdimatomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5358241903Sdim{
5359241903Sdim    return atomic_exchange(__p, __r);
5360241903Sdim}
5361241903Sdim
5362241903Sdimtemplate <class _Tp>
5363241903Sdimbool
5364241903Sdimatomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5365241903Sdim{
5366241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5367241903Sdim    __m.lock();
5368241903Sdim    if (__p->__owner_equivalent(*__v))
5369241903Sdim    {
5370241903Sdim        *__p = __w;
5371241903Sdim        __m.unlock();
5372241903Sdim        return true;
5373241903Sdim    }
5374241903Sdim    *__v = *__p;
5375241903Sdim    __m.unlock();
5376241903Sdim    return false;
5377241903Sdim}
5378241903Sdim
5379241903Sdimtemplate <class _Tp>
5380241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5381241903Sdimbool
5382241903Sdimatomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5383241903Sdim{
5384241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5385241903Sdim}
5386241903Sdim
5387241903Sdimtemplate <class _Tp>
5388241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5389241903Sdimbool
5390241903Sdimatomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5391241903Sdim                                        shared_ptr<_Tp> __w, memory_order, memory_order)
5392241903Sdim{
5393241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5394241903Sdim}
5395241903Sdim
5396241903Sdimtemplate <class _Tp>
5397241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5398241903Sdimbool
5399241903Sdimatomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5400241903Sdim                                      shared_ptr<_Tp> __w, memory_order, memory_order)
5401241903Sdim{
5402241903Sdim    return atomic_compare_exchange_weak(__p, __v, __w);
5403241903Sdim}
5404241903Sdim
5405278724Sdim#endif  // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
5406241903Sdim
5407227825Stheraven//enum class
5408249998Sdimstruct _LIBCPP_TYPE_VIS pointer_safety
5409227825Stheraven{
5410242945Stheraven    enum __lx
5411227825Stheraven    {
5412227825Stheraven        relaxed,
5413227825Stheraven        preferred,
5414227825Stheraven        strict
5415227825Stheraven    };
5416227825Stheraven
5417242945Stheraven    __lx __v_;
5418227825Stheraven
5419227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5420242945Stheraven    pointer_safety(__lx __v) : __v_(__v) {}
5421227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5422227825Stheraven    operator int() const {return __v_;}
5423227825Stheraven};
5424227825Stheraven
5425262801Sdim_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5426262801Sdim_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5427262801Sdim_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5428262801Sdim_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5429262801Sdim_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
5439262801Sdim_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