memory revision 232950
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
605232950Stheraven#include <__undef_min_max>
606232950Stheraven
607227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
608227825Stheraven#pragma GCC system_header
609227825Stheraven#endif
610227825Stheraven
611227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
612227825Stheraven
613227825Stheraven// addressof
614227825Stheraven
615227825Stheraventemplate <class _Tp>
616227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
617227825Stheraven_Tp*
618227825Stheravenaddressof(_Tp& __x) _NOEXCEPT
619227825Stheraven{
620227825Stheraven    return (_Tp*)&(char&)__x;
621227825Stheraven}
622227825Stheraven
623227825Stheraven#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
624227825Stheraven// Objective-C++ Automatic Reference Counting uses qualified pointers
625227825Stheraven// that require special addressof() signatures. When
626227825Stheraven// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
627227825Stheraven// itself is providing these definitions. Otherwise, we provide them.
628227825Stheraventemplate <class _Tp>
629227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
630227825Stheraven__strong _Tp*
631227825Stheravenaddressof(__strong _Tp& __x) _NOEXCEPT
632227825Stheraven{
633227825Stheraven  return &__x;
634227825Stheraven}
635227825Stheraven
636227825Stheraven#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
637227825Stheraventemplate <class _Tp>
638227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
639227825Stheraven__weak _Tp*
640227825Stheravenaddressof(__weak _Tp& __x) _NOEXCEPT
641227825Stheraven{
642227825Stheraven  return &__x;
643227825Stheraven}
644227825Stheraven#endif
645227825Stheraven
646227825Stheraventemplate <class _Tp>
647227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
648227825Stheraven__autoreleasing _Tp*
649227825Stheravenaddressof(__autoreleasing _Tp& __x) _NOEXCEPT
650227825Stheraven{
651227825Stheraven  return &__x;
652227825Stheraven}
653227825Stheraven
654227825Stheraventemplate <class _Tp>
655227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
656227825Stheraven__unsafe_unretained _Tp*
657227825Stheravenaddressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
658227825Stheraven{
659227825Stheraven  return &__x;
660227825Stheraven}
661227825Stheraven#endif
662227825Stheraven
663227825Stheraventemplate <class _Tp> class allocator;
664227825Stheraven
665227825Stheraventemplate <>
666227825Stheravenclass _LIBCPP_VISIBLE allocator<void>
667227825Stheraven{
668227825Stheravenpublic:
669227825Stheraven    typedef void*             pointer;
670227825Stheraven    typedef const void*       const_pointer;
671227825Stheraven    typedef void              value_type;
672227825Stheraven
673227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
674227825Stheraven};
675227825Stheraven
676232950Stheraventemplate <>
677232950Stheravenclass _LIBCPP_VISIBLE allocator<const void>
678232950Stheraven{
679232950Stheravenpublic:
680232950Stheraven    typedef const void*       pointer;
681232950Stheraven    typedef const void*       const_pointer;
682232950Stheraven    typedef const void        value_type;
683232950Stheraven
684232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
685232950Stheraven};
686232950Stheraven
687227825Stheraven// pointer_traits
688227825Stheraven
689227825Stheraventemplate <class _Tp>
690227825Stheravenstruct __has_element_type
691227825Stheraven{
692227825Stheravenprivate:
693227825Stheraven    struct __two {char _; char __;};
694227825Stheraven    template <class _Up> static __two __test(...);
695227825Stheraven    template <class _Up> static char __test(typename _Up::element_type* = 0);
696227825Stheravenpublic:
697227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
698227825Stheraven};
699227825Stheraven
700227825Stheraventemplate <class _Ptr, bool = __has_element_type<_Ptr>::value>
701227825Stheravenstruct __pointer_traits_element_type;
702227825Stheraven
703227825Stheraventemplate <class _Ptr>
704227825Stheravenstruct __pointer_traits_element_type<_Ptr, true>
705227825Stheraven{
706227825Stheraven    typedef typename _Ptr::element_type type;
707227825Stheraven};
708227825Stheraven
709227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
710227825Stheraven
711227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
712227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
713227825Stheraven{
714227825Stheraven    typedef typename _Sp<_Tp, _Args...>::element_type type;
715227825Stheraven};
716227825Stheraven
717227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args>
718227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
719227825Stheraven{
720227825Stheraven    typedef _Tp type;
721227825Stheraven};
722227825Stheraven
723227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
724227825Stheraven
725227825Stheraventemplate <template <class> class _Sp, class _Tp>
726227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, true>
727227825Stheraven{
728227825Stheraven    typedef typename _Sp<_Tp>::element_type type;
729227825Stheraven};
730227825Stheraven
731227825Stheraventemplate <template <class> class _Sp, class _Tp>
732227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp>, false>
733227825Stheraven{
734227825Stheraven    typedef _Tp type;
735227825Stheraven};
736227825Stheraven
737227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
738227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
739227825Stheraven{
740227825Stheraven    typedef typename _Sp<_Tp, _A0>::element_type type;
741227825Stheraven};
742227825Stheraven
743227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0>
744227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
745227825Stheraven{
746227825Stheraven    typedef _Tp type;
747227825Stheraven};
748227825Stheraven
749227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
750227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
751227825Stheraven{
752227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
753227825Stheraven};
754227825Stheraven
755227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
756227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
757227825Stheraven{
758227825Stheraven    typedef _Tp type;
759227825Stheraven};
760227825Stheraven
761227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
762227825Stheraven                                                           class _A1, class _A2>
763227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
764227825Stheraven{
765227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
766227825Stheraven};
767227825Stheraven
768227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
769227825Stheraven                                                           class _A1, class _A2>
770227825Stheravenstruct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
771227825Stheraven{
772227825Stheraven    typedef _Tp type;
773227825Stheraven};
774227825Stheraven
775227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
776227825Stheraven
777227825Stheraventemplate <class _Tp>
778227825Stheravenstruct __has_difference_type
779227825Stheraven{
780227825Stheravenprivate:
781227825Stheraven    struct __two {char _; char __;};
782227825Stheraven    template <class _Up> static __two __test(...);
783227825Stheraven    template <class _Up> static char __test(typename _Up::difference_type* = 0);
784227825Stheravenpublic:
785227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
786227825Stheraven};
787227825Stheraven
788227825Stheraventemplate <class _Ptr, bool = __has_difference_type<_Ptr>::value>
789227825Stheravenstruct __pointer_traits_difference_type
790227825Stheraven{
791227825Stheraven    typedef ptrdiff_t type;
792227825Stheraven};
793227825Stheraven
794227825Stheraventemplate <class _Ptr>
795227825Stheravenstruct __pointer_traits_difference_type<_Ptr, true>
796227825Stheraven{
797227825Stheraven    typedef typename _Ptr::difference_type type;
798227825Stheraven};
799227825Stheraven
800227825Stheraventemplate <class _Tp, class _Up>
801227825Stheravenstruct __has_rebind
802227825Stheraven{
803227825Stheravenprivate:
804227825Stheraven    struct __two {char _; char __;};
805227825Stheraven    template <class _Xp> static __two __test(...);
806227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
807227825Stheravenpublic:
808227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
809227825Stheraven};
810227825Stheraven
811227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
812227825Stheravenstruct __pointer_traits_rebind
813227825Stheraven{
814227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
815227825Stheraven    typedef typename _Tp::template rebind<_Up> type;
816227825Stheraven#else
817227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
818227825Stheraven#endif
819227825Stheraven};
820227825Stheraven
821227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
822227825Stheraven
823227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
824227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
825227825Stheraven{
826227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
827227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
828227825Stheraven#else
829227825Stheraven    typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
830227825Stheraven#endif
831227825Stheraven};
832227825Stheraven
833227825Stheraventemplate <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
834227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
835227825Stheraven{
836227825Stheraven    typedef _Sp<_Up, _Args...> type;
837227825Stheraven};
838227825Stheraven
839227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
840227825Stheraven
841227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
842227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
843227825Stheraven{
844227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
845227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up> type;
846227825Stheraven#else
847227825Stheraven    typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
848227825Stheraven#endif
849227825Stheraven};
850227825Stheraven
851227825Stheraventemplate <template <class> class _Sp, class _Tp, class _Up>
852227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
853227825Stheraven{
854227825Stheraven    typedef _Sp<_Up> type;
855227825Stheraven};
856227825Stheraven
857227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
858227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
859227825Stheraven{
860227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
861227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
862227825Stheraven#else
863227825Stheraven    typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
864227825Stheraven#endif
865227825Stheraven};
866227825Stheraven
867227825Stheraventemplate <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
868227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
869227825Stheraven{
870227825Stheraven    typedef _Sp<_Up, _A0> type;
871227825Stheraven};
872227825Stheraven
873227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
874227825Stheraven                                         class _A1, class _Up>
875227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
876227825Stheraven{
877227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
878227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
879227825Stheraven#else
880227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
881227825Stheraven#endif
882227825Stheraven};
883227825Stheraven
884227825Stheraventemplate <template <class, class, class> class _Sp, class _Tp, class _A0,
885227825Stheraven                                         class _A1, class _Up>
886227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
887227825Stheraven{
888227825Stheraven    typedef _Sp<_Up, _A0, _A1> type;
889227825Stheraven};
890227825Stheraven
891227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
892227825Stheraven                                                class _A1, class _A2, class _Up>
893227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
894227825Stheraven{
895227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
896227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
897227825Stheraven#else
898227825Stheraven    typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
899227825Stheraven#endif
900227825Stheraven};
901227825Stheraven
902227825Stheraventemplate <template <class, class, class, class> class _Sp, class _Tp, class _A0,
903227825Stheraven                                                class _A1, class _A2, class _Up>
904227825Stheravenstruct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
905227825Stheraven{
906227825Stheraven    typedef _Sp<_Up, _A0, _A1, _A2> type;
907227825Stheraven};
908227825Stheraven
909227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
910227825Stheraven
911227825Stheraventemplate <class _Ptr>
912227825Stheravenstruct _LIBCPP_VISIBLE pointer_traits
913227825Stheraven{
914227825Stheraven    typedef _Ptr                                                     pointer;
915227825Stheraven    typedef typename __pointer_traits_element_type<pointer>::type    element_type;
916227825Stheraven    typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
917227825Stheraven
918227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
919227825Stheraven    template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
920227825Stheraven#else
921227825Stheraven    template <class _Up> struct rebind
922227825Stheraven        {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
923227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
924227825Stheraven
925227825Stheravenprivate:
926227825Stheraven    struct __nat {};
927227825Stheravenpublic:
928227825Stheraven    _LIBCPP_INLINE_VISIBILITY
929227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
930227825Stheraven                                           __nat, element_type>::type& __r)
931227825Stheraven        {return pointer::pointer_to(__r);}
932227825Stheraven};
933227825Stheraven
934227825Stheraventemplate <class _Tp>
935227825Stheravenstruct _LIBCPP_VISIBLE pointer_traits<_Tp*>
936227825Stheraven{
937227825Stheraven    typedef _Tp*      pointer;
938227825Stheraven    typedef _Tp       element_type;
939227825Stheraven    typedef ptrdiff_t difference_type;
940227825Stheraven
941227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
942227825Stheraven    template <class _Up> using rebind = _Up*;
943227825Stheraven#else
944227825Stheraven    template <class _Up> struct rebind {typedef _Up* other;};
945227825Stheraven#endif
946227825Stheraven
947227825Stheravenprivate:
948227825Stheraven    struct __nat {};
949227825Stheravenpublic:
950227825Stheraven    _LIBCPP_INLINE_VISIBILITY
951227825Stheraven    static pointer pointer_to(typename conditional<is_void<element_type>::value,
952227825Stheraven                                      __nat, element_type>::type& __r) _NOEXCEPT
953227825Stheraven        {return _VSTD::addressof(__r);}
954227825Stheraven};
955227825Stheraven
956227825Stheraven// allocator_traits
957227825Stheraven
958227825Stheravennamespace __has_pointer_type_imp
959227825Stheraven{
960227825Stheraven    template <class _Up> static __two test(...);
961227825Stheraven    template <class _Up> static char test(typename _Up::pointer* = 0);
962227825Stheraven}
963227825Stheraven
964227825Stheraventemplate <class _Tp>
965227825Stheravenstruct __has_pointer_type
966227825Stheraven    : public integral_constant<bool, sizeof(__has_pointer_type_imp::test<_Tp>(0)) == 1>
967227825Stheraven{
968227825Stheraven};
969227825Stheraven
970227825Stheravennamespace __pointer_type_imp
971227825Stheraven{
972227825Stheraven
973227825Stheraventemplate <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
974227825Stheravenstruct __pointer_type
975227825Stheraven{
976227825Stheraven    typedef typename _Dp::pointer type;
977227825Stheraven};
978227825Stheraven
979227825Stheraventemplate <class _Tp, class _Dp>
980227825Stheravenstruct __pointer_type<_Tp, _Dp, false>
981227825Stheraven{
982227825Stheraven    typedef _Tp* type;
983227825Stheraven};
984227825Stheraven
985227825Stheraven}  // __pointer_type_imp
986227825Stheraven
987227825Stheraventemplate <class _Tp, class _Dp>
988227825Stheravenstruct __pointer_type
989227825Stheraven{
990227825Stheraven    typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
991227825Stheraven};
992227825Stheraven
993227825Stheraventemplate <class _Tp>
994227825Stheravenstruct __has_const_pointer
995227825Stheraven{
996227825Stheravenprivate:
997227825Stheraven    struct __two {char _; char __;};
998227825Stheraven    template <class _Up> static __two __test(...);
999227825Stheraven    template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1000227825Stheravenpublic:
1001227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1002227825Stheraven};
1003227825Stheraven
1004227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1005227825Stheravenstruct __const_pointer
1006227825Stheraven{
1007227825Stheraven    typedef typename _Alloc::const_pointer type;
1008227825Stheraven};
1009227825Stheraven
1010227825Stheraventemplate <class _Tp, class _Ptr, class _Alloc>
1011227825Stheravenstruct __const_pointer<_Tp, _Ptr, _Alloc, false>
1012227825Stheraven{
1013227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1014227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1015227825Stheraven#else
1016227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1017227825Stheraven#endif
1018227825Stheraven};
1019227825Stheraven
1020227825Stheraventemplate <class _Tp>
1021227825Stheravenstruct __has_void_pointer
1022227825Stheraven{
1023227825Stheravenprivate:
1024227825Stheraven    struct __two {char _; char __;};
1025227825Stheraven    template <class _Up> static __two __test(...);
1026227825Stheraven    template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1027227825Stheravenpublic:
1028227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1029227825Stheraven};
1030227825Stheraven
1031227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1032227825Stheravenstruct __void_pointer
1033227825Stheraven{
1034227825Stheraven    typedef typename _Alloc::void_pointer type;
1035227825Stheraven};
1036227825Stheraven
1037227825Stheraventemplate <class _Ptr, class _Alloc>
1038227825Stheravenstruct __void_pointer<_Ptr, _Alloc, false>
1039227825Stheraven{
1040227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1041227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1042227825Stheraven#else
1043227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1044227825Stheraven#endif
1045227825Stheraven};
1046227825Stheraven
1047227825Stheraventemplate <class _Tp>
1048227825Stheravenstruct __has_const_void_pointer
1049227825Stheraven{
1050227825Stheravenprivate:
1051227825Stheraven    struct __two {char _; char __;};
1052227825Stheraven    template <class _Up> static __two __test(...);
1053227825Stheraven    template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1054227825Stheravenpublic:
1055227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1056227825Stheraven};
1057227825Stheraven
1058227825Stheraventemplate <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1059227825Stheravenstruct __const_void_pointer
1060227825Stheraven{
1061227825Stheraven    typedef typename _Alloc::const_void_pointer type;
1062227825Stheraven};
1063227825Stheraven
1064227825Stheraventemplate <class _Ptr, class _Alloc>
1065227825Stheravenstruct __const_void_pointer<_Ptr, _Alloc, false>
1066227825Stheraven{
1067227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1068227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1069227825Stheraven#else
1070227825Stheraven    typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1071227825Stheraven#endif
1072227825Stheraven};
1073227825Stheraven
1074232950Stheraventemplate <class _Tp>
1075227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1076232950Stheraven_Tp*
1077232950Stheraven__to_raw_pointer(_Tp* __p) _NOEXCEPT
1078227825Stheraven{
1079227825Stheraven    return __p;
1080227825Stheraven}
1081227825Stheraven
1082227825Stheraventemplate <class _Pointer>
1083227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1084227825Stheraventypename pointer_traits<_Pointer>::element_type*
1085227825Stheraven__to_raw_pointer(_Pointer __p) _NOEXCEPT
1086227825Stheraven{
1087227825Stheraven    return _VSTD::__to_raw_pointer(__p.operator->());
1088227825Stheraven}
1089227825Stheraven
1090227825Stheraventemplate <class _Tp>
1091227825Stheravenstruct __has_size_type
1092227825Stheraven{
1093227825Stheravenprivate:
1094227825Stheraven    struct __two {char _; char __;};
1095227825Stheraven    template <class _Up> static __two __test(...);
1096227825Stheraven    template <class _Up> static char __test(typename _Up::size_type* = 0);
1097227825Stheravenpublic:
1098227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1099227825Stheraven};
1100227825Stheraven
1101227825Stheraventemplate <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1102227825Stheravenstruct __size_type
1103227825Stheraven{
1104227825Stheraven    typedef typename make_unsigned<_DiffType>::type type;
1105227825Stheraven};
1106227825Stheraven
1107227825Stheraventemplate <class _Alloc, class _DiffType>
1108227825Stheravenstruct __size_type<_Alloc, _DiffType, true>
1109227825Stheraven{
1110227825Stheraven    typedef typename _Alloc::size_type type;
1111227825Stheraven};
1112227825Stheraven
1113227825Stheraventemplate <class _Tp>
1114227825Stheravenstruct __has_propagate_on_container_copy_assignment
1115227825Stheraven{
1116227825Stheravenprivate:
1117227825Stheraven    struct __two {char _; char __;};
1118227825Stheraven    template <class _Up> static __two __test(...);
1119227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1120227825Stheravenpublic:
1121227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1122227825Stheraven};
1123227825Stheraven
1124227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1125227825Stheravenstruct __propagate_on_container_copy_assignment
1126227825Stheraven{
1127227825Stheraven    typedef false_type type;
1128227825Stheraven};
1129227825Stheraven
1130227825Stheraventemplate <class _Alloc>
1131227825Stheravenstruct __propagate_on_container_copy_assignment<_Alloc, true>
1132227825Stheraven{
1133227825Stheraven    typedef typename _Alloc::propagate_on_container_copy_assignment type;
1134227825Stheraven};
1135227825Stheraven
1136227825Stheraventemplate <class _Tp>
1137227825Stheravenstruct __has_propagate_on_container_move_assignment
1138227825Stheraven{
1139227825Stheravenprivate:
1140227825Stheraven    struct __two {char _; char __;};
1141227825Stheraven    template <class _Up> static __two __test(...);
1142227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1143227825Stheravenpublic:
1144227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1145227825Stheraven};
1146227825Stheraven
1147227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1148227825Stheravenstruct __propagate_on_container_move_assignment
1149227825Stheraven{
1150227825Stheraven    typedef false_type type;
1151227825Stheraven};
1152227825Stheraven
1153227825Stheraventemplate <class _Alloc>
1154227825Stheravenstruct __propagate_on_container_move_assignment<_Alloc, true>
1155227825Stheraven{
1156227825Stheraven    typedef typename _Alloc::propagate_on_container_move_assignment type;
1157227825Stheraven};
1158227825Stheraven
1159227825Stheraventemplate <class _Tp>
1160227825Stheravenstruct __has_propagate_on_container_swap
1161227825Stheraven{
1162227825Stheravenprivate:
1163227825Stheraven    struct __two {char _; char __;};
1164227825Stheraven    template <class _Up> static __two __test(...);
1165227825Stheraven    template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1166227825Stheravenpublic:
1167227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1168227825Stheraven};
1169227825Stheraven
1170227825Stheraventemplate <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1171227825Stheravenstruct __propagate_on_container_swap
1172227825Stheraven{
1173227825Stheraven    typedef false_type type;
1174227825Stheraven};
1175227825Stheraven
1176227825Stheraventemplate <class _Alloc>
1177227825Stheravenstruct __propagate_on_container_swap<_Alloc, true>
1178227825Stheraven{
1179227825Stheraven    typedef typename _Alloc::propagate_on_container_swap type;
1180227825Stheraven};
1181227825Stheraven
1182227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1183227825Stheravenstruct __has_rebind_other
1184227825Stheraven{
1185227825Stheravenprivate:
1186227825Stheraven    struct __two {char _; char __;};
1187227825Stheraven    template <class _Xp> static __two __test(...);
1188227825Stheraven    template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1189227825Stheravenpublic:
1190227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
1191227825Stheraven};
1192227825Stheraven
1193227825Stheraventemplate <class _Tp, class _Up>
1194227825Stheravenstruct __has_rebind_other<_Tp, _Up, false>
1195227825Stheraven{
1196227825Stheraven    static const bool value = false;
1197227825Stheraven};
1198227825Stheraven
1199227825Stheraventemplate <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1200227825Stheravenstruct __allocator_traits_rebind
1201227825Stheraven{
1202227825Stheraven    typedef typename _Tp::template rebind<_Up>::other type;
1203227825Stheraven};
1204227825Stheraven
1205227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1206227825Stheraven
1207227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1208227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1209227825Stheraven{
1210227825Stheraven    typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1211227825Stheraven};
1212227825Stheraven
1213227825Stheraventemplate <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1214227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1215227825Stheraven{
1216227825Stheraven    typedef _Alloc<_Up, _Args...> type;
1217227825Stheraven};
1218227825Stheraven
1219227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1220227825Stheraven
1221227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1222227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1223227825Stheraven{
1224227825Stheraven    typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1225227825Stheraven};
1226227825Stheraven
1227227825Stheraventemplate <template <class> class _Alloc, class _Tp, class _Up>
1228227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1229227825Stheraven{
1230227825Stheraven    typedef _Alloc<_Up> type;
1231227825Stheraven};
1232227825Stheraven
1233227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1234227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1235227825Stheraven{
1236227825Stheraven    typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1237227825Stheraven};
1238227825Stheraven
1239227825Stheraventemplate <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1240227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1241227825Stheraven{
1242227825Stheraven    typedef _Alloc<_Up, _A0> type;
1243227825Stheraven};
1244227825Stheraven
1245227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1246227825Stheraven                                         class _A1, class _Up>
1247227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1248227825Stheraven{
1249227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1250227825Stheraven};
1251227825Stheraven
1252227825Stheraventemplate <template <class, class, class> class _Alloc, class _Tp, class _A0,
1253227825Stheraven                                         class _A1, class _Up>
1254227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1255227825Stheraven{
1256227825Stheraven    typedef _Alloc<_Up, _A0, _A1> type;
1257227825Stheraven};
1258227825Stheraven
1259227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1260227825Stheraven                                                class _A1, class _A2, class _Up>
1261227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1262227825Stheraven{
1263227825Stheraven    typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1264227825Stheraven};
1265227825Stheraven
1266227825Stheraventemplate <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1267227825Stheraven                                                class _A1, class _A2, class _Up>
1268227825Stheravenstruct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1269227825Stheraven{
1270227825Stheraven    typedef _Alloc<_Up, _A0, _A1, _A2> type;
1271227825Stheraven};
1272227825Stheraven
1273227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1274227825Stheraven
1275227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1276227825Stheraven
1277227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1278227825Stheravenauto
1279227825Stheraven__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1280227825Stheraven    -> decltype(__a.allocate(__sz, __p), true_type());
1281227825Stheraven
1282227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1283227825Stheravenauto
1284227825Stheraven__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1285227825Stheraven    -> false_type;
1286227825Stheraven
1287227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1288227825Stheravenstruct __has_allocate_hint
1289227825Stheraven    : integral_constant<bool,
1290227825Stheraven        is_same<
1291227825Stheraven            decltype(__has_allocate_hint_test(declval<_Alloc>(),
1292227825Stheraven                                          declval<_SizeType>(),
1293227825Stheraven                                          declval<_ConstVoidPtr>())),
1294227825Stheraven            true_type>::value>
1295227825Stheraven{
1296227825Stheraven};
1297227825Stheraven
1298227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1299227825Stheraven
1300227825Stheraventemplate <class _Alloc, class _SizeType, class _ConstVoidPtr>
1301227825Stheravenstruct __has_allocate_hint
1302227825Stheraven    : true_type
1303227825Stheraven{
1304227825Stheraven};
1305227825Stheraven
1306227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1307227825Stheraven
1308227825Stheraven#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1309227825Stheraven
1310227825Stheraventemplate <class _Alloc, class _Tp, class ..._Args>
1311227825Stheravendecltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1312227825Stheraven                                           _VSTD::declval<_Args>()...),
1313227825Stheraven                                           true_type())
1314227825Stheraven__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1315227825Stheraven
1316227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1317227825Stheravenfalse_type
1318227825Stheraven__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1319227825Stheraven
1320227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1321227825Stheravenstruct __has_construct
1322227825Stheraven    : integral_constant<bool,
1323227825Stheraven        is_same<
1324227825Stheraven            decltype(__has_construct_test(declval<_Alloc>(),
1325227825Stheraven                                          declval<_Pointer>(),
1326227825Stheraven                                          declval<_Args>()...)),
1327227825Stheraven            true_type>::value>
1328227825Stheraven{
1329227825Stheraven};
1330227825Stheraven
1331227825Stheraventemplate <class _Alloc, class _Pointer>
1332227825Stheravenauto
1333227825Stheraven__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1334227825Stheraven    -> decltype(__a.destroy(__p), true_type());
1335227825Stheraven
1336227825Stheraventemplate <class _Alloc, class _Pointer>
1337227825Stheravenauto
1338227825Stheraven__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1339227825Stheraven    -> false_type;
1340227825Stheraven
1341227825Stheraventemplate <class _Alloc, class _Pointer>
1342227825Stheravenstruct __has_destroy
1343227825Stheraven    : integral_constant<bool,
1344227825Stheraven        is_same<
1345227825Stheraven            decltype(__has_destroy_test(declval<_Alloc>(),
1346227825Stheraven                                        declval<_Pointer>())),
1347227825Stheraven            true_type>::value>
1348227825Stheraven{
1349227825Stheraven};
1350227825Stheraven
1351227825Stheraventemplate <class _Alloc>
1352227825Stheravenauto
1353227825Stheraven__has_max_size_test(_Alloc&& __a)
1354227825Stheraven    -> decltype(__a.max_size(), true_type());
1355227825Stheraven
1356227825Stheraventemplate <class _Alloc>
1357227825Stheravenauto
1358227825Stheraven__has_max_size_test(const volatile _Alloc& __a)
1359227825Stheraven    -> false_type;
1360227825Stheraven
1361227825Stheraventemplate <class _Alloc>
1362227825Stheravenstruct __has_max_size
1363227825Stheraven    : integral_constant<bool,
1364227825Stheraven        is_same<
1365227825Stheraven            decltype(__has_max_size_test(declval<_Alloc&>())),
1366227825Stheraven            true_type>::value>
1367227825Stheraven{
1368227825Stheraven};
1369227825Stheraven
1370227825Stheraventemplate <class _Alloc>
1371227825Stheravenauto
1372227825Stheraven__has_select_on_container_copy_construction_test(_Alloc&& __a)
1373227825Stheraven    -> decltype(__a.select_on_container_copy_construction(), true_type());
1374227825Stheraven
1375227825Stheraventemplate <class _Alloc>
1376227825Stheravenauto
1377227825Stheraven__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1378227825Stheraven    -> false_type;
1379227825Stheraven
1380227825Stheraventemplate <class _Alloc>
1381227825Stheravenstruct __has_select_on_container_copy_construction
1382227825Stheraven    : integral_constant<bool,
1383227825Stheraven        is_same<
1384227825Stheraven            decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1385227825Stheraven            true_type>::value>
1386227825Stheraven{
1387227825Stheraven};
1388227825Stheraven
1389227825Stheraven#else  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1390227825Stheraven
1391227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1392227825Stheraven
1393227825Stheraventemplate <class _Alloc, class _Pointer, class ..._Args>
1394227825Stheravenstruct __has_construct
1395227825Stheraven    : false_type
1396227825Stheraven{
1397227825Stheraven};
1398227825Stheraven
1399232950Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1400232950Stheraven
1401232950Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1402232950Stheravenstruct __has_construct
1403232950Stheraven    : false_type
1404232950Stheraven{
1405232950Stheraven};
1406232950Stheraven
1407227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1408227825Stheraven
1409227825Stheraventemplate <class _Alloc, class _Pointer>
1410227825Stheravenstruct __has_destroy
1411227825Stheraven    : false_type
1412227825Stheraven{
1413227825Stheraven};
1414227825Stheraven
1415227825Stheraventemplate <class _Alloc>
1416227825Stheravenstruct __has_max_size
1417227825Stheraven    : true_type
1418227825Stheraven{
1419227825Stheraven};
1420227825Stheraven
1421227825Stheraventemplate <class _Alloc>
1422227825Stheravenstruct __has_select_on_container_copy_construction
1423227825Stheraven    : false_type
1424227825Stheraven{
1425227825Stheraven};
1426227825Stheraven
1427227825Stheraven#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
1428227825Stheraven
1429227825Stheraventemplate <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1430227825Stheravenstruct __alloc_traits_difference_type
1431227825Stheraven{
1432227825Stheraven    typedef typename pointer_traits<_Ptr>::difference_type type;
1433227825Stheraven};
1434227825Stheraven
1435227825Stheraventemplate <class _Alloc, class _Ptr>
1436227825Stheravenstruct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1437227825Stheraven{
1438227825Stheraven    typedef typename _Alloc::difference_type type;
1439227825Stheraven};
1440227825Stheraven
1441227825Stheraventemplate <class _Alloc>
1442227825Stheravenstruct _LIBCPP_VISIBLE allocator_traits
1443227825Stheraven{
1444227825Stheraven    typedef _Alloc                              allocator_type;
1445227825Stheraven    typedef typename allocator_type::value_type value_type;
1446227825Stheraven
1447227825Stheraven    typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1448227825Stheraven    typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1449227825Stheraven    typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1450227825Stheraven    typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1451227825Stheraven
1452227825Stheraven    typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1453227825Stheraven    typedef typename __size_type<allocator_type, difference_type>::type size_type;
1454227825Stheraven
1455227825Stheraven    typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1456227825Stheraven                     propagate_on_container_copy_assignment;
1457227825Stheraven    typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1458227825Stheraven                     propagate_on_container_move_assignment;
1459227825Stheraven    typedef typename __propagate_on_container_swap<allocator_type>::type
1460227825Stheraven                     propagate_on_container_swap;
1461227825Stheraven
1462227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1463227825Stheraven    template <class _Tp> using rebind_alloc =
1464227825Stheraven                  typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1465227825Stheraven    template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1466227825Stheraven#else  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1467227825Stheraven    template <class _Tp> struct rebind_alloc
1468227825Stheraven        {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1469227825Stheraven    template <class _Tp> struct rebind_traits
1470227825Stheraven        {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1471227825Stheraven#endif  // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1472227825Stheraven
1473227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1474227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n)
1475227825Stheraven        {return __a.allocate(__n);}
1476227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1477227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1478227825Stheraven        {return allocate(__a, __n, __hint,
1479227825Stheraven            __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1480227825Stheraven
1481227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1482227825Stheraven    static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1483227825Stheraven        {__a.deallocate(__p, __n);}
1484227825Stheraven
1485227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1486227825Stheraven    template <class _Tp, class... _Args>
1487227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1488227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1489227825Stheraven            {__construct(__has_construct<allocator_type, pointer, _Args...>(),
1490227825Stheraven                         __a, __p, _VSTD::forward<_Args>(__args)...);}
1491227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1492227825Stheraven    template <class _Tp>
1493227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1494227825Stheraven        static void construct(allocator_type& __a, _Tp* __p)
1495227825Stheraven            {
1496227825Stheraven                ::new ((void*)__p) _Tp();
1497227825Stheraven            }
1498227825Stheraven    template <class _Tp, class _A0>
1499227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1500227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1501227825Stheraven            {
1502227825Stheraven                ::new ((void*)__p) _Tp(__a0);
1503227825Stheraven            }
1504227825Stheraven    template <class _Tp, class _A0, class _A1>
1505227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1506227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1507227825Stheraven                              const _A1& __a1)
1508227825Stheraven            {
1509227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1);
1510227825Stheraven            }
1511227825Stheraven    template <class _Tp, class _A0, class _A1, class _A2>
1512227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1513227825Stheraven        static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1514227825Stheraven                              const _A1& __a1, const _A2& __a2)
1515227825Stheraven            {
1516227825Stheraven                ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1517227825Stheraven            }
1518227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1519227825Stheraven
1520227825Stheraven    template <class _Tp>
1521227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1522227825Stheraven        static void destroy(allocator_type& __a, _Tp* __p)
1523227825Stheraven            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1524227825Stheraven
1525227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1526227825Stheraven    static size_type max_size(const allocator_type& __a)
1527227825Stheraven        {return __max_size(__has_max_size<const allocator_type>(), __a);}
1528227825Stheraven
1529227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1530227825Stheraven    static allocator_type
1531227825Stheraven        select_on_container_copy_construction(const allocator_type& __a)
1532227825Stheraven            {return select_on_container_copy_construction(
1533227825Stheraven                __has_select_on_container_copy_construction<const allocator_type>(),
1534227825Stheraven                __a);}
1535227825Stheraven
1536232950Stheraven    template <class _Ptr>
1537232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1538232950Stheraven        static
1539232950Stheraven        void
1540232950Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1541232950Stheraven        {
1542232950Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1543232950Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1544232950Stheraven        }
1545232950Stheraven
1546232950Stheraven    template <class _Tp>
1547232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1548232950Stheraven        static
1549232950Stheraven        typename enable_if
1550232950Stheraven        <
1551232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1552232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1553232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1554232950Stheraven            void
1555232950Stheraven        >::type
1556232950Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1557232950Stheraven        {
1558232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1559232950Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1560232950Stheraven            __begin2 += _Np;
1561232950Stheraven        }
1562232950Stheraven
1563232950Stheraven    template <class _Ptr>
1564232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1565232950Stheraven        static
1566232950Stheraven        void
1567232950Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1568232950Stheraven        {
1569232950Stheraven            while (__end1 != __begin1)
1570232950Stheraven                construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
1571232950Stheraven        }
1572232950Stheraven
1573232950Stheraven    template <class _Tp>
1574232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1575232950Stheraven        static
1576232950Stheraven        typename enable_if
1577232950Stheraven        <
1578232950Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1579232950Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1580232950Stheraven             is_trivially_move_constructible<_Tp>::value,
1581232950Stheraven            void
1582232950Stheraven        >::type
1583232950Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1584232950Stheraven        {
1585232950Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1586232950Stheraven            __end2 -= _Np;
1587232950Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1588232950Stheraven        }
1589232950Stheraven
1590227825Stheravenprivate:
1591227825Stheraven
1592227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1593227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1594227825Stheraven        const_void_pointer __hint, true_type)
1595227825Stheraven        {return __a.allocate(__n, __hint);}
1596227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1597227825Stheraven    static pointer allocate(allocator_type& __a, size_type __n,
1598232950Stheraven        const_void_pointer, false_type)
1599227825Stheraven        {return __a.allocate(__n);}
1600227825Stheraven
1601227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1602227825Stheraven    template <class _Tp, class... _Args>
1603227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1604227825Stheraven        static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1605227825Stheraven            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1606227825Stheraven    template <class _Tp, class... _Args>
1607227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1608227825Stheraven        static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1609227825Stheraven            {
1610227825Stheraven                ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1611227825Stheraven            }
1612227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1613227825Stheraven
1614227825Stheraven    template <class _Tp>
1615227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1616227825Stheraven        static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1617227825Stheraven            {__a.destroy(__p);}
1618227825Stheraven    template <class _Tp>
1619227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1620227825Stheraven        static void __destroy(false_type, allocator_type&, _Tp* __p)
1621227825Stheraven            {
1622227825Stheraven                __p->~_Tp();
1623227825Stheraven            }
1624227825Stheraven
1625227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1626227825Stheraven    static size_type __max_size(true_type, const allocator_type& __a)
1627227825Stheraven            {return __a.max_size();}
1628227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1629227825Stheraven    static size_type __max_size(false_type, const allocator_type&)
1630227825Stheraven            {return numeric_limits<size_type>::max();}
1631227825Stheraven
1632227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1633227825Stheraven    static allocator_type
1634227825Stheraven        select_on_container_copy_construction(true_type, const allocator_type& __a)
1635227825Stheraven            {return __a.select_on_container_copy_construction();}
1636227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1637227825Stheraven    static allocator_type
1638227825Stheraven        select_on_container_copy_construction(false_type, const allocator_type& __a)
1639227825Stheraven            {return __a;}
1640227825Stheraven};
1641227825Stheraven
1642232950Stheraven// allocator
1643227825Stheraven
1644227825Stheraventemplate <class _Tp>
1645232950Stheravenclass _LIBCPP_VISIBLE allocator
1646227825Stheraven{
1647227825Stheravenpublic:
1648232950Stheraven    typedef size_t            size_type;
1649232950Stheraven    typedef ptrdiff_t         difference_type;
1650232950Stheraven    typedef _Tp*              pointer;
1651232950Stheraven    typedef const _Tp*        const_pointer;
1652232950Stheraven    typedef _Tp&              reference;
1653232950Stheraven    typedef const _Tp&        const_reference;
1654232950Stheraven    typedef _Tp               value_type;
1655227825Stheraven
1656232950Stheraven    typedef true_type propagate_on_container_move_assignment;
1657227825Stheraven
1658232950Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1659227825Stheraven
1660232950Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1661232950Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1662232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1663232950Stheraven        {return _VSTD::addressof(__x);}
1664232950Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1665232950Stheraven        {return _VSTD::addressof(__x);}
1666232950Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1667232950Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1668232950Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1669232950Stheraven        {::operator delete((void*)__p);}
1670232950Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1671232950Stheraven        {return size_type(~0) / sizeof(_Tp);}
1672232950Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1673232950Stheraven    template <class _Up, class... _Args>
1674232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1675232950Stheraven        void
1676232950Stheraven        construct(_Up* __p, _Args&&... __args)
1677232950Stheraven        {
1678232950Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1679232950Stheraven        }
1680232950Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1681232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1682232950Stheraven        void
1683232950Stheraven        construct(pointer __p)
1684232950Stheraven        {
1685232950Stheraven            ::new((void*)__p) _Tp();
1686232950Stheraven        }
1687232950Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1688232950Stheraven    template <class _A0>
1689232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1690232950Stheraven        typename enable_if
1691232950Stheraven        <
1692232950Stheraven            !is_convertible<_A0, __rv<_A0> >::value,
1693232950Stheraven            void
1694232950Stheraven        >::type
1695232950Stheraven        construct(pointer __p, _A0& __a0)
1696232950Stheraven        {
1697232950Stheraven            ::new((void*)__p) _Tp(__a0);
1698232950Stheraven        }
1699232950Stheraven    template <class _A0>
1700232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1701232950Stheraven        typename enable_if
1702232950Stheraven        <
1703232950Stheraven            !is_convertible<_A0, __rv<_A0> >::value,
1704232950Stheraven            void
1705232950Stheraven        >::type
1706232950Stheraven        construct(pointer __p, const _A0& __a0)
1707232950Stheraven        {
1708232950Stheraven            ::new((void*)__p) _Tp(__a0);
1709232950Stheraven        }
1710232950Stheraven    template <class _A0>
1711232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1712232950Stheraven        typename enable_if
1713232950Stheraven        <
1714232950Stheraven            is_convertible<_A0, __rv<_A0> >::value,
1715232950Stheraven            void
1716232950Stheraven        >::type
1717232950Stheraven        construct(pointer __p, _A0 __a0)
1718232950Stheraven        {
1719232950Stheraven            ::new((void*)__p) _Tp(_VSTD::move(__a0));
1720232950Stheraven        }
1721232950Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1722232950Stheraven    template <class _A0, class _A1>
1723232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1724232950Stheraven        void
1725232950Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1726232950Stheraven        {
1727232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1728232950Stheraven        }
1729232950Stheraven    template <class _A0, class _A1>
1730232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1731232950Stheraven        void
1732232950Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1733232950Stheraven        {
1734232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1735232950Stheraven        }
1736232950Stheraven    template <class _A0, class _A1>
1737232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1738232950Stheraven        void
1739232950Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1740232950Stheraven        {
1741232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1742232950Stheraven        }
1743232950Stheraven    template <class _A0, class _A1>
1744232950Stheraven        _LIBCPP_INLINE_VISIBILITY
1745232950Stheraven        void
1746232950Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1747232950Stheraven        {
1748232950Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1749232950Stheraven        }
1750232950Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1751232950Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1752227825Stheraven};
1753227825Stheraven
1754227825Stheraventemplate <class _Tp>
1755232950Stheravenclass _LIBCPP_VISIBLE allocator<const _Tp>
1756227825Stheraven{
1757227825Stheravenpublic:
1758227825Stheraven    typedef size_t            size_type;
1759227825Stheraven    typedef ptrdiff_t         difference_type;
1760232950Stheraven    typedef const _Tp*        pointer;
1761227825Stheraven    typedef const _Tp*        const_pointer;
1762232950Stheraven    typedef const _Tp&        reference;
1763227825Stheraven    typedef const _Tp&        const_reference;
1764227825Stheraven    typedef _Tp               value_type;
1765227825Stheraven
1766227825Stheraven    typedef true_type propagate_on_container_move_assignment;
1767227825Stheraven
1768227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1769227825Stheraven
1770227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1771227825Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1772227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1773227825Stheraven        {return _VSTD::addressof(__x);}
1774227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1775227825Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1776227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1777227825Stheraven        {::operator delete((void*)__p);}
1778227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1779227825Stheraven        {return size_type(~0) / sizeof(_Tp);}
1780227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1781227825Stheraven    template <class _Up, class... _Args>
1782227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1783227825Stheraven        void
1784227825Stheraven        construct(_Up* __p, _Args&&... __args)
1785227825Stheraven        {
1786227825Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1787227825Stheraven        }
1788227825Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1789227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1790227825Stheraven        void
1791227825Stheraven        construct(pointer __p)
1792227825Stheraven        {
1793227825Stheraven            ::new((void*)__p) _Tp();
1794227825Stheraven        }
1795227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1796227825Stheraven    template <class _A0>
1797227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1798227825Stheraven        typename enable_if
1799227825Stheraven        <
1800227825Stheraven            !is_convertible<_A0, __rv<_A0> >::value,
1801227825Stheraven            void
1802227825Stheraven        >::type
1803227825Stheraven        construct(pointer __p, _A0& __a0)
1804227825Stheraven        {
1805227825Stheraven            ::new((void*)__p) _Tp(__a0);
1806227825Stheraven        }
1807227825Stheraven    template <class _A0>
1808227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1809227825Stheraven        typename enable_if
1810227825Stheraven        <
1811227825Stheraven            !is_convertible<_A0, __rv<_A0> >::value,
1812227825Stheraven            void
1813227825Stheraven        >::type
1814227825Stheraven        construct(pointer __p, const _A0& __a0)
1815227825Stheraven        {
1816227825Stheraven            ::new((void*)__p) _Tp(__a0);
1817227825Stheraven        }
1818227825Stheraven    template <class _A0>
1819227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1820227825Stheraven        typename enable_if
1821227825Stheraven        <
1822227825Stheraven            is_convertible<_A0, __rv<_A0> >::value,
1823227825Stheraven            void
1824227825Stheraven        >::type
1825227825Stheraven        construct(pointer __p, _A0 __a0)
1826227825Stheraven        {
1827227825Stheraven            ::new((void*)__p) _Tp(_VSTD::move(__a0));
1828227825Stheraven        }
1829227825Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1830227825Stheraven    template <class _A0, class _A1>
1831227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1832227825Stheraven        void
1833227825Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1834227825Stheraven        {
1835227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1836227825Stheraven        }
1837227825Stheraven    template <class _A0, class _A1>
1838227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1839227825Stheraven        void
1840227825Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1841227825Stheraven        {
1842227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1843227825Stheraven        }
1844227825Stheraven    template <class _A0, class _A1>
1845227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1846227825Stheraven        void
1847227825Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1848227825Stheraven        {
1849227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1850227825Stheraven        }
1851227825Stheraven    template <class _A0, class _A1>
1852227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1853227825Stheraven        void
1854227825Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1855227825Stheraven        {
1856227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1857227825Stheraven        }
1858227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1859227825Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1860227825Stheraven};
1861227825Stheraven
1862227825Stheraventemplate <class _Tp, class _Up>
1863227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1864227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1865227825Stheraven
1866227825Stheraventemplate <class _Tp, class _Up>
1867227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1868227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1869227825Stheraven
1870227825Stheraventemplate <class _OutputIterator, class _Tp>
1871227825Stheravenclass _LIBCPP_VISIBLE raw_storage_iterator
1872227825Stheraven    : public iterator<output_iterator_tag,
1873227825Stheraven                      _Tp,                                         // purposefully not C++03
1874227825Stheraven                      ptrdiff_t,                                   // purposefully not C++03
1875227825Stheraven                      _Tp*,                                        // purposefully not C++03
1876227825Stheraven                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1877227825Stheraven{
1878227825Stheravenprivate:
1879227825Stheraven    _OutputIterator __x_;
1880227825Stheravenpublic:
1881227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1882227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1883227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1884227825Stheraven        {::new(&*__x_) _Tp(__element); return *this;}
1885227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1886227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
1887227825Stheraven        {raw_storage_iterator __t(*this); ++__x_; return __t;}
1888227825Stheraven};
1889227825Stheraven
1890227825Stheraventemplate <class _Tp>
1891227825Stheravenpair<_Tp*, ptrdiff_t>
1892227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1893227825Stheraven{
1894227825Stheraven    pair<_Tp*, ptrdiff_t> __r(0, 0);
1895227825Stheraven    const ptrdiff_t __m = (~ptrdiff_t(0) ^
1896227825Stheraven                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1897227825Stheraven                           / sizeof(_Tp);
1898227825Stheraven    if (__n > __m)
1899227825Stheraven        __n = __m;
1900227825Stheraven    while (__n > 0)
1901227825Stheraven    {
1902227825Stheraven        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1903227825Stheraven        if (__r.first)
1904227825Stheraven        {
1905227825Stheraven            __r.second = __n;
1906227825Stheraven            break;
1907227825Stheraven        }
1908227825Stheraven        __n /= 2;
1909227825Stheraven    }
1910227825Stheraven    return __r;
1911227825Stheraven}
1912227825Stheraven
1913227825Stheraventemplate <class _Tp>
1914227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1915227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1916227825Stheraven
1917227825Stheraventemplate <class _Tp>
1918227825Stheravenstruct auto_ptr_ref
1919227825Stheraven{
1920227825Stheraven    _Tp* __ptr_;
1921227825Stheraven};
1922227825Stheraven
1923227825Stheraventemplate<class _Tp>
1924227825Stheravenclass _LIBCPP_VISIBLE auto_ptr
1925227825Stheraven{
1926227825Stheravenprivate:
1927227825Stheraven    _Tp* __ptr_;
1928227825Stheravenpublic:
1929227825Stheraven    typedef _Tp element_type;
1930227825Stheraven
1931227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1932227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1933227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1934227825Stheraven        : __ptr_(__p.release()) {}
1935227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1936227825Stheraven        {reset(__p.release()); return *this;}
1937227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1938227825Stheraven        {reset(__p.release()); return *this;}
1939227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1940227825Stheraven        {reset(__p.__ptr_); return *this;}
1941227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1942227825Stheraven
1943227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1944227825Stheraven        {return *__ptr_;}
1945227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1946227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1947227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1948227825Stheraven    {
1949227825Stheraven        _Tp* __t = __ptr_;
1950227825Stheraven        __ptr_ = 0;
1951227825Stheraven        return __t;
1952227825Stheraven    }
1953227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1954227825Stheraven    {
1955227825Stheraven        if (__ptr_ != __p)
1956227825Stheraven            delete __ptr_;
1957227825Stheraven        __ptr_ = __p;
1958227825Stheraven    }
1959227825Stheraven
1960227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1961227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1962227825Stheraven        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1963227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1964227825Stheraven        {return auto_ptr<_Up>(release());}
1965227825Stheraven};
1966227825Stheraven
1967227825Stheraventemplate <>
1968227825Stheravenclass _LIBCPP_VISIBLE auto_ptr<void>
1969227825Stheraven{
1970227825Stheravenpublic:
1971227825Stheraven    typedef void element_type;
1972227825Stheraven};
1973227825Stheraven
1974227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1975227825Stheraven                                                     typename remove_cv<_T2>::type>::value,
1976232950Stheraven                                bool = is_empty<_T1>::value
1977232950Stheraven#if __has_feature(is_final)
1978232950Stheraven                                       && !__is_final(_T1)
1979232950Stheraven#endif
1980232950Stheraven                                ,
1981232950Stheraven                                bool = is_empty<_T2>::value
1982232950Stheraven#if __has_feature(is_final)
1983232950Stheraven                                       && !__is_final(_T2)
1984232950Stheraven#endif
1985232950Stheraven         >
1986227825Stheravenstruct __libcpp_compressed_pair_switch;
1987227825Stheraven
1988227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1989227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1990227825Stheraven
1991227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1992227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
1993227825Stheraven
1994227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1995227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
1996227825Stheraven
1997227825Stheraventemplate <class _T1, class _T2>
1998227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
1999227825Stheraven
2000227825Stheraventemplate <class _T1, class _T2>
2001227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
2002227825Stheraven
2003227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2004227825Stheravenclass __libcpp_compressed_pair_imp;
2005227825Stheraven
2006227825Stheraventemplate <class _T1, class _T2>
2007227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0>
2008227825Stheraven{
2009227825Stheravenprivate:
2010227825Stheraven    _T1 __first_;
2011227825Stheraven    _T2 __second_;
2012227825Stheravenpublic:
2013227825Stheraven    typedef _T1 _T1_param;
2014227825Stheraven    typedef _T2 _T2_param;
2015227825Stheraven
2016227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2017227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2018227825Stheraven
2019227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2020227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2021227825Stheraven
2022227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2023232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2024227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2025232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2026227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2027227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2028227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2029227825Stheraven
2030227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2031227825Stheraven
2032227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2033227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2034227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2035227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2036227825Stheraven        : __first_(__p.first()),
2037227825Stheraven          __second_(__p.second()) {}
2038227825Stheraven
2039227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2040227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2041227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2042227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2043227825Stheraven        {
2044227825Stheraven            __first_ = __p.first();
2045227825Stheraven            __second_ = __p.second();
2046227825Stheraven            return *this;
2047227825Stheraven        }
2048227825Stheraven
2049227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2050227825Stheraven
2051227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2052227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2053227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2054227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2055227825Stheraven        : __first_(_VSTD::forward<_T1>(__p.first())),
2056227825Stheraven          __second_(_VSTD::forward<_T2>(__p.second())) {}
2057227825Stheraven
2058227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2059227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2060227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2061227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2062227825Stheraven        {
2063227825Stheraven            __first_ = _VSTD::forward<_T1>(__p.first());
2064227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2065227825Stheraven            return *this;
2066227825Stheraven        }
2067227825Stheraven
2068232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2069232950Stheraven
2070232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2071232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2072232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2073232950Stheraven                                     tuple<_Args1...> __first_args,
2074232950Stheraven                                     tuple<_Args2...> __second_args,
2075232950Stheraven                                     __tuple_indices<_I1...>,
2076232950Stheraven                                     __tuple_indices<_I2...>)
2077232950Stheraven            : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2078232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2079232950Stheraven            {}
2080232950Stheraven
2081232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2082232950Stheraven
2083227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2084227825Stheraven
2085227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2086227825Stheraven
2087227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2088227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2089227825Stheraven
2090227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2091227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2092227825Stheraven
2093227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2094227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2095227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2096227825Stheraven    {
2097227825Stheraven        using _VSTD::swap;
2098227825Stheraven        swap(__first_, __x.__first_);
2099227825Stheraven        swap(__second_, __x.__second_);
2100227825Stheraven    }
2101227825Stheraven};
2102227825Stheraven
2103227825Stheraventemplate <class _T1, class _T2>
2104227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1>
2105227825Stheraven    : private _T1
2106227825Stheraven{
2107227825Stheravenprivate:
2108227825Stheraven    _T2 __second_;
2109227825Stheravenpublic:
2110227825Stheraven    typedef _T1 _T1_param;
2111227825Stheraven    typedef _T2 _T2_param;
2112227825Stheraven
2113227825Stheraven    typedef _T1&                                        _T1_reference;
2114227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2115227825Stheraven
2116227825Stheraven    typedef const _T1&                                        _T1_const_reference;
2117227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2118227825Stheraven
2119227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2120232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2121227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2122232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2123227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2124227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2125227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2126227825Stheraven
2127227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2128227825Stheraven
2129227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2130227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2131227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2132227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2133227825Stheraven        : _T1(__p.first()), __second_(__p.second()) {}
2134227825Stheraven
2135227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2136227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2137227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2138227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2139227825Stheraven        {
2140227825Stheraven            _T1::operator=(__p.first());
2141227825Stheraven            __second_ = __p.second();
2142227825Stheraven            return *this;
2143227825Stheraven        }
2144227825Stheraven
2145227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2146227825Stheraven
2147227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2148227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2149227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2150227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2151227825Stheraven        : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2152227825Stheraven
2153227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2154227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2155227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2156227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2157227825Stheraven        {
2158227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2159227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2160227825Stheraven            return *this;
2161227825Stheraven        }
2162227825Stheraven
2163232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2164232950Stheraven
2165232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2166232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2167232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2168232950Stheraven                                     tuple<_Args1...> __first_args,
2169232950Stheraven                                     tuple<_Args2...> __second_args,
2170232950Stheraven                                     __tuple_indices<_I1...>,
2171232950Stheraven                                     __tuple_indices<_I2...>)
2172232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2173232950Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2174232950Stheraven            {}
2175232950Stheraven
2176232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2177232950Stheraven
2178227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2179227825Stheraven
2180227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2181227825Stheraven
2182227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2183227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2184227825Stheraven
2185227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2186227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2187227825Stheraven
2188227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2189227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2190227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2191227825Stheraven    {
2192227825Stheraven        using _VSTD::swap;
2193227825Stheraven        swap(__second_, __x.__second_);
2194227825Stheraven    }
2195227825Stheraven};
2196227825Stheraven
2197227825Stheraventemplate <class _T1, class _T2>
2198227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2>
2199227825Stheraven    : private _T2
2200227825Stheraven{
2201227825Stheravenprivate:
2202227825Stheraven    _T1 __first_;
2203227825Stheravenpublic:
2204227825Stheraven    typedef _T1 _T1_param;
2205227825Stheraven    typedef _T2 _T2_param;
2206227825Stheraven
2207227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2208227825Stheraven    typedef _T2&                                        _T2_reference;
2209227825Stheraven
2210227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2211227825Stheraven    typedef const _T2&                                        _T2_const_reference;
2212227825Stheraven
2213227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2214227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2215227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2216227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2217227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2218227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2219227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2220227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2221227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2222227825Stheraven
2223227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2224227825Stheraven
2225227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2226227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2227227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2228227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2229227825Stheraven        : _T2(__p.second()), __first_(__p.first()) {}
2230227825Stheraven
2231227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2232227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2233227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2234227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2235227825Stheraven        {
2236227825Stheraven            _T2::operator=(__p.second());
2237227825Stheraven            __first_ = __p.first();
2238227825Stheraven            return *this;
2239227825Stheraven        }
2240227825Stheraven
2241227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2242227825Stheraven
2243227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2244227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2245227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2246227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2247227825Stheraven        : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2248227825Stheraven
2249227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2250227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2251227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2252227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2253227825Stheraven        {
2254227825Stheraven            _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2255227825Stheraven            __first_ = _VSTD::move(__p.first());
2256227825Stheraven            return *this;
2257227825Stheraven        }
2258227825Stheraven
2259232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2260232950Stheraven
2261232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2262232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2263232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2264232950Stheraven                                     tuple<_Args1...> __first_args,
2265232950Stheraven                                     tuple<_Args2...> __second_args,
2266232950Stheraven                                     __tuple_indices<_I1...>,
2267232950Stheraven                                     __tuple_indices<_I2...>)
2268232950Stheraven            : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2269232950Stheraven              __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2270232950Stheraven              
2271232950Stheraven            {}
2272232950Stheraven
2273232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2274232950Stheraven
2275227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2276227825Stheraven
2277227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2278227825Stheraven
2279227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2280227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2281227825Stheraven
2282227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2283227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2284227825Stheraven
2285227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2286227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2287227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2288227825Stheraven    {
2289227825Stheraven        using _VSTD::swap;
2290227825Stheraven        swap(__first_, __x.__first_);
2291227825Stheraven    }
2292227825Stheraven};
2293227825Stheraven
2294227825Stheraventemplate <class _T1, class _T2>
2295227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3>
2296227825Stheraven    : private _T1,
2297227825Stheraven      private _T2
2298227825Stheraven{
2299227825Stheravenpublic:
2300227825Stheraven    typedef _T1 _T1_param;
2301227825Stheraven    typedef _T2 _T2_param;
2302227825Stheraven
2303227825Stheraven    typedef _T1& _T1_reference;
2304227825Stheraven    typedef _T2& _T2_reference;
2305227825Stheraven
2306227825Stheraven    typedef const _T1& _T1_const_reference;
2307227825Stheraven    typedef const _T2& _T2_const_reference;
2308227825Stheraven
2309227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2310227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2311227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2312227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2313227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2314227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2315227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2316227825Stheraven
2317227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2318227825Stheraven
2319227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2320227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2321227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2322227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2323227825Stheraven        : _T1(__p.first()), _T2(__p.second()) {}
2324227825Stheraven
2325227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2326227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2327227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2328227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2329227825Stheraven        {
2330227825Stheraven            _T1::operator=(__p.first());
2331227825Stheraven            _T2::operator=(__p.second());
2332227825Stheraven            return *this;
2333227825Stheraven        }
2334227825Stheraven
2335227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2336227825Stheraven
2337227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2338227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2339227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2340227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2341227825Stheraven        : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2342227825Stheraven
2343227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2344227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2345227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2346227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2347227825Stheraven        {
2348227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2349227825Stheraven            _T2::operator=(_VSTD::move(__p.second()));
2350227825Stheraven            return *this;
2351227825Stheraven        }
2352227825Stheraven
2353232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2354232950Stheraven
2355232950Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2356232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2357232950Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2358232950Stheraven                                     tuple<_Args1...> __first_args,
2359232950Stheraven                                     tuple<_Args2...> __second_args,
2360232950Stheraven                                     __tuple_indices<_I1...>,
2361232950Stheraven                                     __tuple_indices<_I2...>)
2362232950Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2363232950Stheraven              _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2364232950Stheraven            {}
2365232950Stheraven
2366232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2367232950Stheraven
2368227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2369227825Stheraven
2370227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2371227825Stheraven
2372227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2373227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2374227825Stheraven
2375227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2376227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2377227825Stheraven
2378232950Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2379227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2380227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2381227825Stheraven    {
2382227825Stheraven    }
2383227825Stheraven};
2384227825Stheraven
2385227825Stheraventemplate <class _T1, class _T2>
2386227825Stheravenclass __compressed_pair
2387227825Stheraven    : private __libcpp_compressed_pair_imp<_T1, _T2>
2388227825Stheraven{
2389227825Stheraven    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2390227825Stheravenpublic:
2391227825Stheraven    typedef typename base::_T1_param _T1_param;
2392227825Stheraven    typedef typename base::_T2_param _T2_param;
2393227825Stheraven
2394227825Stheraven    typedef typename base::_T1_reference _T1_reference;
2395227825Stheraven    typedef typename base::_T2_reference _T2_reference;
2396227825Stheraven
2397227825Stheraven    typedef typename base::_T1_const_reference _T1_const_reference;
2398227825Stheraven    typedef typename base::_T2_const_reference _T2_const_reference;
2399227825Stheraven
2400227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2401232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2402227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2403232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2404227825Stheraven        : base(_VSTD::forward<_T2_param>(__t2)) {}
2405227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2406227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2407227825Stheraven
2408227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2409227825Stheraven
2410227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2411227825Stheraven    __compressed_pair(const __compressed_pair& __p)
2412227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2413227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2414227825Stheraven        : base(__p) {}
2415227825Stheraven
2416227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2417227825Stheraven    __compressed_pair& operator=(const __compressed_pair& __p)
2418227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2419227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2420227825Stheraven        {
2421227825Stheraven            base::operator=(__p);
2422227825Stheraven            return *this;
2423227825Stheraven        }
2424227825Stheraven
2425227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2426227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2427227825Stheraven    __compressed_pair(__compressed_pair&& __p)
2428227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2429227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2430227825Stheraven        : base(_VSTD::move(__p)) {}
2431227825Stheraven
2432227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2433227825Stheraven    __compressed_pair& operator=(__compressed_pair&& __p)
2434227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2435227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2436227825Stheraven        {
2437227825Stheraven            base::operator=(_VSTD::move(__p));
2438227825Stheraven            return *this;
2439227825Stheraven        }
2440232950Stheraven
2441232950Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2442232950Stheraven
2443232950Stheraven    template <class... _Args1, class... _Args2>
2444232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2445232950Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2446232950Stheraven                                                      tuple<_Args2...> __second_args)
2447232950Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2448232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2449232950Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2450232950Stheraven            {}
2451232950Stheraven
2452232950Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2453232950Stheraven
2454227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2455227825Stheraven
2456227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2457227825Stheraven
2458227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
2459227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2460227825Stheraven
2461227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return base::second();}
2462227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2463227825Stheraven
2464227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2465227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2466227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2467227825Stheraven        {base::swap(__x);}
2468227825Stheraven};
2469227825Stheraven
2470227825Stheraventemplate <class _T1, class _T2>
2471227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2472227825Stheravenvoid
2473227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2474227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2475227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2476227825Stheraven    {__x.swap(__y);}
2477227825Stheraven
2478232950Stheraven// __same_or_less_cv_qualified
2479232950Stheraven
2480232950Stheraventemplate <class _Ptr1, class _Ptr2,
2481232950Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2482232950Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2483232950Stheraven                        >::value
2484232950Stheraven         >
2485232950Stheravenstruct __same_or_less_cv_qualified_imp
2486232950Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2487232950Stheraven
2488232950Stheraventemplate <class _Ptr1, class _Ptr2>
2489232950Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2490232950Stheraven    : false_type {};
2491232950Stheraven
2492232950Stheraventemplate <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2493232950Stheraven                                         !is_pointer<_Ptr1>::value>
2494232950Stheravenstruct __same_or_less_cv_qualified
2495232950Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2496232950Stheraven
2497232950Stheraventemplate <class _Ptr1, class _Ptr2>
2498232950Stheravenstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2499232950Stheraven    : false_type {};
2500232950Stheraven
2501232950Stheraven// default_delete
2502232950Stheraven
2503227825Stheraventemplate <class _Tp>
2504227825Stheravenstruct _LIBCPP_VISIBLE default_delete
2505227825Stheraven{
2506227825Stheraven    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2507227825Stheraven    template <class _Up>
2508227825Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2509227825Stheraven             typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2510227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2511227825Stheraven        {
2512227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2513227825Stheraven            delete __ptr;
2514227825Stheraven        }
2515227825Stheraven};
2516227825Stheraven
2517227825Stheraventemplate <class _Tp>
2518227825Stheravenstruct _LIBCPP_VISIBLE default_delete<_Tp[]>
2519227825Stheraven{
2520232950Stheravenpublic:
2521232950Stheraven    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2522232950Stheraven    template <class _Up>
2523232950Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2524232950Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2525232950Stheraven    template <class _Up>
2526232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2527232950Stheraven        void operator() (_Up* __ptr,
2528232950Stheraven                         typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2529227825Stheraven        {
2530227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2531227825Stheraven            delete [] __ptr;
2532227825Stheraven        }
2533227825Stheraven};
2534227825Stheraven
2535227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> >
2536227825Stheravenclass _LIBCPP_VISIBLE unique_ptr
2537227825Stheraven{
2538227825Stheravenpublic:
2539227825Stheraven    typedef _Tp element_type;
2540227825Stheraven    typedef _Dp deleter_type;
2541227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2542227825Stheravenprivate:
2543227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2544227825Stheraven
2545232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2546227825Stheraven    unique_ptr(unique_ptr&);
2547227825Stheraven    template <class _Up, class _Ep>
2548227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&);
2549227825Stheraven    unique_ptr& operator=(unique_ptr&);
2550227825Stheraven    template <class _Up, class _Ep>
2551227825Stheraven        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2552227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2553227825Stheraven
2554227825Stheraven    struct __nat {int __for_bool_;};
2555227825Stheraven
2556227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2557227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2558227825Stheravenpublic:
2559227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2560227825Stheraven        : __ptr_(pointer())
2561227825Stheraven        {
2562227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2563227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2564227825Stheraven        }
2565227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2566227825Stheraven        : __ptr_(pointer())
2567227825Stheraven        {
2568227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2569227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2570227825Stheraven        }
2571227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2572227825Stheraven        : __ptr_(_VSTD::move(__p))
2573227825Stheraven        {
2574227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2575227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2576227825Stheraven        }
2577227825Stheraven
2578227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2579227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2580227825Stheraven                                        is_reference<deleter_type>::value,
2581227825Stheraven                                        deleter_type,
2582227825Stheraven                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
2583227825Stheraven             _NOEXCEPT
2584227825Stheraven        : __ptr_(__p, __d) {}
2585227825Stheraven
2586227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2587227825Stheraven             _NOEXCEPT
2588227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2589227825Stheraven        {
2590227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2591227825Stheraven        }
2592227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2593227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2594227825Stheraven    template <class _Up, class _Ep>
2595227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2596227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2597227825Stheraven                   typename enable_if
2598227825Stheraven                      <
2599227825Stheraven                        !is_array<_Up>::value &&
2600227825Stheraven                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2601227825Stheraven                         is_convertible<_Ep, deleter_type>::value &&
2602227825Stheraven                         (
2603227825Stheraven                            !is_reference<deleter_type>::value ||
2604227825Stheraven                            is_same<deleter_type, _Ep>::value
2605227825Stheraven                         ),
2606227825Stheraven                         __nat
2607227825Stheraven                      >::type = __nat()) _NOEXCEPT
2608227825Stheraven            : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2609227825Stheraven
2610227825Stheraven    template <class _Up>
2611227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2612227825Stheraven                typename enable_if<
2613227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2614227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2615227825Stheraven                                      __nat
2616227825Stheraven                                  >::type = __nat()) _NOEXCEPT
2617227825Stheraven            : __ptr_(__p.release())
2618227825Stheraven            {
2619227825Stheraven            }
2620227825Stheraven
2621227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2622227825Stheraven            {
2623227825Stheraven                reset(__u.release());
2624227825Stheraven                __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2625227825Stheraven                return *this;
2626227825Stheraven            }
2627227825Stheraven
2628227825Stheraven        template <class _Up, class _Ep>
2629227825Stheraven            _LIBCPP_INLINE_VISIBILITY
2630227825Stheraven            typename enable_if
2631227825Stheraven            <
2632232950Stheraven                !is_array<_Up>::value &&
2633232950Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2634232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2635227825Stheraven                unique_ptr&
2636227825Stheraven            >::type
2637227825Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2638227825Stheraven            {
2639227825Stheraven                reset(__u.release());
2640227825Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2641227825Stheraven                return *this;
2642227825Stheraven            }
2643227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2644227825Stheraven
2645227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2646227825Stheraven    {
2647227825Stheraven        return __rv<unique_ptr>(*this);
2648227825Stheraven    }
2649227825Stheraven
2650227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2651227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2652227825Stheraven
2653227825Stheraven    template <class _Up, class _Ep>
2654227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2655227825Stheraven    {
2656227825Stheraven        reset(__u.release());
2657227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2658227825Stheraven        return *this;
2659227825Stheraven    }
2660227825Stheraven
2661227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2662227825Stheraven        : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2663227825Stheraven
2664227825Stheraven    template <class _Up>
2665227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2666227825Stheraven                typename enable_if<
2667227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2668227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2669227825Stheraven                                      unique_ptr&
2670227825Stheraven                                  >::type
2671227825Stheraven        operator=(auto_ptr<_Up> __p)
2672227825Stheraven            {reset(__p.release()); return *this;}
2673227825Stheraven
2674227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2675227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2676227825Stheraven
2677227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2678227825Stheraven    {
2679227825Stheraven        reset();
2680227825Stheraven        return *this;
2681227825Stheraven    }
2682227825Stheraven
2683227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2684227825Stheraven        {return *__ptr_.first();}
2685227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2686227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2687227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2688227825Stheraven        {return __ptr_.second();}
2689227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2690227825Stheraven        {return __ptr_.second();}
2691232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2692232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2693232950Stheraven        {return __ptr_.first() != nullptr;}
2694227825Stheraven
2695227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2696227825Stheraven    {
2697227825Stheraven        pointer __t = __ptr_.first();
2698227825Stheraven        __ptr_.first() = pointer();
2699227825Stheraven        return __t;
2700227825Stheraven    }
2701227825Stheraven
2702227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2703227825Stheraven    {
2704227825Stheraven        pointer __tmp = __ptr_.first();
2705227825Stheraven        __ptr_.first() = __p;
2706227825Stheraven        if (__tmp)
2707227825Stheraven            __ptr_.second()(__tmp);
2708227825Stheraven    }
2709227825Stheraven
2710227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2711227825Stheraven        {__ptr_.swap(__u.__ptr_);}
2712227825Stheraven};
2713227825Stheraven
2714227825Stheraventemplate <class _Tp, class _Dp>
2715227825Stheravenclass _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp>
2716227825Stheraven{
2717227825Stheravenpublic:
2718227825Stheraven    typedef _Tp element_type;
2719227825Stheraven    typedef _Dp deleter_type;
2720227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2721227825Stheravenprivate:
2722227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2723227825Stheraven
2724232950Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2725227825Stheraven    unique_ptr(unique_ptr&);
2726227825Stheraven    template <class _Up>
2727227825Stheraven        unique_ptr(unique_ptr<_Up>&);
2728227825Stheraven    unique_ptr& operator=(unique_ptr&);
2729227825Stheraven    template <class _Up>
2730227825Stheraven        unique_ptr& operator=(unique_ptr<_Up>&);
2731227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2732227825Stheraven
2733227825Stheraven    struct __nat {int __for_bool_;};
2734227825Stheraven
2735227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2736227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2737227825Stheravenpublic:
2738227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2739227825Stheraven        : __ptr_(pointer())
2740227825Stheraven        {
2741227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2742227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2743227825Stheraven        }
2744227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2745227825Stheraven        : __ptr_(pointer())
2746227825Stheraven        {
2747227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2748227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2749227825Stheraven        }
2750227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2751232950Stheraven    template <class _Pp,
2752232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2753227825Stheraven             >
2754232950Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2755227825Stheraven        : __ptr_(__p)
2756227825Stheraven        {
2757227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2758227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2759227825Stheraven        }
2760227825Stheraven
2761232950Stheraven    template <class _Pp,
2762232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2763227825Stheraven             >
2764232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2765227825Stheraven                                       is_reference<deleter_type>::value,
2766227825Stheraven                                       deleter_type,
2767227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2768227825Stheraven             _NOEXCEPT
2769227825Stheraven        : __ptr_(__p, __d) {}
2770227825Stheraven
2771227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2772227825Stheraven                                       is_reference<deleter_type>::value,
2773227825Stheraven                                       deleter_type,
2774227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2775227825Stheraven             _NOEXCEPT
2776227825Stheraven        : __ptr_(pointer(), __d) {}
2777227825Stheraven
2778232950Stheraven    template <class _Pp,
2779232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2780227825Stheraven             >
2781232950Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2782227825Stheraven             _NOEXCEPT
2783227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2784227825Stheraven        {
2785227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2786227825Stheraven        }
2787227825Stheraven
2788227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2789227825Stheraven             _NOEXCEPT
2790227825Stheraven        : __ptr_(pointer(), _VSTD::move(__d))
2791227825Stheraven        {
2792227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2793227825Stheraven        }
2794227825Stheraven
2795227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2796227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2797227825Stheraven
2798227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2799227825Stheraven        {
2800227825Stheraven            reset(__u.release());
2801227825Stheraven            __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2802227825Stheraven            return *this;
2803227825Stheraven        }
2804232950Stheraven
2805232950Stheraven    template <class _Up, class _Ep>
2806232950Stheraven        _LIBCPP_INLINE_VISIBILITY
2807232950Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2808232950Stheraven                   typename enable_if
2809232950Stheraven                            <
2810232950Stheraven                                is_array<_Up>::value &&
2811232950Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2812232950Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2813232950Stheraven                                (
2814232950Stheraven                                    !is_reference<deleter_type>::value ||
2815232950Stheraven                                    is_same<deleter_type, _Ep>::value
2816232950Stheraven                                ),
2817232950Stheraven                                __nat
2818232950Stheraven                            >::type = __nat()
2819232950Stheraven                  ) _NOEXCEPT
2820232950Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2821232950Stheraven
2822232950Stheraven
2823232950Stheraven        template <class _Up, class _Ep>
2824232950Stheraven            _LIBCPP_INLINE_VISIBILITY
2825232950Stheraven            typename enable_if
2826232950Stheraven            <
2827232950Stheraven                is_array<_Up>::value &&
2828232950Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2829232950Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2830232950Stheraven                unique_ptr&
2831232950Stheraven            >::type
2832232950Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2833232950Stheraven            {
2834232950Stheraven                reset(__u.release());
2835232950Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2836232950Stheraven                return *this;
2837232950Stheraven            }
2838227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2839227825Stheraven
2840227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2841227825Stheraven        : __ptr_(__p)
2842227825Stheraven        {
2843227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2844227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2845227825Stheraven        }
2846227825Stheraven
2847227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2848227825Stheraven        : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2849227825Stheraven
2850227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2851227825Stheraven        : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2852227825Stheraven
2853227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2854227825Stheraven    {
2855227825Stheraven        return __rv<unique_ptr>(*this);
2856227825Stheraven    }
2857227825Stheraven
2858227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2859227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2860227825Stheraven
2861227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2862227825Stheraven    {
2863227825Stheraven        reset(__u->release());
2864227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2865227825Stheraven        return *this;
2866227825Stheraven    }
2867227825Stheraven
2868227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2869227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2870227825Stheraven
2871227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2872227825Stheraven    {
2873227825Stheraven        reset();
2874227825Stheraven        return *this;
2875227825Stheraven    }
2876227825Stheraven
2877227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2878227825Stheraven        {return __ptr_.first()[__i];}
2879227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2880227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2881227825Stheraven        {return __ptr_.second();}
2882227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2883227825Stheraven        {return __ptr_.second();}
2884232950Stheraven    _LIBCPP_INLINE_VISIBILITY
2885232950Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2886232950Stheraven        {return __ptr_.first() != nullptr;}
2887227825Stheraven
2888227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2889227825Stheraven    {
2890227825Stheraven        pointer __t = __ptr_.first();
2891227825Stheraven        __ptr_.first() = pointer();
2892227825Stheraven        return __t;
2893227825Stheraven    }
2894227825Stheraven
2895227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2896232950Stheraven    template <class _Pp,
2897232950Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2898227825Stheraven             >
2899232950Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2900227825Stheraven    {
2901227825Stheraven        pointer __tmp = __ptr_.first();
2902227825Stheraven        __ptr_.first() = __p;
2903227825Stheraven        if (__tmp)
2904227825Stheraven            __ptr_.second()(__tmp);
2905227825Stheraven    }
2906227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2907227825Stheraven    {
2908227825Stheraven        pointer __tmp = __ptr_.first();
2909227825Stheraven        __ptr_.first() = nullptr;
2910227825Stheraven        if (__tmp)
2911227825Stheraven            __ptr_.second()(__tmp);
2912227825Stheraven    }
2913227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2914227825Stheraven    {
2915227825Stheraven        pointer __tmp = __ptr_.first();
2916227825Stheraven        __ptr_.first() = nullptr;
2917227825Stheraven        if (__tmp)
2918227825Stheraven            __ptr_.second()(__tmp);
2919227825Stheraven    }
2920227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2921227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2922227825Stheraven    {
2923227825Stheraven        pointer __tmp = __ptr_.first();
2924227825Stheraven        __ptr_.first() = __p;
2925227825Stheraven        if (__tmp)
2926227825Stheraven            __ptr_.second()(__tmp);
2927227825Stheraven    }
2928227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2929227825Stheraven
2930227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2931227825Stheravenprivate:
2932227825Stheraven
2933227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2934227825Stheraven    template <class _Up>
2935227825Stheraven        explicit unique_ptr(_Up);
2936227825Stheraven    template <class _Up>
2937227825Stheraven        unique_ptr(_Up __u,
2938227825Stheraven                   typename conditional<
2939227825Stheraven                                       is_reference<deleter_type>::value,
2940227825Stheraven                                       deleter_type,
2941227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type,
2942227825Stheraven                   typename enable_if
2943227825Stheraven                      <
2944227825Stheraven                         is_convertible<_Up, pointer>::value,
2945227825Stheraven                         __nat
2946227825Stheraven                      >::type = __nat());
2947227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2948227825Stheraven};
2949227825Stheraven
2950227825Stheraventemplate <class _Tp, class _Dp>
2951227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2952227825Stheravenvoid
2953227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2954227825Stheraven
2955227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2956227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2957227825Stheravenbool
2958227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2959227825Stheraven
2960227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2961227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2962227825Stheravenbool
2963227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2964227825Stheraven
2965227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2966227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2967227825Stheravenbool
2968232950Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2969232950Stheraven{
2970232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2971232950Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2972232950Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2973232950Stheraven    return less<_V>()(__x.get(), __y.get());
2974232950Stheraven}
2975227825Stheraven
2976227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2977227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2978227825Stheravenbool
2979227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2980227825Stheraven
2981227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2982227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2983227825Stheravenbool
2984227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2985227825Stheraven
2986227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2987227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2988227825Stheravenbool
2989227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2990227825Stheraven
2991232950Stheraventemplate <class _T1, class _D1>
2992232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
2993232950Stheravenbool
2994232950Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2995232950Stheraven{
2996232950Stheraven    return !__x;
2997232950Stheraven}
2998232950Stheraven
2999232950Stheraventemplate <class _T1, class _D1>
3000232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3001232950Stheravenbool
3002232950Stheravenoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3003232950Stheraven{
3004232950Stheraven    return !__x;
3005232950Stheraven}
3006232950Stheraven
3007232950Stheraventemplate <class _T1, class _D1>
3008232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3009232950Stheravenbool
3010232950Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3011232950Stheraven{
3012232950Stheraven    return static_cast<bool>(__x);
3013232950Stheraven}
3014232950Stheraven
3015232950Stheraventemplate <class _T1, class _D1>
3016232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3017232950Stheravenbool
3018232950Stheravenoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3019232950Stheraven{
3020232950Stheraven    return static_cast<bool>(__x);
3021232950Stheraven}
3022232950Stheraven
3023232950Stheraventemplate <class _T1, class _D1>
3024232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3025232950Stheravenbool
3026232950Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3027232950Stheraven{
3028232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3029232950Stheraven    return less<_P1>()(__x.get(), nullptr);
3030232950Stheraven}
3031232950Stheraven
3032232950Stheraventemplate <class _T1, class _D1>
3033232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3034232950Stheravenbool
3035232950Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3036232950Stheraven{
3037232950Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3038232950Stheraven    return less<_P1>()(nullptr, __x.get());
3039232950Stheraven}
3040232950Stheraven
3041232950Stheraventemplate <class _T1, class _D1>
3042232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3043232950Stheravenbool
3044232950Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3045232950Stheraven{
3046232950Stheraven    return nullptr < __x;
3047232950Stheraven}
3048232950Stheraven
3049232950Stheraventemplate <class _T1, class _D1>
3050232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3051232950Stheravenbool
3052232950Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3053232950Stheraven{
3054232950Stheraven    return __x < nullptr;
3055232950Stheraven}
3056232950Stheraven
3057232950Stheraventemplate <class _T1, class _D1>
3058232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3059232950Stheravenbool
3060232950Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3061232950Stheraven{
3062232950Stheraven    return !(nullptr < __x);
3063232950Stheraven}
3064232950Stheraven
3065232950Stheraventemplate <class _T1, class _D1>
3066232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3067232950Stheravenbool
3068232950Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3069232950Stheraven{
3070232950Stheraven    return !(__x < nullptr);
3071232950Stheraven}
3072232950Stheraven
3073232950Stheraventemplate <class _T1, class _D1>
3074232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3075232950Stheravenbool
3076232950Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3077232950Stheraven{
3078232950Stheraven    return !(__x < nullptr);
3079232950Stheraven}
3080232950Stheraven
3081232950Stheraventemplate <class _T1, class _D1>
3082232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
3083232950Stheravenbool
3084232950Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3085232950Stheraven{
3086232950Stheraven    return !(nullptr < __x);
3087232950Stheraven}
3088232950Stheraven
3089227825Stheraventemplate <class _Tp> struct hash;
3090227825Stheraven
3091232950Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3092232950Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3093232950Stheraven// multiplication, which can be very slow on 32-bit systems.
3094232950Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3095232950Stheravenstruct __murmur2_or_cityhash;
3096232950Stheraven
3097232950Stheraventemplate <class _Size>
3098232950Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3099227825Stheraven{
3100232950Stheraven    _Size operator()(const void* __key, _Size __len);
3101232950Stheraven};
3102232950Stheraven
3103232950Stheraven// murmur2
3104232950Stheraventemplate <class _Size>
3105232950Stheraven_Size
3106232950Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3107232950Stheraven{
3108232950Stheraven    const _Size __m = 0x5bd1e995;
3109232950Stheraven    const _Size __r = 24;
3110232950Stheraven    _Size __h = __len;
3111232950Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3112232950Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3113232950Stheraven    {
3114232950Stheraven        _Size __k = *(const _Size*)__data;
3115232950Stheraven        __k *= __m;
3116232950Stheraven        __k ^= __k >> __r;
3117232950Stheraven        __k *= __m;
3118232950Stheraven        __h *= __m;
3119232950Stheraven        __h ^= __k;
3120232950Stheraven    }
3121232950Stheraven    switch (__len)
3122232950Stheraven    {
3123232950Stheraven    case 3:
3124232950Stheraven        __h ^= __data[2] << 16;
3125232950Stheraven    case 2:
3126232950Stheraven        __h ^= __data[1] << 8;
3127232950Stheraven    case 1:
3128232950Stheraven        __h ^= __data[0];
3129232950Stheraven        __h *= __m;
3130232950Stheraven    }
3131232950Stheraven    __h ^= __h >> 13;
3132232950Stheraven    __h *= __m;
3133232950Stheraven    __h ^= __h >> 15;
3134232950Stheraven    return __h;
3135232950Stheraven}
3136232950Stheraven
3137232950Stheraventemplate <class _Size>
3138232950Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3139232950Stheraven{
3140232950Stheraven    _Size operator()(const void* __key, _Size __len);
3141232950Stheraven
3142232950Stheraven private:
3143232950Stheraven  // Some primes between 2^63 and 2^64.
3144232950Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3145232950Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3146232950Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3147232950Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3148232950Stheraven
3149232950Stheraven  static _Size __rotate(_Size __val, int __shift) {
3150232950Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3151232950Stheraven  }
3152232950Stheraven
3153232950Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3154232950Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3155232950Stheraven  }
3156232950Stheraven
3157232950Stheraven  static _Size __shift_mix(_Size __val) {
3158232950Stheraven    return __val ^ (__val >> 47);
3159232950Stheraven  }
3160232950Stheraven
3161232950Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3162232950Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3163232950Stheraven    _Size __a = (__u ^ __v) * __mul;
3164232950Stheraven    __a ^= (__a >> 47);
3165232950Stheraven    _Size __b = (__v ^ __a) * __mul;
3166232950Stheraven    __b ^= (__b >> 47);
3167232950Stheraven    __b *= __mul;
3168232950Stheraven    return __b;
3169232950Stheraven  }
3170232950Stheraven
3171232950Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3172232950Stheraven    if (__len > 8) {
3173232950Stheraven      const _Size __a = *(const _Size*)__s;
3174232950Stheraven      const _Size __b = *(const _Size*)(__s + __len - 8);
3175232950Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3176232950Stheraven    }
3177232950Stheraven    if (__len >= 4) {
3178232950Stheraven      const uint32_t __a = *(const uint32_t*)(__s);
3179232950Stheraven      const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3180232950Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3181232950Stheraven    }
3182232950Stheraven    if (__len > 0) {
3183232950Stheraven      const unsigned char __a = __s[0];
3184232950Stheraven      const unsigned char __b = __s[__len >> 1];
3185232950Stheraven      const unsigned char __c = __s[__len - 1];
3186232950Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3187232950Stheraven                           (static_cast<uint32_t>(__b) << 8);
3188232950Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3189232950Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3190232950Stheraven    }
3191232950Stheraven    return __k2;
3192232950Stheraven  }
3193232950Stheraven
3194232950Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3195232950Stheraven    const _Size __a = *(const _Size*)(__s) * __k1;
3196232950Stheraven    const _Size __b = *(const _Size*)(__s + 8);
3197232950Stheraven    const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3198232950Stheraven    const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3199232950Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3200232950Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3201232950Stheraven  }
3202232950Stheraven
3203232950Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3204232950Stheraven  // Callers do best to use "random-looking" values for a and b.
3205232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3206232950Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3207232950Stheraven    __a += __w;
3208232950Stheraven    __b = __rotate(__b + __a + __z, 21);
3209232950Stheraven    const _Size __c = __a;
3210232950Stheraven    __a += __x;
3211232950Stheraven    __a += __y;
3212232950Stheraven    __b += __rotate(__a, 44);
3213232950Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3214232950Stheraven  }
3215232950Stheraven
3216232950Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3217232950Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3218232950Stheraven      const char* __s, _Size __a, _Size __b) {
3219232950Stheraven    return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3220232950Stheraven                                         *(const _Size*)(__s + 8),
3221232950Stheraven                                         *(const _Size*)(__s + 16),
3222232950Stheraven                                         *(const _Size*)(__s + 24),
3223232950Stheraven                                         __a,
3224232950Stheraven                                         __b);
3225232950Stheraven  }
3226232950Stheraven
3227232950Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3228232950Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3229232950Stheraven    _Size __z = *(const _Size*)(__s + 24);
3230232950Stheraven    _Size __a = *(const _Size*)(__s) +
3231232950Stheraven                (__len + *(const _Size*)(__s + __len - 16)) * __k0;
3232232950Stheraven    _Size __b = __rotate(__a + __z, 52);
3233232950Stheraven    _Size __c = __rotate(__a, 37);
3234232950Stheraven    __a += *(const _Size*)(__s + 8);
3235232950Stheraven    __c += __rotate(__a, 7);
3236232950Stheraven    __a += *(const _Size*)(__s + 16);
3237232950Stheraven    _Size __vf = __a + __z;
3238232950Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3239232950Stheraven    __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3240232950Stheraven    __z += *(const _Size*)(__s + __len - 8);
3241232950Stheraven    __b = __rotate(__a + __z, 52);
3242232950Stheraven    __c = __rotate(__a, 37);
3243232950Stheraven    __a += *(const _Size*)(__s + __len - 24);
3244232950Stheraven    __c += __rotate(__a, 7);
3245232950Stheraven    __a += *(const _Size*)(__s + __len - 16);
3246232950Stheraven    _Size __wf = __a + __z;
3247232950Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3248232950Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3249232950Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3250232950Stheraven  }
3251232950Stheraven};
3252232950Stheraven
3253232950Stheraven// cityhash64
3254232950Stheraventemplate <class _Size>
3255232950Stheraven_Size
3256232950Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3257232950Stheraven{
3258232950Stheraven  const char* __s = static_cast<const char*>(__key);
3259232950Stheraven  if (__len <= 32) {
3260232950Stheraven    if (__len <= 16) {
3261232950Stheraven      return __hash_len_0_to_16(__s, __len);
3262232950Stheraven    } else {
3263232950Stheraven      return __hash_len_17_to_32(__s, __len);
3264232950Stheraven    }
3265232950Stheraven  } else if (__len <= 64) {
3266232950Stheraven    return __hash_len_33_to_64(__s, __len);
3267232950Stheraven  }
3268232950Stheraven
3269232950Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3270232950Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3271232950Stheraven  _Size __x = *(const _Size*)(__s + __len - 40);
3272232950Stheraven  _Size __y = *(const _Size*)(__s + __len - 16) +
3273232950Stheraven              *(const _Size*)(__s + __len - 56);
3274232950Stheraven  _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3275232950Stheraven                          *(const _Size*)(__s + __len - 24));
3276232950Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3277232950Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3278232950Stheraven  __x = __x * __k1 + *(const _Size*)(__s);
3279232950Stheraven
3280232950Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3281232950Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3282232950Stheraven  do {
3283232950Stheraven    __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3284232950Stheraven    __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3285232950Stheraven    __x ^= __w.second;
3286232950Stheraven    __y += __v.first + *(const _Size*)(__s + 40);
3287232950Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3288232950Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3289232950Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3290232950Stheraven                                        __y + *(const _Size*)(__s + 16));
3291232950Stheraven    std::swap(__z, __x);
3292232950Stheraven    __s += 64;
3293232950Stheraven    __len -= 64;
3294232950Stheraven  } while (__len != 0);
3295232950Stheraven  return __hash_len_16(
3296232950Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3297232950Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3298232950Stheraven}
3299232950Stheraven
3300232950Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3301232950Stheravenstruct __scalar_hash;
3302232950Stheraven
3303232950Stheraventemplate <class _Tp>
3304232950Stheravenstruct __scalar_hash<_Tp, 0>
3305232950Stheraven    : public unary_function<_Tp, size_t>
3306232950Stheraven{
3307227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3308232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3309227825Stheraven    {
3310232950Stheraven        union
3311232950Stheraven        {
3312232950Stheraven            _Tp    __t;
3313232950Stheraven            size_t __a;
3314232950Stheraven        } __u;
3315232950Stheraven        __u.__a = 0;
3316232950Stheraven        __u.__t = __v;
3317232950Stheraven        return __u.__a;
3318227825Stheraven    }
3319227825Stheraven};
3320227825Stheraven
3321232950Stheraventemplate <class _Tp>
3322232950Stheravenstruct __scalar_hash<_Tp, 1>
3323232950Stheraven    : public unary_function<_Tp, size_t>
3324232950Stheraven{
3325232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3326232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3327232950Stheraven    {
3328232950Stheraven        union
3329232950Stheraven        {
3330232950Stheraven            _Tp    __t;
3331232950Stheraven            size_t __a;
3332232950Stheraven        } __u;
3333232950Stheraven        __u.__t = __v;
3334232950Stheraven        return __u.__a;
3335232950Stheraven    }
3336232950Stheraven};
3337232950Stheraven
3338232950Stheraventemplate <class _Tp>
3339232950Stheravenstruct __scalar_hash<_Tp, 2>
3340232950Stheraven    : public unary_function<_Tp, size_t>
3341232950Stheraven{
3342232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3343232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3344232950Stheraven    {
3345232950Stheraven        union
3346232950Stheraven        {
3347232950Stheraven            _Tp __t;
3348232950Stheraven            struct
3349232950Stheraven            {
3350232950Stheraven                size_t __a;
3351232950Stheraven                size_t __b;
3352232950Stheraven            };
3353232950Stheraven        } __u;
3354232950Stheraven        __u.__t = __v;
3355232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3356232950Stheraven    }
3357232950Stheraven};
3358232950Stheraven
3359232950Stheraventemplate <class _Tp>
3360232950Stheravenstruct __scalar_hash<_Tp, 3>
3361232950Stheraven    : public unary_function<_Tp, size_t>
3362232950Stheraven{
3363232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3364232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3365232950Stheraven    {
3366232950Stheraven        union
3367232950Stheraven        {
3368232950Stheraven            _Tp __t;
3369232950Stheraven            struct
3370232950Stheraven            {
3371232950Stheraven                size_t __a;
3372232950Stheraven                size_t __b;
3373232950Stheraven                size_t __c;
3374232950Stheraven            };
3375232950Stheraven        } __u;
3376232950Stheraven        __u.__t = __v;
3377232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3378232950Stheraven    }
3379232950Stheraven};
3380232950Stheraven
3381232950Stheraventemplate <class _Tp>
3382232950Stheravenstruct __scalar_hash<_Tp, 4>
3383232950Stheraven    : public unary_function<_Tp, size_t>
3384232950Stheraven{
3385232950Stheraven    _LIBCPP_INLINE_VISIBILITY
3386232950Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3387232950Stheraven    {
3388232950Stheraven        union
3389232950Stheraven        {
3390232950Stheraven            _Tp __t;
3391232950Stheraven            struct
3392232950Stheraven            {
3393232950Stheraven                size_t __a;
3394232950Stheraven                size_t __b;
3395232950Stheraven                size_t __c;
3396232950Stheraven                size_t __d;
3397232950Stheraven            };
3398232950Stheraven        } __u;
3399232950Stheraven        __u.__t = __v;
3400232950Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3401232950Stheraven    }
3402232950Stheraven};
3403232950Stheraven
3404232950Stheraventemplate<class _Tp>
3405232950Stheravenstruct _LIBCPP_VISIBLE hash<_Tp*>
3406232950Stheraven    : public __scalar_hash<_Tp*>
3407232950Stheraven{
3408232950Stheraven};
3409232950Stheraven
3410227825Stheraventemplate <class _Tp, class _Dp>
3411227825Stheravenstruct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
3412227825Stheraven{
3413227825Stheraven    typedef unique_ptr<_Tp, _Dp> argument_type;
3414227825Stheraven    typedef size_t               result_type;
3415227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3416227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3417227825Stheraven    {
3418227825Stheraven        typedef typename argument_type::pointer pointer;
3419227825Stheraven        return hash<pointer>()(__ptr.get());
3420227825Stheraven    }
3421227825Stheraven};
3422227825Stheraven
3423227825Stheravenstruct __destruct_n
3424227825Stheraven{
3425227825Stheravenprivate:
3426227825Stheraven    size_t size;
3427227825Stheraven
3428227825Stheraven    template <class _Tp>
3429227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3430227825Stheraven        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3431227825Stheraven
3432227825Stheraven    template <class _Tp>
3433227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3434227825Stheraven        {}
3435227825Stheraven
3436227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3437227825Stheraven        {++size;}
3438227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3439227825Stheraven        {}
3440227825Stheraven
3441227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3442227825Stheraven        {size = __s;}
3443227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3444227825Stheraven        {}
3445227825Stheravenpublic:
3446227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3447227825Stheraven        : size(__s) {}
3448227825Stheraven
3449227825Stheraven    template <class _Tp>
3450227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3451227825Stheraven        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3452227825Stheraven
3453227825Stheraven    template <class _Tp>
3454227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3455227825Stheraven        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3456227825Stheraven
3457227825Stheraven    template <class _Tp>
3458227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3459227825Stheraven        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3460227825Stheraven};
3461227825Stheraven
3462227825Stheraventemplate <class _Alloc>
3463227825Stheravenclass __allocator_destructor
3464227825Stheraven{
3465227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
3466227825Stheravenpublic:
3467227825Stheraven    typedef typename __alloc_traits::pointer pointer;
3468227825Stheraven    typedef typename __alloc_traits::size_type size_type;
3469227825Stheravenprivate:
3470227825Stheraven    _Alloc& __alloc_;
3471227825Stheraven    size_type __s_;
3472227825Stheravenpublic:
3473227825Stheraven    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3474227825Stheraven             _NOEXCEPT
3475227825Stheraven        : __alloc_(__a), __s_(__s) {}
3476227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3477227825Stheraven    void operator()(pointer __p) _NOEXCEPT
3478227825Stheraven        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3479227825Stheraven};
3480227825Stheraven
3481227825Stheraventemplate <class _InputIterator, class _ForwardIterator>
3482227825Stheraven_ForwardIterator
3483227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3484227825Stheraven{
3485227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3486232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3487232950Stheraven    _ForwardIterator __s = __r;
3488232950Stheraven    try
3489232950Stheraven    {
3490232950Stheraven#endif
3491232950Stheraven        for (; __f != __l; ++__f, ++__r)
3492232950Stheraven            ::new(&*__r) value_type(*__f);
3493232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3494232950Stheraven    }
3495232950Stheraven    catch (...)
3496232950Stheraven    {
3497232950Stheraven        for (; __s != __r; ++__s)
3498232950Stheraven            __s->~value_type();
3499232950Stheraven        throw;
3500232950Stheraven    }
3501232950Stheraven#endif
3502227825Stheraven    return __r;
3503227825Stheraven}
3504227825Stheraven
3505227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator>
3506227825Stheraven_ForwardIterator
3507227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3508227825Stheraven{
3509227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3510232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3511232950Stheraven    _ForwardIterator __s = __r;
3512232950Stheraven    try
3513232950Stheraven    {
3514232950Stheraven#endif
3515232950Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3516232950Stheraven            ::new(&*__r) value_type(*__f);
3517232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3518232950Stheraven    }
3519232950Stheraven    catch (...)
3520232950Stheraven    {
3521232950Stheraven        for (; __s != __r; ++__s)
3522232950Stheraven            __s->~value_type();
3523232950Stheraven        throw;
3524232950Stheraven    }
3525232950Stheraven#endif
3526227825Stheraven    return __r;
3527227825Stheraven}
3528227825Stheraven
3529227825Stheraventemplate <class _ForwardIterator, class _Tp>
3530227825Stheravenvoid
3531227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3532227825Stheraven{
3533227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3534232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3535232950Stheraven    _ForwardIterator __s = __f;
3536232950Stheraven    try
3537232950Stheraven    {
3538232950Stheraven#endif
3539232950Stheraven        for (; __f != __l; ++__f)
3540232950Stheraven            ::new(&*__f) value_type(__x);
3541232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3542232950Stheraven    }
3543232950Stheraven    catch (...)
3544232950Stheraven    {
3545232950Stheraven        for (; __s != __f; ++__s)
3546232950Stheraven            __s->~value_type();
3547232950Stheraven        throw;
3548232950Stheraven    }
3549232950Stheraven#endif
3550227825Stheraven}
3551227825Stheraven
3552227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp>
3553227825Stheraven_ForwardIterator
3554227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3555227825Stheraven{
3556227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3557232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3558232950Stheraven    _ForwardIterator __s = __f;
3559232950Stheraven    try
3560232950Stheraven    {
3561232950Stheraven#endif
3562232950Stheraven        for (; __n > 0; ++__f, --__n)
3563232950Stheraven            ::new(&*__f) value_type(__x);
3564232950Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3565232950Stheraven    }
3566232950Stheraven    catch (...)
3567232950Stheraven    {
3568232950Stheraven        for (; __s != __f; ++__s)
3569232950Stheraven            __s->~value_type();
3570232950Stheraven        throw;
3571232950Stheraven    }
3572232950Stheraven#endif
3573227825Stheraven    return __f;
3574227825Stheraven}
3575227825Stheraven
3576227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3577227825Stheraven    : public std::exception
3578227825Stheraven{
3579227825Stheravenpublic:
3580227825Stheraven    virtual ~bad_weak_ptr() _NOEXCEPT;
3581227825Stheraven    virtual const char* what() const  _NOEXCEPT;
3582227825Stheraven};
3583227825Stheraven
3584227825Stheraventemplate<class _Tp> class weak_ptr;
3585227825Stheraven
3586227825Stheravenclass __shared_count
3587227825Stheraven{
3588227825Stheraven    __shared_count(const __shared_count&);
3589227825Stheraven    __shared_count& operator=(const __shared_count&);
3590227825Stheraven
3591227825Stheravenprotected:
3592227825Stheraven    long __shared_owners_;
3593227825Stheraven    virtual ~__shared_count();
3594227825Stheravenprivate:
3595227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT = 0;
3596227825Stheraven
3597227825Stheravenpublic:
3598227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3599227825Stheraven    explicit __shared_count(long __refs = 0) _NOEXCEPT
3600227825Stheraven        : __shared_owners_(__refs) {}
3601227825Stheraven
3602227825Stheraven    void __add_shared() _NOEXCEPT;
3603227825Stheraven    bool __release_shared() _NOEXCEPT;
3604227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3605227825Stheraven    long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3606227825Stheraven};
3607227825Stheraven
3608227825Stheravenclass __shared_weak_count
3609227825Stheraven    : private __shared_count
3610227825Stheraven{
3611227825Stheraven    long __shared_weak_owners_;
3612227825Stheraven
3613227825Stheravenpublic:
3614227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3615227825Stheraven    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3616227825Stheraven        : __shared_count(__refs),
3617227825Stheraven          __shared_weak_owners_(__refs) {}
3618227825Stheravenprotected:
3619227825Stheraven    virtual ~__shared_weak_count();
3620227825Stheraven
3621227825Stheravenpublic:
3622227825Stheraven    void __add_shared() _NOEXCEPT;
3623227825Stheraven    void __add_weak() _NOEXCEPT;
3624227825Stheraven    void __release_shared() _NOEXCEPT;
3625227825Stheraven    void __release_weak() _NOEXCEPT;
3626227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3627227825Stheraven    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3628227825Stheraven    __shared_weak_count* lock() _NOEXCEPT;
3629227825Stheraven
3630227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3631227825Stheravenprivate:
3632227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3633227825Stheraven};
3634227825Stheraven
3635227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3636227825Stheravenclass __shared_ptr_pointer
3637227825Stheraven    : public __shared_weak_count
3638227825Stheraven{
3639227825Stheraven    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3640227825Stheravenpublic:
3641227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3642227825Stheraven    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3643227825Stheraven        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3644227825Stheraven
3645227825Stheraven#ifndef _LIBCPP_NO_RTTI
3646227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3647227825Stheraven#endif
3648227825Stheraven
3649227825Stheravenprivate:
3650227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3651227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3652227825Stheraven};
3653227825Stheraven
3654227825Stheraven#ifndef _LIBCPP_NO_RTTI
3655227825Stheraven
3656227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3657227825Stheravenconst void*
3658227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3659227825Stheraven{
3660227825Stheraven    return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3661227825Stheraven}
3662227825Stheraven
3663227825Stheraven#endif  // _LIBCPP_NO_RTTI
3664227825Stheraven
3665227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3666227825Stheravenvoid
3667227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3668227825Stheraven{
3669227825Stheraven    __data_.first().second()(__data_.first().first());
3670227825Stheraven    __data_.first().second().~_Dp();
3671227825Stheraven}
3672227825Stheraven
3673227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3674227825Stheravenvoid
3675227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3676227825Stheraven{
3677227825Stheraven    typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3678227825Stheraven    __data_.second().~_Alloc();
3679227825Stheraven    __a.deallocate(this, 1);
3680227825Stheraven}
3681227825Stheraven
3682227825Stheraventemplate <class _Tp, class _Alloc>
3683227825Stheravenclass __shared_ptr_emplace
3684227825Stheraven    : public __shared_weak_count
3685227825Stheraven{
3686227825Stheraven    __compressed_pair<_Alloc, _Tp> __data_;
3687227825Stheravenpublic:
3688227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3689227825Stheraven
3690227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3691227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3692227825Stheraven        :  __data_(_VSTD::move(__a)) {}
3693227825Stheraven
3694227825Stheraven    template <class ..._Args>
3695227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3696227825Stheraven        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3697232950Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3698232950Stheraven                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3699227825Stheraven
3700227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3701227825Stheraven
3702227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3703227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3704227825Stheraven        :  __data_(__a) {}
3705227825Stheraven
3706227825Stheraven    template <class _A0>
3707227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3708227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3709227825Stheraven            :  __data_(__a, _Tp(__a0)) {}
3710227825Stheraven
3711227825Stheraven    template <class _A0, class _A1>
3712227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3713227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3714227825Stheraven            :  __data_(__a, _Tp(__a0, __a1)) {}
3715227825Stheraven
3716227825Stheraven    template <class _A0, class _A1, class _A2>
3717227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3718227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3719227825Stheraven            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3720227825Stheraven
3721227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3722227825Stheraven
3723227825Stheravenprivate:
3724227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3725227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3726227825Stheravenpublic:
3727227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3728227825Stheraven    _Tp* get() _NOEXCEPT {return &__data_.second();}
3729227825Stheraven};
3730227825Stheraven
3731227825Stheraventemplate <class _Tp, class _Alloc>
3732227825Stheravenvoid
3733227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3734227825Stheraven{
3735227825Stheraven    __data_.second().~_Tp();
3736227825Stheraven}
3737227825Stheraven
3738227825Stheraventemplate <class _Tp, class _Alloc>
3739227825Stheravenvoid
3740227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3741227825Stheraven{
3742227825Stheraven    typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3743227825Stheraven    __data_.first().~_Alloc();
3744227825Stheraven    __a.deallocate(this, 1);
3745227825Stheraven}
3746227825Stheraven
3747227825Stheraventemplate<class _Tp> class enable_shared_from_this;
3748227825Stheraven
3749227825Stheraventemplate<class _Tp>
3750227825Stheravenclass _LIBCPP_VISIBLE shared_ptr
3751227825Stheraven{
3752227825Stheravenpublic:
3753227825Stheraven    typedef _Tp element_type;
3754227825Stheravenprivate:
3755227825Stheraven    element_type*      __ptr_;
3756227825Stheraven    __shared_weak_count* __cntrl_;
3757227825Stheraven
3758227825Stheraven    struct __nat {int __for_bool_;};
3759227825Stheravenpublic:
3760227825Stheraven    shared_ptr() _NOEXCEPT;
3761227825Stheraven    shared_ptr(nullptr_t) _NOEXCEPT;
3762232950Stheraven    template<class _Yp,
3763232950Stheraven             class = typename enable_if
3764232950Stheraven                     <
3765232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3766232950Stheraven                     >::type
3767232950Stheraven            >
3768232950Stheraven        explicit shared_ptr(_Yp* __p);
3769232950Stheraven    template<class _Yp, class _Dp,
3770232950Stheraven             class = typename enable_if
3771232950Stheraven                     <
3772232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3773232950Stheraven                     >::type
3774232950Stheraven            >
3775232950Stheraven        shared_ptr(_Yp* __p, _Dp __d);
3776232950Stheraven    template<class _Yp, class _Dp, class _Alloc,
3777232950Stheraven             class = typename enable_if
3778232950Stheraven                     <
3779232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3780232950Stheraven                     >::type
3781232950Stheraven            >
3782232950Stheraven        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3783227825Stheraven    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3784227825Stheraven    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3785227825Stheraven    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3786227825Stheraven    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3787227825Stheraven    template<class _Yp>
3788227825Stheraven        shared_ptr(const shared_ptr<_Yp>& __r,
3789227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3790227825Stheraven                       _NOEXCEPT;
3791227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3792227825Stheraven    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3793227825Stheraven    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3794227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3795227825Stheraven                       _NOEXCEPT;
3796227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3797227825Stheraven    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3798227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3799227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3800232950Stheraven    template<class _Yp,
3801232950Stheraven             class = typename enable_if
3802232950Stheraven                     <
3803232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3804232950Stheraven                     >::type
3805232950Stheraven            >
3806232950Stheraven        shared_ptr(auto_ptr<_Yp>&& __r);
3807227825Stheraven#else
3808232950Stheraven    template<class _Yp,
3809232950Stheraven             class = typename enable_if
3810232950Stheraven                     <
3811232950Stheraven                        is_convertible<_Yp*, element_type*>::value
3812232950Stheraven                     >::type
3813232950Stheraven            >
3814232950Stheraven        shared_ptr(auto_ptr<_Yp> __r);
3815227825Stheraven#endif
3816227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3817232950Stheraven    template <class _Yp, class _Dp,
3818232950Stheraven                 class = typename enable_if
3819232950Stheraven                 <
3820232950Stheraven                    !is_array<_Yp>::value &&
3821232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3822232950Stheraven                 >::type
3823232950Stheraven             >
3824232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3825227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3826232950Stheraven    template <class _Yp, class _Dp,
3827232950Stheraven                 class = typename enable_if
3828232950Stheraven                 <
3829232950Stheraven                    !is_array<_Yp>::value &&
3830232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3831232950Stheraven                 >::type
3832232950Stheraven             >
3833232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3834227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3835227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
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             > shared_ptr(unique_ptr<_Yp, _Dp>,
3843227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3844232950Stheraven    template <class _Yp, class _Dp,
3845232950Stheraven                 class = typename enable_if
3846232950Stheraven                 <
3847232950Stheraven                    !is_array<_Yp>::value &&
3848232950Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3849232950Stheraven                 >::type
3850232950Stheraven             >
3851232950Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>,
3852227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3853227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3854227825Stheraven
3855227825Stheraven    ~shared_ptr();
3856227825Stheraven
3857227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3858232950Stheraven    template<class _Yp>
3859232950Stheraven        typename enable_if
3860232950Stheraven        <
3861232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3862232950Stheraven            shared_ptr&
3863232950Stheraven        >::type
3864232950Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3865227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3866227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3867232950Stheraven    template<class _Yp>
3868232950Stheraven        typename enable_if
3869232950Stheraven        <
3870232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3871232950Stheraven            shared_ptr<_Tp>&
3872232950Stheraven        >::type
3873232950Stheraven        operator=(shared_ptr<_Yp>&& __r);
3874232950Stheraven    template<class _Yp>
3875232950Stheraven        typename enable_if
3876232950Stheraven        <
3877232950Stheraven            !is_array<_Yp>::value &&
3878232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3879232950Stheraven            shared_ptr&
3880232950Stheraven        >::type
3881232950Stheraven        operator=(auto_ptr<_Yp>&& __r);
3882227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3883232950Stheraven    template<class _Yp>
3884232950Stheraven        typename enable_if
3885232950Stheraven        <
3886232950Stheraven            !is_array<_Yp>::value &&
3887232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3888232950Stheraven            shared_ptr&
3889232950Stheraven        >::type
3890232950Stheraven        operator=(auto_ptr<_Yp> __r);
3891227825Stheraven#endif
3892232950Stheraven    template <class _Yp, class _Dp>
3893232950Stheraven        typename enable_if
3894232950Stheraven        <
3895232950Stheraven            !is_array<_Yp>::value &&
3896232950Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3897232950Stheraven            shared_ptr&
3898232950Stheraven        >::type
3899227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3900232950Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3901227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3902232950Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3903227825Stheraven#endif
3904227825Stheraven
3905227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3906227825Stheraven    void reset() _NOEXCEPT;
3907232950Stheraven    template<class _Yp>
3908232950Stheraven        typename enable_if
3909232950Stheraven        <
3910232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3911232950Stheraven            void
3912232950Stheraven        >::type
3913232950Stheraven        reset(_Yp* __p);
3914232950Stheraven    template<class _Yp, class _Dp>
3915232950Stheraven        typename enable_if
3916232950Stheraven        <
3917232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3918232950Stheraven            void
3919232950Stheraven        >::type
3920232950Stheraven        reset(_Yp* __p, _Dp __d);
3921232950Stheraven    template<class _Yp, class _Dp, class _Alloc>
3922232950Stheraven        typename enable_if
3923232950Stheraven        <
3924232950Stheraven            is_convertible<_Yp*, element_type*>::value,
3925232950Stheraven            void
3926232950Stheraven        >::type
3927232950Stheraven        reset(_Yp* __p, _Dp __d, _Alloc __a);
3928227825Stheraven
3929227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3930227825Stheraven    element_type* get() const _NOEXCEPT {return __ptr_;}
3931227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3932227825Stheraven    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3933227825Stheraven        {return *__ptr_;}
3934227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3935227825Stheraven    element_type* operator->() const _NOEXCEPT {return __ptr_;}
3936227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3937227825Stheraven    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3938227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3939227825Stheraven    bool unique() const _NOEXCEPT {return use_count() == 1;}
3940227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3941232950Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3942232950Stheraven    template <class _Up>
3943227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3944232950Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
3945227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3946232950Stheraven    template <class _Up>
3947227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3948232950Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
3949227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3950227825Stheraven
3951227825Stheraven#ifndef _LIBCPP_NO_RTTI
3952227825Stheraven    template <class _Dp>
3953227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3954227825Stheraven        _Dp* __get_deleter() const _NOEXCEPT
3955227825Stheraven            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3956227825Stheraven#endif  // _LIBCPP_NO_RTTI
3957227825Stheraven
3958227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3959227825Stheraven
3960227825Stheraven    template<class ..._Args>
3961227825Stheraven        static
3962227825Stheraven        shared_ptr<_Tp>
3963227825Stheraven        make_shared(_Args&& ...__args);
3964227825Stheraven
3965227825Stheraven    template<class _Alloc, class ..._Args>
3966227825Stheraven        static
3967227825Stheraven        shared_ptr<_Tp>
3968227825Stheraven        allocate_shared(const _Alloc& __a, _Args&& ...__args);
3969227825Stheraven
3970227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3971227825Stheraven
3972227825Stheraven    static shared_ptr<_Tp> make_shared();
3973227825Stheraven
3974227825Stheraven    template<class _A0>
3975227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&);
3976227825Stheraven
3977227825Stheraven    template<class _A0, class _A1>
3978227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3979227825Stheraven
3980227825Stheraven    template<class _A0, class _A1, class _A2>
3981227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3982227825Stheraven
3983227825Stheraven    template<class _Alloc>
3984227825Stheraven        static shared_ptr<_Tp>
3985227825Stheraven        allocate_shared(const _Alloc& __a);
3986227825Stheraven
3987227825Stheraven    template<class _Alloc, class _A0>
3988227825Stheraven        static shared_ptr<_Tp>
3989227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0);
3990227825Stheraven
3991227825Stheraven    template<class _Alloc, class _A0, class _A1>
3992227825Stheraven        static shared_ptr<_Tp>
3993227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3994227825Stheraven
3995227825Stheraven    template<class _Alloc, class _A0, class _A1, class _A2>
3996227825Stheraven        static shared_ptr<_Tp>
3997227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3998227825Stheraven
3999227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4000227825Stheraven
4001227825Stheravenprivate:
4002227825Stheraven
4003227825Stheraven    template <class _Yp>
4004227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4005227825Stheraven        void
4006227825Stheraven        __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
4007227825Stheraven        {
4008227825Stheraven            if (__e)
4009227825Stheraven                __e->__weak_this_ = *this;
4010227825Stheraven        }
4011227825Stheraven
4012227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4013227825Stheraven    void __enable_weak_this(const void*) _NOEXCEPT {}
4014227825Stheraven
4015227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
4016227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
4017227825Stheraven};
4018227825Stheraven
4019227825Stheraventemplate<class _Tp>
4020227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4021227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4022227825Stheraven    : __ptr_(0),
4023227825Stheraven      __cntrl_(0)
4024227825Stheraven{
4025227825Stheraven}
4026227825Stheraven
4027227825Stheraventemplate<class _Tp>
4028227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4029227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4030227825Stheraven    : __ptr_(0),
4031227825Stheraven      __cntrl_(0)
4032227825Stheraven{
4033227825Stheraven}
4034227825Stheraven
4035227825Stheraventemplate<class _Tp>
4036232950Stheraventemplate<class _Yp, class>
4037227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p)
4038227825Stheraven    : __ptr_(__p)
4039227825Stheraven{
4040227825Stheraven    unique_ptr<_Yp> __hold(__p);
4041227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4042227825Stheraven    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4043227825Stheraven    __hold.release();
4044227825Stheraven    __enable_weak_this(__p);
4045227825Stheraven}
4046227825Stheraven
4047227825Stheraventemplate<class _Tp>
4048232950Stheraventemplate<class _Yp, class _Dp, class>
4049227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4050227825Stheraven    : __ptr_(__p)
4051227825Stheraven{
4052227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4053227825Stheraven    try
4054227825Stheraven    {
4055227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4056227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4057227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4058227825Stheraven        __enable_weak_this(__p);
4059227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4060227825Stheraven    }
4061227825Stheraven    catch (...)
4062227825Stheraven    {
4063227825Stheraven        __d(__p);
4064227825Stheraven        throw;
4065227825Stheraven    }
4066227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4067227825Stheraven}
4068227825Stheraven
4069227825Stheraventemplate<class _Tp>
4070227825Stheraventemplate<class _Dp>
4071227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4072227825Stheraven    : __ptr_(0)
4073227825Stheraven{
4074227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4075227825Stheraven    try
4076227825Stheraven    {
4077227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4078227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4079227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4080227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4081227825Stheraven    }
4082227825Stheraven    catch (...)
4083227825Stheraven    {
4084227825Stheraven        __d(__p);
4085227825Stheraven        throw;
4086227825Stheraven    }
4087227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4088227825Stheraven}
4089227825Stheraven
4090227825Stheraventemplate<class _Tp>
4091232950Stheraventemplate<class _Yp, class _Dp, class _Alloc, class>
4092227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4093227825Stheraven    : __ptr_(__p)
4094227825Stheraven{
4095227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4096227825Stheraven    try
4097227825Stheraven    {
4098227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4099227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4100227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4101227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4102227825Stheraven        _A2 __a2(__a);
4103227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4104227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4105227825Stheraven        __cntrl_ = __hold2.release();
4106227825Stheraven        __enable_weak_this(__p);
4107227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4108227825Stheraven    }
4109227825Stheraven    catch (...)
4110227825Stheraven    {
4111227825Stheraven        __d(__p);
4112227825Stheraven        throw;
4113227825Stheraven    }
4114227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4115227825Stheraven}
4116227825Stheraven
4117227825Stheraventemplate<class _Tp>
4118227825Stheraventemplate<class _Dp, class _Alloc>
4119227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4120227825Stheraven    : __ptr_(0)
4121227825Stheraven{
4122227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4123227825Stheraven    try
4124227825Stheraven    {
4125227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4126227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4127227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4128227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4129227825Stheraven        _A2 __a2(__a);
4130227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4131227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4132227825Stheraven        __cntrl_ = __hold2.release();
4133227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4134227825Stheraven    }
4135227825Stheraven    catch (...)
4136227825Stheraven    {
4137227825Stheraven        __d(__p);
4138227825Stheraven        throw;
4139227825Stheraven    }
4140227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4141227825Stheraven}
4142227825Stheraven
4143227825Stheraventemplate<class _Tp>
4144227825Stheraventemplate<class _Yp>
4145227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4146227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4147227825Stheraven    : __ptr_(__p),
4148227825Stheraven      __cntrl_(__r.__cntrl_)
4149227825Stheraven{
4150227825Stheraven    if (__cntrl_)
4151227825Stheraven        __cntrl_->__add_shared();
4152227825Stheraven}
4153227825Stheraven
4154227825Stheraventemplate<class _Tp>
4155227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4156227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4157227825Stheraven    : __ptr_(__r.__ptr_),
4158227825Stheraven      __cntrl_(__r.__cntrl_)
4159227825Stheraven{
4160227825Stheraven    if (__cntrl_)
4161227825Stheraven        __cntrl_->__add_shared();
4162227825Stheraven}
4163227825Stheraven
4164227825Stheraventemplate<class _Tp>
4165227825Stheraventemplate<class _Yp>
4166227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4167227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4168227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4169227825Stheraven         _NOEXCEPT
4170227825Stheraven    : __ptr_(__r.__ptr_),
4171227825Stheraven      __cntrl_(__r.__cntrl_)
4172227825Stheraven{
4173227825Stheraven    if (__cntrl_)
4174227825Stheraven        __cntrl_->__add_shared();
4175227825Stheraven}
4176227825Stheraven
4177227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4178227825Stheraven
4179227825Stheraventemplate<class _Tp>
4180227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4181227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4182227825Stheraven    : __ptr_(__r.__ptr_),
4183227825Stheraven      __cntrl_(__r.__cntrl_)
4184227825Stheraven{
4185227825Stheraven    __r.__ptr_ = 0;
4186227825Stheraven    __r.__cntrl_ = 0;
4187227825Stheraven}
4188227825Stheraven
4189227825Stheraventemplate<class _Tp>
4190227825Stheraventemplate<class _Yp>
4191227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4192227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4193227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4194227825Stheraven         _NOEXCEPT
4195227825Stheraven    : __ptr_(__r.__ptr_),
4196227825Stheraven      __cntrl_(__r.__cntrl_)
4197227825Stheraven{
4198227825Stheraven    __r.__ptr_ = 0;
4199227825Stheraven    __r.__cntrl_ = 0;
4200227825Stheraven}
4201227825Stheraven
4202227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4203227825Stheraven
4204227825Stheraventemplate<class _Tp>
4205232950Stheraventemplate<class _Yp, class>
4206227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4207227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4208227825Stheraven#else
4209227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4210227825Stheraven#endif
4211227825Stheraven    : __ptr_(__r.get())
4212227825Stheraven{
4213227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4214227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4215227825Stheraven    __enable_weak_this(__r.get());
4216227825Stheraven    __r.release();
4217227825Stheraven}
4218227825Stheraven
4219227825Stheraventemplate<class _Tp>
4220232950Stheraventemplate <class _Yp, class _Dp, class>
4221227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4222227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4223227825Stheraven#else
4224227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4225227825Stheraven#endif
4226227825Stheraven           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4227227825Stheraven    : __ptr_(__r.get())
4228227825Stheraven{
4229227825Stheraven    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4230227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), 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*,
4246227825Stheraven                                 reference_wrapper<typename remove_reference<_Dp>::type>,
4247227825Stheraven                                 allocator<_Yp> > _CntrlBlk;
4248227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4249227825Stheraven    __enable_weak_this(__r.get());
4250227825Stheraven    __r.release();
4251227825Stheraven}
4252227825Stheraven
4253227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4254227825Stheraven
4255227825Stheraventemplate<class _Tp>
4256227825Stheraventemplate<class ..._Args>
4257227825Stheravenshared_ptr<_Tp>
4258227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args)
4259227825Stheraven{
4260227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4261227825Stheraven    typedef allocator<_CntrlBlk> _A2;
4262227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4263227825Stheraven    _A2 __a2;
4264227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4265227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4266227825Stheraven    shared_ptr<_Tp> __r;
4267227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4268227825Stheraven    __r.__cntrl_ = __hold2.release();
4269227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4270227825Stheraven    return __r;
4271227825Stheraven}
4272227825Stheraven
4273227825Stheraventemplate<class _Tp>
4274227825Stheraventemplate<class _Alloc, class ..._Args>
4275227825Stheravenshared_ptr<_Tp>
4276227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4277227825Stheraven{
4278227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4279227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4280227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4281227825Stheraven    _A2 __a2(__a);
4282227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4283227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4284227825Stheraven    shared_ptr<_Tp> __r;
4285227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4286227825Stheraven    __r.__cntrl_ = __hold2.release();
4287227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4288227825Stheraven    return __r;
4289227825Stheraven}
4290227825Stheraven
4291227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4292227825Stheraven
4293227825Stheraventemplate<class _Tp>
4294227825Stheravenshared_ptr<_Tp>
4295227825Stheravenshared_ptr<_Tp>::make_shared()
4296227825Stheraven{
4297227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4298227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4299227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4300227825Stheraven    _Alloc2 __alloc2;
4301227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4302227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2);
4303227825Stheraven    shared_ptr<_Tp> __r;
4304227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4305227825Stheraven    __r.__cntrl_ = __hold2.release();
4306227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4307227825Stheraven    return __r;
4308227825Stheraven}
4309227825Stheraven
4310227825Stheraventemplate<class _Tp>
4311227825Stheraventemplate<class _A0>
4312227825Stheravenshared_ptr<_Tp>
4313227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0)
4314227825Stheraven{
4315227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4316227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4317227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4318227825Stheraven    _Alloc2 __alloc2;
4319227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4320227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4321227825Stheraven    shared_ptr<_Tp> __r;
4322227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4323227825Stheraven    __r.__cntrl_ = __hold2.release();
4324227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4325227825Stheraven    return __r;
4326227825Stheraven}
4327227825Stheraven
4328227825Stheraventemplate<class _Tp>
4329227825Stheraventemplate<class _A0, class _A1>
4330227825Stheravenshared_ptr<_Tp>
4331227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4332227825Stheraven{
4333227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4334227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4335227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4336227825Stheraven    _Alloc2 __alloc2;
4337227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4338227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4339227825Stheraven    shared_ptr<_Tp> __r;
4340227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4341227825Stheraven    __r.__cntrl_ = __hold2.release();
4342227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4343227825Stheraven    return __r;
4344227825Stheraven}
4345227825Stheraven
4346227825Stheraventemplate<class _Tp>
4347227825Stheraventemplate<class _A0, class _A1, class _A2>
4348227825Stheravenshared_ptr<_Tp>
4349227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4350227825Stheraven{
4351227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4352227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4353227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4354227825Stheraven    _Alloc2 __alloc2;
4355227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4356227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4357227825Stheraven    shared_ptr<_Tp> __r;
4358227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4359227825Stheraven    __r.__cntrl_ = __hold2.release();
4360227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4361227825Stheraven    return __r;
4362227825Stheraven}
4363227825Stheraven
4364227825Stheraventemplate<class _Tp>
4365227825Stheraventemplate<class _Alloc>
4366227825Stheravenshared_ptr<_Tp>
4367227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4368227825Stheraven{
4369227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4370227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4371227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4372227825Stheraven    _Alloc2 __alloc2(__a);
4373227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4374227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a);
4375227825Stheraven    shared_ptr<_Tp> __r;
4376227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4377227825Stheraven    __r.__cntrl_ = __hold2.release();
4378227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4379227825Stheraven    return __r;
4380227825Stheraven}
4381227825Stheraven
4382227825Stheraventemplate<class _Tp>
4383227825Stheraventemplate<class _Alloc, class _A0>
4384227825Stheravenshared_ptr<_Tp>
4385227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4386227825Stheraven{
4387227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4388227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4389227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4390227825Stheraven    _Alloc2 __alloc2(__a);
4391227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4392227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4393227825Stheraven    shared_ptr<_Tp> __r;
4394227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4395227825Stheraven    __r.__cntrl_ = __hold2.release();
4396227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4397227825Stheraven    return __r;
4398227825Stheraven}
4399227825Stheraven
4400227825Stheraventemplate<class _Tp>
4401227825Stheraventemplate<class _Alloc, class _A0, class _A1>
4402227825Stheravenshared_ptr<_Tp>
4403227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4404227825Stheraven{
4405227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4406227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4407227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4408227825Stheraven    _Alloc2 __alloc2(__a);
4409227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4410227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4411227825Stheraven    shared_ptr<_Tp> __r;
4412227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4413227825Stheraven    __r.__cntrl_ = __hold2.release();
4414227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4415227825Stheraven    return __r;
4416227825Stheraven}
4417227825Stheraven
4418227825Stheraventemplate<class _Tp>
4419227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2>
4420227825Stheravenshared_ptr<_Tp>
4421227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4422227825Stheraven{
4423227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4424227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4425227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4426227825Stheraven    _Alloc2 __alloc2(__a);
4427227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4428227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4429227825Stheraven    shared_ptr<_Tp> __r;
4430227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4431227825Stheraven    __r.__cntrl_ = __hold2.release();
4432227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4433227825Stheraven    return __r;
4434227825Stheraven}
4435227825Stheraven
4436227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4437227825Stheraven
4438227825Stheraventemplate<class _Tp>
4439227825Stheravenshared_ptr<_Tp>::~shared_ptr()
4440227825Stheraven{
4441227825Stheraven    if (__cntrl_)
4442227825Stheraven        __cntrl_->__release_shared();
4443227825Stheraven}
4444227825Stheraven
4445227825Stheraventemplate<class _Tp>
4446227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4447227825Stheravenshared_ptr<_Tp>&
4448227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4449227825Stheraven{
4450227825Stheraven    shared_ptr(__r).swap(*this);
4451227825Stheraven    return *this;
4452227825Stheraven}
4453227825Stheraven
4454227825Stheraventemplate<class _Tp>
4455227825Stheraventemplate<class _Yp>
4456227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4457232950Stheraventypename enable_if
4458232950Stheraven<
4459232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4460232950Stheraven    shared_ptr<_Tp>&
4461232950Stheraven>::type
4462227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4463227825Stheraven{
4464227825Stheraven    shared_ptr(__r).swap(*this);
4465227825Stheraven    return *this;
4466227825Stheraven}
4467227825Stheraven
4468227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4469227825Stheraven
4470227825Stheraventemplate<class _Tp>
4471227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4472227825Stheravenshared_ptr<_Tp>&
4473227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4474227825Stheraven{
4475227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4476227825Stheraven    return *this;
4477227825Stheraven}
4478227825Stheraven
4479227825Stheraventemplate<class _Tp>
4480227825Stheraventemplate<class _Yp>
4481227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4482232950Stheraventypename enable_if
4483232950Stheraven<
4484232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4485232950Stheraven    shared_ptr<_Tp>&
4486232950Stheraven>::type
4487227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4488227825Stheraven{
4489227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4490227825Stheraven    return *this;
4491227825Stheraven}
4492227825Stheraven
4493227825Stheraventemplate<class _Tp>
4494227825Stheraventemplate<class _Yp>
4495227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4496232950Stheraventypename enable_if
4497232950Stheraven<
4498232950Stheraven    !is_array<_Yp>::value &&
4499232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4500232950Stheraven    shared_ptr<_Tp>&
4501232950Stheraven>::type
4502227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4503227825Stheraven{
4504227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4505227825Stheraven    return *this;
4506227825Stheraven}
4507227825Stheraven
4508227825Stheraventemplate<class _Tp>
4509227825Stheraventemplate <class _Yp, class _Dp>
4510227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4511232950Stheraventypename enable_if
4512232950Stheraven<
4513232950Stheraven    !is_array<_Yp>::value &&
4514232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4515232950Stheraven    shared_ptr<_Tp>&
4516232950Stheraven>::type
4517227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4518227825Stheraven{
4519227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4520227825Stheraven    return *this;
4521227825Stheraven}
4522227825Stheraven
4523227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4524227825Stheraven
4525227825Stheraventemplate<class _Tp>
4526227825Stheraventemplate<class _Yp>
4527227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4528232950Stheraventypename enable_if
4529232950Stheraven<
4530232950Stheraven    !is_array<_Yp>::value &&
4531232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4532232950Stheraven    shared_ptr<_Tp>&
4533232950Stheraven>::type
4534227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4535227825Stheraven{
4536227825Stheraven    shared_ptr(__r).swap(*this);
4537227825Stheraven    return *this;
4538227825Stheraven}
4539227825Stheraven
4540227825Stheraventemplate<class _Tp>
4541227825Stheraventemplate <class _Yp, class _Dp>
4542227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4543232950Stheraventypename enable_if
4544232950Stheraven<
4545232950Stheraven    !is_array<_Yp>::value &&
4546232950Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4547232950Stheraven    shared_ptr<_Tp>&
4548232950Stheraven>::type
4549227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4550227825Stheraven{
4551227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4552227825Stheraven    return *this;
4553227825Stheraven}
4554227825Stheraven
4555227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4556227825Stheraven
4557227825Stheraventemplate<class _Tp>
4558227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4559227825Stheravenvoid
4560227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4561227825Stheraven{
4562227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
4563227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
4564227825Stheraven}
4565227825Stheraven
4566227825Stheraventemplate<class _Tp>
4567227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4568227825Stheravenvoid
4569227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT
4570227825Stheraven{
4571227825Stheraven    shared_ptr().swap(*this);
4572227825Stheraven}
4573227825Stheraven
4574227825Stheraventemplate<class _Tp>
4575227825Stheraventemplate<class _Yp>
4576227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4577232950Stheraventypename enable_if
4578232950Stheraven<
4579232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4580232950Stheraven    void
4581232950Stheraven>::type
4582227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p)
4583227825Stheraven{
4584227825Stheraven    shared_ptr(__p).swap(*this);
4585227825Stheraven}
4586227825Stheraven
4587227825Stheraventemplate<class _Tp>
4588227825Stheraventemplate<class _Yp, class _Dp>
4589227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4590232950Stheraventypename enable_if
4591232950Stheraven<
4592232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4593232950Stheraven    void
4594232950Stheraven>::type
4595227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4596227825Stheraven{
4597227825Stheraven    shared_ptr(__p, __d).swap(*this);
4598227825Stheraven}
4599227825Stheraven
4600227825Stheraventemplate<class _Tp>
4601227825Stheraventemplate<class _Yp, class _Dp, class _Alloc>
4602227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4603232950Stheraventypename enable_if
4604232950Stheraven<
4605232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
4606232950Stheraven    void
4607232950Stheraven>::type
4608227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4609227825Stheraven{
4610227825Stheraven    shared_ptr(__p, __d, __a).swap(*this);
4611227825Stheraven}
4612227825Stheraven
4613227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4614227825Stheraven
4615227825Stheraventemplate<class _Tp, class ..._Args>
4616227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4617232950Stheraventypename enable_if
4618232950Stheraven<
4619232950Stheraven    !is_array<_Tp>::value,
4620232950Stheraven    shared_ptr<_Tp>
4621232950Stheraven>::type
4622227825Stheravenmake_shared(_Args&& ...__args)
4623227825Stheraven{
4624227825Stheraven    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4625227825Stheraven}
4626227825Stheraven
4627227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args>
4628227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4629232950Stheraventypename enable_if
4630232950Stheraven<
4631232950Stheraven    !is_array<_Tp>::value,
4632232950Stheraven    shared_ptr<_Tp>
4633232950Stheraven>::type
4634227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args)
4635227825Stheraven{
4636227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4637227825Stheraven}
4638227825Stheraven
4639227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4640227825Stheraven
4641227825Stheraventemplate<class _Tp>
4642227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4643227825Stheravenshared_ptr<_Tp>
4644227825Stheravenmake_shared()
4645227825Stheraven{
4646227825Stheraven    return shared_ptr<_Tp>::make_shared();
4647227825Stheraven}
4648227825Stheraven
4649227825Stheraventemplate<class _Tp, class _A0>
4650227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4651227825Stheravenshared_ptr<_Tp>
4652227825Stheravenmake_shared(_A0& __a0)
4653227825Stheraven{
4654227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0);
4655227825Stheraven}
4656227825Stheraven
4657227825Stheraventemplate<class _Tp, class _A0, class _A1>
4658227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4659227825Stheravenshared_ptr<_Tp>
4660227825Stheravenmake_shared(_A0& __a0, _A1& __a1)
4661227825Stheraven{
4662227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4663227825Stheraven}
4664227825Stheraven
4665227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2>
4666227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4667227825Stheravenshared_ptr<_Tp>
4668227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4669227825Stheraven{
4670227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4671227825Stheraven}
4672227825Stheraven
4673227825Stheraventemplate<class _Tp, class _Alloc>
4674227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4675227825Stheravenshared_ptr<_Tp>
4676227825Stheravenallocate_shared(const _Alloc& __a)
4677227825Stheraven{
4678227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a);
4679227825Stheraven}
4680227825Stheraven
4681227825Stheraventemplate<class _Tp, class _Alloc, class _A0>
4682227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4683227825Stheravenshared_ptr<_Tp>
4684227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0)
4685227825Stheraven{
4686227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4687227825Stheraven}
4688227825Stheraven
4689227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1>
4690227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4691227825Stheravenshared_ptr<_Tp>
4692227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4693227825Stheraven{
4694227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4695227825Stheraven}
4696227825Stheraven
4697227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4698227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4699227825Stheravenshared_ptr<_Tp>
4700227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4701227825Stheraven{
4702227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4703227825Stheraven}
4704227825Stheraven
4705227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4706227825Stheraven
4707227825Stheraventemplate<class _Tp, class _Up>
4708227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4709227825Stheravenbool
4710227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4711227825Stheraven{
4712227825Stheraven    return __x.get() == __y.get();
4713227825Stheraven}
4714227825Stheraven
4715227825Stheraventemplate<class _Tp, class _Up>
4716227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4717227825Stheravenbool
4718227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4719227825Stheraven{
4720227825Stheraven    return !(__x == __y);
4721227825Stheraven}
4722227825Stheraven
4723227825Stheraventemplate<class _Tp, class _Up>
4724227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4725227825Stheravenbool
4726227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4727227825Stheraven{
4728232950Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4729232950Stheraven    return less<_V>()(__x.get(), __y.get());
4730227825Stheraven}
4731227825Stheraven
4732232950Stheraventemplate<class _Tp, class _Up>
4733232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4734232950Stheravenbool
4735232950Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4736232950Stheraven{
4737232950Stheraven    return __y < __x;
4738232950Stheraven}
4739232950Stheraven
4740232950Stheraventemplate<class _Tp, class _Up>
4741232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4742232950Stheravenbool
4743232950Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4744232950Stheraven{
4745232950Stheraven    return !(__y < __x);
4746232950Stheraven}
4747232950Stheraven
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 !(__x < __y);
4754232950Stheraven}
4755232950Stheraven
4756227825Stheraventemplate<class _Tp>
4757227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4758232950Stheravenbool
4759232950Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4760232950Stheraven{
4761232950Stheraven    return !__x;
4762232950Stheraven}
4763232950Stheraven
4764232950Stheraventemplate<class _Tp>
4765232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4766232950Stheravenbool
4767232950Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4768232950Stheraven{
4769232950Stheraven    return !__x;
4770232950Stheraven}
4771232950Stheraven
4772232950Stheraventemplate<class _Tp>
4773232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4774232950Stheravenbool
4775232950Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4776232950Stheraven{
4777232950Stheraven    return static_cast<bool>(__x);
4778232950Stheraven}
4779232950Stheraven
4780232950Stheraventemplate<class _Tp>
4781232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4782232950Stheravenbool
4783232950Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4784232950Stheraven{
4785232950Stheraven    return static_cast<bool>(__x);
4786232950Stheraven}
4787232950Stheraven
4788232950Stheraventemplate<class _Tp>
4789232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4790232950Stheravenbool
4791232950Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4792232950Stheraven{
4793232950Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4794232950Stheraven}
4795232950Stheraven
4796232950Stheraventemplate<class _Tp>
4797232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4798232950Stheravenbool
4799232950Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4800232950Stheraven{
4801232950Stheraven    return less<_Tp*>()(nullptr, __x.get());
4802232950Stheraven}
4803232950Stheraven
4804232950Stheraventemplate<class _Tp>
4805232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4806232950Stheravenbool
4807232950Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4808232950Stheraven{
4809232950Stheraven    return nullptr < __x;
4810232950Stheraven}
4811232950Stheraven
4812232950Stheraventemplate<class _Tp>
4813232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4814232950Stheravenbool
4815232950Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4816232950Stheraven{
4817232950Stheraven    return __x < nullptr;
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 !(__x < nullptr);
4842232950Stheraven}
4843232950Stheraven
4844232950Stheraventemplate<class _Tp>
4845232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4846232950Stheravenbool
4847232950Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4848232950Stheraven{
4849232950Stheraven    return !(nullptr < __x);
4850232950Stheraven}
4851232950Stheraven
4852232950Stheraventemplate<class _Tp>
4853232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
4854227825Stheravenvoid
4855227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4856227825Stheraven{
4857227825Stheraven    __x.swap(__y);
4858227825Stheraven}
4859227825Stheraven
4860227825Stheraventemplate<class _Tp, class _Up>
4861227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4862232950Stheraventypename enable_if
4863232950Stheraven<
4864232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4865232950Stheraven    shared_ptr<_Tp>
4866232950Stheraven>::type
4867227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4868227825Stheraven{
4869227825Stheraven    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4870227825Stheraven}
4871227825Stheraven
4872227825Stheraventemplate<class _Tp, class _Up>
4873227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4874232950Stheraventypename enable_if
4875232950Stheraven<
4876232950Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4877232950Stheraven    shared_ptr<_Tp>
4878232950Stheraven>::type
4879227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4880227825Stheraven{
4881227825Stheraven    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4882227825Stheraven    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4883227825Stheraven}
4884227825Stheraven
4885227825Stheraventemplate<class _Tp, class _Up>
4886232950Stheraventypename enable_if
4887232950Stheraven<
4888232950Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4889232950Stheraven    shared_ptr<_Tp>
4890232950Stheraven>::type
4891227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4892227825Stheraven{
4893232950Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4894232950Stheraven    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4895227825Stheraven}
4896227825Stheraven
4897227825Stheraven#ifndef _LIBCPP_NO_RTTI
4898227825Stheraven
4899227825Stheraventemplate<class _Dp, class _Tp>
4900227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4901227825Stheraven_Dp*
4902227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4903227825Stheraven{
4904227825Stheraven    return __p.template __get_deleter<_Dp>();
4905227825Stheraven}
4906227825Stheraven
4907227825Stheraven#endif  // _LIBCPP_NO_RTTI
4908227825Stheraven
4909227825Stheraventemplate<class _Tp>
4910227825Stheravenclass _LIBCPP_VISIBLE weak_ptr
4911227825Stheraven{
4912227825Stheravenpublic:
4913227825Stheraven    typedef _Tp element_type;
4914227825Stheravenprivate:
4915227825Stheraven    element_type*        __ptr_;
4916227825Stheraven    __shared_weak_count* __cntrl_;
4917227825Stheraven
4918227825Stheravenpublic:
4919227825Stheraven    weak_ptr() _NOEXCEPT;
4920227825Stheraven    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4921227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4922227825Stheraven                        _NOEXCEPT;
4923227825Stheraven    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4924227825Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4925227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4926227825Stheraven                         _NOEXCEPT;
4927227825Stheraven
4928232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4929232950Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4930232950Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4931232950Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4932232950Stheraven                         _NOEXCEPT;
4933232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4934227825Stheraven    ~weak_ptr();
4935227825Stheraven
4936227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4937232950Stheraven    template<class _Yp>
4938232950Stheraven        typename enable_if
4939232950Stheraven        <
4940232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4941232950Stheraven            weak_ptr&
4942232950Stheraven        >::type
4943232950Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4944227825Stheraven
4945232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4946232950Stheraven
4947232950Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4948232950Stheraven    template<class _Yp>
4949232950Stheraven        typename enable_if
4950232950Stheraven        <
4951232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4952232950Stheraven            weak_ptr&
4953232950Stheraven        >::type
4954232950Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4955232950Stheraven
4956232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4957232950Stheraven
4958232950Stheraven    template<class _Yp>
4959232950Stheraven        typename enable_if
4960232950Stheraven        <
4961232950Stheraven            is_convertible<_Yp*, element_type*>::value,
4962232950Stheraven            weak_ptr&
4963232950Stheraven        >::type
4964232950Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4965232950Stheraven
4966227825Stheraven    void swap(weak_ptr& __r) _NOEXCEPT;
4967227825Stheraven    void reset() _NOEXCEPT;
4968227825Stheraven
4969227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4970227825Stheraven    long use_count() const _NOEXCEPT
4971227825Stheraven        {return __cntrl_ ? __cntrl_->use_count() : 0;}
4972227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4973227825Stheraven    bool expired() const _NOEXCEPT
4974227825Stheraven        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4975227825Stheraven    shared_ptr<_Tp> lock() const _NOEXCEPT;
4976227825Stheraven    template<class _Up>
4977227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4978227825Stheraven        bool owner_before(const shared_ptr<_Up>& __r) const
4979227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
4980227825Stheraven    template<class _Up>
4981227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4982227825Stheraven        bool owner_before(const weak_ptr<_Up>& __r) const
4983227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
4984227825Stheraven
4985227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
4986227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
4987227825Stheraven};
4988227825Stheraven
4989227825Stheraventemplate<class _Tp>
4990227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4991227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4992227825Stheraven    : __ptr_(0),
4993227825Stheraven      __cntrl_(0)
4994227825Stheraven{
4995227825Stheraven}
4996227825Stheraven
4997227825Stheraventemplate<class _Tp>
4998227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4999227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5000227825Stheraven    : __ptr_(__r.__ptr_),
5001227825Stheraven      __cntrl_(__r.__cntrl_)
5002227825Stheraven{
5003227825Stheraven    if (__cntrl_)
5004227825Stheraven        __cntrl_->__add_weak();
5005227825Stheraven}
5006227825Stheraven
5007227825Stheraventemplate<class _Tp>
5008227825Stheraventemplate<class _Yp>
5009227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5010227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5011227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5012227825Stheraven                         _NOEXCEPT
5013227825Stheraven    : __ptr_(__r.__ptr_),
5014227825Stheraven      __cntrl_(__r.__cntrl_)
5015227825Stheraven{
5016227825Stheraven    if (__cntrl_)
5017227825Stheraven        __cntrl_->__add_weak();
5018227825Stheraven}
5019227825Stheraven
5020227825Stheraventemplate<class _Tp>
5021227825Stheraventemplate<class _Yp>
5022227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5023227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5024227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5025227825Stheraven         _NOEXCEPT
5026227825Stheraven    : __ptr_(__r.__ptr_),
5027227825Stheraven      __cntrl_(__r.__cntrl_)
5028227825Stheraven{
5029227825Stheraven    if (__cntrl_)
5030227825Stheraven        __cntrl_->__add_weak();
5031227825Stheraven}
5032227825Stheraven
5033232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5034232950Stheraven
5035227825Stheraventemplate<class _Tp>
5036232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5037232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5038232950Stheraven    : __ptr_(__r.__ptr_),
5039232950Stheraven      __cntrl_(__r.__cntrl_)
5040232950Stheraven{
5041232950Stheraven    __r.__ptr_ = 0;
5042232950Stheraven    __r.__cntrl_ = 0;
5043232950Stheraven}
5044232950Stheraven
5045232950Stheraventemplate<class _Tp>
5046232950Stheraventemplate<class _Yp>
5047232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5048232950Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5049232950Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5050232950Stheraven         _NOEXCEPT
5051232950Stheraven    : __ptr_(__r.__ptr_),
5052232950Stheraven      __cntrl_(__r.__cntrl_)
5053232950Stheraven{
5054232950Stheraven    __r.__ptr_ = 0;
5055232950Stheraven    __r.__cntrl_ = 0;
5056232950Stheraven}
5057232950Stheraven
5058232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5059232950Stheraven
5060232950Stheraventemplate<class _Tp>
5061227825Stheravenweak_ptr<_Tp>::~weak_ptr()
5062227825Stheraven{
5063227825Stheraven    if (__cntrl_)
5064227825Stheraven        __cntrl_->__release_weak();
5065227825Stheraven}
5066227825Stheraven
5067227825Stheraventemplate<class _Tp>
5068227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5069227825Stheravenweak_ptr<_Tp>&
5070227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5071227825Stheraven{
5072227825Stheraven    weak_ptr(__r).swap(*this);
5073227825Stheraven    return *this;
5074227825Stheraven}
5075227825Stheraven
5076227825Stheraventemplate<class _Tp>
5077227825Stheraventemplate<class _Yp>
5078227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5079232950Stheraventypename enable_if
5080232950Stheraven<
5081232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5082232950Stheraven    weak_ptr<_Tp>&
5083232950Stheraven>::type
5084227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5085227825Stheraven{
5086227825Stheraven    weak_ptr(__r).swap(*this);
5087227825Stheraven    return *this;
5088227825Stheraven}
5089227825Stheraven
5090232950Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5091232950Stheraven
5092227825Stheraventemplate<class _Tp>
5093232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5094232950Stheravenweak_ptr<_Tp>&
5095232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5096232950Stheraven{
5097232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5098232950Stheraven    return *this;
5099232950Stheraven}
5100232950Stheraven
5101232950Stheraventemplate<class _Tp>
5102227825Stheraventemplate<class _Yp>
5103227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5104232950Stheraventypename enable_if
5105232950Stheraven<
5106232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5107232950Stheraven    weak_ptr<_Tp>&
5108232950Stheraven>::type
5109232950Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5110232950Stheraven{
5111232950Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5112232950Stheraven    return *this;
5113232950Stheraven}
5114232950Stheraven
5115232950Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5116232950Stheraven
5117232950Stheraventemplate<class _Tp>
5118232950Stheraventemplate<class _Yp>
5119232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
5120232950Stheraventypename enable_if
5121232950Stheraven<
5122232950Stheraven    is_convertible<_Yp*, _Tp*>::value,
5123232950Stheraven    weak_ptr<_Tp>&
5124232950Stheraven>::type
5125227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5126227825Stheraven{
5127227825Stheraven    weak_ptr(__r).swap(*this);
5128227825Stheraven    return *this;
5129227825Stheraven}
5130227825Stheraven
5131227825Stheraventemplate<class _Tp>
5132227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5133227825Stheravenvoid
5134227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5135227825Stheraven{
5136227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
5137227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
5138227825Stheraven}
5139227825Stheraven
5140227825Stheraventemplate<class _Tp>
5141227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5142227825Stheravenvoid
5143227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5144227825Stheraven{
5145227825Stheraven    __x.swap(__y);
5146227825Stheraven}
5147227825Stheraven
5148227825Stheraventemplate<class _Tp>
5149227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5150227825Stheravenvoid
5151227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT
5152227825Stheraven{
5153227825Stheraven    weak_ptr().swap(*this);
5154227825Stheraven}
5155227825Stheraven
5156227825Stheraventemplate<class _Tp>
5157227825Stheraventemplate<class _Yp>
5158227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5159227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5160227825Stheraven    : __ptr_(__r.__ptr_),
5161227825Stheraven      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5162227825Stheraven{
5163227825Stheraven    if (__cntrl_ == 0)
5164227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
5165227825Stheraven        throw bad_weak_ptr();
5166227825Stheraven#else
5167227825Stheraven        assert(!"bad_weak_ptr");
5168227825Stheraven#endif
5169227825Stheraven}
5170227825Stheraven
5171227825Stheraventemplate<class _Tp>
5172227825Stheravenshared_ptr<_Tp>
5173227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT
5174227825Stheraven{
5175227825Stheraven    shared_ptr<_Tp> __r;
5176227825Stheraven    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5177227825Stheraven    if (__r.__cntrl_)
5178227825Stheraven        __r.__ptr_ = __ptr_;
5179227825Stheraven    return __r;
5180227825Stheraven}
5181227825Stheraven
5182227825Stheraventemplate <class _Tp> struct owner_less;
5183227825Stheraven
5184227825Stheraventemplate <class _Tp>
5185227825Stheravenstruct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> >
5186227825Stheraven    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5187227825Stheraven{
5188227825Stheraven    typedef bool result_type;
5189227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5190227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5191227825Stheraven        {return __x.owner_before(__y);}
5192227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5193227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5194227825Stheraven        {return __x.owner_before(__y);}
5195227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5196227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5197227825Stheraven        {return __x.owner_before(__y);}
5198227825Stheraven};
5199227825Stheraven
5200227825Stheraventemplate <class _Tp>
5201227825Stheravenstruct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> >
5202227825Stheraven    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5203227825Stheraven{
5204227825Stheraven    typedef bool result_type;
5205227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5206227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5207227825Stheraven        {return __x.owner_before(__y);}
5208227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5209227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5210227825Stheraven        {return __x.owner_before(__y);}
5211227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5212227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5213227825Stheraven        {return __x.owner_before(__y);}
5214227825Stheraven};
5215227825Stheraven
5216227825Stheraventemplate<class _Tp>
5217227825Stheravenclass _LIBCPP_VISIBLE enable_shared_from_this
5218227825Stheraven{
5219227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5220227825Stheravenprotected:
5221227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5222227825Stheraven    enable_shared_from_this() _NOEXCEPT {}
5223227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5224227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5225227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5226227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5227227825Stheraven        {return *this;}
5228227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5229227825Stheraven    ~enable_shared_from_this() {}
5230227825Stheravenpublic:
5231227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5232227825Stheraven    shared_ptr<_Tp> shared_from_this()
5233227825Stheraven        {return shared_ptr<_Tp>(__weak_this_);}
5234227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5235227825Stheraven    shared_ptr<_Tp const> shared_from_this() const
5236227825Stheraven        {return shared_ptr<const _Tp>(__weak_this_);}
5237227825Stheraven
5238227825Stheraven    template <class _Up> friend class shared_ptr;
5239227825Stheraven};
5240227825Stheraven
5241227825Stheraventemplate <class _Tp>
5242227825Stheravenstruct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
5243227825Stheraven{
5244227825Stheraven    typedef shared_ptr<_Tp>      argument_type;
5245227825Stheraven    typedef size_t               result_type;
5246227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5247227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5248227825Stheraven    {
5249227825Stheraven        return hash<_Tp*>()(__ptr.get());
5250227825Stheraven    }
5251227825Stheraven};
5252227825Stheraven
5253232950Stheraventemplate<class _CharT, class _Traits, class _Yp>
5254227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5255227825Stheravenbasic_ostream<_CharT, _Traits>&
5256232950Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5257227825Stheraven
5258227825Stheraven//enum class
5259227825Stheravenstruct _LIBCPP_VISIBLE pointer_safety
5260227825Stheraven{
5261227825Stheraven    enum _
5262227825Stheraven    {
5263227825Stheraven        relaxed,
5264227825Stheraven        preferred,
5265227825Stheraven        strict
5266227825Stheraven    };
5267227825Stheraven
5268227825Stheraven    _ __v_;
5269227825Stheraven
5270227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5271227825Stheraven    pointer_safety(_ __v) : __v_(__v) {}
5272227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5273227825Stheraven    operator int() const {return __v_;}
5274227825Stheraven};
5275227825Stheraven
5276227825Stheravenvoid declare_reachable(void* __p);
5277227825Stheravenvoid declare_no_pointers(char* __p, size_t __n);
5278227825Stheravenvoid undeclare_no_pointers(char* __p, size_t __n);
5279227825Stheravenpointer_safety get_pointer_safety() _NOEXCEPT;
5280227825Stheravenvoid* __undeclare_reachable(void* __p);
5281227825Stheraven
5282227825Stheraventemplate <class _Tp>
5283227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5284227825Stheraven_Tp*
5285227825Stheravenundeclare_reachable(_Tp* __p)
5286227825Stheraven{
5287227825Stheraven    return static_cast<_Tp*>(__undeclare_reachable(__p));
5288227825Stheraven}
5289227825Stheraven
5290227825Stheravenvoid* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5291227825Stheraven
5292227825Stheraven_LIBCPP_END_NAMESPACE_STD
5293227825Stheraven
5294227825Stheraven#endif  // _LIBCPP_MEMORY
5295