memory revision 249998
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===-------------------------- memory ------------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_MEMORY
12227825Stheraven#define _LIBCPP_MEMORY
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    memory synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheravenstruct allocator_arg_t { };
21227825Stheravenconstexpr allocator_arg_t allocator_arg = allocator_arg_t();
22227825Stheraven
23227825Stheraventemplate <class T, class Alloc> struct uses_allocator;
24227825Stheraven
25227825Stheraventemplate <class Ptr>
26227825Stheravenstruct pointer_traits
27227825Stheraven{
28227825Stheraven    typedef Ptr pointer;
29227825Stheraven    typedef <details> element_type;
30227825Stheraven    typedef <details> difference_type;
31227825Stheraven
32227825Stheraven    template <class U> using rebind = <details>;
33227825Stheraven
34227825Stheraven    static pointer pointer_to(<details>);
35227825Stheraven};
36227825Stheraven
37227825Stheraventemplate <class T>
38227825Stheravenstruct pointer_traits<T*>
39227825Stheraven{
40227825Stheraven    typedef T* pointer;
41227825Stheraven    typedef T element_type;
42227825Stheraven    typedef ptrdiff_t difference_type;
43227825Stheraven
44227825Stheraven    template <class U> using rebind = U*;
45227825Stheraven
46227825Stheraven    static pointer pointer_to(<details>) noexcept;
47227825Stheraven};
48227825Stheraven
49227825Stheraventemplate <class Alloc>
50227825Stheravenstruct allocator_traits
51227825Stheraven{
52227825Stheraven    typedef Alloc                        allocator_type;
53227825Stheraven    typedef typename allocator_type::value_type
54227825Stheraven                                         value_type;
55227825Stheraven
56227825Stheraven    typedef Alloc::pointer | value_type* pointer;
57227825Stheraven    typedef Alloc::const_pointer
58227825Stheraven          | pointer_traits<pointer>::rebind<const value_type>
59227825Stheraven                                         const_pointer;
60227825Stheraven    typedef Alloc::void_pointer
61227825Stheraven          | pointer_traits<pointer>::rebind<void>
62227825Stheraven                                         void_pointer;
63227825Stheraven    typedef Alloc::const_void_pointer
64227825Stheraven          | pointer_traits<pointer>::rebind<const void>
65227825Stheraven                                         const_void_pointer;
66227825Stheraven    typedef Alloc::difference_type
67227825Stheraven          | pointer_traits<pointer>::difference_type
68227825Stheraven                                         difference_type;
69227825Stheraven    typedef Alloc::size_type
70227825Stheraven          | make_unsigned<difference_type>::type
71227825Stheraven                                         size_type;
72227825Stheraven    typedef Alloc::propagate_on_container_copy_assignment
73227825Stheraven          | false_type                   propagate_on_container_copy_assignment;
74227825Stheraven    typedef Alloc::propagate_on_container_move_assignment
75227825Stheraven          | false_type                   propagate_on_container_move_assignment;
76227825Stheraven    typedef Alloc::propagate_on_container_swap
77227825Stheraven          | false_type                   propagate_on_container_swap;
78227825Stheraven
79227825Stheraven    template <class T> using rebind_alloc  = Alloc::rebind<U>::other | Alloc<T, Args...>;
80227825Stheraven    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
81227825Stheraven
82227825Stheraven    static pointer allocate(allocator_type& a, size_type n);
83227825Stheraven    static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
84227825Stheraven
85227825Stheraven    static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
86227825Stheraven
87227825Stheraven    template <class T, class... Args>
88227825Stheraven        static void construct(allocator_type& a, T* p, Args&&... args);
89227825Stheraven
90227825Stheraven    template <class T>
91227825Stheraven        static void destroy(allocator_type& a, T* p);
92227825Stheraven
93227825Stheraven    static size_type max_size(const allocator_type& a);
94227825Stheraven
95227825Stheraven    static allocator_type
96227825Stheraven        select_on_container_copy_construction(const allocator_type& a);
97227825Stheraven};
98227825Stheraven
99227825Stheraventemplate <>
100227825Stheravenclass allocator<void>
101227825Stheraven{
102227825Stheravenpublic:
103227825Stheraven    typedef void*                                 pointer;
104227825Stheraven    typedef const void*                           const_pointer;
105227825Stheraven    typedef void                                  value_type;
106227825Stheraven
107227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
108227825Stheraven};
109227825Stheraven
110227825Stheraventemplate <class T>
111227825Stheravenclass allocator
112227825Stheraven{
113227825Stheravenpublic:
114227825Stheraven    typedef size_t                                size_type;
115227825Stheraven    typedef ptrdiff_t                             difference_type;
116227825Stheraven    typedef T*                                    pointer;
117227825Stheraven    typedef const T*                              const_pointer;
118227825Stheraven    typedef typename add_lvalue_reference<T>::type       reference;
119227825Stheraven    typedef typename add_lvalue_reference<const T>::type const_reference;
120227825Stheraven    typedef T                                     value_type;
121227825Stheraven
122227825Stheraven    template <class U> struct rebind {typedef allocator<U> other;};
123227825Stheraven
124227825Stheraven    allocator() noexcept;
125227825Stheraven    allocator(const allocator&) noexcept;
126227825Stheraven    template <class U> allocator(const allocator<U>&) noexcept;
127227825Stheraven    ~allocator();
128227825Stheraven    pointer address(reference x) const noexcept;
129227825Stheraven    const_pointer address(const_reference x) const noexcept;
130227825Stheraven    pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
131227825Stheraven    void deallocate(pointer p, size_type n) noexcept;
132227825Stheraven    size_type max_size() const noexcept;
133227825Stheraven    template<class U, class... Args>
134227825Stheraven        void construct(U* p, Args&&... args);
135227825Stheraven    template <class U>
136227825Stheraven        void destroy(U* p);
137227825Stheraven};
138227825Stheraven
139227825Stheraventemplate <class T, class U>
140227825Stheravenbool operator==(const allocator<T>&, const allocator<U>&) noexcept;
141227825Stheraven
142227825Stheraventemplate <class T, class U>
143227825Stheravenbool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
144227825Stheraven
145227825Stheraventemplate <class OutputIterator, class T>
146227825Stheravenclass raw_storage_iterator
147227825Stheraven    : public iterator<output_iterator_tag,
148227825Stheraven                      T,                               // purposefully not C++03
149227825Stheraven                      ptrdiff_t,                       // purposefully not C++03
150227825Stheraven                      T*,                              // purposefully not C++03
151227825Stheraven                      raw_storage_iterator&>           // purposefully not C++03
152227825Stheraven{
153227825Stheravenpublic:
154227825Stheraven    explicit raw_storage_iterator(OutputIterator x);
155227825Stheraven    raw_storage_iterator& operator*();
156227825Stheraven    raw_storage_iterator& operator=(const T& element);
157227825Stheraven    raw_storage_iterator& operator++();
158227825Stheraven    raw_storage_iterator  operator++(int);
159227825Stheraven};
160227825Stheraven
161227825Stheraventemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162227825Stheraventemplate <class T> void               return_temporary_buffer(T* p) noexcept;
163227825Stheraven
164227825Stheraventemplate <class T> T* addressof(T& r) noexcept;
165227825Stheraven
166227825Stheraventemplate <class InputIterator, class ForwardIterator>
167227825StheravenForwardIterator
168227825Stheravenuninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
169227825Stheraven
170227825Stheraventemplate <class InputIterator, class Size, class ForwardIterator>
171227825StheravenForwardIterator
172227825Stheravenuninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
173227825Stheraven
174227825Stheraventemplate <class ForwardIterator, class T>
175227825Stheravenvoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
176227825Stheraven
177227825Stheraventemplate <class ForwardIterator, class Size, class T>
178227825StheravenForwardIterator
179227825Stheravenuninitialized_fill_n(ForwardIterator first, Size n, const T& x);
180227825Stheraven
181227825Stheraventemplate <class Y> struct auto_ptr_ref {};
182227825Stheraven
183227825Stheraventemplate<class X>
184227825Stheravenclass auto_ptr
185227825Stheraven{
186227825Stheravenpublic:
187227825Stheraven    typedef X element_type;
188227825Stheraven
189227825Stheraven    explicit auto_ptr(X* p =0) throw();
190227825Stheraven    auto_ptr(auto_ptr&) throw();
191227825Stheraven    template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192227825Stheraven    auto_ptr& operator=(auto_ptr&) throw();
193227825Stheraven    template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194227825Stheraven    auto_ptr& operator=(auto_ptr_ref<X> r) throw();
195227825Stheraven    ~auto_ptr() throw();
196227825Stheraven
197227825Stheraven    typename add_lvalue_reference<X>::type operator*() const throw();
198227825Stheraven    X* operator->() const throw();
199227825Stheraven    X* get() const throw();
200227825Stheraven    X* release() throw();
201227825Stheraven    void reset(X* p =0) throw();
202227825Stheraven
203227825Stheraven    auto_ptr(auto_ptr_ref<X>) throw();
204227825Stheraven    template<class Y> operator auto_ptr_ref<Y>() throw();
205227825Stheraven    template<class Y> operator auto_ptr<Y>() throw();
206227825Stheraven};
207227825Stheraven
208227825Stheraventemplate <class T>
209227825Stheravenstruct default_delete
210227825Stheraven{
211227825Stheraven    constexpr default_delete() noexcept = default;
212227825Stheraven    template <class U> default_delete(const default_delete<U>&) noexcept;
213227825Stheraven
214227825Stheraven    void operator()(T*) const noexcept;
215227825Stheraven};
216227825Stheraven
217227825Stheraventemplate <class T>
218227825Stheravenstruct default_delete<T[]>
219227825Stheraven{
220227825Stheraven    constexpr default_delete() noexcept = default;
221227825Stheraven    void operator()(T*) const noexcept;
222227825Stheraven    template <class U> void operator()(U*) const = delete;
223227825Stheraven};
224227825Stheraven
225227825Stheraventemplate <class T, class D = default_delete<T>>
226227825Stheravenclass unique_ptr
227227825Stheraven{
228227825Stheravenpublic:
229227825Stheraven    typedef see below pointer;
230227825Stheraven    typedef T element_type;
231227825Stheraven    typedef D deleter_type;
232227825Stheraven
233227825Stheraven    // constructors
234227825Stheraven    constexpr unique_ptr() noexcept;
235227825Stheraven    explicit unique_ptr(pointer p) noexcept;
236227825Stheraven    unique_ptr(pointer p, see below d1) noexcept;
237227825Stheraven    unique_ptr(pointer p, see below d2) noexcept;
238227825Stheraven    unique_ptr(unique_ptr&& u) noexcept;
239227825Stheraven    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
240227825Stheraven    template <class U, class E>
241227825Stheraven        unique_ptr(unique_ptr<U, E>&& u) noexcept;
242227825Stheraven    template <class U>
243227825Stheraven        unique_ptr(auto_ptr<U>&& u) noexcept;
244227825Stheraven
245227825Stheraven    // destructor
246227825Stheraven    ~unique_ptr();
247227825Stheraven
248227825Stheraven    // assignment
249227825Stheraven    unique_ptr& operator=(unique_ptr&& u) noexcept;
250227825Stheraven    template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251227825Stheraven    unique_ptr& operator=(nullptr_t) noexcept;
252227825Stheraven
253227825Stheraven    // observers
254227825Stheraven    typename add_lvalue_reference<T>::type operator*() const;
255227825Stheraven    pointer operator->() const noexcept;
256227825Stheraven    pointer get() const noexcept;
257227825Stheraven    deleter_type& get_deleter() noexcept;
258227825Stheraven    const deleter_type& get_deleter() const noexcept;
259227825Stheraven    explicit operator bool() const noexcept;
260227825Stheraven
261227825Stheraven    // modifiers
262227825Stheraven    pointer release() noexcept;
263227825Stheraven    void reset(pointer p = pointer()) noexcept;
264227825Stheraven    void swap(unique_ptr& u) noexcept;
265227825Stheraven};
266227825Stheraven
267227825Stheraventemplate <class T, class D>
268227825Stheravenclass unique_ptr<T[], D>
269227825Stheraven{
270227825Stheravenpublic:
271227825Stheraven    typedef implementation-defined pointer;
272227825Stheraven    typedef T element_type;
273227825Stheraven    typedef D deleter_type;
274227825Stheraven
275227825Stheraven    // constructors
276227825Stheraven    constexpr unique_ptr() noexcept;
277227825Stheraven    explicit unique_ptr(pointer p) noexcept;
278227825Stheraven    unique_ptr(pointer p, see below d) noexcept;
279227825Stheraven    unique_ptr(pointer p, see below d) noexcept;
280227825Stheraven    unique_ptr(unique_ptr&& u) noexcept;
281227825Stheraven    unique_ptr(nullptr_t) noexcept : unique_ptr() { }
282227825Stheraven
283227825Stheraven    // destructor
284227825Stheraven    ~unique_ptr();
285227825Stheraven
286227825Stheraven    // assignment
287227825Stheraven    unique_ptr& operator=(unique_ptr&& u) noexcept;
288227825Stheraven    unique_ptr& operator=(nullptr_t) noexcept;
289227825Stheraven
290227825Stheraven    // observers
291227825Stheraven    T& operator[](size_t i) const;
292227825Stheraven    pointer get() const noexcept;
293227825Stheraven    deleter_type& get_deleter() noexcept;
294227825Stheraven    const deleter_type& get_deleter() const noexcept;
295227825Stheraven    explicit operator bool() const noexcept;
296227825Stheraven
297227825Stheraven    // modifiers
298227825Stheraven    pointer release() noexcept;
299227825Stheraven    void reset(pointer p = pointer()) noexcept;
300227825Stheraven    void reset(nullptr_t) noexcept;
301227825Stheraven    template <class U> void reset(U) = delete;
302227825Stheraven    void swap(unique_ptr& u) noexcept;
303227825Stheraven};
304227825Stheraven
305227825Stheraventemplate <class T, class D>
306227825Stheraven    void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
307227825Stheraven
308227825Stheraventemplate <class T1, class D1, class T2, class D2>
309227825Stheraven    bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
310227825Stheraventemplate <class T1, class D1, class T2, class D2>
311227825Stheraven    bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312227825Stheraventemplate <class T1, class D1, class T2, class D2>
313227825Stheraven    bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314227825Stheraventemplate <class T1, class D1, class T2, class D2>
315227825Stheraven    bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316227825Stheraventemplate <class T1, class D1, class T2, class D2>
317227825Stheraven    bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318227825Stheraventemplate <class T1, class D1, class T2, class D2>
319227825Stheraven    bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
320227825Stheraven
321227825Stheraventemplate <class T, class D>
322227825Stheraven    bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323227825Stheraventemplate <class T, class D>
324227825Stheraven    bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325227825Stheraventemplate <class T, class D>
326227825Stheraven    bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327227825Stheraventemplate <class T, class D>
328227825Stheraven    bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
329227825Stheraven
330227825Stheraventemplate <class T, class D>
331227825Stheraven    bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332227825Stheraventemplate <class T, class D>
333227825Stheraven    bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334227825Stheraventemplate <class T, class D>
335227825Stheraven    bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336227825Stheraventemplate <class T, class D>
337227825Stheraven    bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338227825Stheraventemplate <class T, class D>
339227825Stheraven    bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340227825Stheraventemplate <class T, class D>
341227825Stheraven    bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342227825Stheraventemplate <class T, class D>
343227825Stheraven    bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344227825Stheraventemplate <class T, class D>
345227825Stheraven    bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
346227825Stheraven
347227825Stheravenclass bad_weak_ptr
348227825Stheraven    : public std::exception
349227825Stheraven{
350227825Stheraven    bad_weak_ptr() noexcept;
351227825Stheraven};
352227825Stheraven
353227825Stheraventemplate<class T>
354227825Stheravenclass shared_ptr
355227825Stheraven{
356227825Stheravenpublic:
357227825Stheraven    typedef T element_type;
358227825Stheraven
359227825Stheraven    // constructors:
360227825Stheraven    constexpr shared_ptr() noexcept;
361227825Stheraven    template<class Y> explicit shared_ptr(Y* p);
362227825Stheraven    template<class Y, class D> shared_ptr(Y* p, D d);
363227825Stheraven    template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
364227825Stheraven    template <class D> shared_ptr(nullptr_t p, D d);
365227825Stheraven    template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
366227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
367227825Stheraven    shared_ptr(const shared_ptr& r) noexcept;
368227825Stheraven    template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
369227825Stheraven    shared_ptr(shared_ptr&& r) noexcept;
370227825Stheraven    template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
371227825Stheraven    template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
372227825Stheraven    template<class Y> shared_ptr(auto_ptr<Y>&& r);
373227825Stheraven    template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
374227825Stheraven    shared_ptr(nullptr_t) : shared_ptr() { }
375227825Stheraven
376227825Stheraven    // destructor:
377227825Stheraven    ~shared_ptr();
378227825Stheraven
379227825Stheraven    // assignment:
380227825Stheraven    shared_ptr& operator=(const shared_ptr& r) noexcept;
381227825Stheraven    template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
382227825Stheraven    shared_ptr& operator=(shared_ptr&& r) noexcept;
383227825Stheraven    template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
384227825Stheraven    template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
385227825Stheraven    template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
386227825Stheraven
387227825Stheraven    // modifiers:
388227825Stheraven    void swap(shared_ptr& r) noexcept;
389227825Stheraven    void reset() noexcept;
390227825Stheraven    template<class Y> void reset(Y* p);
391227825Stheraven    template<class Y, class D> void reset(Y* p, D d);
392227825Stheraven    template<class Y, class D, class A> void reset(Y* p, D d, A a);
393227825Stheraven
394227825Stheraven    // observers:
395227825Stheraven    T* get() const noexcept;
396227825Stheraven    T& operator*() const noexcept;
397227825Stheraven    T* operator->() const noexcept;
398227825Stheraven    long use_count() const noexcept;
399227825Stheraven    bool unique() const noexcept;
400227825Stheraven    explicit operator bool() const noexcept;
401227825Stheraven    template<class U> bool owner_before(shared_ptr<U> const& b) const;
402227825Stheraven    template<class U> bool owner_before(weak_ptr<U> const& b) const;
403227825Stheraven};
404227825Stheraven
405227825Stheraven// shared_ptr comparisons:
406227825Stheraventemplate<class T, class U>
407227825Stheraven    bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
408227825Stheraventemplate<class T, class U>
409227825Stheraven    bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
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;
418227825Stheraven
419227825Stheraventemplate <class T>
420227825Stheraven    bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
421227825Stheraventemplate <class T>
422227825Stheraven    bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
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>
430227825Stheravenbool 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>
434227825Stheraven    bool 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;
443227825Stheraven
444227825Stheraven// shared_ptr specialized algorithms:
445227825Stheraventemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
446227825Stheraven
447227825Stheraven// shared_ptr casts:
448227825Stheraventemplate<class T, class U>
449227825Stheraven    shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
450227825Stheraventemplate<class T, class U>
451227825Stheraven    shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
452227825Stheraventemplate<class T, class U>
453227825Stheraven    shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
454227825Stheraven
455227825Stheraven// shared_ptr I/O:
456227825Stheraventemplate<class E, class T, class Y>
457227825Stheraven    basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
458227825Stheraven
459227825Stheraven// shared_ptr get_deleter:
460227825Stheraventemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
461227825Stheraven
462227825Stheraventemplate<class T, class... Args>
463227825Stheraven    shared_ptr<T> make_shared(Args&&... args);
464227825Stheraventemplate<class T, class A, class... Args>
465227825Stheraven    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
466227825Stheraven
467227825Stheraventemplate<class T>
468227825Stheravenclass weak_ptr
469227825Stheraven{
470227825Stheravenpublic:
471227825Stheraven    typedef T element_type;
472227825Stheraven
473227825Stheraven    // constructors
474227825Stheraven    constexpr weak_ptr() noexcept;
475227825Stheraven    template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
476227825Stheraven    weak_ptr(weak_ptr const& r) noexcept;
477227825Stheraven    template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
478227825Stheraven
479227825Stheraven    // destructor
480227825Stheraven    ~weak_ptr();
481227825Stheraven
482227825Stheraven    // assignment
483227825Stheraven    weak_ptr& operator=(weak_ptr const& r) noexcept;
484227825Stheraven    template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
485227825Stheraven    template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
486227825Stheraven
487227825Stheraven    // modifiers
488227825Stheraven    void swap(weak_ptr& r) noexcept;
489227825Stheraven    void reset() noexcept;
490227825Stheraven
491227825Stheraven    // observers
492227825Stheraven    long use_count() const noexcept;
493227825Stheraven    bool expired() const noexcept;
494227825Stheraven    shared_ptr<T> lock() const noexcept;
495227825Stheraven    template<class U> bool owner_before(shared_ptr<U> const& b);
496227825Stheraven    template<class U> bool owner_before(weak_ptr<U> const& b);
497227825Stheraven};
498227825Stheraven
499227825Stheraven// weak_ptr specialized algorithms:
500227825Stheraventemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
501227825Stheraven
502227825Stheraven// class owner_less:
503227825Stheraventemplate<class T> struct owner_less;
504227825Stheraven
505227825Stheraventemplate<class T>
506227825Stheravenstruct owner_less<shared_ptr<T>>
507227825Stheraven    : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
508227825Stheraven{
509227825Stheraven    typedef bool result_type;
510227825Stheraven    bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
511227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
512227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
513227825Stheraven};
514227825Stheraven
515227825Stheraventemplate<class T>
516227825Stheravenstruct owner_less<weak_ptr<T>>
517227825Stheraven    : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
518227825Stheraven{
519227825Stheraven    typedef bool result_type;
520227825Stheraven    bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
521227825Stheraven    bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
522227825Stheraven    bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
523227825Stheraven};
524227825Stheraven
525227825Stheraventemplate<class T>
526227825Stheravenclass enable_shared_from_this
527227825Stheraven{
528227825Stheravenprotected:
529227825Stheraven    constexpr enable_shared_from_this() noexcept;
530227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) noexcept;
531227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
532227825Stheraven    ~enable_shared_from_this();
533227825Stheravenpublic:
534227825Stheraven    shared_ptr<T> shared_from_this();
535227825Stheraven    shared_ptr<T const> shared_from_this() const;
536227825Stheraven};
537227825Stheraven
538227825Stheraventemplate<class T>
539227825Stheraven    bool atomic_is_lock_free(const shared_ptr<T>* p);
540227825Stheraventemplate<class T>
541227825Stheraven    shared_ptr<T> atomic_load(const shared_ptr<T>* p);
542227825Stheraventemplate<class T>
543227825Stheraven    shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
544227825Stheraventemplate<class T>
545227825Stheraven    void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
546227825Stheraventemplate<class T>
547227825Stheraven    void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
548227825Stheraventemplate<class T>
549227825Stheraven    shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
550227825Stheraventemplate<class T>
551227825Stheraven    shared_ptr<T>
552227825Stheraven    atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
553227825Stheraventemplate<class T>
554227825Stheraven    bool
555227825Stheraven    atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
556227825Stheraventemplate<class T>
557227825Stheraven    bool
558227825Stheraven    atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
559227825Stheraventemplate<class T>
560227825Stheraven    bool
561227825Stheraven    atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
562227825Stheraven                                          shared_ptr<T> w, memory_order success,
563227825Stheraven                                          memory_order failure);
564227825Stheraventemplate<class T>
565227825Stheraven    bool
566227825Stheraven    atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
567227825Stheraven                                            shared_ptr<T> w, memory_order success,
568227825Stheraven                                            memory_order failure);
569227825Stheraven// Hash support
570227825Stheraventemplate <class T> struct hash;
571227825Stheraventemplate <class T, class D> struct hash<unique_ptr<T, D> >;
572227825Stheraventemplate <class T> struct hash<shared_ptr<T> >;
573227825Stheraven
574227825Stheraven// Pointer safety
575227825Stheravenenum class pointer_safety { relaxed, preferred, strict };
576227825Stheravenvoid declare_reachable(void *p);
577227825Stheraventemplate <class T> T *undeclare_reachable(T *p);
578227825Stheravenvoid declare_no_pointers(char *p, size_t n);
579227825Stheravenvoid undeclare_no_pointers(char *p, size_t n);
580227825Stheravenpointer_safety get_pointer_safety() noexcept;
581227825Stheraven
582227825Stheravenvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space);
583227825Stheraven
584227825Stheraven}  // std
585227825Stheraven
586227825Stheraven*/
587227825Stheraven
588227825Stheraven#include <__config>
589227825Stheraven#include <type_traits>
590227825Stheraven#include <typeinfo>
591227825Stheraven#include <cstddef>
592227825Stheraven#include <cstdint>
593227825Stheraven#include <new>
594227825Stheraven#include <utility>
595227825Stheraven#include <limits>
596227825Stheraven#include <iterator>
597227825Stheraven#include <__functional_base>
598227825Stheraven#include <iosfwd>
599232950Stheraven#include <tuple>
600232950Stheraven#include <cstring>
601227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS)
602227825Stheraven    #include <cassert>
603227825Stheraven#endif
604227825Stheraven
605241903Sdim#if __has_feature(cxx_atomic)
606241903Sdim#  include <atomic>
607241903Sdim#endif
608241903Sdim
609232950Stheraven#include <__undef_min_max>
610232950Stheraven
611227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
612227825Stheraven#pragma GCC system_header
613227825Stheraven#endif
614227825Stheraven
615227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
616227825Stheraven
617227825Stheraven// addressof
618227825Stheraven
619227825Stheraventemplate <class _Tp>
620227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
621227825Stheraven_Tp*
622227825Stheravenaddressof(_Tp& __x) _NOEXCEPT
623227825Stheraven{
624249998Sdim    return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
625227825Stheraven}
626227825Stheraven
627227825Stheraven#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
628227825Stheraven// Objective-C++ Automatic Reference Counting uses qualified pointers
629227825Stheraven// that require special addressof() signatures. When
630227825Stheraven// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
631227825Stheraven// itself is providing these definitions. Otherwise, we provide them.
632227825Stheraventemplate <class _Tp>
633227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
634227825Stheraven__strong _Tp*
635227825Stheravenaddressof(__strong _Tp& __x) _NOEXCEPT
636227825Stheraven{
637227825Stheraven  return &__x;
638227825Stheraven}
639227825Stheraven
640227825Stheraven#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
641227825Stheraventemplate <class _Tp>
642227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
643227825Stheraven__weak _Tp*
644227825Stheravenaddressof(__weak _Tp& __x) _NOEXCEPT
645227825Stheraven{
646227825Stheraven  return &__x;
647227825Stheraven}
648227825Stheraven#endif
649227825Stheraven
650227825Stheraventemplate <class _Tp>
651227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
652227825Stheraven__autoreleasing _Tp*
653227825Stheravenaddressof(__autoreleasing _Tp& __x) _NOEXCEPT
654227825Stheraven{
655227825Stheraven  return &__x;
656227825Stheraven}
657227825Stheraven
658227825Stheraventemplate <class _Tp>
659227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
660227825Stheraven__unsafe_unretained _Tp*
661227825Stheravenaddressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
662227825Stheraven{
663227825Stheraven  return &__x;
664227825Stheraven}
665227825Stheraven#endif
666227825Stheraven
667227825Stheraventemplate <class _Tp> class allocator;
668227825Stheraven
669227825Stheraventemplate <>
670249998Sdimclass _LIBCPP_TYPE_VIS allocator<void>
671227825Stheraven{
672227825Stheravenpublic:
673227825Stheraven    typedef void*             pointer;
674227825Stheraven    typedef const void*       const_pointer;
675227825Stheraven    typedef void              value_type;
676227825Stheraven
677227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
678227825Stheraven};
679227825Stheraven
680232950Stheraventemplate <>
681249998Sdimclass _LIBCPP_TYPE_VIS allocator<const void>
682232950Stheraven{
683232950Stheravenpublic:
684232950Stheraven    typedef const void*       pointer;
685232950Stheraven    typedef const void*       const_pointer;
686232950Stheraven    typedef const void        value_type;
687232950Stheraven
688232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
689232950Stheraven};
690232950Stheraven
691227825Stheraven// pointer_traits
692227825Stheraven
693227825Stheraventemplate <class _Tp>
694227825Stheravenstruct __has_element_type
695227825Stheraven{
696227825Stheravenprivate:
697242945Stheraven    struct __two {char __lx; char __lxx;};
698227825Stheraven    template <class _Up> static __two __test(...);
699227825Stheraven    template <class _Up> static char __test(typename _Up::element_type* = 0);
700227825Stheravenpublic:
701227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
702227825Stheraven};
703227825Stheraven
704227825Stheraventemplate <class _Ptr, bool = __has_element_type<_Ptr>::value>
705227825Stheravenstruct __pointer_traits_element_type;
706227825Stheraven
707227825Stheraventemplate <class _Ptr>
708227825Stheravenstruct __pointer_traits_element_type<_Ptr, true>
709227825Stheraven{
710227825Stheraven    typedef typename _Ptr::element_type type;
711227825Stheraven};
712227825Stheraven
713227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
714227825Stheraven
715227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
716227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
717227825Stheraven{
718227825Stheraven    typedef typename _Sp<_Tp, _Args...>::element_type type;
719227825Stheraven};
720227825Stheraven
721227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
722227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
723227825Stheraven{
724227825Stheraven    typedef _Tp type;
725227825Stheraven};
726227825Stheraven
727227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
728227825Stheraven
729227825Stheraventemplate <template <class> class _Sp, class _Tp>
730227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, true>
731227825Stheraven{
732227825Stheraven    typedef typename _Sp<_Tp>::element_type type;
733227825Stheraven};
734227825Stheraven
735227825Stheraventemplate <template <class> class _Sp, class _Tp>
736227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, false>
737227825Stheraven{
738227825Stheraven    typedef _Tp type;
739227825Stheraven};
740227825Stheraven
741227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
742227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
743227825Stheraven{
744227825Stheraven    typedef typename _Sp<_Tp, _A0>::element_type type;
745227825Stheraven};
746227825Stheraven
747227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
748227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
749227825Stheraven{
750227825Stheraven    typedef _Tp type;
751227825Stheraven};
752227825Stheraven
753227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
754227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
755227825Stheraven{
756227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
757227825Stheraven};
758227825Stheraven
759227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
760227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
761227825Stheraven{
762227825Stheraven    typedef _Tp type;
763227825Stheraven};
764227825Stheraven
765227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
766227825Stheraven                                                           class _A1, class _A2>
767227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
768227825Stheraven{
769227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
770227825Stheraven};
771227825Stheraven
772227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
773227825Stheraven                                                           class _A1, class _A2>
774227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
775227825Stheraven{
776227825Stheraven    typedef _Tp type;
777227825Stheraven};
778227825Stheraven
779227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
780227825Stheraven
781227825Stheraventemplate <class _Tp>
782227825Stheravenstruct __has_difference_type
783227825Stheraven{
784227825Stheravenprivate:
785242945Stheraven    struct __two {char __lx; char __lxx;};
786227825Stheraven    template <class _Up> static __two __test(...);
787227825Stheraven    template <class _Up> static char __test(typename _Up::difference_type* = 0);
788227825Stheravenpublic:
789227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
790227825Stheraven};
791227825Stheraven
792227825Stheraventemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value>
793227825Stheravenstruct __pointer_traits_difference_type
794227825Stheraven{
795227825Stheraven    typedef ptrdiff_t type;
796227825Stheraven};
797227825Stheraven
798227825Stheraventemplate <class _Ptr>
799227825Stheravenstruct __pointer_traits_difference_type<_Ptr, true>
800227825Stheraven{
801227825Stheraven    typedef typename _Ptr::difference_type type;
802227825Stheraven};
803227825Stheraven
804227825Stheraventemplate <class _Tp, class _Up>
805227825Stheravenstruct __has_rebind
806227825Stheraven{
807227825Stheravenprivate:
808242945Stheraven    struct __two {char __lx; char __lxx;};
809227825Stheraven    template <class _Xp> static __two __test(...);
810227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
811227825Stheravenpublic:
812227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
813227825Stheraven};
814227825Stheraven
815227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
816227825Stheravenstruct __pointer_traits_rebind
817227825Stheraven{
818227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
819227825Stheraven    typedef typename _Tp::template rebind<_Up> type;
820227825Stheraven#else
821227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
822227825Stheraven#endif
823227825Stheraven};
824227825Stheraven
825227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
826227825Stheraven
827227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
828227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
829227825Stheraven{
830227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
831227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
832227825Stheraven#else
833227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
834227825Stheraven#endif
835227825Stheraven};
836227825Stheraven
837227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
838227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
839227825Stheraven{
840227825Stheraven    typedef _Sp<_Up, _Args...> type;
841227825Stheraven};
842227825Stheraven
843227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
844227825Stheraven
845227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
846227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
847227825Stheraven{
848227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
849227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up> type;
850227825Stheraven#else
851227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
852227825Stheraven#endif
853227825Stheraven};
854227825Stheraven
855227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
856227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
857227825Stheraven{
858227825Stheraven    typedef _Sp<_Up> type;
859227825Stheraven};
860227825Stheraven
861227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
862227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
863227825Stheraven{
864227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
865227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
866227825Stheraven#else
867227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
868227825Stheraven#endif
869227825Stheraven};
870227825Stheraven
871227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
872227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
873227825Stheraven{
874227825Stheraven    typedef _Sp<_Up, _A0> type;
875227825Stheraven};
876227825Stheraven
877227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
878227825Stheraven                                         class _A1, class _Up>
879227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
880227825Stheraven{
881227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
882227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
883227825Stheraven#else
884227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
885227825Stheraven#endif
886227825Stheraven};
887227825Stheraven
888227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
889227825Stheraven                                         class _A1, class _Up>
890227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
891227825Stheraven{
892227825Stheraven    typedef _Sp<_Up, _A0, _A1> type;
893227825Stheraven};
894227825Stheraven
895227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
896227825Stheraven                                                class _A1, class _A2, class _Up>
897227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
898227825Stheraven{
899227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
900227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
901227825Stheraven#else
902227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
903227825Stheraven#endif
904227825Stheraven};
905227825Stheraven
906227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
907227825Stheraven                                                class _A1, class _A2, class _Up>
908227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
909227825Stheraven{
910227825Stheraven    typedef _Sp<_Up, _A0, _A1, _A2> type;
911227825Stheraven};
912227825Stheraven
913227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
914227825Stheraven
915227825Stheraventemplate <class _Ptr>
916249998Sdimstruct _LIBCPP_TYPE_VIS pointer_traits
917227825Stheraven{
918227825Stheraven    typedef _Ptr                                                     pointer;
919227825Stheraven    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
920227825Stheraven    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
921227825Stheraven
922227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
923227825Stheraven    template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
924227825Stheraven#else
925227825Stheraven    template <class _Up> struct rebind
926227825Stheraven        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
927227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
928227825Stheraven
929227825Stheravenprivate:
930227825Stheraven    struct __nat {};
931227825Stheravenpublic:
932227825Stheraven    _LIBCPP_INLINE_VISIBILITY
933227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
934227825Stheraven                                           __nat, element_type>::type& __r)
935227825Stheraven        {return pointer::pointer_to(__r);}
936227825Stheraven};
937227825Stheraven
938227825Stheraventemplate <class _Tp>
939249998Sdimstruct _LIBCPP_TYPE_VIS pointer_traits<_Tp*>
940227825Stheraven{
941227825Stheraven    typedef _Tp*      pointer;
942227825Stheraven    typedef _Tp       element_type;
943227825Stheraven    typedef ptrdiff_t difference_type;
944227825Stheraven
945227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
946227825Stheraven    template <class _Up> using rebind = _Up*;
947227825Stheraven#else
948227825Stheraven    template <class _Up> struct rebind {typedef _Up* other;};
949227825Stheraven#endif
950227825Stheraven
951227825Stheravenprivate:
952227825Stheraven    struct __nat {};
953227825Stheravenpublic:
954227825Stheraven    _LIBCPP_INLINE_VISIBILITY
955227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
956227825Stheraven                                      __nat, element_type>::type& __r) _NOEXCEPT
957227825Stheraven        {return _VSTD::addressof(__r);}
958227825Stheraven};
959227825Stheraven
960227825Stheraven// allocator_traits
961227825Stheraven
962227825Stheravennamespace __has_pointer_type_imp
963227825Stheraven{
964227825Stheraven    template <class _Up> static __two test(...);
965227825Stheraven    template <class _Up> static char test(typename _Up::pointer* = 0);
966227825Stheraven}
967227825Stheraven
968227825Stheraventemplate <class _Tp>
969227825Stheravenstruct __has_pointer_type
970227825Stheraven    : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
971227825Stheraven{
972227825Stheraven};
973227825Stheraven
974227825Stheravennamespace __pointer_type_imp
975227825Stheraven{
976227825Stheraven
977227825Stheraventemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
978227825Stheravenstruct __pointer_type
979227825Stheraven{
980227825Stheraven    typedef typename _Dp::pointer type;
981227825Stheraven};
982227825Stheraven
983227825Stheraventemplate <class _Tp, class _Dp>
984227825Stheravenstruct __pointer_type<_Tp, _Dp, false>
985227825Stheraven{
986227825Stheraven    typedef _Tp* type;
987227825Stheraven};
988227825Stheraven
989227825Stheraven}  // __pointer_type_imp
990227825Stheraven
991227825Stheraventemplate <class _Tp, class _Dp>
992227825Stheravenstruct __pointer_type
993227825Stheraven{
994227825Stheraven    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
995227825Stheraven};
996227825Stheraven
997227825Stheraventemplate <class _Tp>
998227825Stheravenstruct __has_const_pointer
999227825Stheraven{
1000227825Stheravenprivate:
1001242945Stheraven    struct __two {char __lx; char __lxx;};
1002227825Stheraven    template <class _Up> static __two __test(...);
1003227825Stheraven    template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1004227825Stheravenpublic:
1005227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1006227825Stheraven};
1007227825Stheraven
1008227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1009227825Stheravenstruct __const_pointer
1010227825Stheraven{
1011227825Stheraven    typedef typename _Alloc::const_pointer type;
1012227825Stheraven};
1013227825Stheraven
1014227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc>
1015227825Stheravenstruct __const_pointer<_Tp, _Ptr, _Alloc, false>
1016227825Stheraven{
1017227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1018227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1019227825Stheraven#else
1020227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1021227825Stheraven#endif
1022227825Stheraven};
1023227825Stheraven
1024227825Stheraventemplate <class _Tp>
1025227825Stheravenstruct __has_void_pointer
1026227825Stheraven{
1027227825Stheravenprivate:
1028242945Stheraven    struct __two {char __lx; char __lxx;};
1029227825Stheraven    template <class _Up> static __two __test(...);
1030227825Stheraven    template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1031227825Stheravenpublic:
1032227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1033227825Stheraven};
1034227825Stheraven
1035227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1036227825Stheravenstruct __void_pointer
1037227825Stheraven{
1038227825Stheraven    typedef typename _Alloc::void_pointer type;
1039227825Stheraven};
1040227825Stheraven
1041227825Stheraventemplate <class _Ptr, class _Alloc>
1042227825Stheravenstruct __void_pointer<_Ptr, _Alloc, false>
1043227825Stheraven{
1044227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1045227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1046227825Stheraven#else
1047227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1048227825Stheraven#endif
1049227825Stheraven};
1050227825Stheraven
1051227825Stheraventemplate <class _Tp>
1052227825Stheravenstruct __has_const_void_pointer
1053227825Stheraven{
1054227825Stheravenprivate:
1055242945Stheraven    struct __two {char __lx; char __lxx;};
1056227825Stheraven    template <class _Up> static __two __test(...);
1057227825Stheraven    template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1058227825Stheravenpublic:
1059227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1060227825Stheraven};
1061227825Stheraven
1062227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1063227825Stheravenstruct __const_void_pointer
1064227825Stheraven{
1065227825Stheraven    typedef typename _Alloc::const_void_pointer type;
1066227825Stheraven};
1067227825Stheraven
1068227825Stheraventemplate <class _Ptr, class _Alloc>
1069227825Stheravenstruct __const_void_pointer<_Ptr, _Alloc, false>
1070227825Stheraven{
1071227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1072227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1073227825Stheraven#else
1074227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1075227825Stheraven#endif
1076227825Stheraven};
1077227825Stheraven
1078232950Stheraventemplate <class _Tp>
1079227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1080232950Stheraven_Tp*
1081232950Stheraven__to_raw_pointer(_Tp* __p) _NOEXCEPT
1082227825Stheraven{
1083227825Stheraven    return __p;
1084227825Stheraven}
1085227825Stheraven
1086227825Stheraventemplate <class _Pointer>
1087227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1088227825Stheraventypename pointer_traits<_Pointer>::element_type*
1089227825Stheraven__to_raw_pointer(_Pointer __p) _NOEXCEPT
1090227825Stheraven{
1091227825Stheraven    return _VSTD::__to_raw_pointer(__p.operator->());
1092227825Stheraven}
1093227825Stheraven
1094227825Stheraventemplate <class _Tp>
1095227825Stheravenstruct __has_size_type
1096227825Stheraven{
1097227825Stheravenprivate:
1098242945Stheraven    struct __two {char __lx; char __lxx;};
1099227825Stheraven    template <class _Up> static __two __test(...);
1100227825Stheraven    template <class _Up> static char __test(typename _Up::size_type* = 0);
1101227825Stheravenpublic:
1102227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1103227825Stheraven};
1104227825Stheraven
1105227825Stheraventemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1106227825Stheravenstruct __size_type
1107227825Stheraven{
1108227825Stheraven    typedef typename make_unsigned<_DiffType>::type type;
1109227825Stheraven};
1110227825Stheraven
1111227825Stheraventemplate <class _Alloc, class _DiffType>
1112227825Stheravenstruct __size_type<_Alloc, _DiffType, true>
1113227825Stheraven{
1114227825Stheraven    typedef typename _Alloc::size_type type;
1115227825Stheraven};
1116227825Stheraven
1117227825Stheraventemplate <class _Tp>
1118227825Stheravenstruct __has_propagate_on_container_copy_assignment
1119227825Stheraven{
1120227825Stheravenprivate:
1121242945Stheraven    struct __two {char __lx; char __lxx;};
1122227825Stheraven    template <class _Up> static __two __test(...);
1123227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1124227825Stheravenpublic:
1125227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1126227825Stheraven};
1127227825Stheraven
1128227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1129227825Stheravenstruct __propagate_on_container_copy_assignment
1130227825Stheraven{
1131227825Stheraven    typedef false_type type;
1132227825Stheraven};
1133227825Stheraven
1134227825Stheraventemplate <class _Alloc>
1135227825Stheravenstruct __propagate_on_container_copy_assignment<_Alloc, true>
1136227825Stheraven{
1137227825Stheraven    typedef typename _Alloc::propagate_on_container_copy_assignment type;
1138227825Stheraven};
1139227825Stheraven
1140227825Stheraventemplate <class _Tp>
1141227825Stheravenstruct __has_propagate_on_container_move_assignment
1142227825Stheraven{
1143227825Stheravenprivate:
1144242945Stheraven    struct __two {char __lx; char __lxx;};
1145227825Stheraven    template <class _Up> static __two __test(...);
1146227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1147227825Stheravenpublic:
1148227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1149227825Stheraven};
1150227825Stheraven
1151227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1152227825Stheravenstruct __propagate_on_container_move_assignment
1153227825Stheraven{
1154227825Stheraven    typedef false_type type;
1155227825Stheraven};
1156227825Stheraven
1157227825Stheraventemplate <class _Alloc>
1158227825Stheravenstruct __propagate_on_container_move_assignment<_Alloc, true>
1159227825Stheraven{
1160227825Stheraven    typedef typename _Alloc::propagate_on_container_move_assignment type;
1161227825Stheraven};
1162227825Stheraven
1163227825Stheraventemplate <class _Tp>
1164227825Stheravenstruct __has_propagate_on_container_swap
1165227825Stheraven{
1166227825Stheravenprivate:
1167242945Stheraven    struct __two {char __lx; char __lxx;};
1168227825Stheraven    template <class _Up> static __two __test(...);
1169227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1170227825Stheravenpublic:
1171227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1172227825Stheraven};
1173227825Stheraven
1174227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1175227825Stheravenstruct __propagate_on_container_swap
1176227825Stheraven{
1177227825Stheraven    typedef false_type type;
1178227825Stheraven};
1179227825Stheraven
1180227825Stheraventemplate <class _Alloc>
1181227825Stheravenstruct __propagate_on_container_swap<_Alloc, true>
1182227825Stheraven{
1183227825Stheraven    typedef typename _Alloc::propagate_on_container_swap type;
1184227825Stheraven};
1185227825Stheraven
1186227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1187227825Stheravenstruct __has_rebind_other
1188227825Stheraven{
1189227825Stheravenprivate:
1190242945Stheraven    struct __two {char __lx; char __lxx;};
1191227825Stheraven    template <class _Xp> static __two __test(...);
1192227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1193227825Stheravenpublic:
1194227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1195227825Stheraven};
1196227825Stheraven
1197227825Stheraventemplate <class _Tp, class _Up>
1198227825Stheravenstruct __has_rebind_other<_Tp, _Up, false>
1199227825Stheraven{
1200227825Stheraven    static const bool value = false;
1201227825Stheraven};
1202227825Stheraven
1203227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1204227825Stheravenstruct __allocator_traits_rebind
1205227825Stheraven{
1206227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
1207227825Stheraven};
1208227825Stheraven
1209227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1210227825Stheraven
1211227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1212227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1213227825Stheraven{
1214227825Stheraven    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1215227825Stheraven};
1216227825Stheraven
1217227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1218227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1219227825Stheraven{
1220227825Stheraven    typedef _Alloc<_Up, _Args...> type;
1221227825Stheraven};
1222227825Stheraven
1223227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1224227825Stheraven
1225227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1226227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1227227825Stheraven{
1228227825Stheraven    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1229227825Stheraven};
1230227825Stheraven
1231227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1232227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1233227825Stheraven{
1234227825Stheraven    typedef _Alloc<_Up> type;
1235227825Stheraven};
1236227825Stheraven
1237227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1238227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1239227825Stheraven{
1240227825Stheraven    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1241227825Stheraven};
1242227825Stheraven
1243227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1244227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1245227825Stheraven{
1246227825Stheraven    typedef _Alloc<_Up, _A0> type;
1247227825Stheraven};
1248227825Stheraven
1249227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1250227825Stheraven                                         class _A1, class _Up>
1251227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1252227825Stheraven{
1253227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1254227825Stheraven};
1255227825Stheraven
1256227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1257227825Stheraven                                         class _A1, class _Up>
1258227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1259227825Stheraven{
1260227825Stheraven    typedef _Alloc<_Up, _A0, _A1> type;
1261227825Stheraven};
1262227825Stheraven
1263227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1264227825Stheraven                                                class _A1, class _A2, class _Up>
1265227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1266227825Stheraven{
1267227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1268227825Stheraven};
1269227825Stheraven
1270227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1271227825Stheraven                                                class _A1, class _A2, class _Up>
1272227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1273227825Stheraven{
1274227825Stheraven    typedef _Alloc<_Up, _A0, _A1, _A2> type;
1275227825Stheraven};
1276227825Stheraven
1277227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1278227825Stheraven
1279227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1280227825Stheraven
1281227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1282227825Stheravenauto
1283227825Stheraven__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1284227825Stheraven    -> decltype(__a.allocate(__sz, __p), true_type());
1285227825Stheraven
1286227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1287227825Stheravenauto
1288227825Stheraven__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1289227825Stheraven    -> false_type;
1290227825Stheraven
1291227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1292227825Stheravenstruct __has_allocate_hint
1293227825Stheraven    : integral_constant<bool,
1294227825Stheraven        is_same<
1295227825Stheraven            decltype(__has_allocate_hint_test(declval<_Alloc>(),
1296227825Stheraven                                          declval<_SizeType>(),
1297227825Stheraven                                          declval<_ConstVoidPtr>())),
1298227825Stheraven            true_type>::value>
1299227825Stheraven{
1300227825Stheraven};
1301227825Stheraven
1302227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1303227825Stheraven
1304227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1305227825Stheravenstruct __has_allocate_hint
1306227825Stheraven    : true_type
1307227825Stheraven{
1308227825Stheraven};
1309227825Stheraven
1310227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1311227825Stheraven
1312227825Stheraven#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1313227825Stheraven
1314227825Stheraventemplate <class _Alloc, class _Tp, class ..._Args>
1315227825Stheravendecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1316227825Stheraven                                           _VSTD::declval<_Args>()...),
1317227825Stheraven                                           true_type())
1318227825Stheraven__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1319227825Stheraven
1320227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1321227825Stheravenfalse_type
1322227825Stheraven__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1323227825Stheraven
1324227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1325227825Stheravenstruct __has_construct
1326227825Stheraven    : integral_constant<bool,
1327227825Stheraven        is_same<
1328227825Stheraven            decltype(__has_construct_test(declval<_Alloc>(),
1329227825Stheraven                                          declval<_Pointer>(),
1330227825Stheraven                                          declval<_Args>()...)),
1331227825Stheraven            true_type>::value>
1332227825Stheraven{
1333227825Stheraven};
1334227825Stheraven
1335227825Stheraventemplate <class _Alloc, class _Pointer>
1336227825Stheravenauto
1337227825Stheraven__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1338227825Stheraven    -> decltype(__a.destroy(__p), true_type());
1339227825Stheraven
1340227825Stheraventemplate <class _Alloc, class _Pointer>
1341227825Stheravenauto
1342227825Stheraven__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1343227825Stheraven    -> false_type;
1344227825Stheraven
1345227825Stheraventemplate <class _Alloc, class _Pointer>
1346227825Stheravenstruct __has_destroy
1347227825Stheraven    : integral_constant<bool,
1348227825Stheraven        is_same<
1349227825Stheraven            decltype(__has_destroy_test(declval<_Alloc>(),
1350227825Stheraven                                        declval<_Pointer>())),
1351227825Stheraven            true_type>::value>
1352227825Stheraven{
1353227825Stheraven};
1354227825Stheraven
1355227825Stheraventemplate <class _Alloc>
1356227825Stheravenauto
1357227825Stheraven__has_max_size_test(_Alloc&& __a)
1358227825Stheraven    -> decltype(__a.max_size(), true_type());
1359227825Stheraven
1360227825Stheraventemplate <class _Alloc>
1361227825Stheravenauto
1362227825Stheraven__has_max_size_test(const volatile _Alloc& __a)
1363227825Stheraven    -> false_type;
1364227825Stheraven
1365227825Stheraventemplate <class _Alloc>
1366227825Stheravenstruct __has_max_size
1367227825Stheraven    : integral_constant<bool,
1368227825Stheraven        is_same<
1369227825Stheraven            decltype(__has_max_size_test(declval<_Alloc&>())),
1370227825Stheraven            true_type>::value>
1371227825Stheraven{
1372227825Stheraven};
1373227825Stheraven
1374227825Stheraventemplate <class _Alloc>
1375227825Stheravenauto
1376227825Stheraven__has_select_on_container_copy_construction_test(_Alloc&& __a)
1377227825Stheraven    -> decltype(__a.select_on_container_copy_construction(), true_type());
1378227825Stheraven
1379227825Stheraventemplate <class _Alloc>
1380227825Stheravenauto
1381227825Stheraven__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1382227825Stheraven    -> false_type;
1383227825Stheraven
1384227825Stheraventemplate <class _Alloc>
1385227825Stheravenstruct __has_select_on_container_copy_construction
1386227825Stheraven    : integral_constant<bool,
1387227825Stheraven        is_same<
1388227825Stheraven            decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1389227825Stheraven            true_type>::value>
1390227825Stheraven{
1391227825Stheraven};
1392227825Stheraven
1393227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1394227825Stheraven
1395227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1396227825Stheraven
1397227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1398227825Stheravenstruct __has_construct
1399227825Stheraven    : false_type
1400227825Stheraven{
1401227825Stheraven};
1402227825Stheraven
1403232950Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1404232950Stheraven
1405232950Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1406232950Stheravenstruct __has_construct
1407232950Stheraven    : false_type
1408232950Stheraven{
1409232950Stheraven};
1410232950Stheraven
1411227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1412227825Stheraven
1413227825Stheraventemplate <class _Alloc, class _Pointer>
1414227825Stheravenstruct __has_destroy
1415227825Stheraven    : false_type
1416227825Stheraven{
1417227825Stheraven};
1418227825Stheraven
1419227825Stheraventemplate <class _Alloc>
1420227825Stheravenstruct __has_max_size
1421227825Stheraven    : true_type
1422227825Stheraven{
1423227825Stheraven};
1424227825Stheraven
1425227825Stheraventemplate <class _Alloc>
1426227825Stheravenstruct __has_select_on_container_copy_construction
1427227825Stheraven    : false_type
1428227825Stheraven{
1429227825Stheraven};
1430227825Stheraven
1431227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1432227825Stheraven
1433227825Stheraventemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1434227825Stheravenstruct __alloc_traits_difference_type
1435227825Stheraven{
1436227825Stheraven    typedef typename pointer_traits<_Ptr>::difference_type type;
1437227825Stheraven};
1438227825Stheraven
1439227825Stheraventemplate <class _Alloc, class _Ptr>
1440227825Stheravenstruct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1441227825Stheraven{
1442227825Stheraven    typedef typename _Alloc::difference_type type;
1443227825Stheraven};
1444227825Stheraven
1445227825Stheraventemplate <class _Alloc>
1446249998Sdimstruct _LIBCPP_TYPE_VIS allocator_traits
1447227825Stheraven{
1448227825Stheraven    typedef _Alloc                              allocator_type;
1449227825Stheraven    typedef typename allocator_type::value_type value_type;
1450227825Stheraven
1451227825Stheraven    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1452227825Stheraven    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1453227825Stheraven    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1454227825Stheraven    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1455227825Stheraven
1456227825Stheraven    typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1457227825Stheraven    typedef typename __size_type<allocator_type, difference_type>::type size_type;
1458227825Stheraven
1459227825Stheraven    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1460227825Stheraven                     propagate_on_container_copy_assignment;
1461227825Stheraven    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1462227825Stheraven                     propagate_on_container_move_assignment;
1463227825Stheraven    typedef typename __propagate_on_container_swap<allocator_type>::type
1464227825Stheraven                     propagate_on_container_swap;
1465227825Stheraven
1466227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1467227825Stheraven    template <class _Tp> using rebind_alloc =
1468227825Stheraven                  typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1469227825Stheraven    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1470227825Stheraven#else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1471227825Stheraven    template <class _Tp> struct rebind_alloc
1472227825Stheraven        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1473227825Stheraven    template <class _Tp> struct rebind_traits
1474227825Stheraven        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1475227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1476227825Stheraven
1477227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1478227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n)
1479227825Stheraven        {return __a.allocate(__n);}
1480227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1481227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1482227825Stheraven        {return allocate(__a, __n, __hint,
1483227825Stheraven            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1484227825Stheraven
1485227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1486227825Stheraven    static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1487227825Stheraven        {__a.deallocate(__p, __n);}
1488227825Stheraven
1489227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1490227825Stheraven    template <class _Tp, class... _Args>
1491227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1492227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1493227825Stheraven            {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1494227825Stheraven                         __a, __p, _VSTD::forward<_Args>(__args)...);}
1495227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1496227825Stheraven    template <class _Tp>
1497227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1498227825Stheraven        static void construct(allocator_type& __a, _Tp* __p)
1499227825Stheraven            {
1500227825Stheraven                ::new ((void*)__p) _Tp();
1501227825Stheraven            }
1502227825Stheraven    template <class _Tp, class _A0>
1503227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1504227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1505227825Stheraven            {
1506227825Stheraven                ::new ((void*)__p) _Tp(__a0);
1507227825Stheraven            }
1508227825Stheraven    template <class _Tp, class _A0, class _A1>
1509227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1510227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1511227825Stheraven                              const _A1& __a1)
1512227825Stheraven            {
1513227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1);
1514227825Stheraven            }
1515227825Stheraven    template <class _Tp, class _A0, class _A1, class _A2>
1516227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1517227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1518227825Stheraven                              const _A1& __a1, const _A2& __a2)
1519227825Stheraven            {
1520227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1521227825Stheraven            }
1522227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1523227825Stheraven
1524227825Stheraven    template <class _Tp>
1525227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1526227825Stheraven        static void destroy(allocator_type& __a, _Tp* __p)
1527227825Stheraven            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1528227825Stheraven
1529227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1530227825Stheraven    static size_type max_size(const allocator_type& __a)
1531227825Stheraven        {return __max_size(__has_max_size<const allocator_type>(), __a);}
1532227825Stheraven
1533227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1534227825Stheraven    static allocator_type
1535227825Stheraven        select_on_container_copy_construction(const allocator_type& __a)
1536227825Stheraven            {return select_on_container_copy_construction(
1537227825Stheraven                __has_select_on_container_copy_construction<const allocator_type>(),
1538227825Stheraven                __a);}
1539227825Stheraven
1540232950Stheraven    template <class _Ptr>
1541232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1542232950Stheraven        static
1543232950Stheraven        void
1544232950Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1545232950Stheraven        {
1546232950Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1547232950Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1548232950Stheraven        }
1549232950Stheraven
1550232950Stheraven    template <class _Tp>
1551232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1552232950Stheraven        static
1553232950Stheraven        typename enable_if
1554232950Stheraven        <
1555232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1556232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1557232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1558232950Stheraven            void
1559232950Stheraven        >::type
1560232950Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1561232950Stheraven        {
1562232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1563232950Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1564232950Stheraven            __begin2 += _Np;
1565232950Stheraven        }
1566232950Stheraven
1567232950Stheraven    template <class _Ptr>
1568232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1569232950Stheraven        static
1570232950Stheraven        void
1571232950Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1572232950Stheraven        {
1573232950Stheraven            while (__end1 != __begin1)
1574246487Stheraven            {
1575246487Stheraven                construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1576246487Stheraven                --__end2;
1577246487Stheraven            }
1578232950Stheraven        }
1579232950Stheraven
1580232950Stheraven    template <class _Tp>
1581232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1582232950Stheraven        static
1583232950Stheraven        typename enable_if
1584232950Stheraven        <
1585232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1586232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1587232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1588232950Stheraven            void
1589232950Stheraven        >::type
1590232950Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1591232950Stheraven        {
1592232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1593232950Stheraven            __end2 -= _Np;
1594232950Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1595232950Stheraven        }
1596232950Stheraven
1597227825Stheravenprivate:
1598227825Stheraven
1599227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1600227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1601227825Stheraven        const_void_pointer __hint, true_type)
1602227825Stheraven        {return __a.allocate(__n, __hint);}
1603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1604227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1605232950Stheraven        const_void_pointer, false_type)
1606227825Stheraven        {return __a.allocate(__n);}
1607227825Stheraven
1608227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1609227825Stheraven    template <class _Tp, class... _Args>
1610227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1611227825Stheraven        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1612227825Stheraven            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1613227825Stheraven    template <class _Tp, class... _Args>
1614227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1615227825Stheraven        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1616227825Stheraven            {
1617227825Stheraven                ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1618227825Stheraven            }
1619227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1620227825Stheraven
1621227825Stheraven    template <class _Tp>
1622227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1623227825Stheraven        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1624227825Stheraven            {__a.destroy(__p);}
1625227825Stheraven    template <class _Tp>
1626227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1627227825Stheraven        static void __destroy(false_type, allocator_type&, _Tp* __p)
1628227825Stheraven            {
1629227825Stheraven                __p->~_Tp();
1630227825Stheraven            }
1631227825Stheraven
1632227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1633227825Stheraven    static size_type __max_size(true_type, const allocator_type& __a)
1634227825Stheraven            {return __a.max_size();}
1635227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1636227825Stheraven    static size_type __max_size(false_type, const allocator_type&)
1637227825Stheraven            {return numeric_limits<size_type>::max();}
1638227825Stheraven
1639227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1640227825Stheraven    static allocator_type
1641227825Stheraven        select_on_container_copy_construction(true_type, const allocator_type& __a)
1642227825Stheraven            {return __a.select_on_container_copy_construction();}
1643227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1644227825Stheraven    static allocator_type
1645227825Stheraven        select_on_container_copy_construction(false_type, const allocator_type& __a)
1646227825Stheraven            {return __a;}
1647227825Stheraven};
1648227825Stheraven
1649232950Stheraven// allocator
1650227825Stheraven
1651227825Stheraventemplate <class _Tp>
1652249998Sdimclass _LIBCPP_TYPE_VIS allocator
1653227825Stheraven{
1654227825Stheravenpublic:
1655232950Stheraven    typedef size_t            size_type;
1656232950Stheraven    typedef ptrdiff_t         difference_type;
1657232950Stheraven    typedef _Tp*              pointer;
1658232950Stheraven    typedef const _Tp*        const_pointer;
1659232950Stheraven    typedef _Tp&              reference;
1660232950Stheraven    typedef const _Tp&        const_reference;
1661232950Stheraven    typedef _Tp               value_type;
1662227825Stheraven
1663232950Stheraven    typedef true_type propagate_on_container_move_assignment;
1664227825Stheraven
1665232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1666227825Stheraven
1667232950Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1668232950Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1669232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1670232950Stheraven        {return _VSTD::addressof(__x);}
1671232950Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1672232950Stheraven        {return _VSTD::addressof(__x);}
1673232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1674232950Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1675232950Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1676232950Stheraven        {::operator delete((void*)__p);}
1677232950Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1678232950Stheraven        {return size_type(~0) / sizeof(_Tp);}
1679232950Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1680232950Stheraven    template <class _Up, class... _Args>
1681232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1682232950Stheraven        void
1683232950Stheraven        construct(_Up* __p, _Args&&... __args)
1684232950Stheraven        {
1685232950Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1686232950Stheraven        }
1687232950Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1688232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1689232950Stheraven        void
1690232950Stheraven        construct(pointer __p)
1691232950Stheraven        {
1692232950Stheraven            ::new((void*)__p) _Tp();
1693232950Stheraven        }
1694232950Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1695234976Stheraven
1696232950Stheraven    template <class _A0>
1697232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1698234976Stheraven        void
1699232950Stheraven        construct(pointer __p, _A0& __a0)
1700232950Stheraven        {
1701232950Stheraven            ::new((void*)__p) _Tp(__a0);
1702232950Stheraven        }
1703232950Stheraven    template <class _A0>
1704232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1705234976Stheraven        void
1706232950Stheraven        construct(pointer __p, const _A0& __a0)
1707232950Stheraven        {
1708232950Stheraven            ::new((void*)__p) _Tp(__a0);
1709232950Stheraven        }
1710232950Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1711232950Stheraven    template <class _A0, class _A1>
1712232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1713232950Stheraven        void
1714232950Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1715232950Stheraven        {
1716232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1717232950Stheraven        }
1718232950Stheraven    template <class _A0, class _A1>
1719232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1720232950Stheraven        void
1721232950Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1722232950Stheraven        {
1723232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1724232950Stheraven        }
1725232950Stheraven    template <class _A0, class _A1>
1726232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1727232950Stheraven        void
1728232950Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1729232950Stheraven        {
1730232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1731232950Stheraven        }
1732232950Stheraven    template <class _A0, class _A1>
1733232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1734232950Stheraven        void
1735232950Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1736232950Stheraven        {
1737232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1738232950Stheraven        }
1739232950Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1740232950Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1741227825Stheraven};
1742227825Stheraven
1743227825Stheraventemplate <class _Tp>
1744249998Sdimclass _LIBCPP_TYPE_VIS allocator<const _Tp>
1745227825Stheraven{
1746227825Stheravenpublic:
1747227825Stheraven    typedef size_t            size_type;
1748227825Stheraven    typedef ptrdiff_t         difference_type;
1749232950Stheraven    typedef const _Tp*        pointer;
1750227825Stheraven    typedef const _Tp*        const_pointer;
1751232950Stheraven    typedef const _Tp&        reference;
1752227825Stheraven    typedef const _Tp&        const_reference;
1753227825Stheraven    typedef _Tp               value_type;
1754227825Stheraven
1755227825Stheraven    typedef true_type propagate_on_container_move_assignment;
1756227825Stheraven
1757227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1758227825Stheraven
1759227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1760227825Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1761227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1762227825Stheraven        {return _VSTD::addressof(__x);}
1763227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1764227825Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1765227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1766227825Stheraven        {::operator delete((void*)__p);}
1767227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1768227825Stheraven        {return size_type(~0) / sizeof(_Tp);}
1769227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1770227825Stheraven    template <class _Up, class... _Args>
1771227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1772227825Stheraven        void
1773227825Stheraven        construct(_Up* __p, _Args&&... __args)
1774227825Stheraven        {
1775227825Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1776227825Stheraven        }
1777227825Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1778227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1779227825Stheraven        void
1780227825Stheraven        construct(pointer __p)
1781227825Stheraven        {
1782227825Stheraven            ::new((void*)__p) _Tp();
1783227825Stheraven        }
1784227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1785234976Stheraven
1786227825Stheraven    template <class _A0>
1787227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1788234976Stheraven        void
1789227825Stheraven        construct(pointer __p, _A0& __a0)
1790227825Stheraven        {
1791227825Stheraven            ::new((void*)__p) _Tp(__a0);
1792227825Stheraven        }
1793227825Stheraven    template <class _A0>
1794227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1795234976Stheraven        void
1796227825Stheraven        construct(pointer __p, const _A0& __a0)
1797227825Stheraven        {
1798227825Stheraven            ::new((void*)__p) _Tp(__a0);
1799227825Stheraven        }
1800227825Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1801227825Stheraven    template <class _A0, class _A1>
1802227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1803227825Stheraven        void
1804227825Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1805227825Stheraven        {
1806227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1807227825Stheraven        }
1808227825Stheraven    template <class _A0, class _A1>
1809227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1810227825Stheraven        void
1811227825Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1812227825Stheraven        {
1813227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1814227825Stheraven        }
1815227825Stheraven    template <class _A0, class _A1>
1816227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1817227825Stheraven        void
1818227825Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1819227825Stheraven        {
1820227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1821227825Stheraven        }
1822227825Stheraven    template <class _A0, class _A1>
1823227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1824227825Stheraven        void
1825227825Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1826227825Stheraven        {
1827227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1828227825Stheraven        }
1829227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1830227825Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1831227825Stheraven};
1832227825Stheraven
1833227825Stheraventemplate <class _Tp, class _Up>
1834227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1835227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1836227825Stheraven
1837227825Stheraventemplate <class _Tp, class _Up>
1838227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1839227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1840227825Stheraven
1841227825Stheraventemplate <class _OutputIterator, class _Tp>
1842249998Sdimclass _LIBCPP_TYPE_VIS raw_storage_iterator
1843227825Stheraven    : public iterator<output_iterator_tag,
1844227825Stheraven                      _Tp,                                         // purposefully not C++03
1845227825Stheraven                      ptrdiff_t,                                   // purposefully not C++03
1846227825Stheraven                      _Tp*,                                        // purposefully not C++03
1847227825Stheraven                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1848227825Stheraven{
1849227825Stheravenprivate:
1850227825Stheraven    _OutputIterator __x_;
1851227825Stheravenpublic:
1852227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1853227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1854227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1855227825Stheraven        {::new(&*__x_) _Tp(__element); return *this;}
1856227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1857227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
1858227825Stheraven        {raw_storage_iterator __t(*this); ++__x_; return __t;}
1859227825Stheraven};
1860227825Stheraven
1861227825Stheraventemplate <class _Tp>
1862227825Stheravenpair<_Tp*, ptrdiff_t>
1863227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1864227825Stheraven{
1865227825Stheraven    pair<_Tp*, ptrdiff_t> __r(0, 0);
1866227825Stheraven    const ptrdiff_t __m = (~ptrdiff_t(0) ^
1867227825Stheraven                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1868227825Stheraven                           / sizeof(_Tp);
1869227825Stheraven    if (__n > __m)
1870227825Stheraven        __n = __m;
1871227825Stheraven    while (__n > 0)
1872227825Stheraven    {
1873227825Stheraven        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1874227825Stheraven        if (__r.first)
1875227825Stheraven        {
1876227825Stheraven            __r.second = __n;
1877227825Stheraven            break;
1878227825Stheraven        }
1879227825Stheraven        __n /= 2;
1880227825Stheraven    }
1881227825Stheraven    return __r;
1882227825Stheraven}
1883227825Stheraven
1884227825Stheraventemplate <class _Tp>
1885227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1886227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1887227825Stheraven
1888227825Stheraventemplate <class _Tp>
1889227825Stheravenstruct auto_ptr_ref
1890227825Stheraven{
1891227825Stheraven    _Tp* __ptr_;
1892227825Stheraven};
1893227825Stheraven
1894227825Stheraventemplate<class _Tp>
1895249998Sdimclass _LIBCPP_TYPE_VIS auto_ptr
1896227825Stheraven{
1897227825Stheravenprivate:
1898227825Stheraven    _Tp* __ptr_;
1899227825Stheravenpublic:
1900227825Stheraven    typedef _Tp element_type;
1901227825Stheraven
1902227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1903227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1904227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1905227825Stheraven        : __ptr_(__p.release()) {}
1906227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1907227825Stheraven        {reset(__p.release()); return *this;}
1908227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1909227825Stheraven        {reset(__p.release()); return *this;}
1910227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1911227825Stheraven        {reset(__p.__ptr_); return *this;}
1912227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1913227825Stheraven
1914227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1915227825Stheraven        {return *__ptr_;}
1916227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1917227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1918227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1919227825Stheraven    {
1920227825Stheraven        _Tp* __t = __ptr_;
1921227825Stheraven        __ptr_ = 0;
1922227825Stheraven        return __t;
1923227825Stheraven    }
1924227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1925227825Stheraven    {
1926227825Stheraven        if (__ptr_ != __p)
1927227825Stheraven            delete __ptr_;
1928227825Stheraven        __ptr_ = __p;
1929227825Stheraven    }
1930227825Stheraven
1931227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1932227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1933227825Stheraven        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1934227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1935227825Stheraven        {return auto_ptr<_Up>(release());}
1936227825Stheraven};
1937227825Stheraven
1938227825Stheraventemplate <>
1939249998Sdimclass _LIBCPP_TYPE_VIS auto_ptr<void>
1940227825Stheraven{
1941227825Stheravenpublic:
1942227825Stheraven    typedef void element_type;
1943227825Stheraven};
1944227825Stheraven
1945227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1946227825Stheraven                                                     typename remove_cv<_T2>::type>::value,
1947232950Stheraven                                bool = is_empty<_T1>::value
1948232950Stheraven#if __has_feature(is_final)
1949232950Stheraven                                       && !__is_final(_T1)
1950232950Stheraven#endif
1951232950Stheraven                                ,
1952232950Stheraven                                bool = is_empty<_T2>::value
1953232950Stheraven#if __has_feature(is_final)
1954232950Stheraven                                       && !__is_final(_T2)
1955232950Stheraven#endif
1956232950Stheraven         >
1957227825Stheravenstruct __libcpp_compressed_pair_switch;
1958227825Stheraven
1959227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1960227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1961227825Stheraven
1962227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1963227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
1964227825Stheraven
1965227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1966227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
1967227825Stheraven
1968227825Stheraventemplate <class _T1, class _T2>
1969227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
1970227825Stheraven
1971227825Stheraventemplate <class _T1, class _T2>
1972227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
1973227825Stheraven
1974227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1975227825Stheravenclass __libcpp_compressed_pair_imp;
1976227825Stheraven
1977227825Stheraventemplate <class _T1, class _T2>
1978227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0>
1979227825Stheraven{
1980227825Stheravenprivate:
1981227825Stheraven    _T1 __first_;
1982227825Stheraven    _T2 __second_;
1983227825Stheravenpublic:
1984227825Stheraven    typedef _T1 _T1_param;
1985227825Stheraven    typedef _T2 _T2_param;
1986227825Stheraven
1987227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
1988227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
1989227825Stheraven
1990227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1991227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1992227825Stheraven
1993227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1994232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1995227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1996232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
1997227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
1998227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
1999227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2000227825Stheraven
2001227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2002227825Stheraven
2003227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2004227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2005227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2006227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2007227825Stheraven        : __first_(__p.first()),
2008227825Stheraven          __second_(__p.second()) {}
2009227825Stheraven
2010227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2011227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2012227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2013227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2014227825Stheraven        {
2015227825Stheraven            __first_ = __p.first();
2016227825Stheraven            __second_ = __p.second();
2017227825Stheraven            return *this;
2018227825Stheraven        }
2019227825Stheraven
2020227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2021227825Stheraven
2022227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2023227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2024227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2025227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2026227825Stheraven        : __first_(_VSTD::forward<_T1>(__p.first())),
2027227825Stheraven          __second_(_VSTD::forward<_T2>(__p.second())) {}
2028227825Stheraven
2029227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2030227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2031227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2032227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2033227825Stheraven        {
2034227825Stheraven            __first_ = _VSTD::forward<_T1>(__p.first());
2035227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2036227825Stheraven            return *this;
2037227825Stheraven        }
2038227825Stheraven
2039232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2040232950Stheraven
2041232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2042232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2043232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2044232950Stheraven                                     tuple<_Args1...> __first_args,
2045232950Stheraven                                     tuple<_Args2...> __second_args,
2046232950Stheraven                                     __tuple_indices<_I1...>,
2047232950Stheraven                                     __tuple_indices<_I2...>)
2048232950Stheraven            : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2049232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2050232950Stheraven            {}
2051232950Stheraven
2052232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2053232950Stheraven
2054227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2055227825Stheraven
2056227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2057227825Stheraven
2058227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2059227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2060227825Stheraven
2061227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2062227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2063227825Stheraven
2064227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2065227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2066227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2067227825Stheraven    {
2068227825Stheraven        using _VSTD::swap;
2069227825Stheraven        swap(__first_, __x.__first_);
2070227825Stheraven        swap(__second_, __x.__second_);
2071227825Stheraven    }
2072227825Stheraven};
2073227825Stheraven
2074227825Stheraventemplate <class _T1, class _T2>
2075227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1>
2076227825Stheraven    : private _T1
2077227825Stheraven{
2078227825Stheravenprivate:
2079227825Stheraven    _T2 __second_;
2080227825Stheravenpublic:
2081227825Stheraven    typedef _T1 _T1_param;
2082227825Stheraven    typedef _T2 _T2_param;
2083227825Stheraven
2084227825Stheraven    typedef _T1&                                        _T1_reference;
2085227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2086227825Stheraven
2087227825Stheraven    typedef const _T1&                                        _T1_const_reference;
2088227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2089227825Stheraven
2090227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2091232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2092227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2093232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2094227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2095227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2096227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2097227825Stheraven
2098227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2099227825Stheraven
2100227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2101227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2102227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2103227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2104227825Stheraven        : _T1(__p.first()), __second_(__p.second()) {}
2105227825Stheraven
2106227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2107227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2108227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2109227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2110227825Stheraven        {
2111227825Stheraven            _T1::operator=(__p.first());
2112227825Stheraven            __second_ = __p.second();
2113227825Stheraven            return *this;
2114227825Stheraven        }
2115227825Stheraven
2116227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2117227825Stheraven
2118227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2119227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2120227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2121227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2122227825Stheraven        : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2123227825Stheraven
2124227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2125227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2126227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2127227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2128227825Stheraven        {
2129227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2130227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2131227825Stheraven            return *this;
2132227825Stheraven        }
2133227825Stheraven
2134232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2135232950Stheraven
2136232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2137232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2138232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2139232950Stheraven                                     tuple<_Args1...> __first_args,
2140232950Stheraven                                     tuple<_Args2...> __second_args,
2141232950Stheraven                                     __tuple_indices<_I1...>,
2142232950Stheraven                                     __tuple_indices<_I2...>)
2143232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2144232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2145232950Stheraven            {}
2146232950Stheraven
2147232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2148232950Stheraven
2149227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2150227825Stheraven
2151227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2152227825Stheraven
2153227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2154227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2155227825Stheraven
2156227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2157227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2158227825Stheraven
2159227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2160227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2161227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2162227825Stheraven    {
2163227825Stheraven        using _VSTD::swap;
2164227825Stheraven        swap(__second_, __x.__second_);
2165227825Stheraven    }
2166227825Stheraven};
2167227825Stheraven
2168227825Stheraventemplate <class _T1, class _T2>
2169227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2>
2170227825Stheraven    : private _T2
2171227825Stheraven{
2172227825Stheravenprivate:
2173227825Stheraven    _T1 __first_;
2174227825Stheravenpublic:
2175227825Stheraven    typedef _T1 _T1_param;
2176227825Stheraven    typedef _T2 _T2_param;
2177227825Stheraven
2178227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2179227825Stheraven    typedef _T2&                                        _T2_reference;
2180227825Stheraven
2181227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2182227825Stheraven    typedef const _T2&                                        _T2_const_reference;
2183227825Stheraven
2184227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2185227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2186227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2187227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2188227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2189227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2190227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2191227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2192227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2193227825Stheraven
2194227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2195227825Stheraven
2196227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2197227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2198227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2199227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2200227825Stheraven        : _T2(__p.second()), __first_(__p.first()) {}
2201227825Stheraven
2202227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2203227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2204227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2205227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2206227825Stheraven        {
2207227825Stheraven            _T2::operator=(__p.second());
2208227825Stheraven            __first_ = __p.first();
2209227825Stheraven            return *this;
2210227825Stheraven        }
2211227825Stheraven
2212227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2213227825Stheraven
2214227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2215227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2216227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2217227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2218227825Stheraven        : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2219227825Stheraven
2220227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2221227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2222227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2223227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2224227825Stheraven        {
2225227825Stheraven            _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2226227825Stheraven            __first_ = _VSTD::move(__p.first());
2227227825Stheraven            return *this;
2228227825Stheraven        }
2229227825Stheraven
2230232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2231232950Stheraven
2232232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2233232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2234232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2235232950Stheraven                                     tuple<_Args1...> __first_args,
2236232950Stheraven                                     tuple<_Args2...> __second_args,
2237232950Stheraven                                     __tuple_indices<_I1...>,
2238232950Stheraven                                     __tuple_indices<_I2...>)
2239232950Stheraven            : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2240232950Stheraven              __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2241232950Stheraven              
2242232950Stheraven            {}
2243232950Stheraven
2244232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2245232950Stheraven
2246227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2247227825Stheraven
2248227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2249227825Stheraven
2250227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2251227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2252227825Stheraven
2253227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2254227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2255227825Stheraven
2256227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2257227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2258227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2259227825Stheraven    {
2260227825Stheraven        using _VSTD::swap;
2261227825Stheraven        swap(__first_, __x.__first_);
2262227825Stheraven    }
2263227825Stheraven};
2264227825Stheraven
2265227825Stheraventemplate <class _T1, class _T2>
2266227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3>
2267227825Stheraven    : private _T1,
2268227825Stheraven      private _T2
2269227825Stheraven{
2270227825Stheravenpublic:
2271227825Stheraven    typedef _T1 _T1_param;
2272227825Stheraven    typedef _T2 _T2_param;
2273227825Stheraven
2274227825Stheraven    typedef _T1& _T1_reference;
2275227825Stheraven    typedef _T2& _T2_reference;
2276227825Stheraven
2277227825Stheraven    typedef const _T1& _T1_const_reference;
2278227825Stheraven    typedef const _T2& _T2_const_reference;
2279227825Stheraven
2280227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2281227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2282227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2283227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2284227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2285227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2286227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2287227825Stheraven
2288227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2289227825Stheraven
2290227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2291227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2292227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2293227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2294227825Stheraven        : _T1(__p.first()), _T2(__p.second()) {}
2295227825Stheraven
2296227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2297227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2298227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2299227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2300227825Stheraven        {
2301227825Stheraven            _T1::operator=(__p.first());
2302227825Stheraven            _T2::operator=(__p.second());
2303227825Stheraven            return *this;
2304227825Stheraven        }
2305227825Stheraven
2306227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2307227825Stheraven
2308227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2309227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2310227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2311227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2312227825Stheraven        : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2313227825Stheraven
2314227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2315227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2316227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2317227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2318227825Stheraven        {
2319227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2320227825Stheraven            _T2::operator=(_VSTD::move(__p.second()));
2321227825Stheraven            return *this;
2322227825Stheraven        }
2323227825Stheraven
2324232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2325232950Stheraven
2326232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2327232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2328232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2329232950Stheraven                                     tuple<_Args1...> __first_args,
2330232950Stheraven                                     tuple<_Args2...> __second_args,
2331232950Stheraven                                     __tuple_indices<_I1...>,
2332232950Stheraven                                     __tuple_indices<_I2...>)
2333232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2334232950Stheraven              _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2335232950Stheraven            {}
2336232950Stheraven
2337232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2338232950Stheraven
2339227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2340227825Stheraven
2341227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2342227825Stheraven
2343227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2344227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2345227825Stheraven
2346227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2347227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2348227825Stheraven
2349232950Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2350227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2351227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2352227825Stheraven    {
2353227825Stheraven    }
2354227825Stheraven};
2355227825Stheraven
2356227825Stheraventemplate <class _T1, class _T2>
2357227825Stheravenclass __compressed_pair
2358227825Stheraven    : private __libcpp_compressed_pair_imp<_T1, _T2>
2359227825Stheraven{
2360227825Stheraven    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2361227825Stheravenpublic:
2362227825Stheraven    typedef typename base::_T1_param _T1_param;
2363227825Stheraven    typedef typename base::_T2_param _T2_param;
2364227825Stheraven
2365227825Stheraven    typedef typename base::_T1_reference _T1_reference;
2366227825Stheraven    typedef typename base::_T2_reference _T2_reference;
2367227825Stheraven
2368227825Stheraven    typedef typename base::_T1_const_reference _T1_const_reference;
2369227825Stheraven    typedef typename base::_T2_const_reference _T2_const_reference;
2370227825Stheraven
2371227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2372232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2373227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2374232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2375227825Stheraven        : base(_VSTD::forward<_T2_param>(__t2)) {}
2376227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2377227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2378227825Stheraven
2379227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2380227825Stheraven
2381227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2382227825Stheraven    __compressed_pair(const __compressed_pair& __p)
2383227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2384227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2385227825Stheraven        : base(__p) {}
2386227825Stheraven
2387227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2388227825Stheraven    __compressed_pair& operator=(const __compressed_pair& __p)
2389227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2390227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2391227825Stheraven        {
2392227825Stheraven            base::operator=(__p);
2393227825Stheraven            return *this;
2394227825Stheraven        }
2395227825Stheraven
2396227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2397227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2398227825Stheraven    __compressed_pair(__compressed_pair&& __p)
2399227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2400227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2401227825Stheraven        : base(_VSTD::move(__p)) {}
2402227825Stheraven
2403227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2404227825Stheraven    __compressed_pair& operator=(__compressed_pair&& __p)
2405227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2406227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2407227825Stheraven        {
2408227825Stheraven            base::operator=(_VSTD::move(__p));
2409227825Stheraven            return *this;
2410227825Stheraven        }
2411232950Stheraven
2412232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2413232950Stheraven
2414232950Stheraven    template <class... _Args1, class... _Args2>
2415232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2416232950Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2417232950Stheraven                                                      tuple<_Args2...> __second_args)
2418232950Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2419232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2420232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2421232950Stheraven            {}
2422232950Stheraven
2423232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2424232950Stheraven
2425227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2426227825Stheraven
2427227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2428227825Stheraven
2429227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
2430227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2431227825Stheraven
2432227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return base::second();}
2433227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2434227825Stheraven
2435227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2436227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2437227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2438227825Stheraven        {base::swap(__x);}
2439227825Stheraven};
2440227825Stheraven
2441227825Stheraventemplate <class _T1, class _T2>
2442227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2443227825Stheravenvoid
2444227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2445227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2446227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2447227825Stheraven    {__x.swap(__y);}
2448227825Stheraven
2449232950Stheraven// __same_or_less_cv_qualified
2450232950Stheraven
2451232950Stheraventemplate <class _Ptr1, class _Ptr2,
2452232950Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2453232950Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2454232950Stheraven                        >::value
2455232950Stheraven         >
2456232950Stheravenstruct __same_or_less_cv_qualified_imp
2457232950Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2458232950Stheraven
2459232950Stheraventemplate <class _Ptr1, class _Ptr2>
2460232950Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2461232950Stheraven    : false_type {};
2462232950Stheraven
2463232950Stheraventemplate <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2464232950Stheraven                                         !is_pointer<_Ptr1>::value>
2465232950Stheravenstruct __same_or_less_cv_qualified
2466232950Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2467232950Stheraven
2468232950Stheraventemplate <class _Ptr1, class _Ptr2>
2469232950Stheravenstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2470232950Stheraven    : false_type {};
2471232950Stheraven
2472232950Stheraven// default_delete
2473232950Stheraven
2474227825Stheraventemplate <class _Tp>
2475249998Sdimstruct _LIBCPP_TYPE_VIS default_delete
2476227825Stheraven{
2477241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2478241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2479241903Sdim#else
2480241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2481241903Sdim#endif
2482227825Stheraven    template <class _Up>
2483227825Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2484227825Stheraven             typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2485227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2486227825Stheraven        {
2487227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2488249998Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2489227825Stheraven            delete __ptr;
2490227825Stheraven        }
2491227825Stheraven};
2492227825Stheraven
2493227825Stheraventemplate <class _Tp>
2494249998Sdimstruct _LIBCPP_TYPE_VIS default_delete<_Tp[]>
2495227825Stheraven{
2496232950Stheravenpublic:
2497241903Sdim#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2498241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2499241903Sdim#else
2500241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2501241903Sdim#endif
2502232950Stheraven    template <class _Up>
2503232950Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2504232950Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2505232950Stheraven    template <class _Up>
2506232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2507232950Stheraven        void operator() (_Up* __ptr,
2508232950Stheraven                         typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2509227825Stheraven        {
2510227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2511249998Sdim            static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
2512227825Stheraven            delete [] __ptr;
2513227825Stheraven        }
2514227825Stheraven};
2515227825Stheraven
2516227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> >
2517249998Sdimclass _LIBCPP_TYPE_VIS unique_ptr
2518227825Stheraven{
2519227825Stheravenpublic:
2520227825Stheraven    typedef _Tp element_type;
2521227825Stheraven    typedef _Dp deleter_type;
2522227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2523227825Stheravenprivate:
2524227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2525227825Stheraven
2526232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2527227825Stheraven    unique_ptr(unique_ptr&);
2528227825Stheraven    template <class _Up, class _Ep>
2529227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&);
2530227825Stheraven    unique_ptr& operator=(unique_ptr&);
2531227825Stheraven    template <class _Up, class _Ep>
2532227825Stheraven        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2533227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2534227825Stheraven
2535227825Stheraven    struct __nat {int __for_bool_;};
2536227825Stheraven
2537227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2538227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2539227825Stheravenpublic:
2540241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2541227825Stheraven        : __ptr_(pointer())
2542227825Stheraven        {
2543227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2544227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2545227825Stheraven        }
2546241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2547227825Stheraven        : __ptr_(pointer())
2548227825Stheraven        {
2549227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2550227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2551227825Stheraven        }
2552227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2553227825Stheraven        : __ptr_(_VSTD::move(__p))
2554227825Stheraven        {
2555227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2556227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2557227825Stheraven        }
2558227825Stheraven
2559227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2560227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2561227825Stheraven                                        is_reference<deleter_type>::value,
2562227825Stheraven                                        deleter_type,
2563227825Stheraven                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
2564227825Stheraven             _NOEXCEPT
2565227825Stheraven        : __ptr_(__p, __d) {}
2566227825Stheraven
2567227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2568227825Stheraven             _NOEXCEPT
2569227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2570227825Stheraven        {
2571227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2572227825Stheraven        }
2573227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2574227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2575227825Stheraven    template <class _Up, class _Ep>
2576227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2577227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2578227825Stheraven                   typename enable_if
2579227825Stheraven                      <
2580227825Stheraven                        !is_array<_Up>::value &&
2581227825Stheraven                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2582227825Stheraven                         is_convertible<_Ep, deleter_type>::value &&
2583227825Stheraven                         (
2584227825Stheraven                            !is_reference<deleter_type>::value ||
2585227825Stheraven                            is_same<deleter_type, _Ep>::value
2586227825Stheraven                         ),
2587227825Stheraven                         __nat
2588227825Stheraven                      >::type = __nat()) _NOEXCEPT
2589227825Stheraven            : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2590227825Stheraven
2591227825Stheraven    template <class _Up>
2592227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2593227825Stheraven                typename enable_if<
2594227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2595227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2596227825Stheraven                                      __nat
2597227825Stheraven                                  >::type = __nat()) _NOEXCEPT
2598227825Stheraven            : __ptr_(__p.release())
2599227825Stheraven            {
2600227825Stheraven            }
2601227825Stheraven
2602227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2603227825Stheraven            {
2604227825Stheraven                reset(__u.release());
2605227825Stheraven                __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2606227825Stheraven                return *this;
2607227825Stheraven            }
2608227825Stheraven
2609227825Stheraven        template <class _Up, class _Ep>
2610227825Stheraven            _LIBCPP_INLINE_VISIBILITY
2611227825Stheraven            typename enable_if
2612227825Stheraven            <
2613232950Stheraven                !is_array<_Up>::value &&
2614232950Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2615232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2616227825Stheraven                unique_ptr&
2617227825Stheraven            >::type
2618227825Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2619227825Stheraven            {
2620227825Stheraven                reset(__u.release());
2621227825Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2622227825Stheraven                return *this;
2623227825Stheraven            }
2624227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2625227825Stheraven
2626227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2627227825Stheraven    {
2628227825Stheraven        return __rv<unique_ptr>(*this);
2629227825Stheraven    }
2630227825Stheraven
2631227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2632227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2633227825Stheraven
2634227825Stheraven    template <class _Up, class _Ep>
2635227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2636227825Stheraven    {
2637227825Stheraven        reset(__u.release());
2638227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2639227825Stheraven        return *this;
2640227825Stheraven    }
2641227825Stheraven
2642227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2643227825Stheraven        : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2644227825Stheraven
2645227825Stheraven    template <class _Up>
2646227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2647227825Stheraven                typename enable_if<
2648227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2649227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2650227825Stheraven                                      unique_ptr&
2651227825Stheraven                                  >::type
2652227825Stheraven        operator=(auto_ptr<_Up> __p)
2653227825Stheraven            {reset(__p.release()); return *this;}
2654227825Stheraven
2655227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2656227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2657227825Stheraven
2658227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2659227825Stheraven    {
2660227825Stheraven        reset();
2661227825Stheraven        return *this;
2662227825Stheraven    }
2663227825Stheraven
2664227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2665227825Stheraven        {return *__ptr_.first();}
2666227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2667227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2668227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2669227825Stheraven        {return __ptr_.second();}
2670227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2671227825Stheraven        {return __ptr_.second();}
2672232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2673232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2674232950Stheraven        {return __ptr_.first() != nullptr;}
2675227825Stheraven
2676227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2677227825Stheraven    {
2678227825Stheraven        pointer __t = __ptr_.first();
2679227825Stheraven        __ptr_.first() = pointer();
2680227825Stheraven        return __t;
2681227825Stheraven    }
2682227825Stheraven
2683227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2684227825Stheraven    {
2685227825Stheraven        pointer __tmp = __ptr_.first();
2686227825Stheraven        __ptr_.first() = __p;
2687227825Stheraven        if (__tmp)
2688227825Stheraven            __ptr_.second()(__tmp);
2689227825Stheraven    }
2690227825Stheraven
2691227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2692227825Stheraven        {__ptr_.swap(__u.__ptr_);}
2693227825Stheraven};
2694227825Stheraven
2695227825Stheraventemplate <class _Tp, class _Dp>
2696249998Sdimclass _LIBCPP_TYPE_VIS unique_ptr<_Tp[], _Dp>
2697227825Stheraven{
2698227825Stheravenpublic:
2699227825Stheraven    typedef _Tp element_type;
2700227825Stheraven    typedef _Dp deleter_type;
2701227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2702227825Stheravenprivate:
2703227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2704227825Stheraven
2705232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2706227825Stheraven    unique_ptr(unique_ptr&);
2707227825Stheraven    template <class _Up>
2708227825Stheraven        unique_ptr(unique_ptr<_Up>&);
2709227825Stheraven    unique_ptr& operator=(unique_ptr&);
2710227825Stheraven    template <class _Up>
2711227825Stheraven        unique_ptr& operator=(unique_ptr<_Up>&);
2712227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2713227825Stheraven
2714227825Stheraven    struct __nat {int __for_bool_;};
2715227825Stheraven
2716227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2717227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2718227825Stheravenpublic:
2719241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
2720227825Stheraven        : __ptr_(pointer())
2721227825Stheraven        {
2722227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2723227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2724227825Stheraven        }
2725241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
2726227825Stheraven        : __ptr_(pointer())
2727227825Stheraven        {
2728227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2729227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2730227825Stheraven        }
2731227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2732232950Stheraven    template <class _Pp,
2733232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2734227825Stheraven             >
2735232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2736227825Stheraven        : __ptr_(__p)
2737227825Stheraven        {
2738227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2739227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2740227825Stheraven        }
2741227825Stheraven
2742232950Stheraven    template <class _Pp,
2743232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2744227825Stheraven             >
2745232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2746227825Stheraven                                       is_reference<deleter_type>::value,
2747227825Stheraven                                       deleter_type,
2748227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2749227825Stheraven             _NOEXCEPT
2750227825Stheraven        : __ptr_(__p, __d) {}
2751227825Stheraven
2752227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2753227825Stheraven                                       is_reference<deleter_type>::value,
2754227825Stheraven                                       deleter_type,
2755227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2756227825Stheraven             _NOEXCEPT
2757227825Stheraven        : __ptr_(pointer(), __d) {}
2758227825Stheraven
2759232950Stheraven    template <class _Pp,
2760232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2761227825Stheraven             >
2762232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2763227825Stheraven             _NOEXCEPT
2764227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2765227825Stheraven        {
2766227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2767227825Stheraven        }
2768227825Stheraven
2769227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2770227825Stheraven             _NOEXCEPT
2771227825Stheraven        : __ptr_(pointer(), _VSTD::move(__d))
2772227825Stheraven        {
2773227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2774227825Stheraven        }
2775227825Stheraven
2776227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2777227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2778227825Stheraven
2779227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2780227825Stheraven        {
2781227825Stheraven            reset(__u.release());
2782227825Stheraven            __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2783227825Stheraven            return *this;
2784227825Stheraven        }
2785232950Stheraven
2786232950Stheraven    template <class _Up, class _Ep>
2787232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2788232950Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2789232950Stheraven                   typename enable_if
2790232950Stheraven                            <
2791232950Stheraven                                is_array<_Up>::value &&
2792232950Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2793232950Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2794232950Stheraven                                (
2795232950Stheraven                                    !is_reference<deleter_type>::value ||
2796232950Stheraven                                    is_same<deleter_type, _Ep>::value
2797232950Stheraven                                ),
2798232950Stheraven                                __nat
2799232950Stheraven                            >::type = __nat()
2800232950Stheraven                  ) _NOEXCEPT
2801232950Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2802232950Stheraven
2803232950Stheraven
2804232950Stheraven        template <class _Up, class _Ep>
2805232950Stheraven            _LIBCPP_INLINE_VISIBILITY
2806232950Stheraven            typename enable_if
2807232950Stheraven            <
2808232950Stheraven                is_array<_Up>::value &&
2809232950Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2810232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2811232950Stheraven                unique_ptr&
2812232950Stheraven            >::type
2813232950Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2814232950Stheraven            {
2815232950Stheraven                reset(__u.release());
2816232950Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2817232950Stheraven                return *this;
2818232950Stheraven            }
2819227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2820227825Stheraven
2821227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2822227825Stheraven        : __ptr_(__p)
2823227825Stheraven        {
2824227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2825227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2826227825Stheraven        }
2827227825Stheraven
2828227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2829227825Stheraven        : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2830227825Stheraven
2831227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2832227825Stheraven        : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2833227825Stheraven
2834227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2835227825Stheraven    {
2836227825Stheraven        return __rv<unique_ptr>(*this);
2837227825Stheraven    }
2838227825Stheraven
2839227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2840227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2841227825Stheraven
2842227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2843227825Stheraven    {
2844227825Stheraven        reset(__u->release());
2845227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2846227825Stheraven        return *this;
2847227825Stheraven    }
2848227825Stheraven
2849227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2850227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2851227825Stheraven
2852227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2853227825Stheraven    {
2854227825Stheraven        reset();
2855227825Stheraven        return *this;
2856227825Stheraven    }
2857227825Stheraven
2858227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2859227825Stheraven        {return __ptr_.first()[__i];}
2860227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2861227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2862227825Stheraven        {return __ptr_.second();}
2863227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2864227825Stheraven        {return __ptr_.second();}
2865232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2866232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2867232950Stheraven        {return __ptr_.first() != nullptr;}
2868227825Stheraven
2869227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2870227825Stheraven    {
2871227825Stheraven        pointer __t = __ptr_.first();
2872227825Stheraven        __ptr_.first() = pointer();
2873227825Stheraven        return __t;
2874227825Stheraven    }
2875227825Stheraven
2876227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2877232950Stheraven    template <class _Pp,
2878232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2879227825Stheraven             >
2880232950Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2881227825Stheraven    {
2882227825Stheraven        pointer __tmp = __ptr_.first();
2883227825Stheraven        __ptr_.first() = __p;
2884227825Stheraven        if (__tmp)
2885227825Stheraven            __ptr_.second()(__tmp);
2886227825Stheraven    }
2887227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2888227825Stheraven    {
2889227825Stheraven        pointer __tmp = __ptr_.first();
2890227825Stheraven        __ptr_.first() = nullptr;
2891227825Stheraven        if (__tmp)
2892227825Stheraven            __ptr_.second()(__tmp);
2893227825Stheraven    }
2894227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2895227825Stheraven    {
2896227825Stheraven        pointer __tmp = __ptr_.first();
2897227825Stheraven        __ptr_.first() = nullptr;
2898227825Stheraven        if (__tmp)
2899227825Stheraven            __ptr_.second()(__tmp);
2900227825Stheraven    }
2901227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2902227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2903227825Stheraven    {
2904227825Stheraven        pointer __tmp = __ptr_.first();
2905227825Stheraven        __ptr_.first() = __p;
2906227825Stheraven        if (__tmp)
2907227825Stheraven            __ptr_.second()(__tmp);
2908227825Stheraven    }
2909227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2910227825Stheraven
2911227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2912227825Stheravenprivate:
2913227825Stheraven
2914227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2915227825Stheraven    template <class _Up>
2916227825Stheraven        explicit unique_ptr(_Up);
2917227825Stheraven    template <class _Up>
2918227825Stheraven        unique_ptr(_Up __u,
2919227825Stheraven                   typename conditional<
2920227825Stheraven                                       is_reference<deleter_type>::value,
2921227825Stheraven                                       deleter_type,
2922227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type,
2923227825Stheraven                   typename enable_if
2924227825Stheraven                      <
2925227825Stheraven                         is_convertible<_Up, pointer>::value,
2926227825Stheraven                         __nat
2927227825Stheraven                      >::type = __nat());
2928227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2929227825Stheraven};
2930227825Stheraven
2931227825Stheraventemplate <class _Tp, class _Dp>
2932227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2933227825Stheravenvoid
2934227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2935227825Stheraven
2936227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2937227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2938227825Stheravenbool
2939227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2940227825Stheraven
2941227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2942227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2943227825Stheravenbool
2944227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2945227825Stheraven
2946227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2947227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2948227825Stheravenbool
2949232950Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2950232950Stheraven{
2951232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2952232950Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2953232950Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2954232950Stheraven    return less<_V>()(__x.get(), __y.get());
2955232950Stheraven}
2956227825Stheraven
2957227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2958227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2959227825Stheravenbool
2960227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2961227825Stheraven
2962227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2963227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2964227825Stheravenbool
2965227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2966227825Stheraven
2967227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2968227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2969227825Stheravenbool
2970227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2971227825Stheraven
2972232950Stheraventemplate <class _T1, class _D1>
2973232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2974232950Stheravenbool
2975241903Sdimoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2976232950Stheraven{
2977232950Stheraven    return !__x;
2978232950Stheraven}
2979232950Stheraven
2980232950Stheraventemplate <class _T1, class _D1>
2981232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2982232950Stheravenbool
2983241903Sdimoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2984232950Stheraven{
2985232950Stheraven    return !__x;
2986232950Stheraven}
2987232950Stheraven
2988232950Stheraventemplate <class _T1, class _D1>
2989232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2990232950Stheravenbool
2991241903Sdimoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2992232950Stheraven{
2993232950Stheraven    return static_cast<bool>(__x);
2994232950Stheraven}
2995232950Stheraven
2996232950Stheraventemplate <class _T1, class _D1>
2997232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2998232950Stheravenbool
2999241903Sdimoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3000232950Stheraven{
3001232950Stheraven    return static_cast<bool>(__x);
3002232950Stheraven}
3003232950Stheraven
3004232950Stheraventemplate <class _T1, class _D1>
3005232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3006232950Stheravenbool
3007232950Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3008232950Stheraven{
3009232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3010232950Stheraven    return less<_P1>()(__x.get(), nullptr);
3011232950Stheraven}
3012232950Stheraven
3013232950Stheraventemplate <class _T1, class _D1>
3014232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3015232950Stheravenbool
3016232950Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3017232950Stheraven{
3018232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3019232950Stheraven    return less<_P1>()(nullptr, __x.get());
3020232950Stheraven}
3021232950Stheraven
3022232950Stheraventemplate <class _T1, class _D1>
3023232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3024232950Stheravenbool
3025232950Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3026232950Stheraven{
3027232950Stheraven    return nullptr < __x;
3028232950Stheraven}
3029232950Stheraven
3030232950Stheraventemplate <class _T1, class _D1>
3031232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3032232950Stheravenbool
3033232950Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3034232950Stheraven{
3035232950Stheraven    return __x < nullptr;
3036232950Stheraven}
3037232950Stheraven
3038232950Stheraventemplate <class _T1, class _D1>
3039232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3040232950Stheravenbool
3041232950Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3042232950Stheraven{
3043232950Stheraven    return !(nullptr < __x);
3044232950Stheraven}
3045232950Stheraven
3046232950Stheraventemplate <class _T1, class _D1>
3047232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3048232950Stheravenbool
3049232950Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3050232950Stheraven{
3051232950Stheraven    return !(__x < nullptr);
3052232950Stheraven}
3053232950Stheraven
3054232950Stheraventemplate <class _T1, class _D1>
3055232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3056232950Stheravenbool
3057232950Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3058232950Stheraven{
3059232950Stheraven    return !(__x < nullptr);
3060232950Stheraven}
3061232950Stheraven
3062232950Stheraventemplate <class _T1, class _D1>
3063232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3064232950Stheravenbool
3065232950Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3066232950Stheraven{
3067232950Stheraven    return !(nullptr < __x);
3068232950Stheraven}
3069232950Stheraven
3070234976Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3071234976Stheraven
3072234976Stheraventemplate <class _Tp, class _Dp>
3073234976Stheraveninline _LIBCPP_INLINE_VISIBILITY
3074234976Stheravenunique_ptr<_Tp, _Dp>
3075234976Stheravenmove(unique_ptr<_Tp, _Dp>& __t)
3076234976Stheraven{
3077234976Stheraven    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3078234976Stheraven}
3079234976Stheraven
3080234976Stheraven#endif
3081234976Stheraven
3082227825Stheraventemplate <class _Tp> struct hash;
3083227825Stheraven
3084232950Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3085232950Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3086232950Stheraven// multiplication, which can be very slow on 32-bit systems.
3087232950Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3088232950Stheravenstruct __murmur2_or_cityhash;
3089232950Stheraven
3090232950Stheraventemplate <class _Size>
3091232950Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3092227825Stheraven{
3093232950Stheraven    _Size operator()(const void* __key, _Size __len);
3094232950Stheraven};
3095232950Stheraven
3096232950Stheraven// murmur2
3097232950Stheraventemplate <class _Size>
3098232950Stheraven_Size
3099232950Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3100232950Stheraven{
3101232950Stheraven    const _Size __m = 0x5bd1e995;
3102232950Stheraven    const _Size __r = 24;
3103232950Stheraven    _Size __h = __len;
3104232950Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3105232950Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3106232950Stheraven    {
3107232950Stheraven        _Size __k = *(const _Size*)__data;
3108232950Stheraven        __k *= __m;
3109232950Stheraven        __k ^= __k >> __r;
3110232950Stheraven        __k *= __m;
3111232950Stheraven        __h *= __m;
3112232950Stheraven        __h ^= __k;
3113232950Stheraven    }
3114232950Stheraven    switch (__len)
3115232950Stheraven    {
3116232950Stheraven    case 3:
3117232950Stheraven        __h ^= __data[2] << 16;
3118232950Stheraven    case 2:
3119232950Stheraven        __h ^= __data[1] << 8;
3120232950Stheraven    case 1:
3121232950Stheraven        __h ^= __data[0];
3122232950Stheraven        __h *= __m;
3123232950Stheraven    }
3124232950Stheraven    __h ^= __h >> 13;
3125232950Stheraven    __h *= __m;
3126232950Stheraven    __h ^= __h >> 15;
3127232950Stheraven    return __h;
3128232950Stheraven}
3129232950Stheraven
3130232950Stheraventemplate <class _Size>
3131232950Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3132232950Stheraven{
3133232950Stheraven    _Size operator()(const void* __key, _Size __len);
3134232950Stheraven
3135232950Stheraven private:
3136232950Stheraven  // Some primes between 2^63 and 2^64.
3137232950Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3138232950Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3139232950Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3140232950Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3141232950Stheraven
3142232950Stheraven  static _Size __rotate(_Size __val, int __shift) {
3143232950Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3144232950Stheraven  }
3145232950Stheraven
3146232950Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3147232950Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3148232950Stheraven  }
3149232950Stheraven
3150232950Stheraven  static _Size __shift_mix(_Size __val) {
3151232950Stheraven    return __val ^ (__val >> 47);
3152232950Stheraven  }
3153232950Stheraven
3154232950Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3155232950Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3156232950Stheraven    _Size __a = (__u ^ __v) * __mul;
3157232950Stheraven    __a ^= (__a >> 47);
3158232950Stheraven    _Size __b = (__v ^ __a) * __mul;
3159232950Stheraven    __b ^= (__b >> 47);
3160232950Stheraven    __b *= __mul;
3161232950Stheraven    return __b;
3162232950Stheraven  }
3163232950Stheraven
3164232950Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3165232950Stheraven    if (__len > 8) {
3166232950Stheraven      const _Size __a = *(const _Size*)__s;
3167232950Stheraven      const _Size __b = *(const _Size*)(__s + __len - 8);
3168232950Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3169232950Stheraven    }
3170232950Stheraven    if (__len >= 4) {
3171232950Stheraven      const uint32_t __a = *(const uint32_t*)(__s);
3172232950Stheraven      const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3173232950Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3174232950Stheraven    }
3175232950Stheraven    if (__len > 0) {
3176232950Stheraven      const unsigned char __a = __s[0];
3177232950Stheraven      const unsigned char __b = __s[__len >> 1];
3178232950Stheraven      const unsigned char __c = __s[__len - 1];
3179232950Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3180232950Stheraven                           (static_cast<uint32_t>(__b) << 8);
3181232950Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3182232950Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3183232950Stheraven    }
3184232950Stheraven    return __k2;
3185232950Stheraven  }
3186232950Stheraven
3187232950Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3188232950Stheraven    const _Size __a = *(const _Size*)(__s) * __k1;
3189232950Stheraven    const _Size __b = *(const _Size*)(__s + 8);
3190232950Stheraven    const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3191232950Stheraven    const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3192232950Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3193232950Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3194232950Stheraven  }
3195232950Stheraven
3196232950Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3197232950Stheraven  // Callers do best to use "random-looking" values for a and b.
3198232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3199232950Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3200232950Stheraven    __a += __w;
3201232950Stheraven    __b = __rotate(__b + __a + __z, 21);
3202232950Stheraven    const _Size __c = __a;
3203232950Stheraven    __a += __x;
3204232950Stheraven    __a += __y;
3205232950Stheraven    __b += __rotate(__a, 44);
3206232950Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3207232950Stheraven  }
3208232950Stheraven
3209232950Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3210232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3211232950Stheraven      const char* __s, _Size __a, _Size __b) {
3212232950Stheraven    return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3213232950Stheraven                                         *(const _Size*)(__s + 8),
3214232950Stheraven                                         *(const _Size*)(__s + 16),
3215232950Stheraven                                         *(const _Size*)(__s + 24),
3216232950Stheraven                                         __a,
3217232950Stheraven                                         __b);
3218232950Stheraven  }
3219232950Stheraven
3220232950Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3221232950Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3222232950Stheraven    _Size __z = *(const _Size*)(__s + 24);
3223232950Stheraven    _Size __a = *(const _Size*)(__s) +
3224232950Stheraven                (__len + *(const _Size*)(__s + __len - 16)) * __k0;
3225232950Stheraven    _Size __b = __rotate(__a + __z, 52);
3226232950Stheraven    _Size __c = __rotate(__a, 37);
3227232950Stheraven    __a += *(const _Size*)(__s + 8);
3228232950Stheraven    __c += __rotate(__a, 7);
3229232950Stheraven    __a += *(const _Size*)(__s + 16);
3230232950Stheraven    _Size __vf = __a + __z;
3231232950Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3232232950Stheraven    __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3233232950Stheraven    __z += *(const _Size*)(__s + __len - 8);
3234232950Stheraven    __b = __rotate(__a + __z, 52);
3235232950Stheraven    __c = __rotate(__a, 37);
3236232950Stheraven    __a += *(const _Size*)(__s + __len - 24);
3237232950Stheraven    __c += __rotate(__a, 7);
3238232950Stheraven    __a += *(const _Size*)(__s + __len - 16);
3239232950Stheraven    _Size __wf = __a + __z;
3240232950Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3241232950Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3242232950Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3243232950Stheraven  }
3244232950Stheraven};
3245232950Stheraven
3246232950Stheraven// cityhash64
3247232950Stheraventemplate <class _Size>
3248232950Stheraven_Size
3249232950Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3250232950Stheraven{
3251232950Stheraven  const char* __s = static_cast<const char*>(__key);
3252232950Stheraven  if (__len <= 32) {
3253232950Stheraven    if (__len <= 16) {
3254232950Stheraven      return __hash_len_0_to_16(__s, __len);
3255232950Stheraven    } else {
3256232950Stheraven      return __hash_len_17_to_32(__s, __len);
3257232950Stheraven    }
3258232950Stheraven  } else if (__len <= 64) {
3259232950Stheraven    return __hash_len_33_to_64(__s, __len);
3260232950Stheraven  }
3261232950Stheraven
3262232950Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3263232950Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3264232950Stheraven  _Size __x = *(const _Size*)(__s + __len - 40);
3265232950Stheraven  _Size __y = *(const _Size*)(__s + __len - 16) +
3266232950Stheraven              *(const _Size*)(__s + __len - 56);
3267232950Stheraven  _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3268232950Stheraven                          *(const _Size*)(__s + __len - 24));
3269232950Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3270232950Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3271232950Stheraven  __x = __x * __k1 + *(const _Size*)(__s);
3272232950Stheraven
3273232950Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3274232950Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3275232950Stheraven  do {
3276232950Stheraven    __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3277232950Stheraven    __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3278232950Stheraven    __x ^= __w.second;
3279232950Stheraven    __y += __v.first + *(const _Size*)(__s + 40);
3280232950Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3281232950Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3282232950Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3283232950Stheraven                                        __y + *(const _Size*)(__s + 16));
3284232950Stheraven    std::swap(__z, __x);
3285232950Stheraven    __s += 64;
3286232950Stheraven    __len -= 64;
3287232950Stheraven  } while (__len != 0);
3288232950Stheraven  return __hash_len_16(
3289232950Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3290232950Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3291232950Stheraven}
3292232950Stheraven
3293232950Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3294232950Stheravenstruct __scalar_hash;
3295232950Stheraven
3296232950Stheraventemplate <class _Tp>
3297232950Stheravenstruct __scalar_hash<_Tp, 0>
3298232950Stheraven    : public unary_function<_Tp, size_t>
3299232950Stheraven{
3300227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3301232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3302227825Stheraven    {
3303232950Stheraven        union
3304232950Stheraven        {
3305232950Stheraven            _Tp    __t;
3306232950Stheraven            size_t __a;
3307232950Stheraven        } __u;
3308232950Stheraven        __u.__a = 0;
3309232950Stheraven        __u.__t = __v;
3310232950Stheraven        return __u.__a;
3311227825Stheraven    }
3312227825Stheraven};
3313227825Stheraven
3314232950Stheraventemplate <class _Tp>
3315232950Stheravenstruct __scalar_hash<_Tp, 1>
3316232950Stheraven    : public unary_function<_Tp, size_t>
3317232950Stheraven{
3318232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3319232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3320232950Stheraven    {
3321232950Stheraven        union
3322232950Stheraven        {
3323232950Stheraven            _Tp    __t;
3324232950Stheraven            size_t __a;
3325232950Stheraven        } __u;
3326232950Stheraven        __u.__t = __v;
3327232950Stheraven        return __u.__a;
3328232950Stheraven    }
3329232950Stheraven};
3330232950Stheraven
3331232950Stheraventemplate <class _Tp>
3332232950Stheravenstruct __scalar_hash<_Tp, 2>
3333232950Stheraven    : public unary_function<_Tp, size_t>
3334232950Stheraven{
3335232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3336232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3337232950Stheraven    {
3338232950Stheraven        union
3339232950Stheraven        {
3340232950Stheraven            _Tp __t;
3341232950Stheraven            struct
3342232950Stheraven            {
3343232950Stheraven                size_t __a;
3344232950Stheraven                size_t __b;
3345232950Stheraven            };
3346232950Stheraven        } __u;
3347232950Stheraven        __u.__t = __v;
3348232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3349232950Stheraven    }
3350232950Stheraven};
3351232950Stheraven
3352232950Stheraventemplate <class _Tp>
3353232950Stheravenstruct __scalar_hash<_Tp, 3>
3354232950Stheraven    : public unary_function<_Tp, size_t>
3355232950Stheraven{
3356232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3357232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3358232950Stheraven    {
3359232950Stheraven        union
3360232950Stheraven        {
3361232950Stheraven            _Tp __t;
3362232950Stheraven            struct
3363232950Stheraven            {
3364232950Stheraven                size_t __a;
3365232950Stheraven                size_t __b;
3366232950Stheraven                size_t __c;
3367232950Stheraven            };
3368232950Stheraven        } __u;
3369232950Stheraven        __u.__t = __v;
3370232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3371232950Stheraven    }
3372232950Stheraven};
3373232950Stheraven
3374232950Stheraventemplate <class _Tp>
3375232950Stheravenstruct __scalar_hash<_Tp, 4>
3376232950Stheraven    : public unary_function<_Tp, size_t>
3377232950Stheraven{
3378232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3379232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3380232950Stheraven    {
3381232950Stheraven        union
3382232950Stheraven        {
3383232950Stheraven            _Tp __t;
3384232950Stheraven            struct
3385232950Stheraven            {
3386232950Stheraven                size_t __a;
3387232950Stheraven                size_t __b;
3388232950Stheraven                size_t __c;
3389232950Stheraven                size_t __d;
3390232950Stheraven            };
3391232950Stheraven        } __u;
3392232950Stheraven        __u.__t = __v;
3393232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3394232950Stheraven    }
3395232950Stheraven};
3396232950Stheraven
3397232950Stheraventemplate<class _Tp>
3398249998Sdimstruct _LIBCPP_TYPE_VIS hash<_Tp*>
3399241903Sdim    : public unary_function<_Tp*, size_t>
3400232950Stheraven{
3401241903Sdim    _LIBCPP_INLINE_VISIBILITY
3402241903Sdim    size_t operator()(_Tp* __v) const _NOEXCEPT
3403241903Sdim    {
3404241903Sdim        union
3405241903Sdim        {
3406241903Sdim            _Tp* __t;
3407241903Sdim            size_t __a;
3408241903Sdim        } __u;
3409241903Sdim        __u.__t = __v;
3410241903Sdim        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3411241903Sdim    }
3412232950Stheraven};
3413232950Stheraven
3414227825Stheraventemplate <class _Tp, class _Dp>
3415249998Sdimstruct _LIBCPP_TYPE_VIS hash<unique_ptr<_Tp, _Dp> >
3416227825Stheraven{
3417227825Stheraven    typedef unique_ptr<_Tp, _Dp> argument_type;
3418227825Stheraven    typedef size_t               result_type;
3419227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3420227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3421227825Stheraven    {
3422227825Stheraven        typedef typename argument_type::pointer pointer;
3423227825Stheraven        return hash<pointer>()(__ptr.get());
3424227825Stheraven    }
3425227825Stheraven};
3426227825Stheraven
3427227825Stheravenstruct __destruct_n
3428227825Stheraven{
3429227825Stheravenprivate:
3430227825Stheraven    size_t size;
3431227825Stheraven
3432227825Stheraven    template <class _Tp>
3433227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3434227825Stheraven        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3435227825Stheraven
3436227825Stheraven    template <class _Tp>
3437227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3438227825Stheraven        {}
3439227825Stheraven
3440227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3441227825Stheraven        {++size;}
3442227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3443227825Stheraven        {}
3444227825Stheraven
3445227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3446227825Stheraven        {size = __s;}
3447227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3448227825Stheraven        {}
3449227825Stheravenpublic:
3450227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3451227825Stheraven        : size(__s) {}
3452227825Stheraven
3453227825Stheraven    template <class _Tp>
3454227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3455227825Stheraven        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3456227825Stheraven
3457227825Stheraven    template <class _Tp>
3458227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3459227825Stheraven        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3460227825Stheraven
3461227825Stheraven    template <class _Tp>
3462227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3463227825Stheraven        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3464227825Stheraven};
3465227825Stheraven
3466227825Stheraventemplate <class _Alloc>
3467227825Stheravenclass __allocator_destructor
3468227825Stheraven{
3469227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
3470227825Stheravenpublic:
3471227825Stheraven    typedef typename __alloc_traits::pointer pointer;
3472227825Stheraven    typedef typename __alloc_traits::size_type size_type;
3473227825Stheravenprivate:
3474227825Stheraven    _Alloc& __alloc_;
3475227825Stheraven    size_type __s_;
3476227825Stheravenpublic:
3477227825Stheraven    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3478227825Stheraven             _NOEXCEPT
3479227825Stheraven        : __alloc_(__a), __s_(__s) {}
3480227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3481227825Stheraven    void operator()(pointer __p) _NOEXCEPT
3482227825Stheraven        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3483227825Stheraven};
3484227825Stheraven
3485227825Stheraventemplate <class _InputIterator, class _ForwardIterator>
3486227825Stheraven_ForwardIterator
3487227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3488227825Stheraven{
3489227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3490232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3491232950Stheraven    _ForwardIterator __s = __r;
3492232950Stheraven    try
3493232950Stheraven    {
3494232950Stheraven#endif
3495232950Stheraven        for (; __f != __l; ++__f, ++__r)
3496232950Stheraven            ::new(&*__r) value_type(*__f);
3497232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3498232950Stheraven    }
3499232950Stheraven    catch (...)
3500232950Stheraven    {
3501232950Stheraven        for (; __s != __r; ++__s)
3502232950Stheraven            __s->~value_type();
3503232950Stheraven        throw;
3504232950Stheraven    }
3505232950Stheraven#endif
3506227825Stheraven    return __r;
3507227825Stheraven}
3508227825Stheraven
3509227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator>
3510227825Stheraven_ForwardIterator
3511227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3512227825Stheraven{
3513227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3514232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3515232950Stheraven    _ForwardIterator __s = __r;
3516232950Stheraven    try
3517232950Stheraven    {
3518232950Stheraven#endif
3519232950Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3520232950Stheraven            ::new(&*__r) value_type(*__f);
3521232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3522232950Stheraven    }
3523232950Stheraven    catch (...)
3524232950Stheraven    {
3525232950Stheraven        for (; __s != __r; ++__s)
3526232950Stheraven            __s->~value_type();
3527232950Stheraven        throw;
3528232950Stheraven    }
3529232950Stheraven#endif
3530227825Stheraven    return __r;
3531227825Stheraven}
3532227825Stheraven
3533227825Stheraventemplate <class _ForwardIterator, class _Tp>
3534227825Stheravenvoid
3535227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3536227825Stheraven{
3537227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3538232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3539232950Stheraven    _ForwardIterator __s = __f;
3540232950Stheraven    try
3541232950Stheraven    {
3542232950Stheraven#endif
3543232950Stheraven        for (; __f != __l; ++__f)
3544232950Stheraven            ::new(&*__f) value_type(__x);
3545232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3546232950Stheraven    }
3547232950Stheraven    catch (...)
3548232950Stheraven    {
3549232950Stheraven        for (; __s != __f; ++__s)
3550232950Stheraven            __s->~value_type();
3551232950Stheraven        throw;
3552232950Stheraven    }
3553232950Stheraven#endif
3554227825Stheraven}
3555227825Stheraven
3556227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp>
3557227825Stheraven_ForwardIterator
3558227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3559227825Stheraven{
3560227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3561232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3562232950Stheraven    _ForwardIterator __s = __f;
3563232950Stheraven    try
3564232950Stheraven    {
3565232950Stheraven#endif
3566232950Stheraven        for (; __n > 0; ++__f, --__n)
3567232950Stheraven            ::new(&*__f) value_type(__x);
3568232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3569232950Stheraven    }
3570232950Stheraven    catch (...)
3571232950Stheraven    {
3572232950Stheraven        for (; __s != __f; ++__s)
3573232950Stheraven            __s->~value_type();
3574232950Stheraven        throw;
3575232950Stheraven    }
3576232950Stheraven#endif
3577227825Stheraven    return __f;
3578227825Stheraven}
3579227825Stheraven
3580227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3581227825Stheraven    : public std::exception
3582227825Stheraven{
3583227825Stheravenpublic:
3584227825Stheraven    virtual ~bad_weak_ptr() _NOEXCEPT;
3585227825Stheraven    virtual const char* what() const  _NOEXCEPT;
3586227825Stheraven};
3587227825Stheraven
3588249998Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS weak_ptr;
3589227825Stheraven
3590227825Stheravenclass __shared_count
3591227825Stheraven{
3592227825Stheraven    __shared_count(const __shared_count&);
3593227825Stheraven    __shared_count& operator=(const __shared_count&);
3594227825Stheraven
3595227825Stheravenprotected:
3596227825Stheraven    long __shared_owners_;
3597227825Stheraven    virtual ~__shared_count();
3598227825Stheravenprivate:
3599227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT = 0;
3600227825Stheraven
3601227825Stheravenpublic:
3602227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3603227825Stheraven    explicit __shared_count(long __refs = 0) _NOEXCEPT
3604227825Stheraven        : __shared_owners_(__refs) {}
3605227825Stheraven
3606227825Stheraven    void __add_shared() _NOEXCEPT;
3607227825Stheraven    bool __release_shared() _NOEXCEPT;
3608227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3609227825Stheraven    long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3610227825Stheraven};
3611227825Stheraven
3612227825Stheravenclass __shared_weak_count
3613227825Stheraven    : private __shared_count
3614227825Stheraven{
3615227825Stheraven    long __shared_weak_owners_;
3616227825Stheraven
3617227825Stheravenpublic:
3618227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3619227825Stheraven    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3620227825Stheraven        : __shared_count(__refs),
3621227825Stheraven          __shared_weak_owners_(__refs) {}
3622227825Stheravenprotected:
3623227825Stheraven    virtual ~__shared_weak_count();
3624227825Stheraven
3625227825Stheravenpublic:
3626227825Stheraven    void __add_shared() _NOEXCEPT;
3627227825Stheraven    void __add_weak() _NOEXCEPT;
3628227825Stheraven    void __release_shared() _NOEXCEPT;
3629227825Stheraven    void __release_weak() _NOEXCEPT;
3630227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3631227825Stheraven    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3632227825Stheraven    __shared_weak_count* lock() _NOEXCEPT;
3633227825Stheraven
3634249998Sdim    // Define the function out only if we build static libc++ without RTTI.
3635249998Sdim    // Otherwise we may break clients who need to compile their projects with
3636249998Sdim    // -fno-rtti and yet link against a libc++.dylib compiled
3637249998Sdim    // without -fno-rtti.
3638249998Sdim#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3639227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3640249998Sdim#endif
3641227825Stheravenprivate:
3642227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3643227825Stheraven};
3644227825Stheraven
3645227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3646227825Stheravenclass __shared_ptr_pointer
3647227825Stheraven    : public __shared_weak_count
3648227825Stheraven{
3649227825Stheraven    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3650227825Stheravenpublic:
3651227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3652227825Stheraven    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3653227825Stheraven        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3654227825Stheraven
3655227825Stheraven#ifndef _LIBCPP_NO_RTTI
3656227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3657227825Stheraven#endif
3658227825Stheraven
3659227825Stheravenprivate:
3660227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3661227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3662227825Stheraven};
3663227825Stheraven
3664227825Stheraven#ifndef _LIBCPP_NO_RTTI
3665227825Stheraven
3666227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3667227825Stheravenconst void*
3668227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3669227825Stheraven{
3670227825Stheraven    return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3671227825Stheraven}
3672227825Stheraven
3673227825Stheraven#endif  // _LIBCPP_NO_RTTI
3674227825Stheraven
3675227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3676227825Stheravenvoid
3677227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3678227825Stheraven{
3679227825Stheraven    __data_.first().second()(__data_.first().first());
3680227825Stheraven    __data_.first().second().~_Dp();
3681227825Stheraven}
3682227825Stheraven
3683227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3684227825Stheravenvoid
3685227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3686227825Stheraven{
3687227825Stheraven    typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3688227825Stheraven    __data_.second().~_Alloc();
3689227825Stheraven    __a.deallocate(this, 1);
3690227825Stheraven}
3691227825Stheraven
3692227825Stheraventemplate <class _Tp, class _Alloc>
3693227825Stheravenclass __shared_ptr_emplace
3694227825Stheraven    : public __shared_weak_count
3695227825Stheraven{
3696227825Stheraven    __compressed_pair<_Alloc, _Tp> __data_;
3697227825Stheravenpublic:
3698227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3699227825Stheraven
3700227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3701227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3702227825Stheraven        :  __data_(_VSTD::move(__a)) {}
3703227825Stheraven
3704227825Stheraven    template <class ..._Args>
3705227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3706227825Stheraven        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3707232950Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3708232950Stheraven                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3709227825Stheraven
3710227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3711227825Stheraven
3712227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3713227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3714227825Stheraven        :  __data_(__a) {}
3715227825Stheraven
3716227825Stheraven    template <class _A0>
3717227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3718227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3719227825Stheraven            :  __data_(__a, _Tp(__a0)) {}
3720227825Stheraven
3721227825Stheraven    template <class _A0, class _A1>
3722227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3723227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3724227825Stheraven            :  __data_(__a, _Tp(__a0, __a1)) {}
3725227825Stheraven
3726227825Stheraven    template <class _A0, class _A1, class _A2>
3727227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3728227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3729227825Stheraven            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3730227825Stheraven
3731227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3732227825Stheraven
3733227825Stheravenprivate:
3734227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3735227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3736227825Stheravenpublic:
3737227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3738227825Stheraven    _Tp* get() _NOEXCEPT {return &__data_.second();}
3739227825Stheraven};
3740227825Stheraven
3741227825Stheraventemplate <class _Tp, class _Alloc>
3742227825Stheravenvoid
3743227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3744227825Stheraven{
3745227825Stheraven    __data_.second().~_Tp();
3746227825Stheraven}
3747227825Stheraven
3748227825Stheraventemplate <class _Tp, class _Alloc>
3749227825Stheravenvoid
3750227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3751227825Stheraven{
3752227825Stheraven    typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3753227825Stheraven    __data_.first().~_Alloc();
3754227825Stheraven    __a.deallocate(this, 1);
3755227825Stheraven}
3756227825Stheraven
3757249998Sdimtemplate<class _Tp> class _LIBCPP_TYPE_VIS enable_shared_from_this;
3758227825Stheraven
3759227825Stheraventemplate<class _Tp>
3760249998Sdimclass _LIBCPP_TYPE_VIS 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;
3772232950Stheraven    template<class _Yp,
3773232950Stheraven             class = typename enable_if
3774232950Stheraven                     <
3775232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3776232950Stheraven                     >::type
3777232950Stheraven            >
3778232950Stheraven        explicit shared_ptr(_Yp* __p);
3779232950Stheraven    template<class _Yp, class _Dp,
3780232950Stheraven             class = typename enable_if
3781232950Stheraven                     <
3782232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3783232950Stheraven                     >::type
3784232950Stheraven            >
3785232950Stheraven        shared_ptr(_Yp* __p, _Dp __d);
3786232950Stheraven    template<class _Yp, class _Dp, class _Alloc,
3787232950Stheraven             class = typename enable_if
3788232950Stheraven                     <
3789232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3790232950Stheraven                     >::type
3791232950Stheraven            >
3792232950Stheraven        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3793227825Stheraven    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3794227825Stheraven    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3795227825Stheraven    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3796227825Stheraven    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3797227825Stheraven    template<class _Yp>
3798227825Stheraven        shared_ptr(const shared_ptr<_Yp>& __r,
3799227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3800227825Stheraven                       _NOEXCEPT;
3801227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3802227825Stheraven    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3803227825Stheraven    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3804227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3805227825Stheraven                       _NOEXCEPT;
3806227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3807227825Stheraven    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3808227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3809227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3810232950Stheraven    template<class _Yp,
3811232950Stheraven             class = typename enable_if
3812232950Stheraven                     <
3813232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3814232950Stheraven                     >::type
3815232950Stheraven            >
3816232950Stheraven        shared_ptr(auto_ptr<_Yp>&& __r);
3817227825Stheraven#else
3818232950Stheraven    template<class _Yp,
3819232950Stheraven             class = typename enable_if
3820232950Stheraven                     <
3821232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3822232950Stheraven                     >::type
3823232950Stheraven            >
3824232950Stheraven        shared_ptr(auto_ptr<_Yp> __r);
3825227825Stheraven#endif
3826227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3827232950Stheraven    template <class _Yp, class _Dp,
3828232950Stheraven                 class = typename enable_if
3829232950Stheraven                 <
3830232950Stheraven                    !is_array<_Yp>::value &&
3831232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3832232950Stheraven                 >::type
3833232950Stheraven             >
3834232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3835227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3836232950Stheraven    template <class _Yp, class _Dp,
3837232950Stheraven                 class = typename enable_if
3838232950Stheraven                 <
3839232950Stheraven                    !is_array<_Yp>::value &&
3840232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3841232950Stheraven                 >::type
3842232950Stheraven             >
3843232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3844227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3845227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3846232950Stheraven    template <class _Yp, class _Dp,
3847232950Stheraven                 class = typename enable_if
3848232950Stheraven                 <
3849232950Stheraven                    !is_array<_Yp>::value &&
3850232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3851232950Stheraven                 >::type
3852232950Stheraven             > shared_ptr(unique_ptr<_Yp, _Dp>,
3853227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3854232950Stheraven    template <class _Yp, class _Dp,
3855232950Stheraven                 class = typename enable_if
3856232950Stheraven                 <
3857232950Stheraven                    !is_array<_Yp>::value &&
3858232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3859232950Stheraven                 >::type
3860232950Stheraven             >
3861232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>,
3862227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3863227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3864227825Stheraven
3865227825Stheraven    ~shared_ptr();
3866227825Stheraven
3867227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3868232950Stheraven    template<class _Yp>
3869232950Stheraven        typename enable_if
3870232950Stheraven        <
3871232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3872232950Stheraven            shared_ptr&
3873232950Stheraven        >::type
3874232950Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3875227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3876227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3877232950Stheraven    template<class _Yp>
3878232950Stheraven        typename enable_if
3879232950Stheraven        <
3880232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3881232950Stheraven            shared_ptr<_Tp>&
3882232950Stheraven        >::type
3883232950Stheraven        operator=(shared_ptr<_Yp>&& __r);
3884232950Stheraven    template<class _Yp>
3885232950Stheraven        typename enable_if
3886232950Stheraven        <
3887232950Stheraven            !is_array<_Yp>::value &&
3888232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3889232950Stheraven            shared_ptr&
3890232950Stheraven        >::type
3891232950Stheraven        operator=(auto_ptr<_Yp>&& __r);
3892227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3893232950Stheraven    template<class _Yp>
3894232950Stheraven        typename enable_if
3895232950Stheraven        <
3896232950Stheraven            !is_array<_Yp>::value &&
3897232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3898232950Stheraven            shared_ptr&
3899232950Stheraven        >::type
3900232950Stheraven        operator=(auto_ptr<_Yp> __r);
3901227825Stheraven#endif
3902232950Stheraven    template <class _Yp, class _Dp>
3903232950Stheraven        typename enable_if
3904232950Stheraven        <
3905232950Stheraven            !is_array<_Yp>::value &&
3906232950Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3907232950Stheraven            shared_ptr&
3908232950Stheraven        >::type
3909227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3910232950Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3911227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3912232950Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3913227825Stheraven#endif
3914227825Stheraven
3915227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3916227825Stheraven    void reset() _NOEXCEPT;
3917232950Stheraven    template<class _Yp>
3918232950Stheraven        typename enable_if
3919232950Stheraven        <
3920232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3921232950Stheraven            void
3922232950Stheraven        >::type
3923232950Stheraven        reset(_Yp* __p);
3924232950Stheraven    template<class _Yp, class _Dp>
3925232950Stheraven        typename enable_if
3926232950Stheraven        <
3927232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3928232950Stheraven            void
3929232950Stheraven        >::type
3930232950Stheraven        reset(_Yp* __p, _Dp __d);
3931232950Stheraven    template<class _Yp, class _Dp, class _Alloc>
3932232950Stheraven        typename enable_if
3933232950Stheraven        <
3934232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3935232950Stheraven            void
3936232950Stheraven        >::type
3937232950Stheraven        reset(_Yp* __p, _Dp __d, _Alloc __a);
3938227825Stheraven
3939227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3940227825Stheraven    element_type* get() const _NOEXCEPT {return __ptr_;}
3941227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3942227825Stheraven    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3943227825Stheraven        {return *__ptr_;}
3944227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3945227825Stheraven    element_type* operator->() const _NOEXCEPT {return __ptr_;}
3946227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3947227825Stheraven    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3948227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3949227825Stheraven    bool unique() const _NOEXCEPT {return use_count() == 1;}
3950227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3951232950Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3952232950Stheraven    template <class _Up>
3953227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3954232950Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
3955227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3956232950Stheraven    template <class _Up>
3957227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3958232950Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
3959227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3960241903Sdim    _LIBCPP_INLINE_VISIBILITY
3961241903Sdim    bool
3962241903Sdim    __owner_equivalent(const shared_ptr& __p) const
3963241903Sdim        {return __cntrl_ == __p.__cntrl_;}
3964227825Stheraven
3965227825Stheraven#ifndef _LIBCPP_NO_RTTI
3966227825Stheraven    template <class _Dp>
3967227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3968227825Stheraven        _Dp* __get_deleter() const _NOEXCEPT
3969227825Stheraven            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3970227825Stheraven#endif  // _LIBCPP_NO_RTTI
3971227825Stheraven
3972227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3973227825Stheraven
3974227825Stheraven    template<class ..._Args>
3975227825Stheraven        static
3976227825Stheraven        shared_ptr<_Tp>
3977227825Stheraven        make_shared(_Args&& ...__args);
3978227825Stheraven
3979227825Stheraven    template<class _Alloc, class ..._Args>
3980227825Stheraven        static
3981227825Stheraven        shared_ptr<_Tp>
3982227825Stheraven        allocate_shared(const _Alloc& __a, _Args&& ...__args);
3983227825Stheraven
3984227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3985227825Stheraven
3986227825Stheraven    static shared_ptr<_Tp> make_shared();
3987227825Stheraven
3988227825Stheraven    template<class _A0>
3989227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&);
3990227825Stheraven
3991227825Stheraven    template<class _A0, class _A1>
3992227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3993227825Stheraven
3994227825Stheraven    template<class _A0, class _A1, class _A2>
3995227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3996227825Stheraven
3997227825Stheraven    template<class _Alloc>
3998227825Stheraven        static shared_ptr<_Tp>
3999227825Stheraven        allocate_shared(const _Alloc& __a);
4000227825Stheraven
4001227825Stheraven    template<class _Alloc, class _A0>
4002227825Stheraven        static shared_ptr<_Tp>
4003227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0);
4004227825Stheraven
4005227825Stheraven    template<class _Alloc, class _A0, class _A1>
4006227825Stheraven        static shared_ptr<_Tp>
4007227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4008227825Stheraven
4009227825Stheraven    template<class _Alloc, class _A0, class _A1, class _A2>
4010227825Stheraven        static shared_ptr<_Tp>
4011227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4012227825Stheraven
4013227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4014227825Stheraven
4015227825Stheravenprivate:
4016227825Stheraven
4017227825Stheraven    template <class _Yp>
4018227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4019227825Stheraven        void
4020227825Stheraven        __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4021227825Stheraven        {
4022227825Stheraven            if (__e)
4023227825Stheraven                __e->__weak_this_ = *this;
4024227825Stheraven        }
4025227825Stheraven
4026227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4027227825Stheraven    void __enable_weak_this(const void*) _NOEXCEPT {}
4028227825Stheraven
4029249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
4030249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
4031227825Stheraven};
4032227825Stheraven
4033227825Stheraventemplate<class _Tp>
4034227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4035241903Sdim_LIBCPP_CONSTEXPR
4036227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4037227825Stheraven    : __ptr_(0),
4038227825Stheraven      __cntrl_(0)
4039227825Stheraven{
4040227825Stheraven}
4041227825Stheraven
4042227825Stheraventemplate<class _Tp>
4043227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4044241903Sdim_LIBCPP_CONSTEXPR
4045227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4046227825Stheraven    : __ptr_(0),
4047227825Stheraven      __cntrl_(0)
4048227825Stheraven{
4049227825Stheraven}
4050227825Stheraven
4051227825Stheraventemplate<class _Tp>
4052232950Stheraventemplate<class _Yp, class>
4053227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p)
4054227825Stheraven    : __ptr_(__p)
4055227825Stheraven{
4056227825Stheraven    unique_ptr<_Yp> __hold(__p);
4057227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4058227825Stheraven    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4059227825Stheraven    __hold.release();
4060227825Stheraven    __enable_weak_this(__p);
4061227825Stheraven}
4062227825Stheraven
4063227825Stheraventemplate<class _Tp>
4064232950Stheraventemplate<class _Yp, class _Dp, class>
4065227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4066227825Stheraven    : __ptr_(__p)
4067227825Stheraven{
4068227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4069227825Stheraven    try
4070227825Stheraven    {
4071227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4072227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4073227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4074227825Stheraven        __enable_weak_this(__p);
4075227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4076227825Stheraven    }
4077227825Stheraven    catch (...)
4078227825Stheraven    {
4079227825Stheraven        __d(__p);
4080227825Stheraven        throw;
4081227825Stheraven    }
4082227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4083227825Stheraven}
4084227825Stheraven
4085227825Stheraventemplate<class _Tp>
4086227825Stheraventemplate<class _Dp>
4087227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4088227825Stheraven    : __ptr_(0)
4089227825Stheraven{
4090227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4091227825Stheraven    try
4092227825Stheraven    {
4093227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4094227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4095227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4096227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4097227825Stheraven    }
4098227825Stheraven    catch (...)
4099227825Stheraven    {
4100227825Stheraven        __d(__p);
4101227825Stheraven        throw;
4102227825Stheraven    }
4103227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4104227825Stheraven}
4105227825Stheraven
4106227825Stheraventemplate<class _Tp>
4107232950Stheraventemplate<class _Yp, class _Dp, class _Alloc, class>
4108227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4109227825Stheraven    : __ptr_(__p)
4110227825Stheraven{
4111227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4112227825Stheraven    try
4113227825Stheraven    {
4114227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4115227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4116227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4117227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4118227825Stheraven        _A2 __a2(__a);
4119227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4120227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4121227825Stheraven        __cntrl_ = __hold2.release();
4122227825Stheraven        __enable_weak_this(__p);
4123227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4124227825Stheraven    }
4125227825Stheraven    catch (...)
4126227825Stheraven    {
4127227825Stheraven        __d(__p);
4128227825Stheraven        throw;
4129227825Stheraven    }
4130227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4131227825Stheraven}
4132227825Stheraven
4133227825Stheraventemplate<class _Tp>
4134227825Stheraventemplate<class _Dp, class _Alloc>
4135227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4136227825Stheraven    : __ptr_(0)
4137227825Stheraven{
4138227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4139227825Stheraven    try
4140227825Stheraven    {
4141227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4142227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4143227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4144227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4145227825Stheraven        _A2 __a2(__a);
4146227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4147227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4148227825Stheraven        __cntrl_ = __hold2.release();
4149227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4150227825Stheraven    }
4151227825Stheraven    catch (...)
4152227825Stheraven    {
4153227825Stheraven        __d(__p);
4154227825Stheraven        throw;
4155227825Stheraven    }
4156227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4157227825Stheraven}
4158227825Stheraven
4159227825Stheraventemplate<class _Tp>
4160227825Stheraventemplate<class _Yp>
4161227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4162227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4163227825Stheraven    : __ptr_(__p),
4164227825Stheraven      __cntrl_(__r.__cntrl_)
4165227825Stheraven{
4166227825Stheraven    if (__cntrl_)
4167227825Stheraven        __cntrl_->__add_shared();
4168227825Stheraven}
4169227825Stheraven
4170227825Stheraventemplate<class _Tp>
4171227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4172227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4173227825Stheraven    : __ptr_(__r.__ptr_),
4174227825Stheraven      __cntrl_(__r.__cntrl_)
4175227825Stheraven{
4176227825Stheraven    if (__cntrl_)
4177227825Stheraven        __cntrl_->__add_shared();
4178227825Stheraven}
4179227825Stheraven
4180227825Stheraventemplate<class _Tp>
4181227825Stheraventemplate<class _Yp>
4182227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4183227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4184227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4185227825Stheraven         _NOEXCEPT
4186227825Stheraven    : __ptr_(__r.__ptr_),
4187227825Stheraven      __cntrl_(__r.__cntrl_)
4188227825Stheraven{
4189227825Stheraven    if (__cntrl_)
4190227825Stheraven        __cntrl_->__add_shared();
4191227825Stheraven}
4192227825Stheraven
4193227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4194227825Stheraven
4195227825Stheraventemplate<class _Tp>
4196227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4197227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4198227825Stheraven    : __ptr_(__r.__ptr_),
4199227825Stheraven      __cntrl_(__r.__cntrl_)
4200227825Stheraven{
4201227825Stheraven    __r.__ptr_ = 0;
4202227825Stheraven    __r.__cntrl_ = 0;
4203227825Stheraven}
4204227825Stheraven
4205227825Stheraventemplate<class _Tp>
4206227825Stheraventemplate<class _Yp>
4207227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4208227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4209227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4210227825Stheraven         _NOEXCEPT
4211227825Stheraven    : __ptr_(__r.__ptr_),
4212227825Stheraven      __cntrl_(__r.__cntrl_)
4213227825Stheraven{
4214227825Stheraven    __r.__ptr_ = 0;
4215227825Stheraven    __r.__cntrl_ = 0;
4216227825Stheraven}
4217227825Stheraven
4218227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4219227825Stheraven
4220227825Stheraventemplate<class _Tp>
4221232950Stheraventemplate<class _Yp, class>
4222227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4223227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4224227825Stheraven#else
4225227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4226227825Stheraven#endif
4227227825Stheraven    : __ptr_(__r.get())
4228227825Stheraven{
4229227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4230227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4231227825Stheraven    __enable_weak_this(__r.get());
4232227825Stheraven    __r.release();
4233227825Stheraven}
4234227825Stheraven
4235227825Stheraventemplate<class _Tp>
4236232950Stheraventemplate <class _Yp, class _Dp, class>
4237227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4238227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4239227825Stheraven#else
4240227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4241227825Stheraven#endif
4242227825Stheraven           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4243227825Stheraven    : __ptr_(__r.get())
4244227825Stheraven{
4245227825Stheraven    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4246227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4247227825Stheraven    __enable_weak_this(__r.get());
4248227825Stheraven    __r.release();
4249227825Stheraven}
4250227825Stheraven
4251227825Stheraventemplate<class _Tp>
4252232950Stheraventemplate <class _Yp, class _Dp, class>
4253227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4254227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4255227825Stheraven#else
4256227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4257227825Stheraven#endif
4258227825Stheraven           typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4259227825Stheraven    : __ptr_(__r.get())
4260227825Stheraven{
4261227825Stheraven    typedef __shared_ptr_pointer<_Yp*,
4262227825Stheraven                                 reference_wrapper<typename remove_reference<_Dp>::type>,
4263227825Stheraven                                 allocator<_Yp> > _CntrlBlk;
4264227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4265227825Stheraven    __enable_weak_this(__r.get());
4266227825Stheraven    __r.release();
4267227825Stheraven}
4268227825Stheraven
4269227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4270227825Stheraven
4271227825Stheraventemplate<class _Tp>
4272227825Stheraventemplate<class ..._Args>
4273227825Stheravenshared_ptr<_Tp>
4274227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args)
4275227825Stheraven{
4276227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4277227825Stheraven    typedef allocator<_CntrlBlk> _A2;
4278227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4279227825Stheraven    _A2 __a2;
4280227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4281227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4282227825Stheraven    shared_ptr<_Tp> __r;
4283227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4284227825Stheraven    __r.__cntrl_ = __hold2.release();
4285227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4286227825Stheraven    return __r;
4287227825Stheraven}
4288227825Stheraven
4289227825Stheraventemplate<class _Tp>
4290227825Stheraventemplate<class _Alloc, class ..._Args>
4291227825Stheravenshared_ptr<_Tp>
4292227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4293227825Stheraven{
4294227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4295227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4296227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4297227825Stheraven    _A2 __a2(__a);
4298227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4299227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4300227825Stheraven    shared_ptr<_Tp> __r;
4301227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4302227825Stheraven    __r.__cntrl_ = __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;
4386227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4387227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4388227825Stheraven    _Alloc2 __alloc2(__a);
4389227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4390227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a);
4391227825Stheraven    shared_ptr<_Tp> __r;
4392227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4393227825Stheraven    __r.__cntrl_ = __hold2.release();
4394227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4395227825Stheraven    return __r;
4396227825Stheraven}
4397227825Stheraven
4398227825Stheraventemplate<class _Tp>
4399227825Stheraventemplate<class _Alloc, class _A0>
4400227825Stheravenshared_ptr<_Tp>
4401227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4402227825Stheraven{
4403227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4404227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4405227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4406227825Stheraven    _Alloc2 __alloc2(__a);
4407227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4408227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4409227825Stheraven    shared_ptr<_Tp> __r;
4410227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4411227825Stheraven    __r.__cntrl_ = __hold2.release();
4412227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4413227825Stheraven    return __r;
4414227825Stheraven}
4415227825Stheraven
4416227825Stheraventemplate<class _Tp>
4417227825Stheraventemplate<class _Alloc, class _A0, class _A1>
4418227825Stheravenshared_ptr<_Tp>
4419227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4420227825Stheraven{
4421227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4422227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4423227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4424227825Stheraven    _Alloc2 __alloc2(__a);
4425227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4426227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4427227825Stheraven    shared_ptr<_Tp> __r;
4428227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4429227825Stheraven    __r.__cntrl_ = __hold2.release();
4430227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4431227825Stheraven    return __r;
4432227825Stheraven}
4433227825Stheraven
4434227825Stheraventemplate<class _Tp>
4435227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2>
4436227825Stheravenshared_ptr<_Tp>
4437227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4438227825Stheraven{
4439227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4440227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4441227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4442227825Stheraven    _Alloc2 __alloc2(__a);
4443227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4444227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4445227825Stheraven    shared_ptr<_Tp> __r;
4446227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4447227825Stheraven    __r.__cntrl_ = __hold2.release();
4448227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4449227825Stheraven    return __r;
4450227825Stheraven}
4451227825Stheraven
4452227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4453227825Stheraven
4454227825Stheraventemplate<class _Tp>
4455227825Stheravenshared_ptr<_Tp>::~shared_ptr()
4456227825Stheraven{
4457227825Stheraven    if (__cntrl_)
4458227825Stheraven        __cntrl_->__release_shared();
4459227825Stheraven}
4460227825Stheraven
4461227825Stheraventemplate<class _Tp>
4462227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4463227825Stheravenshared_ptr<_Tp>&
4464227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4465227825Stheraven{
4466227825Stheraven    shared_ptr(__r).swap(*this);
4467227825Stheraven    return *this;
4468227825Stheraven}
4469227825Stheraven
4470227825Stheraventemplate<class _Tp>
4471227825Stheraventemplate<class _Yp>
4472227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4473232950Stheraventypename enable_if
4474232950Stheraven<
4475232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4476232950Stheraven    shared_ptr<_Tp>&
4477232950Stheraven>::type
4478227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4479227825Stheraven{
4480227825Stheraven    shared_ptr(__r).swap(*this);
4481227825Stheraven    return *this;
4482227825Stheraven}
4483227825Stheraven
4484227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4485227825Stheraven
4486227825Stheraventemplate<class _Tp>
4487227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4488227825Stheravenshared_ptr<_Tp>&
4489227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4490227825Stheraven{
4491227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4492227825Stheraven    return *this;
4493227825Stheraven}
4494227825Stheraven
4495227825Stheraventemplate<class _Tp>
4496227825Stheraventemplate<class _Yp>
4497227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4498232950Stheraventypename enable_if
4499232950Stheraven<
4500232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4501232950Stheraven    shared_ptr<_Tp>&
4502232950Stheraven>::type
4503227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4504227825Stheraven{
4505227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4506227825Stheraven    return *this;
4507227825Stheraven}
4508227825Stheraven
4509227825Stheraventemplate<class _Tp>
4510227825Stheraventemplate<class _Yp>
4511227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4512232950Stheraventypename enable_if
4513232950Stheraven<
4514232950Stheraven    !is_array<_Yp>::value &&
4515232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4516232950Stheraven    shared_ptr<_Tp>&
4517232950Stheraven>::type
4518227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4519227825Stheraven{
4520227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4521227825Stheraven    return *this;
4522227825Stheraven}
4523227825Stheraven
4524227825Stheraventemplate<class _Tp>
4525227825Stheraventemplate <class _Yp, class _Dp>
4526227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4527232950Stheraventypename enable_if
4528232950Stheraven<
4529232950Stheraven    !is_array<_Yp>::value &&
4530232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4531232950Stheraven    shared_ptr<_Tp>&
4532232950Stheraven>::type
4533227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4534227825Stheraven{
4535227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4536227825Stheraven    return *this;
4537227825Stheraven}
4538227825Stheraven
4539227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4540227825Stheraven
4541227825Stheraventemplate<class _Tp>
4542227825Stheraventemplate<class _Yp>
4543227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4544232950Stheraventypename enable_if
4545232950Stheraven<
4546232950Stheraven    !is_array<_Yp>::value &&
4547232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4548232950Stheraven    shared_ptr<_Tp>&
4549232950Stheraven>::type
4550227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4551227825Stheraven{
4552227825Stheraven    shared_ptr(__r).swap(*this);
4553227825Stheraven    return *this;
4554227825Stheraven}
4555227825Stheraven
4556227825Stheraventemplate<class _Tp>
4557227825Stheraventemplate <class _Yp, class _Dp>
4558227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4559232950Stheraventypename enable_if
4560232950Stheraven<
4561232950Stheraven    !is_array<_Yp>::value &&
4562232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4563232950Stheraven    shared_ptr<_Tp>&
4564232950Stheraven>::type
4565227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4566227825Stheraven{
4567227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4568227825Stheraven    return *this;
4569227825Stheraven}
4570227825Stheraven
4571227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4572227825Stheraven
4573227825Stheraventemplate<class _Tp>
4574227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4575227825Stheravenvoid
4576227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4577227825Stheraven{
4578227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
4579227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
4580227825Stheraven}
4581227825Stheraven
4582227825Stheraventemplate<class _Tp>
4583227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4584227825Stheravenvoid
4585227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT
4586227825Stheraven{
4587227825Stheraven    shared_ptr().swap(*this);
4588227825Stheraven}
4589227825Stheraven
4590227825Stheraventemplate<class _Tp>
4591227825Stheraventemplate<class _Yp>
4592227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4593232950Stheraventypename enable_if
4594232950Stheraven<
4595232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4596232950Stheraven    void
4597232950Stheraven>::type
4598227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p)
4599227825Stheraven{
4600227825Stheraven    shared_ptr(__p).swap(*this);
4601227825Stheraven}
4602227825Stheraven
4603227825Stheraventemplate<class _Tp>
4604227825Stheraventemplate<class _Yp, class _Dp>
4605227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4606232950Stheraventypename enable_if
4607232950Stheraven<
4608232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4609232950Stheraven    void
4610232950Stheraven>::type
4611227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4612227825Stheraven{
4613227825Stheraven    shared_ptr(__p, __d).swap(*this);
4614227825Stheraven}
4615227825Stheraven
4616227825Stheraventemplate<class _Tp>
4617227825Stheraventemplate<class _Yp, class _Dp, class _Alloc>
4618227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4619232950Stheraventypename enable_if
4620232950Stheraven<
4621232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4622232950Stheraven    void
4623232950Stheraven>::type
4624227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4625227825Stheraven{
4626227825Stheraven    shared_ptr(__p, __d, __a).swap(*this);
4627227825Stheraven}
4628227825Stheraven
4629227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4630227825Stheraven
4631227825Stheraventemplate<class _Tp, class ..._Args>
4632227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4633232950Stheraventypename enable_if
4634232950Stheraven<
4635232950Stheraven    !is_array<_Tp>::value,
4636232950Stheraven    shared_ptr<_Tp>
4637232950Stheraven>::type
4638227825Stheravenmake_shared(_Args&& ...__args)
4639227825Stheraven{
4640227825Stheraven    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4641227825Stheraven}
4642227825Stheraven
4643227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args>
4644227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4645232950Stheraventypename enable_if
4646232950Stheraven<
4647232950Stheraven    !is_array<_Tp>::value,
4648232950Stheraven    shared_ptr<_Tp>
4649232950Stheraven>::type
4650227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args)
4651227825Stheraven{
4652227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4653227825Stheraven}
4654227825Stheraven
4655227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4656227825Stheraven
4657227825Stheraventemplate<class _Tp>
4658227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4659227825Stheravenshared_ptr<_Tp>
4660227825Stheravenmake_shared()
4661227825Stheraven{
4662227825Stheraven    return shared_ptr<_Tp>::make_shared();
4663227825Stheraven}
4664227825Stheraven
4665227825Stheraventemplate<class _Tp, class _A0>
4666227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4667227825Stheravenshared_ptr<_Tp>
4668227825Stheravenmake_shared(_A0& __a0)
4669227825Stheraven{
4670227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0);
4671227825Stheraven}
4672227825Stheraven
4673227825Stheraventemplate<class _Tp, class _A0, class _A1>
4674227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4675227825Stheravenshared_ptr<_Tp>
4676227825Stheravenmake_shared(_A0& __a0, _A1& __a1)
4677227825Stheraven{
4678227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4679227825Stheraven}
4680227825Stheraven
4681227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2>
4682227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4683227825Stheravenshared_ptr<_Tp>
4684227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4685227825Stheraven{
4686227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4687227825Stheraven}
4688227825Stheraven
4689227825Stheraventemplate<class _Tp, class _Alloc>
4690227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4691227825Stheravenshared_ptr<_Tp>
4692227825Stheravenallocate_shared(const _Alloc& __a)
4693227825Stheraven{
4694227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a);
4695227825Stheraven}
4696227825Stheraven
4697227825Stheraventemplate<class _Tp, class _Alloc, class _A0>
4698227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4699227825Stheravenshared_ptr<_Tp>
4700227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0)
4701227825Stheraven{
4702227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4703227825Stheraven}
4704227825Stheraven
4705227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1>
4706227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4707227825Stheravenshared_ptr<_Tp>
4708227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4709227825Stheraven{
4710227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4711227825Stheraven}
4712227825Stheraven
4713227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4714227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4715227825Stheravenshared_ptr<_Tp>
4716227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4717227825Stheraven{
4718227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4719227825Stheraven}
4720227825Stheraven
4721227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4722227825Stheraven
4723227825Stheraventemplate<class _Tp, class _Up>
4724227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4725227825Stheravenbool
4726227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4727227825Stheraven{
4728227825Stheraven    return __x.get() == __y.get();
4729227825Stheraven}
4730227825Stheraven
4731227825Stheraventemplate<class _Tp, class _Up>
4732227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4733227825Stheravenbool
4734227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4735227825Stheraven{
4736227825Stheraven    return !(__x == __y);
4737227825Stheraven}
4738227825Stheraven
4739227825Stheraventemplate<class _Tp, class _Up>
4740227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4741227825Stheravenbool
4742227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4743227825Stheraven{
4744232950Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4745232950Stheraven    return less<_V>()(__x.get(), __y.get());
4746227825Stheraven}
4747227825Stheraven
4748232950Stheraventemplate<class _Tp, class _Up>
4749232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4750232950Stheravenbool
4751232950Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4752232950Stheraven{
4753232950Stheraven    return __y < __x;
4754232950Stheraven}
4755232950Stheraven
4756232950Stheraventemplate<class _Tp, class _Up>
4757232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4758232950Stheravenbool
4759232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4760232950Stheraven{
4761232950Stheraven    return !(__y < __x);
4762232950Stheraven}
4763232950Stheraven
4764232950Stheraventemplate<class _Tp, class _Up>
4765232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4766232950Stheravenbool
4767232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4768232950Stheraven{
4769232950Stheraven    return !(__x < __y);
4770232950Stheraven}
4771232950Stheraven
4772227825Stheraventemplate<class _Tp>
4773227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4774232950Stheravenbool
4775232950Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4776232950Stheraven{
4777232950Stheraven    return !__x;
4778232950Stheraven}
4779232950Stheraven
4780232950Stheraventemplate<class _Tp>
4781232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4782232950Stheravenbool
4783232950Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4784232950Stheraven{
4785232950Stheraven    return !__x;
4786232950Stheraven}
4787232950Stheraven
4788232950Stheraventemplate<class _Tp>
4789232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4790232950Stheravenbool
4791232950Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4792232950Stheraven{
4793232950Stheraven    return static_cast<bool>(__x);
4794232950Stheraven}
4795232950Stheraven
4796232950Stheraventemplate<class _Tp>
4797232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4798232950Stheravenbool
4799232950Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4800232950Stheraven{
4801232950Stheraven    return static_cast<bool>(__x);
4802232950Stheraven}
4803232950Stheraven
4804232950Stheraventemplate<class _Tp>
4805232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4806232950Stheravenbool
4807232950Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4808232950Stheraven{
4809232950Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4810232950Stheraven}
4811232950Stheraven
4812232950Stheraventemplate<class _Tp>
4813232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4814232950Stheravenbool
4815232950Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4816232950Stheraven{
4817232950Stheraven    return less<_Tp*>()(nullptr, __x.get());
4818232950Stheraven}
4819232950Stheraven
4820232950Stheraventemplate<class _Tp>
4821232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4822232950Stheravenbool
4823232950Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4824232950Stheraven{
4825232950Stheraven    return nullptr < __x;
4826232950Stheraven}
4827232950Stheraven
4828232950Stheraventemplate<class _Tp>
4829232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4830232950Stheravenbool
4831232950Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4832232950Stheraven{
4833232950Stheraven    return __x < nullptr;
4834232950Stheraven}
4835232950Stheraven
4836232950Stheraventemplate<class _Tp>
4837232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4838232950Stheravenbool
4839232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4840232950Stheraven{
4841232950Stheraven    return !(nullptr < __x);
4842232950Stheraven}
4843232950Stheraven
4844232950Stheraventemplate<class _Tp>
4845232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4846232950Stheravenbool
4847232950Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4848232950Stheraven{
4849232950Stheraven    return !(__x < nullptr);
4850232950Stheraven}
4851232950Stheraven
4852232950Stheraventemplate<class _Tp>
4853232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4854232950Stheravenbool
4855232950Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4856232950Stheraven{
4857232950Stheraven    return !(__x < nullptr);
4858232950Stheraven}
4859232950Stheraven
4860232950Stheraventemplate<class _Tp>
4861232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4862232950Stheravenbool
4863232950Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4864232950Stheraven{
4865232950Stheraven    return !(nullptr < __x);
4866232950Stheraven}
4867232950Stheraven
4868232950Stheraventemplate<class _Tp>
4869232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4870227825Stheravenvoid
4871227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4872227825Stheraven{
4873227825Stheraven    __x.swap(__y);
4874227825Stheraven}
4875227825Stheraven
4876227825Stheraventemplate<class _Tp, class _Up>
4877227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4878232950Stheraventypename enable_if
4879232950Stheraven<
4880232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4881232950Stheraven    shared_ptr<_Tp>
4882232950Stheraven>::type
4883227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4884227825Stheraven{
4885227825Stheraven    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4886227825Stheraven}
4887227825Stheraven
4888227825Stheraventemplate<class _Tp, class _Up>
4889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4890232950Stheraventypename enable_if
4891232950Stheraven<
4892232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4893232950Stheraven    shared_ptr<_Tp>
4894232950Stheraven>::type
4895227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4896227825Stheraven{
4897227825Stheraven    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4898227825Stheraven    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4899227825Stheraven}
4900227825Stheraven
4901227825Stheraventemplate<class _Tp, class _Up>
4902232950Stheraventypename enable_if
4903232950Stheraven<
4904232950Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4905232950Stheraven    shared_ptr<_Tp>
4906232950Stheraven>::type
4907227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4908227825Stheraven{
4909232950Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4910232950Stheraven    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4911227825Stheraven}
4912227825Stheraven
4913227825Stheraven#ifndef _LIBCPP_NO_RTTI
4914227825Stheraven
4915227825Stheraventemplate<class _Dp, class _Tp>
4916227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4917227825Stheraven_Dp*
4918227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4919227825Stheraven{
4920227825Stheraven    return __p.template __get_deleter<_Dp>();
4921227825Stheraven}
4922227825Stheraven
4923227825Stheraven#endif  // _LIBCPP_NO_RTTI
4924227825Stheraven
4925227825Stheraventemplate<class _Tp>
4926249998Sdimclass _LIBCPP_TYPE_VIS weak_ptr
4927227825Stheraven{
4928227825Stheravenpublic:
4929227825Stheraven    typedef _Tp element_type;
4930227825Stheravenprivate:
4931227825Stheraven    element_type*        __ptr_;
4932227825Stheraven    __shared_weak_count* __cntrl_;
4933227825Stheraven
4934227825Stheravenpublic:
4935241903Sdim    _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4936227825Stheraven    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4937227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4938227825Stheraven                        _NOEXCEPT;
4939227825Stheraven    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4940227825Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4941227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4942227825Stheraven                         _NOEXCEPT;
4943227825Stheraven
4944232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4945232950Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4946232950Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4947232950Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4948232950Stheraven                         _NOEXCEPT;
4949232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4950227825Stheraven    ~weak_ptr();
4951227825Stheraven
4952227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4953232950Stheraven    template<class _Yp>
4954232950Stheraven        typename enable_if
4955232950Stheraven        <
4956232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4957232950Stheraven            weak_ptr&
4958232950Stheraven        >::type
4959232950Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4960227825Stheraven
4961232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4962232950Stheraven
4963232950Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4964232950Stheraven    template<class _Yp>
4965232950Stheraven        typename enable_if
4966232950Stheraven        <
4967232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4968232950Stheraven            weak_ptr&
4969232950Stheraven        >::type
4970232950Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4971232950Stheraven
4972232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4973232950Stheraven
4974232950Stheraven    template<class _Yp>
4975232950Stheraven        typename enable_if
4976232950Stheraven        <
4977232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4978232950Stheraven            weak_ptr&
4979232950Stheraven        >::type
4980232950Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4981232950Stheraven
4982227825Stheraven    void swap(weak_ptr& __r) _NOEXCEPT;
4983227825Stheraven    void reset() _NOEXCEPT;
4984227825Stheraven
4985227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4986227825Stheraven    long use_count() const _NOEXCEPT
4987227825Stheraven        {return __cntrl_ ? __cntrl_->use_count() : 0;}
4988227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4989227825Stheraven    bool expired() const _NOEXCEPT
4990227825Stheraven        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4991227825Stheraven    shared_ptr<_Tp> lock() const _NOEXCEPT;
4992227825Stheraven    template<class _Up>
4993227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4994227825Stheraven        bool owner_before(const shared_ptr<_Up>& __r) const
4995227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
4996227825Stheraven    template<class _Up>
4997227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4998227825Stheraven        bool owner_before(const weak_ptr<_Up>& __r) const
4999227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
5000227825Stheraven
5001249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS weak_ptr;
5002249998Sdim    template <class _Up> friend class _LIBCPP_TYPE_VIS shared_ptr;
5003227825Stheraven};
5004227825Stheraven
5005227825Stheraventemplate<class _Tp>
5006227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5007241903Sdim_LIBCPP_CONSTEXPR
5008227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5009227825Stheraven    : __ptr_(0),
5010227825Stheraven      __cntrl_(0)
5011227825Stheraven{
5012227825Stheraven}
5013227825Stheraven
5014227825Stheraventemplate<class _Tp>
5015227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5016227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5017227825Stheraven    : __ptr_(__r.__ptr_),
5018227825Stheraven      __cntrl_(__r.__cntrl_)
5019227825Stheraven{
5020227825Stheraven    if (__cntrl_)
5021227825Stheraven        __cntrl_->__add_weak();
5022227825Stheraven}
5023227825Stheraven
5024227825Stheraventemplate<class _Tp>
5025227825Stheraventemplate<class _Yp>
5026227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5027227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5028227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5029227825Stheraven                         _NOEXCEPT
5030227825Stheraven    : __ptr_(__r.__ptr_),
5031227825Stheraven      __cntrl_(__r.__cntrl_)
5032227825Stheraven{
5033227825Stheraven    if (__cntrl_)
5034227825Stheraven        __cntrl_->__add_weak();
5035227825Stheraven}
5036227825Stheraven
5037227825Stheraventemplate<class _Tp>
5038227825Stheraventemplate<class _Yp>
5039227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5040227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5041227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5042227825Stheraven         _NOEXCEPT
5043227825Stheraven    : __ptr_(__r.__ptr_),
5044227825Stheraven      __cntrl_(__r.__cntrl_)
5045227825Stheraven{
5046227825Stheraven    if (__cntrl_)
5047227825Stheraven        __cntrl_->__add_weak();
5048227825Stheraven}
5049227825Stheraven
5050232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5051232950Stheraven
5052227825Stheraventemplate<class _Tp>
5053232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5054232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5055232950Stheraven    : __ptr_(__r.__ptr_),
5056232950Stheraven      __cntrl_(__r.__cntrl_)
5057232950Stheraven{
5058232950Stheraven    __r.__ptr_ = 0;
5059232950Stheraven    __r.__cntrl_ = 0;
5060232950Stheraven}
5061232950Stheraven
5062232950Stheraventemplate<class _Tp>
5063232950Stheraventemplate<class _Yp>
5064232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5065232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5066232950Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5067232950Stheraven         _NOEXCEPT
5068232950Stheraven    : __ptr_(__r.__ptr_),
5069232950Stheraven      __cntrl_(__r.__cntrl_)
5070232950Stheraven{
5071232950Stheraven    __r.__ptr_ = 0;
5072232950Stheraven    __r.__cntrl_ = 0;
5073232950Stheraven}
5074232950Stheraven
5075232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5076232950Stheraven
5077232950Stheraventemplate<class _Tp>
5078227825Stheravenweak_ptr<_Tp>::~weak_ptr()
5079227825Stheraven{
5080227825Stheraven    if (__cntrl_)
5081227825Stheraven        __cntrl_->__release_weak();
5082227825Stheraven}
5083227825Stheraven
5084227825Stheraventemplate<class _Tp>
5085227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5086227825Stheravenweak_ptr<_Tp>&
5087227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5088227825Stheraven{
5089227825Stheraven    weak_ptr(__r).swap(*this);
5090227825Stheraven    return *this;
5091227825Stheraven}
5092227825Stheraven
5093227825Stheraventemplate<class _Tp>
5094227825Stheraventemplate<class _Yp>
5095227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5096232950Stheraventypename enable_if
5097232950Stheraven<
5098232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5099232950Stheraven    weak_ptr<_Tp>&
5100232950Stheraven>::type
5101227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5102227825Stheraven{
5103227825Stheraven    weak_ptr(__r).swap(*this);
5104227825Stheraven    return *this;
5105227825Stheraven}
5106227825Stheraven
5107232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5108232950Stheraven
5109227825Stheraventemplate<class _Tp>
5110232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5111232950Stheravenweak_ptr<_Tp>&
5112232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5113232950Stheraven{
5114232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5115232950Stheraven    return *this;
5116232950Stheraven}
5117232950Stheraven
5118232950Stheraventemplate<class _Tp>
5119227825Stheraventemplate<class _Yp>
5120227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5121232950Stheraventypename enable_if
5122232950Stheraven<
5123232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5124232950Stheraven    weak_ptr<_Tp>&
5125232950Stheraven>::type
5126232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5127232950Stheraven{
5128232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5129232950Stheraven    return *this;
5130232950Stheraven}
5131232950Stheraven
5132232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5133232950Stheraven
5134232950Stheraventemplate<class _Tp>
5135232950Stheraventemplate<class _Yp>
5136232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5137232950Stheraventypename enable_if
5138232950Stheraven<
5139232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5140232950Stheraven    weak_ptr<_Tp>&
5141232950Stheraven>::type
5142227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5143227825Stheraven{
5144227825Stheraven    weak_ptr(__r).swap(*this);
5145227825Stheraven    return *this;
5146227825Stheraven}
5147227825Stheraven
5148227825Stheraventemplate<class _Tp>
5149227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5150227825Stheravenvoid
5151227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5152227825Stheraven{
5153227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
5154227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
5155227825Stheraven}
5156227825Stheraven
5157227825Stheraventemplate<class _Tp>
5158227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5159227825Stheravenvoid
5160227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5161227825Stheraven{
5162227825Stheraven    __x.swap(__y);
5163227825Stheraven}
5164227825Stheraven
5165227825Stheraventemplate<class _Tp>
5166227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5167227825Stheravenvoid
5168227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT
5169227825Stheraven{
5170227825Stheraven    weak_ptr().swap(*this);
5171227825Stheraven}
5172227825Stheraven
5173227825Stheraventemplate<class _Tp>
5174227825Stheraventemplate<class _Yp>
5175227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5176227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5177227825Stheraven    : __ptr_(__r.__ptr_),
5178227825Stheraven      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5179227825Stheraven{
5180227825Stheraven    if (__cntrl_ == 0)
5181227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
5182227825Stheraven        throw bad_weak_ptr();
5183227825Stheraven#else
5184227825Stheraven        assert(!"bad_weak_ptr");
5185227825Stheraven#endif
5186227825Stheraven}
5187227825Stheraven
5188227825Stheraventemplate<class _Tp>
5189227825Stheravenshared_ptr<_Tp>
5190227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT
5191227825Stheraven{
5192227825Stheraven    shared_ptr<_Tp> __r;
5193227825Stheraven    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5194227825Stheraven    if (__r.__cntrl_)
5195227825Stheraven        __r.__ptr_ = __ptr_;
5196227825Stheraven    return __r;
5197227825Stheraven}
5198227825Stheraven
5199227825Stheraventemplate <class _Tp> struct owner_less;
5200227825Stheraven
5201227825Stheraventemplate <class _Tp>
5202249998Sdimstruct _LIBCPP_TYPE_VIS owner_less<shared_ptr<_Tp> >
5203227825Stheraven    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5204227825Stheraven{
5205227825Stheraven    typedef bool result_type;
5206227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5207227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5208227825Stheraven        {return __x.owner_before(__y);}
5209227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5210227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5211227825Stheraven        {return __x.owner_before(__y);}
5212227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5213227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5214227825Stheraven        {return __x.owner_before(__y);}
5215227825Stheraven};
5216227825Stheraven
5217227825Stheraventemplate <class _Tp>
5218249998Sdimstruct _LIBCPP_TYPE_VIS owner_less<weak_ptr<_Tp> >
5219227825Stheraven    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5220227825Stheraven{
5221227825Stheraven    typedef bool result_type;
5222227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5223227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5224227825Stheraven        {return __x.owner_before(__y);}
5225227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5226227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5227227825Stheraven        {return __x.owner_before(__y);}
5228227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5229227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5230227825Stheraven        {return __x.owner_before(__y);}
5231227825Stheraven};
5232227825Stheraven
5233227825Stheraventemplate<class _Tp>
5234249998Sdimclass _LIBCPP_TYPE_VIS enable_shared_from_this
5235227825Stheraven{
5236227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5237227825Stheravenprotected:
5238241903Sdim    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5239227825Stheraven    enable_shared_from_this() _NOEXCEPT {}
5240227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5241227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5242227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5243227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5244227825Stheraven        {return *this;}
5245227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5246227825Stheraven    ~enable_shared_from_this() {}
5247227825Stheravenpublic:
5248227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5249227825Stheraven    shared_ptr<_Tp> shared_from_this()
5250227825Stheraven        {return shared_ptr<_Tp>(__weak_this_);}
5251227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5252227825Stheraven    shared_ptr<_Tp const> shared_from_this() const
5253227825Stheraven        {return shared_ptr<const _Tp>(__weak_this_);}
5254227825Stheraven
5255227825Stheraven    template <class _Up> friend class shared_ptr;
5256227825Stheraven};
5257227825Stheraven
5258227825Stheraventemplate <class _Tp>
5259249998Sdimstruct _LIBCPP_TYPE_VIS hash<shared_ptr<_Tp> >
5260227825Stheraven{
5261227825Stheraven    typedef shared_ptr<_Tp>      argument_type;
5262227825Stheraven    typedef size_t               result_type;
5263227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5264227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5265227825Stheraven    {
5266227825Stheraven        return hash<_Tp*>()(__ptr.get());
5267227825Stheraven    }
5268227825Stheraven};
5269227825Stheraven
5270232950Stheraventemplate<class _CharT, class _Traits, class _Yp>
5271227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5272227825Stheravenbasic_ostream<_CharT, _Traits>&
5273232950Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5274227825Stheraven
5275241903Sdim#if __has_feature(cxx_atomic)
5276241903Sdim
5277241903Sdimclass __sp_mut
5278241903Sdim{
5279242945Stheraven    void* __lx;
5280241903Sdimpublic:
5281241903Sdim    void lock() _NOEXCEPT;
5282241903Sdim    void unlock() _NOEXCEPT;
5283241903Sdim
5284241903Sdimprivate:
5285241903Sdim    _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5286241903Sdim    __sp_mut(const __sp_mut&);
5287241903Sdim    __sp_mut& operator=(const __sp_mut&);
5288241903Sdim
5289249998Sdim    friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5290241903Sdim};
5291241903Sdim
5292249998Sdim_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5293241903Sdim
5294241903Sdimtemplate <class _Tp>
5295241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5296241903Sdimbool
5297241903Sdimatomic_is_lock_free(const shared_ptr<_Tp>*)
5298241903Sdim{
5299241903Sdim    return false;
5300241903Sdim}
5301241903Sdim
5302241903Sdimtemplate <class _Tp>
5303241903Sdimshared_ptr<_Tp>
5304241903Sdimatomic_load(const shared_ptr<_Tp>* __p)
5305241903Sdim{
5306241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5307241903Sdim    __m.lock();
5308241903Sdim    shared_ptr<_Tp> __q = *__p;
5309241903Sdim    __m.unlock();
5310241903Sdim    return __q;
5311241903Sdim}
5312241903Sdim  
5313241903Sdimtemplate <class _Tp>
5314241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5315241903Sdimshared_ptr<_Tp>
5316241903Sdimatomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5317241903Sdim{
5318241903Sdim    return atomic_load(__p);
5319241903Sdim}
5320241903Sdim
5321241903Sdimtemplate <class _Tp>
5322241903Sdimvoid
5323241903Sdimatomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5324241903Sdim{
5325241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5326241903Sdim    __m.lock();
5327241903Sdim    __p->swap(__r);
5328241903Sdim    __m.unlock();
5329241903Sdim}
5330241903Sdim
5331241903Sdimtemplate <class _Tp>
5332241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5333241903Sdimvoid
5334241903Sdimatomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5335241903Sdim{
5336241903Sdim    atomic_store(__p, __r);
5337241903Sdim}
5338241903Sdim
5339241903Sdimtemplate <class _Tp>
5340241903Sdimshared_ptr<_Tp>
5341241903Sdimatomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5342241903Sdim{
5343241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5344241903Sdim    __m.lock();
5345241903Sdim    __p->swap(__r);
5346241903Sdim    __m.unlock();
5347241903Sdim    return __r;
5348241903Sdim}
5349241903Sdim  
5350241903Sdimtemplate <class _Tp>
5351241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5352241903Sdimshared_ptr<_Tp>
5353241903Sdimatomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5354241903Sdim{
5355241903Sdim    return atomic_exchange(__p, __r);
5356241903Sdim}
5357241903Sdim
5358241903Sdimtemplate <class _Tp>
5359241903Sdimbool
5360241903Sdimatomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5361241903Sdim{
5362241903Sdim    __sp_mut& __m = __get_sp_mut(__p);
5363241903Sdim    __m.lock();
5364241903Sdim    if (__p->__owner_equivalent(*__v))
5365241903Sdim    {
5366241903Sdim        *__p = __w;
5367241903Sdim        __m.unlock();
5368241903Sdim        return true;
5369241903Sdim    }
5370241903Sdim    *__v = *__p;
5371241903Sdim    __m.unlock();
5372241903Sdim    return false;
5373241903Sdim}
5374241903Sdim
5375241903Sdimtemplate <class _Tp>
5376241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5377241903Sdimbool
5378241903Sdimatomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5379241903Sdim{
5380241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5381241903Sdim}
5382241903Sdim
5383241903Sdimtemplate <class _Tp>
5384241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5385241903Sdimbool
5386241903Sdimatomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5387241903Sdim                                        shared_ptr<_Tp> __w, memory_order, memory_order)
5388241903Sdim{
5389241903Sdim    return atomic_compare_exchange_strong(__p, __v, __w);
5390241903Sdim}
5391241903Sdim
5392241903Sdimtemplate <class _Tp>
5393241903Sdiminline _LIBCPP_INLINE_VISIBILITY
5394241903Sdimbool
5395241903Sdimatomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5396241903Sdim                                      shared_ptr<_Tp> __w, memory_order, memory_order)
5397241903Sdim{
5398241903Sdim    return atomic_compare_exchange_weak(__p, __v, __w);
5399241903Sdim}
5400241903Sdim
5401241903Sdim#endif  // __has_feature(cxx_atomic)
5402241903Sdim
5403227825Stheraven//enum class
5404249998Sdimstruct _LIBCPP_TYPE_VIS pointer_safety
5405227825Stheraven{
5406242945Stheraven    enum __lx
5407227825Stheraven    {
5408227825Stheraven        relaxed,
5409227825Stheraven        preferred,
5410227825Stheraven        strict
5411227825Stheraven    };
5412227825Stheraven
5413242945Stheraven    __lx __v_;
5414227825Stheraven
5415227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5416242945Stheraven    pointer_safety(__lx __v) : __v_(__v) {}
5417227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5418227825Stheraven    operator int() const {return __v_;}
5419227825Stheraven};
5420227825Stheraven
5421227825Stheravenvoid declare_reachable(void* __p);
5422227825Stheravenvoid declare_no_pointers(char* __p, size_t __n);
5423227825Stheravenvoid undeclare_no_pointers(char* __p, size_t __n);
5424227825Stheravenpointer_safety get_pointer_safety() _NOEXCEPT;
5425227825Stheravenvoid* __undeclare_reachable(void* __p);
5426227825Stheraven
5427227825Stheraventemplate <class _Tp>
5428227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5429227825Stheraven_Tp*
5430227825Stheravenundeclare_reachable(_Tp* __p)
5431227825Stheraven{
5432227825Stheraven    return static_cast<_Tp*>(__undeclare_reachable(__p));
5433227825Stheraven}
5434227825Stheraven
5435227825Stheravenvoid* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5436227825Stheraven
5437227825Stheraven_LIBCPP_END_NAMESPACE_STD
5438227825Stheraven
5439227825Stheraven#endif  // _LIBCPP_MEMORY
5440