memory revision 234959
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>
599232924Stheraven#include <tuple>
600232924Stheraven#include <cstring>
601227825Stheraven#if defined(_LIBCPP_NO_EXCEPTIONS)
602227825Stheraven    #include <cassert>
603227825Stheraven#endif
604227825Stheraven
605232924Stheraven#include <__undef_min_max>
606232924Stheraven
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
676232924Stheraventemplate <>
677232924Stheravenclass _LIBCPP_VISIBLE allocator<const void>
678232924Stheraven{
679232924Stheravenpublic:
680232924Stheraven    typedef const void*       pointer;
681232924Stheraven    typedef const void*       const_pointer;
682232924Stheraven    typedef const void        value_type;
683232924Stheraven
684232924Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
685232924Stheraven};
686232924Stheraven
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
1074232924Stheraventemplate <class _Tp>
1075227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1076232924Stheraven_Tp*
1077232924Stheraven__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
1399232924Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1400232924Stheraven
1401232924Stheraventemplate <class _Alloc, class _Pointer, class _Args>
1402232924Stheravenstruct __has_construct
1403232924Stheraven    : false_type
1404232924Stheraven{
1405232924Stheraven};
1406232924Stheraven
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
1536232924Stheraven    template <class _Ptr>
1537232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1538232924Stheraven        static
1539232924Stheraven        void
1540232924Stheraven        __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1541232924Stheraven        {
1542232924Stheraven            for (; __begin1 != __end1; ++__begin1, ++__begin2)
1543232924Stheraven                construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1544232924Stheraven        }
1545232924Stheraven
1546232924Stheraven    template <class _Tp>
1547232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1548232924Stheraven        static
1549232924Stheraven        typename enable_if
1550232924Stheraven        <
1551232924Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1552232924Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1553232924Stheraven             is_trivially_move_constructible<_Tp>::value,
1554232924Stheraven            void
1555232924Stheraven        >::type
1556232924Stheraven        __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1557232924Stheraven        {
1558232924Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1559232924Stheraven            _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1560232924Stheraven            __begin2 += _Np;
1561232924Stheraven        }
1562232924Stheraven
1563232924Stheraven    template <class _Ptr>
1564232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1565232924Stheraven        static
1566232924Stheraven        void
1567232924Stheraven        __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1568232924Stheraven        {
1569232924Stheraven            while (__end1 != __begin1)
1570232924Stheraven                construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
1571232924Stheraven        }
1572232924Stheraven
1573232924Stheraven    template <class _Tp>
1574232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1575232924Stheraven        static
1576232924Stheraven        typename enable_if
1577232924Stheraven        <
1578232924Stheraven            (is_same<allocator_type, allocator<_Tp> >::value
1579232924Stheraven                || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1580232924Stheraven             is_trivially_move_constructible<_Tp>::value,
1581232924Stheraven            void
1582232924Stheraven        >::type
1583232924Stheraven        __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1584232924Stheraven        {
1585232924Stheraven            ptrdiff_t _Np = __end1 - __begin1;
1586232924Stheraven            __end2 -= _Np;
1587232924Stheraven            _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1588232924Stheraven        }
1589232924Stheraven
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,
1598232924Stheraven        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
1642232924Stheraven// allocator
1643227825Stheraven
1644227825Stheraventemplate <class _Tp>
1645232924Stheravenclass _LIBCPP_VISIBLE allocator
1646227825Stheraven{
1647227825Stheravenpublic:
1648232924Stheraven    typedef size_t            size_type;
1649232924Stheraven    typedef ptrdiff_t         difference_type;
1650232924Stheraven    typedef _Tp*              pointer;
1651232924Stheraven    typedef const _Tp*        const_pointer;
1652232924Stheraven    typedef _Tp&              reference;
1653232924Stheraven    typedef const _Tp&        const_reference;
1654232924Stheraven    typedef _Tp               value_type;
1655227825Stheraven
1656232924Stheraven    typedef true_type propagate_on_container_move_assignment;
1657227825Stheraven
1658232924Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1659227825Stheraven
1660232924Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1661232924Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1662232924Stheraven    _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1663232924Stheraven        {return _VSTD::addressof(__x);}
1664232924Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1665232924Stheraven        {return _VSTD::addressof(__x);}
1666232924Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1667232924Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1668232924Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1669232924Stheraven        {::operator delete((void*)__p);}
1670232924Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1671232924Stheraven        {return size_type(~0) / sizeof(_Tp);}
1672232924Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1673232924Stheraven    template <class _Up, class... _Args>
1674232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1675232924Stheraven        void
1676232924Stheraven        construct(_Up* __p, _Args&&... __args)
1677232924Stheraven        {
1678232924Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1679232924Stheraven        }
1680232924Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1681232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1682232924Stheraven        void
1683232924Stheraven        construct(pointer __p)
1684232924Stheraven        {
1685232924Stheraven            ::new((void*)__p) _Tp();
1686232924Stheraven        }
1687232924Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1688234959Stheraven
1689232924Stheraven    template <class _A0>
1690232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1691234959Stheraven        void
1692232924Stheraven        construct(pointer __p, _A0& __a0)
1693232924Stheraven        {
1694232924Stheraven            ::new((void*)__p) _Tp(__a0);
1695232924Stheraven        }
1696232924Stheraven    template <class _A0>
1697232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1698234959Stheraven        void
1699232924Stheraven        construct(pointer __p, const _A0& __a0)
1700232924Stheraven        {
1701232924Stheraven            ::new((void*)__p) _Tp(__a0);
1702232924Stheraven        }
1703232924Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1704232924Stheraven    template <class _A0, class _A1>
1705232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1706232924Stheraven        void
1707232924Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1708232924Stheraven        {
1709232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1710232924Stheraven        }
1711232924Stheraven    template <class _A0, class _A1>
1712232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1713232924Stheraven        void
1714232924Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1715232924Stheraven        {
1716232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1717232924Stheraven        }
1718232924Stheraven    template <class _A0, class _A1>
1719232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1720232924Stheraven        void
1721232924Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1722232924Stheraven        {
1723232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1724232924Stheraven        }
1725232924Stheraven    template <class _A0, class _A1>
1726232924Stheraven        _LIBCPP_INLINE_VISIBILITY
1727232924Stheraven        void
1728232924Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1729232924Stheraven        {
1730232924Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1731232924Stheraven        }
1732232924Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1733232924Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1734227825Stheraven};
1735227825Stheraven
1736227825Stheraventemplate <class _Tp>
1737232924Stheravenclass _LIBCPP_VISIBLE allocator<const _Tp>
1738227825Stheraven{
1739227825Stheravenpublic:
1740227825Stheraven    typedef size_t            size_type;
1741227825Stheraven    typedef ptrdiff_t         difference_type;
1742232924Stheraven    typedef const _Tp*        pointer;
1743227825Stheraven    typedef const _Tp*        const_pointer;
1744232924Stheraven    typedef const _Tp&        reference;
1745227825Stheraven    typedef const _Tp&        const_reference;
1746227825Stheraven    typedef _Tp               value_type;
1747227825Stheraven
1748227825Stheraven    typedef true_type propagate_on_container_move_assignment;
1749227825Stheraven
1750227825Stheraven    template <class _Up> struct rebind {typedef allocator<_Up> other;};
1751227825Stheraven
1752227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1753227825Stheraven    template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1754227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1755227825Stheraven        {return _VSTD::addressof(__x);}
1756227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1757227825Stheraven        {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
1758227825Stheraven    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1759227825Stheraven        {::operator delete((void*)__p);}
1760227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1761227825Stheraven        {return size_type(~0) / sizeof(_Tp);}
1762227825Stheraven#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1763227825Stheraven    template <class _Up, class... _Args>
1764227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1765227825Stheraven        void
1766227825Stheraven        construct(_Up* __p, _Args&&... __args)
1767227825Stheraven        {
1768227825Stheraven            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1769227825Stheraven        }
1770227825Stheraven#else  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1771227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1772227825Stheraven        void
1773227825Stheraven        construct(pointer __p)
1774227825Stheraven        {
1775227825Stheraven            ::new((void*)__p) _Tp();
1776227825Stheraven        }
1777227825Stheraven# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1778234959Stheraven
1779227825Stheraven    template <class _A0>
1780227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1781234959Stheraven        void
1782227825Stheraven        construct(pointer __p, _A0& __a0)
1783227825Stheraven        {
1784227825Stheraven            ::new((void*)__p) _Tp(__a0);
1785227825Stheraven        }
1786227825Stheraven    template <class _A0>
1787227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1788234959Stheraven        void
1789227825Stheraven        construct(pointer __p, const _A0& __a0)
1790227825Stheraven        {
1791227825Stheraven            ::new((void*)__p) _Tp(__a0);
1792227825Stheraven        }
1793227825Stheraven# endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1794227825Stheraven    template <class _A0, class _A1>
1795227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1796227825Stheraven        void
1797227825Stheraven        construct(pointer __p, _A0& __a0, _A1& __a1)
1798227825Stheraven        {
1799227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1800227825Stheraven        }
1801227825Stheraven    template <class _A0, class _A1>
1802227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1803227825Stheraven        void
1804227825Stheraven        construct(pointer __p, const _A0& __a0, _A1& __a1)
1805227825Stheraven        {
1806227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1807227825Stheraven        }
1808227825Stheraven    template <class _A0, class _A1>
1809227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1810227825Stheraven        void
1811227825Stheraven        construct(pointer __p, _A0& __a0, const _A1& __a1)
1812227825Stheraven        {
1813227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1814227825Stheraven        }
1815227825Stheraven    template <class _A0, class _A1>
1816227825Stheraven        _LIBCPP_INLINE_VISIBILITY
1817227825Stheraven        void
1818227825Stheraven        construct(pointer __p, const _A0& __a0, const _A1& __a1)
1819227825Stheraven        {
1820227825Stheraven            ::new((void*)__p) _Tp(__a0, __a1);
1821227825Stheraven        }
1822227825Stheraven#endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1823227825Stheraven    _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1824227825Stheraven};
1825227825Stheraven
1826227825Stheraventemplate <class _Tp, class _Up>
1827227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1828227825Stheravenbool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1829227825Stheraven
1830227825Stheraventemplate <class _Tp, class _Up>
1831227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1832227825Stheravenbool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1833227825Stheraven
1834227825Stheraventemplate <class _OutputIterator, class _Tp>
1835227825Stheravenclass _LIBCPP_VISIBLE raw_storage_iterator
1836227825Stheraven    : public iterator<output_iterator_tag,
1837227825Stheraven                      _Tp,                                         // purposefully not C++03
1838227825Stheraven                      ptrdiff_t,                                   // purposefully not C++03
1839227825Stheraven                      _Tp*,                                        // purposefully not C++03
1840227825Stheraven                      raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1841227825Stheraven{
1842227825Stheravenprivate:
1843227825Stheraven    _OutputIterator __x_;
1844227825Stheravenpublic:
1845227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1846227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1847227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1848227825Stheraven        {::new(&*__x_) _Tp(__element); return *this;}
1849227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1850227825Stheraven    _LIBCPP_INLINE_VISIBILITY raw_storage_iterator  operator++(int)
1851227825Stheraven        {raw_storage_iterator __t(*this); ++__x_; return __t;}
1852227825Stheraven};
1853227825Stheraven
1854227825Stheraventemplate <class _Tp>
1855227825Stheravenpair<_Tp*, ptrdiff_t>
1856227825Stheravenget_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1857227825Stheraven{
1858227825Stheraven    pair<_Tp*, ptrdiff_t> __r(0, 0);
1859227825Stheraven    const ptrdiff_t __m = (~ptrdiff_t(0) ^
1860227825Stheraven                           ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1861227825Stheraven                           / sizeof(_Tp);
1862227825Stheraven    if (__n > __m)
1863227825Stheraven        __n = __m;
1864227825Stheraven    while (__n > 0)
1865227825Stheraven    {
1866227825Stheraven        __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1867227825Stheraven        if (__r.first)
1868227825Stheraven        {
1869227825Stheraven            __r.second = __n;
1870227825Stheraven            break;
1871227825Stheraven        }
1872227825Stheraven        __n /= 2;
1873227825Stheraven    }
1874227825Stheraven    return __r;
1875227825Stheraven}
1876227825Stheraven
1877227825Stheraventemplate <class _Tp>
1878227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1879227825Stheravenvoid return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1880227825Stheraven
1881227825Stheraventemplate <class _Tp>
1882227825Stheravenstruct auto_ptr_ref
1883227825Stheraven{
1884227825Stheraven    _Tp* __ptr_;
1885227825Stheraven};
1886227825Stheraven
1887227825Stheraventemplate<class _Tp>
1888227825Stheravenclass _LIBCPP_VISIBLE auto_ptr
1889227825Stheraven{
1890227825Stheravenprivate:
1891227825Stheraven    _Tp* __ptr_;
1892227825Stheravenpublic:
1893227825Stheraven    typedef _Tp element_type;
1894227825Stheraven
1895227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1896227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1897227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1898227825Stheraven        : __ptr_(__p.release()) {}
1899227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1900227825Stheraven        {reset(__p.release()); return *this;}
1901227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1902227825Stheraven        {reset(__p.release()); return *this;}
1903227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1904227825Stheraven        {reset(__p.__ptr_); return *this;}
1905227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1906227825Stheraven
1907227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1908227825Stheraven        {return *__ptr_;}
1909227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1910227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1911227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1912227825Stheraven    {
1913227825Stheraven        _Tp* __t = __ptr_;
1914227825Stheraven        __ptr_ = 0;
1915227825Stheraven        return __t;
1916227825Stheraven    }
1917227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1918227825Stheraven    {
1919227825Stheraven        if (__ptr_ != __p)
1920227825Stheraven            delete __ptr_;
1921227825Stheraven        __ptr_ = __p;
1922227825Stheraven    }
1923227825Stheraven
1924227825Stheraven    _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1925227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1926227825Stheraven        {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1927227825Stheraven    template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1928227825Stheraven        {return auto_ptr<_Up>(release());}
1929227825Stheraven};
1930227825Stheraven
1931227825Stheraventemplate <>
1932227825Stheravenclass _LIBCPP_VISIBLE auto_ptr<void>
1933227825Stheraven{
1934227825Stheravenpublic:
1935227825Stheraven    typedef void element_type;
1936227825Stheraven};
1937227825Stheraven
1938227825Stheraventemplate <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1939227825Stheraven                                                     typename remove_cv<_T2>::type>::value,
1940232924Stheraven                                bool = is_empty<_T1>::value
1941232924Stheraven#if __has_feature(is_final)
1942232924Stheraven                                       && !__is_final(_T1)
1943232924Stheraven#endif
1944232924Stheraven                                ,
1945232924Stheraven                                bool = is_empty<_T2>::value
1946232924Stheraven#if __has_feature(is_final)
1947232924Stheraven                                       && !__is_final(_T2)
1948232924Stheraven#endif
1949232924Stheraven         >
1950227825Stheravenstruct __libcpp_compressed_pair_switch;
1951227825Stheraven
1952227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1953227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1954227825Stheraven
1955227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1956227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false>  {enum {value = 1};};
1957227825Stheraven
1958227825Stheraventemplate <class _T1, class _T2, bool IsSame>
1959227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true>  {enum {value = 2};};
1960227825Stheraven
1961227825Stheraventemplate <class _T1, class _T2>
1962227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true>    {enum {value = 3};};
1963227825Stheraven
1964227825Stheraventemplate <class _T1, class _T2>
1965227825Stheravenstruct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true>     {enum {value = 1};};
1966227825Stheraven
1967227825Stheraventemplate <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1968227825Stheravenclass __libcpp_compressed_pair_imp;
1969227825Stheraven
1970227825Stheraventemplate <class _T1, class _T2>
1971227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 0>
1972227825Stheraven{
1973227825Stheravenprivate:
1974227825Stheraven    _T1 __first_;
1975227825Stheraven    _T2 __second_;
1976227825Stheravenpublic:
1977227825Stheraven    typedef _T1 _T1_param;
1978227825Stheraven    typedef _T2 _T2_param;
1979227825Stheraven
1980227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
1981227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
1982227825Stheraven
1983227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1984227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1985227825Stheraven
1986227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
1987232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
1988227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
1989232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
1990227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
1991227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
1992227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
1993227825Stheraven
1994227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1995227825Stheraven
1996227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1997227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
1998227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
1999227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2000227825Stheraven        : __first_(__p.first()),
2001227825Stheraven          __second_(__p.second()) {}
2002227825Stheraven
2003227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2004227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2005227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2006227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2007227825Stheraven        {
2008227825Stheraven            __first_ = __p.first();
2009227825Stheraven            __second_ = __p.second();
2010227825Stheraven            return *this;
2011227825Stheraven        }
2012227825Stheraven
2013227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2014227825Stheraven
2015227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2016227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2017227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2018227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2019227825Stheraven        : __first_(_VSTD::forward<_T1>(__p.first())),
2020227825Stheraven          __second_(_VSTD::forward<_T2>(__p.second())) {}
2021227825Stheraven
2022227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2023227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2024227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2025227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2026227825Stheraven        {
2027227825Stheraven            __first_ = _VSTD::forward<_T1>(__p.first());
2028227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2029227825Stheraven            return *this;
2030227825Stheraven        }
2031227825Stheraven
2032232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2033232924Stheraven
2034232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2035232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2036232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2037232924Stheraven                                     tuple<_Args1...> __first_args,
2038232924Stheraven                                     tuple<_Args2...> __second_args,
2039232924Stheraven                                     __tuple_indices<_I1...>,
2040232924Stheraven                                     __tuple_indices<_I2...>)
2041232924Stheraven            : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2042232924Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2043232924Stheraven            {}
2044232924Stheraven
2045232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2046232924Stheraven
2047227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2048227825Stheraven
2049227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2050227825Stheraven
2051227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2052227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2053227825Stheraven
2054227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2055227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2056227825Stheraven
2057227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2058227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2059227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2060227825Stheraven    {
2061227825Stheraven        using _VSTD::swap;
2062227825Stheraven        swap(__first_, __x.__first_);
2063227825Stheraven        swap(__second_, __x.__second_);
2064227825Stheraven    }
2065227825Stheraven};
2066227825Stheraven
2067227825Stheraventemplate <class _T1, class _T2>
2068227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 1>
2069227825Stheraven    : private _T1
2070227825Stheraven{
2071227825Stheravenprivate:
2072227825Stheraven    _T2 __second_;
2073227825Stheravenpublic:
2074227825Stheraven    typedef _T1 _T1_param;
2075227825Stheraven    typedef _T2 _T2_param;
2076227825Stheraven
2077227825Stheraven    typedef _T1&                                        _T1_reference;
2078227825Stheraven    typedef typename remove_reference<_T2>::type& _T2_reference;
2079227825Stheraven
2080227825Stheraven    typedef const _T1&                                        _T1_const_reference;
2081227825Stheraven    typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2082227825Stheraven
2083227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2084232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2085227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2086232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2087227825Stheraven        : __second_(_VSTD::forward<_T2_param>(__t2)) {}
2088227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2089227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
2090227825Stheraven
2091227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2092227825Stheraven
2093227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2094227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2095227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2096227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2097227825Stheraven        : _T1(__p.first()), __second_(__p.second()) {}
2098227825Stheraven
2099227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2100227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2101227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2102227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2103227825Stheraven        {
2104227825Stheraven            _T1::operator=(__p.first());
2105227825Stheraven            __second_ = __p.second();
2106227825Stheraven            return *this;
2107227825Stheraven        }
2108227825Stheraven
2109227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2110227825Stheraven
2111227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2112227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2113227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2114227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2115227825Stheraven        : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
2116227825Stheraven
2117227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2118227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2119227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2120227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2121227825Stheraven        {
2122227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2123227825Stheraven            __second_ = _VSTD::forward<_T2>(__p.second());
2124227825Stheraven            return *this;
2125227825Stheraven        }
2126227825Stheraven
2127232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2128232924Stheraven
2129232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2130232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2131232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2132232924Stheraven                                     tuple<_Args1...> __first_args,
2133232924Stheraven                                     tuple<_Args2...> __second_args,
2134232924Stheraven                                     __tuple_indices<_I1...>,
2135232924Stheraven                                     __tuple_indices<_I2...>)
2136232924Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2137232924Stheraven              __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2138232924Stheraven            {}
2139232924Stheraven
2140232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2141232924Stheraven
2142227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2143227825Stheraven
2144227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2145227825Stheraven
2146227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2147227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2148227825Stheraven
2149227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return __second_;}
2150227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
2151227825Stheraven
2152227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2153227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2154227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2155227825Stheraven    {
2156227825Stheraven        using _VSTD::swap;
2157227825Stheraven        swap(__second_, __x.__second_);
2158227825Stheraven    }
2159227825Stheraven};
2160227825Stheraven
2161227825Stheraventemplate <class _T1, class _T2>
2162227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 2>
2163227825Stheraven    : private _T2
2164227825Stheraven{
2165227825Stheravenprivate:
2166227825Stheraven    _T1 __first_;
2167227825Stheravenpublic:
2168227825Stheraven    typedef _T1 _T1_param;
2169227825Stheraven    typedef _T2 _T2_param;
2170227825Stheraven
2171227825Stheraven    typedef typename remove_reference<_T1>::type& _T1_reference;
2172227825Stheraven    typedef _T2&                                        _T2_reference;
2173227825Stheraven
2174227825Stheraven    typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2175227825Stheraven    typedef const _T2&                                        _T2_const_reference;
2176227825Stheraven
2177227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2178227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2179227825Stheraven        : __first_(_VSTD::forward<_T1_param>(__t1)) {}
2180227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2181227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2182227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2183227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2184227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2185227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
2186227825Stheraven
2187227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2188227825Stheraven
2189227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2190227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2191227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2192227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2193227825Stheraven        : _T2(__p.second()), __first_(__p.first()) {}
2194227825Stheraven
2195227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2196227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2197227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2198227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2199227825Stheraven        {
2200227825Stheraven            _T2::operator=(__p.second());
2201227825Stheraven            __first_ = __p.first();
2202227825Stheraven            return *this;
2203227825Stheraven        }
2204227825Stheraven
2205227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2206227825Stheraven
2207227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2208227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2209227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2210227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2211227825Stheraven        : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
2212227825Stheraven
2213227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2214227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2215227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2216227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2217227825Stheraven        {
2218227825Stheraven            _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2219227825Stheraven            __first_ = _VSTD::move(__p.first());
2220227825Stheraven            return *this;
2221227825Stheraven        }
2222227825Stheraven
2223232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2224232924Stheraven
2225232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2226232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2227232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2228232924Stheraven                                     tuple<_Args1...> __first_args,
2229232924Stheraven                                     tuple<_Args2...> __second_args,
2230232924Stheraven                                     __tuple_indices<_I1...>,
2231232924Stheraven                                     __tuple_indices<_I2...>)
2232232924Stheraven            : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
2233232924Stheraven              __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
2234232924Stheraven              
2235232924Stheraven            {}
2236232924Stheraven
2237232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2238232924Stheraven
2239227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2240227825Stheraven
2241227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2242227825Stheraven
2243227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return __first_;}
2244227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
2245227825Stheraven
2246227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2247227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2248227825Stheraven
2249227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
2250227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2251227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2252227825Stheraven    {
2253227825Stheraven        using _VSTD::swap;
2254227825Stheraven        swap(__first_, __x.__first_);
2255227825Stheraven    }
2256227825Stheraven};
2257227825Stheraven
2258227825Stheraventemplate <class _T1, class _T2>
2259227825Stheravenclass __libcpp_compressed_pair_imp<_T1, _T2, 3>
2260227825Stheraven    : private _T1,
2261227825Stheraven      private _T2
2262227825Stheraven{
2263227825Stheravenpublic:
2264227825Stheraven    typedef _T1 _T1_param;
2265227825Stheraven    typedef _T2 _T2_param;
2266227825Stheraven
2267227825Stheraven    typedef _T1& _T1_reference;
2268227825Stheraven    typedef _T2& _T2_reference;
2269227825Stheraven
2270227825Stheraven    typedef const _T1& _T1_const_reference;
2271227825Stheraven    typedef const _T2& _T2_const_reference;
2272227825Stheraven
2273227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2274227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
2275227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)) {}
2276227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
2277227825Stheraven        : _T2(_VSTD::forward<_T2_param>(__t2)) {}
2278227825Stheraven    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
2279227825Stheraven        : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
2280227825Stheraven
2281227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2282227825Stheraven
2283227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2284227825Stheraven    __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2285227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2286227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2287227825Stheraven        : _T1(__p.first()), _T2(__p.second()) {}
2288227825Stheraven
2289227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2290227825Stheraven    __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2291227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2292227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2293227825Stheraven        {
2294227825Stheraven            _T1::operator=(__p.first());
2295227825Stheraven            _T2::operator=(__p.second());
2296227825Stheraven            return *this;
2297227825Stheraven        }
2298227825Stheraven
2299227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2300227825Stheraven
2301227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2302227825Stheraven    __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
2303227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2304227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2305227825Stheraven        : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
2306227825Stheraven
2307227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2308227825Stheraven    __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2309227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2310227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2311227825Stheraven        {
2312227825Stheraven            _T1::operator=(_VSTD::move(__p.first()));
2313227825Stheraven            _T2::operator=(_VSTD::move(__p.second()));
2314227825Stheraven            return *this;
2315227825Stheraven        }
2316227825Stheraven
2317232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2318232924Stheraven
2319232924Stheraven    template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2320232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2321232924Stheraven        __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2322232924Stheraven                                     tuple<_Args1...> __first_args,
2323232924Stheraven                                     tuple<_Args2...> __second_args,
2324232924Stheraven                                     __tuple_indices<_I1...>,
2325232924Stheraven                                     __tuple_indices<_I2...>)
2326232924Stheraven            : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
2327232924Stheraven              _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
2328232924Stheraven            {}
2329232924Stheraven
2330232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2331232924Stheraven
2332227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2333227825Stheraven
2334227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2335227825Stheraven
2336227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return *this;}
2337227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
2338227825Stheraven
2339227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return *this;}
2340227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
2341227825Stheraven
2342232924Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
2343227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2344227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2345227825Stheraven    {
2346227825Stheraven    }
2347227825Stheraven};
2348227825Stheraven
2349227825Stheraventemplate <class _T1, class _T2>
2350227825Stheravenclass __compressed_pair
2351227825Stheraven    : private __libcpp_compressed_pair_imp<_T1, _T2>
2352227825Stheraven{
2353227825Stheraven    typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2354227825Stheravenpublic:
2355227825Stheraven    typedef typename base::_T1_param _T1_param;
2356227825Stheraven    typedef typename base::_T2_param _T2_param;
2357227825Stheraven
2358227825Stheraven    typedef typename base::_T1_reference _T1_reference;
2359227825Stheraven    typedef typename base::_T2_reference _T2_reference;
2360227825Stheraven
2361227825Stheraven    typedef typename base::_T1_const_reference _T1_const_reference;
2362227825Stheraven    typedef typename base::_T2_const_reference _T2_const_reference;
2363227825Stheraven
2364227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
2365232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
2366227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1)) {}
2367232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
2368227825Stheraven        : base(_VSTD::forward<_T2_param>(__t2)) {}
2369227825Stheraven    _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
2370227825Stheraven        : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
2371227825Stheraven
2372227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2373227825Stheraven
2374227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2375227825Stheraven    __compressed_pair(const __compressed_pair& __p)
2376227825Stheraven        _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2377227825Stheraven                   is_nothrow_copy_constructible<_T2>::value)
2378227825Stheraven        : base(__p) {}
2379227825Stheraven
2380227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2381227825Stheraven    __compressed_pair& operator=(const __compressed_pair& __p)
2382227825Stheraven        _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2383227825Stheraven                   is_nothrow_copy_assignable<_T2>::value)
2384227825Stheraven        {
2385227825Stheraven            base::operator=(__p);
2386227825Stheraven            return *this;
2387227825Stheraven        }
2388227825Stheraven
2389227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2390227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2391227825Stheraven    __compressed_pair(__compressed_pair&& __p)
2392227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2393227825Stheraven                   is_nothrow_move_constructible<_T2>::value)
2394227825Stheraven        : base(_VSTD::move(__p)) {}
2395227825Stheraven
2396227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2397227825Stheraven    __compressed_pair& operator=(__compressed_pair&& __p)
2398227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2399227825Stheraven                   is_nothrow_move_assignable<_T2>::value)
2400227825Stheraven        {
2401227825Stheraven            base::operator=(_VSTD::move(__p));
2402227825Stheraven            return *this;
2403227825Stheraven        }
2404232924Stheraven
2405232924Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2406232924Stheraven
2407232924Stheraven    template <class... _Args1, class... _Args2>
2408232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2409232924Stheraven        __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2410232924Stheraven                                                      tuple<_Args2...> __second_args)
2411232924Stheraven            : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
2412232924Stheraven                   typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2413232924Stheraven                   typename __make_tuple_indices<sizeof...(_Args2) >::type())
2414232924Stheraven            {}
2415232924Stheraven
2416232924Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2417232924Stheraven
2418227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2419227825Stheraven
2420227825Stheraven#endif  // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2421227825Stheraven
2422227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_reference       first() _NOEXCEPT       {return base::first();}
2423227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
2424227825Stheraven
2425227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_reference       second() _NOEXCEPT       {return base::second();}
2426227825Stheraven    _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
2427227825Stheraven
2428227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2429227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2430227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2431227825Stheraven        {base::swap(__x);}
2432227825Stheraven};
2433227825Stheraven
2434227825Stheraventemplate <class _T1, class _T2>
2435227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2436227825Stheravenvoid
2437227825Stheravenswap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2438227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2439227825Stheraven                   __is_nothrow_swappable<_T1>::value)
2440227825Stheraven    {__x.swap(__y);}
2441227825Stheraven
2442232924Stheraven// __same_or_less_cv_qualified
2443232924Stheraven
2444232924Stheraventemplate <class _Ptr1, class _Ptr2,
2445232924Stheraven          bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2446232924Stheraven                         typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2447232924Stheraven                        >::value
2448232924Stheraven         >
2449232924Stheravenstruct __same_or_less_cv_qualified_imp
2450232924Stheraven    : is_convertible<_Ptr1, _Ptr2> {};
2451232924Stheraven
2452232924Stheraventemplate <class _Ptr1, class _Ptr2>
2453232924Stheravenstruct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2454232924Stheraven    : false_type {};
2455232924Stheraven
2456232924Stheraventemplate <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
2457232924Stheraven                                         !is_pointer<_Ptr1>::value>
2458232924Stheravenstruct __same_or_less_cv_qualified
2459232924Stheraven    : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2460232924Stheraven
2461232924Stheraventemplate <class _Ptr1, class _Ptr2>
2462232924Stheravenstruct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
2463232924Stheraven    : false_type {};
2464232924Stheraven
2465232924Stheraven// default_delete
2466232924Stheraven
2467227825Stheraventemplate <class _Tp>
2468227825Stheravenstruct _LIBCPP_VISIBLE default_delete
2469227825Stheraven{
2470227825Stheraven    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2471227825Stheraven    template <class _Up>
2472227825Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
2473227825Stheraven             typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2474227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
2475227825Stheraven        {
2476227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2477227825Stheraven            delete __ptr;
2478227825Stheraven        }
2479227825Stheraven};
2480227825Stheraven
2481227825Stheraventemplate <class _Tp>
2482227825Stheravenstruct _LIBCPP_VISIBLE default_delete<_Tp[]>
2483227825Stheraven{
2484232924Stheravenpublic:
2485232924Stheraven    _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
2486232924Stheraven    template <class _Up>
2487232924Stheraven        _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
2488232924Stheraven             typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2489232924Stheraven    template <class _Up>
2490232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2491232924Stheraven        void operator() (_Up* __ptr,
2492232924Stheraven                         typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
2493227825Stheraven        {
2494227825Stheraven            static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
2495227825Stheraven            delete [] __ptr;
2496227825Stheraven        }
2497227825Stheraven};
2498227825Stheraven
2499227825Stheraventemplate <class _Tp, class _Dp = default_delete<_Tp> >
2500227825Stheravenclass _LIBCPP_VISIBLE unique_ptr
2501227825Stheraven{
2502227825Stheravenpublic:
2503227825Stheraven    typedef _Tp element_type;
2504227825Stheraven    typedef _Dp deleter_type;
2505227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2506227825Stheravenprivate:
2507227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2508227825Stheraven
2509232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2510227825Stheraven    unique_ptr(unique_ptr&);
2511227825Stheraven    template <class _Up, class _Ep>
2512227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&);
2513227825Stheraven    unique_ptr& operator=(unique_ptr&);
2514227825Stheraven    template <class _Up, class _Ep>
2515227825Stheraven        unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2516227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2517227825Stheraven
2518227825Stheraven    struct __nat {int __for_bool_;};
2519227825Stheraven
2520227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2521227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2522227825Stheravenpublic:
2523227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2524227825Stheraven        : __ptr_(pointer())
2525227825Stheraven        {
2526227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2527227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2528227825Stheraven        }
2529227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2530227825Stheraven        : __ptr_(pointer())
2531227825Stheraven        {
2532227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2533227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2534227825Stheraven        }
2535227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
2536227825Stheraven        : __ptr_(_VSTD::move(__p))
2537227825Stheraven        {
2538227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2539227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2540227825Stheraven        }
2541227825Stheraven
2542227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2543227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2544227825Stheraven                                        is_reference<deleter_type>::value,
2545227825Stheraven                                        deleter_type,
2546227825Stheraven                                        typename add_lvalue_reference<const deleter_type>::type>::type __d)
2547227825Stheraven             _NOEXCEPT
2548227825Stheraven        : __ptr_(__p, __d) {}
2549227825Stheraven
2550227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
2551227825Stheraven             _NOEXCEPT
2552227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2553227825Stheraven        {
2554227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2555227825Stheraven        }
2556227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2557227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2558227825Stheraven    template <class _Up, class _Ep>
2559227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2560227825Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2561227825Stheraven                   typename enable_if
2562227825Stheraven                      <
2563227825Stheraven                        !is_array<_Up>::value &&
2564227825Stheraven                         is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2565227825Stheraven                         is_convertible<_Ep, deleter_type>::value &&
2566227825Stheraven                         (
2567227825Stheraven                            !is_reference<deleter_type>::value ||
2568227825Stheraven                            is_same<deleter_type, _Ep>::value
2569227825Stheraven                         ),
2570227825Stheraven                         __nat
2571227825Stheraven                      >::type = __nat()) _NOEXCEPT
2572227825Stheraven            : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2573227825Stheraven
2574227825Stheraven    template <class _Up>
2575227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2576227825Stheraven                typename enable_if<
2577227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2578227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2579227825Stheraven                                      __nat
2580227825Stheraven                                  >::type = __nat()) _NOEXCEPT
2581227825Stheraven            : __ptr_(__p.release())
2582227825Stheraven            {
2583227825Stheraven            }
2584227825Stheraven
2585227825Stheraven        _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2586227825Stheraven            {
2587227825Stheraven                reset(__u.release());
2588227825Stheraven                __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2589227825Stheraven                return *this;
2590227825Stheraven            }
2591227825Stheraven
2592227825Stheraven        template <class _Up, class _Ep>
2593227825Stheraven            _LIBCPP_INLINE_VISIBILITY
2594227825Stheraven            typename enable_if
2595227825Stheraven            <
2596232924Stheraven                !is_array<_Up>::value &&
2597232924Stheraven                is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2598232924Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2599227825Stheraven                unique_ptr&
2600227825Stheraven            >::type
2601227825Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2602227825Stheraven            {
2603227825Stheraven                reset(__u.release());
2604227825Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2605227825Stheraven                return *this;
2606227825Stheraven            }
2607227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2608227825Stheraven
2609227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2610227825Stheraven    {
2611227825Stheraven        return __rv<unique_ptr>(*this);
2612227825Stheraven    }
2613227825Stheraven
2614227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2615227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2616227825Stheraven
2617227825Stheraven    template <class _Up, class _Ep>
2618227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2619227825Stheraven    {
2620227825Stheraven        reset(__u.release());
2621227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2622227825Stheraven        return *this;
2623227825Stheraven    }
2624227825Stheraven
2625227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2626227825Stheraven        : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2627227825Stheraven
2628227825Stheraven    template <class _Up>
2629227825Stheraven        _LIBCPP_INLINE_VISIBILITY
2630227825Stheraven                typename enable_if<
2631227825Stheraven                                      is_convertible<_Up*, _Tp*>::value &&
2632227825Stheraven                                      is_same<_Dp, default_delete<_Tp> >::value,
2633227825Stheraven                                      unique_ptr&
2634227825Stheraven                                  >::type
2635227825Stheraven        operator=(auto_ptr<_Up> __p)
2636227825Stheraven            {reset(__p.release()); return *this;}
2637227825Stheraven
2638227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2639227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2640227825Stheraven
2641227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2642227825Stheraven    {
2643227825Stheraven        reset();
2644227825Stheraven        return *this;
2645227825Stheraven    }
2646227825Stheraven
2647227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2648227825Stheraven        {return *__ptr_.first();}
2649227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2650227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2651227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2652227825Stheraven        {return __ptr_.second();}
2653227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2654227825Stheraven        {return __ptr_.second();}
2655232924Stheraven    _LIBCPP_INLINE_VISIBILITY
2656232924Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2657232924Stheraven        {return __ptr_.first() != nullptr;}
2658227825Stheraven
2659227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2660227825Stheraven    {
2661227825Stheraven        pointer __t = __ptr_.first();
2662227825Stheraven        __ptr_.first() = pointer();
2663227825Stheraven        return __t;
2664227825Stheraven    }
2665227825Stheraven
2666227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
2667227825Stheraven    {
2668227825Stheraven        pointer __tmp = __ptr_.first();
2669227825Stheraven        __ptr_.first() = __p;
2670227825Stheraven        if (__tmp)
2671227825Stheraven            __ptr_.second()(__tmp);
2672227825Stheraven    }
2673227825Stheraven
2674227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2675227825Stheraven        {__ptr_.swap(__u.__ptr_);}
2676227825Stheraven};
2677227825Stheraven
2678227825Stheraventemplate <class _Tp, class _Dp>
2679227825Stheravenclass _LIBCPP_VISIBLE unique_ptr<_Tp[], _Dp>
2680227825Stheraven{
2681227825Stheravenpublic:
2682227825Stheraven    typedef _Tp element_type;
2683227825Stheraven    typedef _Dp deleter_type;
2684227825Stheraven    typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2685227825Stheravenprivate:
2686227825Stheraven    __compressed_pair<pointer, deleter_type> __ptr_;
2687227825Stheraven
2688232924Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2689227825Stheraven    unique_ptr(unique_ptr&);
2690227825Stheraven    template <class _Up>
2691227825Stheraven        unique_ptr(unique_ptr<_Up>&);
2692227825Stheraven    unique_ptr& operator=(unique_ptr&);
2693227825Stheraven    template <class _Up>
2694227825Stheraven        unique_ptr& operator=(unique_ptr<_Up>&);
2695227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2696227825Stheraven
2697227825Stheraven    struct __nat {int __for_bool_;};
2698227825Stheraven
2699227825Stheraven    typedef       typename remove_reference<deleter_type>::type& _Dp_reference;
2700227825Stheraven    typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2701227825Stheravenpublic:
2702227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
2703227825Stheraven        : __ptr_(pointer())
2704227825Stheraven        {
2705227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2706227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2707227825Stheraven        }
2708227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
2709227825Stheraven        : __ptr_(pointer())
2710227825Stheraven        {
2711227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2712227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2713227825Stheraven        }
2714227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2715232924Stheraven    template <class _Pp,
2716232924Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2717227825Stheraven             >
2718232924Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
2719227825Stheraven        : __ptr_(__p)
2720227825Stheraven        {
2721227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2722227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2723227825Stheraven        }
2724227825Stheraven
2725232924Stheraven    template <class _Pp,
2726232924Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2727227825Stheraven             >
2728232924Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
2729227825Stheraven                                       is_reference<deleter_type>::value,
2730227825Stheraven                                       deleter_type,
2731227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2732227825Stheraven             _NOEXCEPT
2733227825Stheraven        : __ptr_(__p, __d) {}
2734227825Stheraven
2735227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2736227825Stheraven                                       is_reference<deleter_type>::value,
2737227825Stheraven                                       deleter_type,
2738227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type __d)
2739227825Stheraven             _NOEXCEPT
2740227825Stheraven        : __ptr_(pointer(), __d) {}
2741227825Stheraven
2742232924Stheraven    template <class _Pp,
2743232924Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2744227825Stheraven             >
2745232924Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
2746227825Stheraven             _NOEXCEPT
2747227825Stheraven        : __ptr_(__p, _VSTD::move(__d))
2748227825Stheraven        {
2749227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2750227825Stheraven        }
2751227825Stheraven
2752227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
2753227825Stheraven             _NOEXCEPT
2754227825Stheraven        : __ptr_(pointer(), _VSTD::move(__d))
2755227825Stheraven        {
2756227825Stheraven            static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2757227825Stheraven        }
2758227825Stheraven
2759227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
2760227825Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2761227825Stheraven
2762227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
2763227825Stheraven        {
2764227825Stheraven            reset(__u.release());
2765227825Stheraven            __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2766227825Stheraven            return *this;
2767227825Stheraven        }
2768232924Stheraven
2769232924Stheraven    template <class _Up, class _Ep>
2770232924Stheraven        _LIBCPP_INLINE_VISIBILITY
2771232924Stheraven        unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2772232924Stheraven                   typename enable_if
2773232924Stheraven                            <
2774232924Stheraven                                is_array<_Up>::value &&
2775232924Stheraven                                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
2776232924Stheraven                                && is_convertible<_Ep, deleter_type>::value &&
2777232924Stheraven                                (
2778232924Stheraven                                    !is_reference<deleter_type>::value ||
2779232924Stheraven                                    is_same<deleter_type, _Ep>::value
2780232924Stheraven                                ),
2781232924Stheraven                                __nat
2782232924Stheraven                            >::type = __nat()
2783232924Stheraven                  ) _NOEXCEPT
2784232924Stheraven        : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2785232924Stheraven
2786232924Stheraven
2787232924Stheraven        template <class _Up, class _Ep>
2788232924Stheraven            _LIBCPP_INLINE_VISIBILITY
2789232924Stheraven            typename enable_if
2790232924Stheraven            <
2791232924Stheraven                is_array<_Up>::value &&
2792232924Stheraven                __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2793232924Stheraven                is_assignable<deleter_type&, _Ep&&>::value,
2794232924Stheraven                unique_ptr&
2795232924Stheraven            >::type
2796232924Stheraven            operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2797232924Stheraven            {
2798232924Stheraven                reset(__u.release());
2799232924Stheraven                __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2800232924Stheraven                return *this;
2801232924Stheraven            }
2802227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2803227825Stheraven
2804227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2805227825Stheraven        : __ptr_(__p)
2806227825Stheraven        {
2807227825Stheraven            static_assert(!is_pointer<deleter_type>::value,
2808227825Stheraven                "unique_ptr constructed with null function pointer deleter");
2809227825Stheraven        }
2810227825Stheraven
2811227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
2812227825Stheraven        : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2813227825Stheraven
2814227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
2815227825Stheraven        : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2816227825Stheraven
2817227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2818227825Stheraven    {
2819227825Stheraven        return __rv<unique_ptr>(*this);
2820227825Stheraven    }
2821227825Stheraven
2822227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
2823227825Stheraven        : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2824227825Stheraven
2825227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2826227825Stheraven    {
2827227825Stheraven        reset(__u->release());
2828227825Stheraven        __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2829227825Stheraven        return *this;
2830227825Stheraven    }
2831227825Stheraven
2832227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2833227825Stheraven    _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2834227825Stheraven
2835227825Stheraven    _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
2836227825Stheraven    {
2837227825Stheraven        reset();
2838227825Stheraven        return *this;
2839227825Stheraven    }
2840227825Stheraven
2841227825Stheraven    _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2842227825Stheraven        {return __ptr_.first()[__i];}
2843227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2844227825Stheraven    _LIBCPP_INLINE_VISIBILITY       _Dp_reference get_deleter() _NOEXCEPT
2845227825Stheraven        {return __ptr_.second();}
2846227825Stheraven    _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2847227825Stheraven        {return __ptr_.second();}
2848232924Stheraven    _LIBCPP_INLINE_VISIBILITY
2849232924Stheraven        _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2850232924Stheraven        {return __ptr_.first() != nullptr;}
2851227825Stheraven
2852227825Stheraven    _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
2853227825Stheraven    {
2854227825Stheraven        pointer __t = __ptr_.first();
2855227825Stheraven        __ptr_.first() = pointer();
2856227825Stheraven        return __t;
2857227825Stheraven    }
2858227825Stheraven
2859227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2860232924Stheraven    template <class _Pp,
2861232924Stheraven              class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
2862227825Stheraven             >
2863232924Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
2864227825Stheraven    {
2865227825Stheraven        pointer __tmp = __ptr_.first();
2866227825Stheraven        __ptr_.first() = __p;
2867227825Stheraven        if (__tmp)
2868227825Stheraven            __ptr_.second()(__tmp);
2869227825Stheraven    }
2870227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
2871227825Stheraven    {
2872227825Stheraven        pointer __tmp = __ptr_.first();
2873227825Stheraven        __ptr_.first() = nullptr;
2874227825Stheraven        if (__tmp)
2875227825Stheraven            __ptr_.second()(__tmp);
2876227825Stheraven    }
2877227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
2878227825Stheraven    {
2879227825Stheraven        pointer __tmp = __ptr_.first();
2880227825Stheraven        __ptr_.first() = nullptr;
2881227825Stheraven        if (__tmp)
2882227825Stheraven            __ptr_.second()(__tmp);
2883227825Stheraven    }
2884227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2885227825Stheraven    _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2886227825Stheraven    {
2887227825Stheraven        pointer __tmp = __ptr_.first();
2888227825Stheraven        __ptr_.first() = __p;
2889227825Stheraven        if (__tmp)
2890227825Stheraven            __ptr_.second()(__tmp);
2891227825Stheraven    }
2892227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2893227825Stheraven
2894227825Stheraven    _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2895227825Stheravenprivate:
2896227825Stheraven
2897227825Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2898227825Stheraven    template <class _Up>
2899227825Stheraven        explicit unique_ptr(_Up);
2900227825Stheraven    template <class _Up>
2901227825Stheraven        unique_ptr(_Up __u,
2902227825Stheraven                   typename conditional<
2903227825Stheraven                                       is_reference<deleter_type>::value,
2904227825Stheraven                                       deleter_type,
2905227825Stheraven                                       typename add_lvalue_reference<const deleter_type>::type>::type,
2906227825Stheraven                   typename enable_if
2907227825Stheraven                      <
2908227825Stheraven                         is_convertible<_Up, pointer>::value,
2909227825Stheraven                         __nat
2910227825Stheraven                      >::type = __nat());
2911227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2912227825Stheraven};
2913227825Stheraven
2914227825Stheraventemplate <class _Tp, class _Dp>
2915227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2916227825Stheravenvoid
2917227825Stheravenswap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2918227825Stheraven
2919227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2920227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2921227825Stheravenbool
2922227825Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2923227825Stheraven
2924227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2925227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2926227825Stheravenbool
2927227825Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2928227825Stheraven
2929227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2930227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2931227825Stheravenbool
2932232924Stheravenoperator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2933232924Stheraven{
2934232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2935232924Stheraven    typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2936232924Stheraven    typedef typename common_type<_P1, _P2>::type _V;
2937232924Stheraven    return less<_V>()(__x.get(), __y.get());
2938232924Stheraven}
2939227825Stheraven
2940227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2941227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2942227825Stheravenbool
2943227825Stheravenoperator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2944227825Stheraven
2945227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2946227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2947227825Stheravenbool
2948227825Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2949227825Stheraven
2950227825Stheraventemplate <class _T1, class _D1, class _T2, class _D2>
2951227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
2952227825Stheravenbool
2953227825Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2954227825Stheraven
2955232924Stheraventemplate <class _T1, class _D1>
2956232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2957232924Stheravenbool
2958232924Stheravenoperator==(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2959232924Stheraven{
2960232924Stheraven    return !__x;
2961232924Stheraven}
2962232924Stheraven
2963232924Stheraventemplate <class _T1, class _D1>
2964232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2965232924Stheravenbool
2966232924Stheravenoperator==(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2967232924Stheraven{
2968232924Stheraven    return !__x;
2969232924Stheraven}
2970232924Stheraven
2971232924Stheraventemplate <class _T1, class _D1>
2972232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2973232924Stheravenbool
2974232924Stheravenoperator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2975232924Stheraven{
2976232924Stheraven    return static_cast<bool>(__x);
2977232924Stheraven}
2978232924Stheraven
2979232924Stheraventemplate <class _T1, class _D1>
2980232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2981232924Stheravenbool
2982232924Stheravenoperator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2983232924Stheraven{
2984232924Stheraven    return static_cast<bool>(__x);
2985232924Stheraven}
2986232924Stheraven
2987232924Stheraventemplate <class _T1, class _D1>
2988232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2989232924Stheravenbool
2990232924Stheravenoperator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2991232924Stheraven{
2992232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2993232924Stheraven    return less<_P1>()(__x.get(), nullptr);
2994232924Stheraven}
2995232924Stheraven
2996232924Stheraventemplate <class _T1, class _D1>
2997232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
2998232924Stheravenbool
2999232924Stheravenoperator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3000232924Stheraven{
3001232924Stheraven    typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3002232924Stheraven    return less<_P1>()(nullptr, __x.get());
3003232924Stheraven}
3004232924Stheraven
3005232924Stheraventemplate <class _T1, class _D1>
3006232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3007232924Stheravenbool
3008232924Stheravenoperator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3009232924Stheraven{
3010232924Stheraven    return nullptr < __x;
3011232924Stheraven}
3012232924Stheraven
3013232924Stheraventemplate <class _T1, class _D1>
3014232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3015232924Stheravenbool
3016232924Stheravenoperator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3017232924Stheraven{
3018232924Stheraven    return __x < nullptr;
3019232924Stheraven}
3020232924Stheraven
3021232924Stheraventemplate <class _T1, class _D1>
3022232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3023232924Stheravenbool
3024232924Stheravenoperator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3025232924Stheraven{
3026232924Stheraven    return !(nullptr < __x);
3027232924Stheraven}
3028232924Stheraven
3029232924Stheraventemplate <class _T1, class _D1>
3030232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3031232924Stheravenbool
3032232924Stheravenoperator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3033232924Stheraven{
3034232924Stheraven    return !(__x < nullptr);
3035232924Stheraven}
3036232924Stheraven
3037232924Stheraventemplate <class _T1, class _D1>
3038232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3039232924Stheravenbool
3040232924Stheravenoperator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3041232924Stheraven{
3042232924Stheraven    return !(__x < nullptr);
3043232924Stheraven}
3044232924Stheraven
3045232924Stheraventemplate <class _T1, class _D1>
3046232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
3047232924Stheravenbool
3048232924Stheravenoperator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3049232924Stheraven{
3050232924Stheraven    return !(nullptr < __x);
3051232924Stheraven}
3052232924Stheraven
3053234959Stheraven#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3054234959Stheraven
3055234959Stheraventemplate <class _Tp, class _Dp>
3056234959Stheraveninline _LIBCPP_INLINE_VISIBILITY
3057234959Stheravenunique_ptr<_Tp, _Dp>
3058234959Stheravenmove(unique_ptr<_Tp, _Dp>& __t)
3059234959Stheraven{
3060234959Stheraven    return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3061234959Stheraven}
3062234959Stheraven
3063234959Stheraven#endif
3064234959Stheraven
3065227825Stheraventemplate <class _Tp> struct hash;
3066227825Stheraven
3067232924Stheraven// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3068232924Stheraven// is 64 bits.  This is because cityhash64 uses 64bit x 64bit
3069232924Stheraven// multiplication, which can be very slow on 32-bit systems.
3070232924Stheraventemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
3071232924Stheravenstruct __murmur2_or_cityhash;
3072232924Stheraven
3073232924Stheraventemplate <class _Size>
3074232924Stheravenstruct __murmur2_or_cityhash<_Size, 32>
3075227825Stheraven{
3076232924Stheraven    _Size operator()(const void* __key, _Size __len);
3077232924Stheraven};
3078232924Stheraven
3079232924Stheraven// murmur2
3080232924Stheraventemplate <class _Size>
3081232924Stheraven_Size
3082232924Stheraven__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
3083232924Stheraven{
3084232924Stheraven    const _Size __m = 0x5bd1e995;
3085232924Stheraven    const _Size __r = 24;
3086232924Stheraven    _Size __h = __len;
3087232924Stheraven    const unsigned char* __data = static_cast<const unsigned char*>(__key);
3088232924Stheraven    for (; __len >= 4; __data += 4, __len -= 4)
3089232924Stheraven    {
3090232924Stheraven        _Size __k = *(const _Size*)__data;
3091232924Stheraven        __k *= __m;
3092232924Stheraven        __k ^= __k >> __r;
3093232924Stheraven        __k *= __m;
3094232924Stheraven        __h *= __m;
3095232924Stheraven        __h ^= __k;
3096232924Stheraven    }
3097232924Stheraven    switch (__len)
3098232924Stheraven    {
3099232924Stheraven    case 3:
3100232924Stheraven        __h ^= __data[2] << 16;
3101232924Stheraven    case 2:
3102232924Stheraven        __h ^= __data[1] << 8;
3103232924Stheraven    case 1:
3104232924Stheraven        __h ^= __data[0];
3105232924Stheraven        __h *= __m;
3106232924Stheraven    }
3107232924Stheraven    __h ^= __h >> 13;
3108232924Stheraven    __h *= __m;
3109232924Stheraven    __h ^= __h >> 15;
3110232924Stheraven    return __h;
3111232924Stheraven}
3112232924Stheraven
3113232924Stheraventemplate <class _Size>
3114232924Stheravenstruct __murmur2_or_cityhash<_Size, 64>
3115232924Stheraven{
3116232924Stheraven    _Size operator()(const void* __key, _Size __len);
3117232924Stheraven
3118232924Stheraven private:
3119232924Stheraven  // Some primes between 2^63 and 2^64.
3120232924Stheraven  static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3121232924Stheraven  static const _Size __k1 = 0xb492b66fbe98f273ULL;
3122232924Stheraven  static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3123232924Stheraven  static const _Size __k3 = 0xc949d7c7509e6557ULL;
3124232924Stheraven
3125232924Stheraven  static _Size __rotate(_Size __val, int __shift) {
3126232924Stheraven    return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3127232924Stheraven  }
3128232924Stheraven
3129232924Stheraven  static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3130232924Stheraven    return (__val >> __shift) | (__val << (64 - __shift));
3131232924Stheraven  }
3132232924Stheraven
3133232924Stheraven  static _Size __shift_mix(_Size __val) {
3134232924Stheraven    return __val ^ (__val >> 47);
3135232924Stheraven  }
3136232924Stheraven
3137232924Stheraven  static _Size __hash_len_16(_Size __u, _Size __v) {
3138232924Stheraven    const _Size __mul = 0x9ddfea08eb382d69ULL;
3139232924Stheraven    _Size __a = (__u ^ __v) * __mul;
3140232924Stheraven    __a ^= (__a >> 47);
3141232924Stheraven    _Size __b = (__v ^ __a) * __mul;
3142232924Stheraven    __b ^= (__b >> 47);
3143232924Stheraven    __b *= __mul;
3144232924Stheraven    return __b;
3145232924Stheraven  }
3146232924Stheraven
3147232924Stheraven  static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3148232924Stheraven    if (__len > 8) {
3149232924Stheraven      const _Size __a = *(const _Size*)__s;
3150232924Stheraven      const _Size __b = *(const _Size*)(__s + __len - 8);
3151232924Stheraven      return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3152232924Stheraven    }
3153232924Stheraven    if (__len >= 4) {
3154232924Stheraven      const uint32_t __a = *(const uint32_t*)(__s);
3155232924Stheraven      const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
3156232924Stheraven      return __hash_len_16(__len + (__a << 3), __b);
3157232924Stheraven    }
3158232924Stheraven    if (__len > 0) {
3159232924Stheraven      const unsigned char __a = __s[0];
3160232924Stheraven      const unsigned char __b = __s[__len >> 1];
3161232924Stheraven      const unsigned char __c = __s[__len - 1];
3162232924Stheraven      const uint32_t __y = static_cast<uint32_t>(__a) +
3163232924Stheraven                           (static_cast<uint32_t>(__b) << 8);
3164232924Stheraven      const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3165232924Stheraven      return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3166232924Stheraven    }
3167232924Stheraven    return __k2;
3168232924Stheraven  }
3169232924Stheraven
3170232924Stheraven  static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
3171232924Stheraven    const _Size __a = *(const _Size*)(__s) * __k1;
3172232924Stheraven    const _Size __b = *(const _Size*)(__s + 8);
3173232924Stheraven    const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
3174232924Stheraven    const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
3175232924Stheraven    return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3176232924Stheraven                         __a + __rotate(__b ^ __k3, 20) - __c + __len);
3177232924Stheraven  }
3178232924Stheraven
3179232924Stheraven  // Return a 16-byte hash for 48 bytes.  Quick and dirty.
3180232924Stheraven  // Callers do best to use "random-looking" values for a and b.
3181232924Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3182232924Stheraven      _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3183232924Stheraven    __a += __w;
3184232924Stheraven    __b = __rotate(__b + __a + __z, 21);
3185232924Stheraven    const _Size __c = __a;
3186232924Stheraven    __a += __x;
3187232924Stheraven    __a += __y;
3188232924Stheraven    __b += __rotate(__a, 44);
3189232924Stheraven    return pair<_Size, _Size>(__a + __z, __b + __c);
3190232924Stheraven  }
3191232924Stheraven
3192232924Stheraven  // Return a 16-byte hash for s[0] ... s[31], a, and b.  Quick and dirty.
3193232924Stheraven  static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3194232924Stheraven      const char* __s, _Size __a, _Size __b) {
3195232924Stheraven    return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
3196232924Stheraven                                         *(const _Size*)(__s + 8),
3197232924Stheraven                                         *(const _Size*)(__s + 16),
3198232924Stheraven                                         *(const _Size*)(__s + 24),
3199232924Stheraven                                         __a,
3200232924Stheraven                                         __b);
3201232924Stheraven  }
3202232924Stheraven
3203232924Stheraven  // Return an 8-byte hash for 33 to 64 bytes.
3204232924Stheraven  static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
3205232924Stheraven    _Size __z = *(const _Size*)(__s + 24);
3206232924Stheraven    _Size __a = *(const _Size*)(__s) +
3207232924Stheraven                (__len + *(const _Size*)(__s + __len - 16)) * __k0;
3208232924Stheraven    _Size __b = __rotate(__a + __z, 52);
3209232924Stheraven    _Size __c = __rotate(__a, 37);
3210232924Stheraven    __a += *(const _Size*)(__s + 8);
3211232924Stheraven    __c += __rotate(__a, 7);
3212232924Stheraven    __a += *(const _Size*)(__s + 16);
3213232924Stheraven    _Size __vf = __a + __z;
3214232924Stheraven    _Size __vs = __b + __rotate(__a, 31) + __c;
3215232924Stheraven    __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
3216232924Stheraven    __z += *(const _Size*)(__s + __len - 8);
3217232924Stheraven    __b = __rotate(__a + __z, 52);
3218232924Stheraven    __c = __rotate(__a, 37);
3219232924Stheraven    __a += *(const _Size*)(__s + __len - 24);
3220232924Stheraven    __c += __rotate(__a, 7);
3221232924Stheraven    __a += *(const _Size*)(__s + __len - 16);
3222232924Stheraven    _Size __wf = __a + __z;
3223232924Stheraven    _Size __ws = __b + __rotate(__a, 31) + __c;
3224232924Stheraven    _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3225232924Stheraven    return __shift_mix(__r * __k0 + __vs) * __k2;
3226232924Stheraven  }
3227232924Stheraven};
3228232924Stheraven
3229232924Stheraven// cityhash64
3230232924Stheraventemplate <class _Size>
3231232924Stheraven_Size
3232232924Stheraven__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
3233232924Stheraven{
3234232924Stheraven  const char* __s = static_cast<const char*>(__key);
3235232924Stheraven  if (__len <= 32) {
3236232924Stheraven    if (__len <= 16) {
3237232924Stheraven      return __hash_len_0_to_16(__s, __len);
3238232924Stheraven    } else {
3239232924Stheraven      return __hash_len_17_to_32(__s, __len);
3240232924Stheraven    }
3241232924Stheraven  } else if (__len <= 64) {
3242232924Stheraven    return __hash_len_33_to_64(__s, __len);
3243232924Stheraven  }
3244232924Stheraven
3245232924Stheraven  // For strings over 64 bytes we hash the end first, and then as we
3246232924Stheraven  // loop we keep 56 bytes of state: v, w, x, y, and z.
3247232924Stheraven  _Size __x = *(const _Size*)(__s + __len - 40);
3248232924Stheraven  _Size __y = *(const _Size*)(__s + __len - 16) +
3249232924Stheraven              *(const _Size*)(__s + __len - 56);
3250232924Stheraven  _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
3251232924Stheraven                          *(const _Size*)(__s + __len - 24));
3252232924Stheraven  pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3253232924Stheraven  pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
3254232924Stheraven  __x = __x * __k1 + *(const _Size*)(__s);
3255232924Stheraven
3256232924Stheraven  // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3257232924Stheraven  __len = (__len - 1) & ~static_cast<_Size>(63);
3258232924Stheraven  do {
3259232924Stheraven    __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
3260232924Stheraven    __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
3261232924Stheraven    __x ^= __w.second;
3262232924Stheraven    __y += __v.first + *(const _Size*)(__s + 40);
3263232924Stheraven    __z = __rotate(__z + __w.first, 33) * __k1;
3264232924Stheraven    __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3265232924Stheraven    __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
3266232924Stheraven                                        __y + *(const _Size*)(__s + 16));
3267232924Stheraven    std::swap(__z, __x);
3268232924Stheraven    __s += 64;
3269232924Stheraven    __len -= 64;
3270232924Stheraven  } while (__len != 0);
3271232924Stheraven  return __hash_len_16(
3272232924Stheraven      __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3273232924Stheraven      __hash_len_16(__v.second, __w.second) + __x);
3274232924Stheraven}
3275232924Stheraven
3276232924Stheraventemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3277232924Stheravenstruct __scalar_hash;
3278232924Stheraven
3279232924Stheraventemplate <class _Tp>
3280232924Stheravenstruct __scalar_hash<_Tp, 0>
3281232924Stheraven    : public unary_function<_Tp, size_t>
3282232924Stheraven{
3283227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3284232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3285227825Stheraven    {
3286232924Stheraven        union
3287232924Stheraven        {
3288232924Stheraven            _Tp    __t;
3289232924Stheraven            size_t __a;
3290232924Stheraven        } __u;
3291232924Stheraven        __u.__a = 0;
3292232924Stheraven        __u.__t = __v;
3293232924Stheraven        return __u.__a;
3294227825Stheraven    }
3295227825Stheraven};
3296227825Stheraven
3297232924Stheraventemplate <class _Tp>
3298232924Stheravenstruct __scalar_hash<_Tp, 1>
3299232924Stheraven    : public unary_function<_Tp, size_t>
3300232924Stheraven{
3301232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3302232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3303232924Stheraven    {
3304232924Stheraven        union
3305232924Stheraven        {
3306232924Stheraven            _Tp    __t;
3307232924Stheraven            size_t __a;
3308232924Stheraven        } __u;
3309232924Stheraven        __u.__t = __v;
3310232924Stheraven        return __u.__a;
3311232924Stheraven    }
3312232924Stheraven};
3313232924Stheraven
3314232924Stheraventemplate <class _Tp>
3315232924Stheravenstruct __scalar_hash<_Tp, 2>
3316232924Stheraven    : public unary_function<_Tp, size_t>
3317232924Stheraven{
3318232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3319232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3320232924Stheraven    {
3321232924Stheraven        union
3322232924Stheraven        {
3323232924Stheraven            _Tp __t;
3324232924Stheraven            struct
3325232924Stheraven            {
3326232924Stheraven                size_t __a;
3327232924Stheraven                size_t __b;
3328232924Stheraven            };
3329232924Stheraven        } __u;
3330232924Stheraven        __u.__t = __v;
3331232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3332232924Stheraven    }
3333232924Stheraven};
3334232924Stheraven
3335232924Stheraventemplate <class _Tp>
3336232924Stheravenstruct __scalar_hash<_Tp, 3>
3337232924Stheraven    : public unary_function<_Tp, size_t>
3338232924Stheraven{
3339232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3340232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3341232924Stheraven    {
3342232924Stheraven        union
3343232924Stheraven        {
3344232924Stheraven            _Tp __t;
3345232924Stheraven            struct
3346232924Stheraven            {
3347232924Stheraven                size_t __a;
3348232924Stheraven                size_t __b;
3349232924Stheraven                size_t __c;
3350232924Stheraven            };
3351232924Stheraven        } __u;
3352232924Stheraven        __u.__t = __v;
3353232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3354232924Stheraven    }
3355232924Stheraven};
3356232924Stheraven
3357232924Stheraventemplate <class _Tp>
3358232924Stheravenstruct __scalar_hash<_Tp, 4>
3359232924Stheraven    : public unary_function<_Tp, size_t>
3360232924Stheraven{
3361232924Stheraven    _LIBCPP_INLINE_VISIBILITY
3362232924Stheraven    size_t operator()(_Tp __v) const _NOEXCEPT
3363232924Stheraven    {
3364232924Stheraven        union
3365232924Stheraven        {
3366232924Stheraven            _Tp __t;
3367232924Stheraven            struct
3368232924Stheraven            {
3369232924Stheraven                size_t __a;
3370232924Stheraven                size_t __b;
3371232924Stheraven                size_t __c;
3372232924Stheraven                size_t __d;
3373232924Stheraven            };
3374232924Stheraven        } __u;
3375232924Stheraven        __u.__t = __v;
3376232924Stheraven        return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3377232924Stheraven    }
3378232924Stheraven};
3379232924Stheraven
3380232924Stheraventemplate<class _Tp>
3381232924Stheravenstruct _LIBCPP_VISIBLE hash<_Tp*>
3382232924Stheraven    : public __scalar_hash<_Tp*>
3383232924Stheraven{
3384232924Stheraven};
3385232924Stheraven
3386227825Stheraventemplate <class _Tp, class _Dp>
3387227825Stheravenstruct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
3388227825Stheraven{
3389227825Stheraven    typedef unique_ptr<_Tp, _Dp> argument_type;
3390227825Stheraven    typedef size_t               result_type;
3391227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3392227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
3393227825Stheraven    {
3394227825Stheraven        typedef typename argument_type::pointer pointer;
3395227825Stheraven        return hash<pointer>()(__ptr.get());
3396227825Stheraven    }
3397227825Stheraven};
3398227825Stheraven
3399227825Stheravenstruct __destruct_n
3400227825Stheraven{
3401227825Stheravenprivate:
3402227825Stheraven    size_t size;
3403227825Stheraven
3404227825Stheraven    template <class _Tp>
3405227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3406227825Stheraven        {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3407227825Stheraven
3408227825Stheraven    template <class _Tp>
3409227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3410227825Stheraven        {}
3411227825Stheraven
3412227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3413227825Stheraven        {++size;}
3414227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3415227825Stheraven        {}
3416227825Stheraven
3417227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3418227825Stheraven        {size = __s;}
3419227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3420227825Stheraven        {}
3421227825Stheravenpublic:
3422227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3423227825Stheraven        : size(__s) {}
3424227825Stheraven
3425227825Stheraven    template <class _Tp>
3426227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3427227825Stheraven        {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3428227825Stheraven
3429227825Stheraven    template <class _Tp>
3430227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3431227825Stheraven        {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3432227825Stheraven
3433227825Stheraven    template <class _Tp>
3434227825Stheraven    _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3435227825Stheraven        {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3436227825Stheraven};
3437227825Stheraven
3438227825Stheraventemplate <class _Alloc>
3439227825Stheravenclass __allocator_destructor
3440227825Stheraven{
3441227825Stheraven    typedef allocator_traits<_Alloc> __alloc_traits;
3442227825Stheravenpublic:
3443227825Stheraven    typedef typename __alloc_traits::pointer pointer;
3444227825Stheraven    typedef typename __alloc_traits::size_type size_type;
3445227825Stheravenprivate:
3446227825Stheraven    _Alloc& __alloc_;
3447227825Stheraven    size_type __s_;
3448227825Stheravenpublic:
3449227825Stheraven    _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3450227825Stheraven             _NOEXCEPT
3451227825Stheraven        : __alloc_(__a), __s_(__s) {}
3452227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3453227825Stheraven    void operator()(pointer __p) _NOEXCEPT
3454227825Stheraven        {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3455227825Stheraven};
3456227825Stheraven
3457227825Stheraventemplate <class _InputIterator, class _ForwardIterator>
3458227825Stheraven_ForwardIterator
3459227825Stheravenuninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3460227825Stheraven{
3461227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3462232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3463232924Stheraven    _ForwardIterator __s = __r;
3464232924Stheraven    try
3465232924Stheraven    {
3466232924Stheraven#endif
3467232924Stheraven        for (; __f != __l; ++__f, ++__r)
3468232924Stheraven            ::new(&*__r) value_type(*__f);
3469232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3470232924Stheraven    }
3471232924Stheraven    catch (...)
3472232924Stheraven    {
3473232924Stheraven        for (; __s != __r; ++__s)
3474232924Stheraven            __s->~value_type();
3475232924Stheraven        throw;
3476232924Stheraven    }
3477232924Stheraven#endif
3478227825Stheraven    return __r;
3479227825Stheraven}
3480227825Stheraven
3481227825Stheraventemplate <class _InputIterator, class _Size, class _ForwardIterator>
3482227825Stheraven_ForwardIterator
3483227825Stheravenuninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3484227825Stheraven{
3485227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3486232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3487232924Stheraven    _ForwardIterator __s = __r;
3488232924Stheraven    try
3489232924Stheraven    {
3490232924Stheraven#endif
3491232924Stheraven        for (; __n > 0; ++__f, ++__r, --__n)
3492232924Stheraven            ::new(&*__r) value_type(*__f);
3493232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3494232924Stheraven    }
3495232924Stheraven    catch (...)
3496232924Stheraven    {
3497232924Stheraven        for (; __s != __r; ++__s)
3498232924Stheraven            __s->~value_type();
3499232924Stheraven        throw;
3500232924Stheraven    }
3501232924Stheraven#endif
3502227825Stheraven    return __r;
3503227825Stheraven}
3504227825Stheraven
3505227825Stheraventemplate <class _ForwardIterator, class _Tp>
3506227825Stheravenvoid
3507227825Stheravenuninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3508227825Stheraven{
3509227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3510232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3511232924Stheraven    _ForwardIterator __s = __f;
3512232924Stheraven    try
3513232924Stheraven    {
3514232924Stheraven#endif
3515232924Stheraven        for (; __f != __l; ++__f)
3516232924Stheraven            ::new(&*__f) value_type(__x);
3517232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3518232924Stheraven    }
3519232924Stheraven    catch (...)
3520232924Stheraven    {
3521232924Stheraven        for (; __s != __f; ++__s)
3522232924Stheraven            __s->~value_type();
3523232924Stheraven        throw;
3524232924Stheraven    }
3525232924Stheraven#endif
3526227825Stheraven}
3527227825Stheraven
3528227825Stheraventemplate <class _ForwardIterator, class _Size, class _Tp>
3529227825Stheraven_ForwardIterator
3530227825Stheravenuninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3531227825Stheraven{
3532227825Stheraven    typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3533232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3534232924Stheraven    _ForwardIterator __s = __f;
3535232924Stheraven    try
3536232924Stheraven    {
3537232924Stheraven#endif
3538232924Stheraven        for (; __n > 0; ++__f, --__n)
3539232924Stheraven            ::new(&*__f) value_type(__x);
3540232924Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
3541232924Stheraven    }
3542232924Stheraven    catch (...)
3543232924Stheraven    {
3544232924Stheraven        for (; __s != __f; ++__s)
3545232924Stheraven            __s->~value_type();
3546232924Stheraven        throw;
3547232924Stheraven    }
3548232924Stheraven#endif
3549227825Stheraven    return __f;
3550227825Stheraven}
3551227825Stheraven
3552227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3553227825Stheraven    : public std::exception
3554227825Stheraven{
3555227825Stheravenpublic:
3556227825Stheraven    virtual ~bad_weak_ptr() _NOEXCEPT;
3557227825Stheraven    virtual const char* what() const  _NOEXCEPT;
3558227825Stheraven};
3559227825Stheraven
3560227825Stheraventemplate<class _Tp> class weak_ptr;
3561227825Stheraven
3562227825Stheravenclass __shared_count
3563227825Stheraven{
3564227825Stheraven    __shared_count(const __shared_count&);
3565227825Stheraven    __shared_count& operator=(const __shared_count&);
3566227825Stheraven
3567227825Stheravenprotected:
3568227825Stheraven    long __shared_owners_;
3569227825Stheraven    virtual ~__shared_count();
3570227825Stheravenprivate:
3571227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT = 0;
3572227825Stheraven
3573227825Stheravenpublic:
3574227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3575227825Stheraven    explicit __shared_count(long __refs = 0) _NOEXCEPT
3576227825Stheraven        : __shared_owners_(__refs) {}
3577227825Stheraven
3578227825Stheraven    void __add_shared() _NOEXCEPT;
3579227825Stheraven    bool __release_shared() _NOEXCEPT;
3580227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3581227825Stheraven    long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
3582227825Stheraven};
3583227825Stheraven
3584227825Stheravenclass __shared_weak_count
3585227825Stheraven    : private __shared_count
3586227825Stheraven{
3587227825Stheraven    long __shared_weak_owners_;
3588227825Stheraven
3589227825Stheravenpublic:
3590227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3591227825Stheraven    explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3592227825Stheraven        : __shared_count(__refs),
3593227825Stheraven          __shared_weak_owners_(__refs) {}
3594227825Stheravenprotected:
3595227825Stheraven    virtual ~__shared_weak_count();
3596227825Stheraven
3597227825Stheravenpublic:
3598227825Stheraven    void __add_shared() _NOEXCEPT;
3599227825Stheraven    void __add_weak() _NOEXCEPT;
3600227825Stheraven    void __release_shared() _NOEXCEPT;
3601227825Stheraven    void __release_weak() _NOEXCEPT;
3602227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3603227825Stheraven    long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3604227825Stheraven    __shared_weak_count* lock() _NOEXCEPT;
3605227825Stheraven
3606227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3607227825Stheravenprivate:
3608227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3609227825Stheraven};
3610227825Stheraven
3611227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3612227825Stheravenclass __shared_ptr_pointer
3613227825Stheraven    : public __shared_weak_count
3614227825Stheraven{
3615227825Stheraven    __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3616227825Stheravenpublic:
3617227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3618227825Stheraven    __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3619227825Stheraven        :  __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3620227825Stheraven
3621227825Stheraven#ifndef _LIBCPP_NO_RTTI
3622227825Stheraven    virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3623227825Stheraven#endif
3624227825Stheraven
3625227825Stheravenprivate:
3626227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3627227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3628227825Stheraven};
3629227825Stheraven
3630227825Stheraven#ifndef _LIBCPP_NO_RTTI
3631227825Stheraven
3632227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3633227825Stheravenconst void*
3634227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3635227825Stheraven{
3636227825Stheraven    return __t == typeid(_Dp) ? &__data_.first().second() : 0;
3637227825Stheraven}
3638227825Stheraven
3639227825Stheraven#endif  // _LIBCPP_NO_RTTI
3640227825Stheraven
3641227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3642227825Stheravenvoid
3643227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3644227825Stheraven{
3645227825Stheraven    __data_.first().second()(__data_.first().first());
3646227825Stheraven    __data_.first().second().~_Dp();
3647227825Stheraven}
3648227825Stheraven
3649227825Stheraventemplate <class _Tp, class _Dp, class _Alloc>
3650227825Stheravenvoid
3651227825Stheraven__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3652227825Stheraven{
3653227825Stheraven    typename _Alloc::template rebind<__shared_ptr_pointer>::other __a(__data_.second());
3654227825Stheraven    __data_.second().~_Alloc();
3655227825Stheraven    __a.deallocate(this, 1);
3656227825Stheraven}
3657227825Stheraven
3658227825Stheraventemplate <class _Tp, class _Alloc>
3659227825Stheravenclass __shared_ptr_emplace
3660227825Stheraven    : public __shared_weak_count
3661227825Stheraven{
3662227825Stheraven    __compressed_pair<_Alloc, _Tp> __data_;
3663227825Stheravenpublic:
3664227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3665227825Stheraven
3666227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3667227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3668227825Stheraven        :  __data_(_VSTD::move(__a)) {}
3669227825Stheraven
3670227825Stheraven    template <class ..._Args>
3671227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3672227825Stheraven        __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3673232924Stheraven            :  __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3674232924Stheraven                   _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3675227825Stheraven
3676227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3677227825Stheraven
3678227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3679227825Stheraven    __shared_ptr_emplace(_Alloc __a)
3680227825Stheraven        :  __data_(__a) {}
3681227825Stheraven
3682227825Stheraven    template <class _A0>
3683227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3684227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3685227825Stheraven            :  __data_(__a, _Tp(__a0)) {}
3686227825Stheraven
3687227825Stheraven    template <class _A0, class _A1>
3688227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3689227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3690227825Stheraven            :  __data_(__a, _Tp(__a0, __a1)) {}
3691227825Stheraven
3692227825Stheraven    template <class _A0, class _A1, class _A2>
3693227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3694227825Stheraven        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3695227825Stheraven            :  __data_(__a, _Tp(__a0, __a1, __a2)) {}
3696227825Stheraven
3697227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3698227825Stheraven
3699227825Stheravenprivate:
3700227825Stheraven    virtual void __on_zero_shared() _NOEXCEPT;
3701227825Stheraven    virtual void __on_zero_shared_weak() _NOEXCEPT;
3702227825Stheravenpublic:
3703227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3704227825Stheraven    _Tp* get() _NOEXCEPT {return &__data_.second();}
3705227825Stheraven};
3706227825Stheraven
3707227825Stheraventemplate <class _Tp, class _Alloc>
3708227825Stheravenvoid
3709227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3710227825Stheraven{
3711227825Stheraven    __data_.second().~_Tp();
3712227825Stheraven}
3713227825Stheraven
3714227825Stheraventemplate <class _Tp, class _Alloc>
3715227825Stheravenvoid
3716227825Stheraven__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3717227825Stheraven{
3718227825Stheraven    typename _Alloc::template rebind<__shared_ptr_emplace>::other __a(__data_.first());
3719227825Stheraven    __data_.first().~_Alloc();
3720227825Stheraven    __a.deallocate(this, 1);
3721227825Stheraven}
3722227825Stheraven
3723227825Stheraventemplate<class _Tp> class enable_shared_from_this;
3724227825Stheraven
3725227825Stheraventemplate<class _Tp>
3726227825Stheravenclass _LIBCPP_VISIBLE shared_ptr
3727227825Stheraven{
3728227825Stheravenpublic:
3729227825Stheraven    typedef _Tp element_type;
3730227825Stheravenprivate:
3731227825Stheraven    element_type*      __ptr_;
3732227825Stheraven    __shared_weak_count* __cntrl_;
3733227825Stheraven
3734227825Stheraven    struct __nat {int __for_bool_;};
3735227825Stheravenpublic:
3736227825Stheraven    shared_ptr() _NOEXCEPT;
3737227825Stheraven    shared_ptr(nullptr_t) _NOEXCEPT;
3738232924Stheraven    template<class _Yp,
3739232924Stheraven             class = typename enable_if
3740232924Stheraven                     <
3741232924Stheraven                        is_convertible<_Yp*, element_type*>::value
3742232924Stheraven                     >::type
3743232924Stheraven            >
3744232924Stheraven        explicit shared_ptr(_Yp* __p);
3745232924Stheraven    template<class _Yp, class _Dp,
3746232924Stheraven             class = typename enable_if
3747232924Stheraven                     <
3748232924Stheraven                        is_convertible<_Yp*, element_type*>::value
3749232924Stheraven                     >::type
3750232924Stheraven            >
3751232924Stheraven        shared_ptr(_Yp* __p, _Dp __d);
3752232924Stheraven    template<class _Yp, class _Dp, class _Alloc,
3753232924Stheraven             class = typename enable_if
3754232924Stheraven                     <
3755232924Stheraven                        is_convertible<_Yp*, element_type*>::value
3756232924Stheraven                     >::type
3757232924Stheraven            >
3758232924Stheraven        shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
3759227825Stheraven    template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3760227825Stheraven    template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3761227825Stheraven    template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3762227825Stheraven    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3763227825Stheraven    template<class _Yp>
3764227825Stheraven        shared_ptr(const shared_ptr<_Yp>& __r,
3765227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3766227825Stheraven                       _NOEXCEPT;
3767227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3768227825Stheraven    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3769227825Stheraven    template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
3770227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3771227825Stheraven                       _NOEXCEPT;
3772227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3773227825Stheraven    template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3774227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
3775227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3776232924Stheraven    template<class _Yp,
3777232924Stheraven             class = typename enable_if
3778232924Stheraven                     <
3779232924Stheraven                        is_convertible<_Yp*, element_type*>::value
3780232924Stheraven                     >::type
3781232924Stheraven            >
3782232924Stheraven        shared_ptr(auto_ptr<_Yp>&& __r);
3783227825Stheraven#else
3784232924Stheraven    template<class _Yp,
3785232924Stheraven             class = typename enable_if
3786232924Stheraven                     <
3787232924Stheraven                        is_convertible<_Yp*, element_type*>::value
3788232924Stheraven                     >::type
3789232924Stheraven            >
3790232924Stheraven        shared_ptr(auto_ptr<_Yp> __r);
3791227825Stheraven#endif
3792227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3793232924Stheraven    template <class _Yp, class _Dp,
3794232924Stheraven                 class = typename enable_if
3795232924Stheraven                 <
3796232924Stheraven                    !is_array<_Yp>::value &&
3797232924Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3798232924Stheraven                 >::type
3799232924Stheraven             >
3800232924Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3801227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3802232924Stheraven    template <class _Yp, class _Dp,
3803232924Stheraven                 class = typename enable_if
3804232924Stheraven                 <
3805232924Stheraven                    !is_array<_Yp>::value &&
3806232924Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3807232924Stheraven                 >::type
3808232924Stheraven             >
3809232924Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>&&,
3810227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3811227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3812232924Stheraven    template <class _Yp, class _Dp,
3813232924Stheraven                 class = typename enable_if
3814232924Stheraven                 <
3815232924Stheraven                    !is_array<_Yp>::value &&
3816232924Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3817232924Stheraven                 >::type
3818232924Stheraven             > shared_ptr(unique_ptr<_Yp, _Dp>,
3819227825Stheraven       typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3820232924Stheraven    template <class _Yp, class _Dp,
3821232924Stheraven                 class = typename enable_if
3822232924Stheraven                 <
3823232924Stheraven                    !is_array<_Yp>::value &&
3824232924Stheraven                    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
3825232924Stheraven                 >::type
3826232924Stheraven             >
3827232924Stheraven       shared_ptr(unique_ptr<_Yp, _Dp>,
3828227825Stheraven       typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
3829227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3830227825Stheraven
3831227825Stheraven    ~shared_ptr();
3832227825Stheraven
3833227825Stheraven    shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3834232924Stheraven    template<class _Yp>
3835232924Stheraven        typename enable_if
3836232924Stheraven        <
3837232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3838232924Stheraven            shared_ptr&
3839232924Stheraven        >::type
3840232924Stheraven        operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3841227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3842227825Stheraven    shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3843232924Stheraven    template<class _Yp>
3844232924Stheraven        typename enable_if
3845232924Stheraven        <
3846232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3847232924Stheraven            shared_ptr<_Tp>&
3848232924Stheraven        >::type
3849232924Stheraven        operator=(shared_ptr<_Yp>&& __r);
3850232924Stheraven    template<class _Yp>
3851232924Stheraven        typename enable_if
3852232924Stheraven        <
3853232924Stheraven            !is_array<_Yp>::value &&
3854232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3855232924Stheraven            shared_ptr&
3856232924Stheraven        >::type
3857232924Stheraven        operator=(auto_ptr<_Yp>&& __r);
3858227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3859232924Stheraven    template<class _Yp>
3860232924Stheraven        typename enable_if
3861232924Stheraven        <
3862232924Stheraven            !is_array<_Yp>::value &&
3863232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3864232924Stheraven            shared_ptr&
3865232924Stheraven        >::type
3866232924Stheraven        operator=(auto_ptr<_Yp> __r);
3867227825Stheraven#endif
3868232924Stheraven    template <class _Yp, class _Dp>
3869232924Stheraven        typename enable_if
3870232924Stheraven        <
3871232924Stheraven            !is_array<_Yp>::value &&
3872232924Stheraven            is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3873232924Stheraven            shared_ptr&
3874232924Stheraven        >::type
3875227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3876232924Stheraven        operator=(unique_ptr<_Yp, _Dp>&& __r);
3877227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3878232924Stheraven        operator=(unique_ptr<_Yp, _Dp> __r);
3879227825Stheraven#endif
3880227825Stheraven
3881227825Stheraven    void swap(shared_ptr& __r) _NOEXCEPT;
3882227825Stheraven    void reset() _NOEXCEPT;
3883232924Stheraven    template<class _Yp>
3884232924Stheraven        typename enable_if
3885232924Stheraven        <
3886232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3887232924Stheraven            void
3888232924Stheraven        >::type
3889232924Stheraven        reset(_Yp* __p);
3890232924Stheraven    template<class _Yp, class _Dp>
3891232924Stheraven        typename enable_if
3892232924Stheraven        <
3893232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3894232924Stheraven            void
3895232924Stheraven        >::type
3896232924Stheraven        reset(_Yp* __p, _Dp __d);
3897232924Stheraven    template<class _Yp, class _Dp, class _Alloc>
3898232924Stheraven        typename enable_if
3899232924Stheraven        <
3900232924Stheraven            is_convertible<_Yp*, element_type*>::value,
3901232924Stheraven            void
3902232924Stheraven        >::type
3903232924Stheraven        reset(_Yp* __p, _Dp __d, _Alloc __a);
3904227825Stheraven
3905227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3906227825Stheraven    element_type* get() const _NOEXCEPT {return __ptr_;}
3907227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3908227825Stheraven    typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3909227825Stheraven        {return *__ptr_;}
3910227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3911227825Stheraven    element_type* operator->() const _NOEXCEPT {return __ptr_;}
3912227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3913227825Stheraven    long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3914227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3915227825Stheraven    bool unique() const _NOEXCEPT {return use_count() == 1;}
3916227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3917232924Stheraven    _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3918232924Stheraven    template <class _Up>
3919227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3920232924Stheraven        bool owner_before(shared_ptr<_Up> const& __p) const
3921227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3922232924Stheraven    template <class _Up>
3923227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3924232924Stheraven        bool owner_before(weak_ptr<_Up> const& __p) const
3925227825Stheraven        {return __cntrl_ < __p.__cntrl_;}
3926227825Stheraven
3927227825Stheraven#ifndef _LIBCPP_NO_RTTI
3928227825Stheraven    template <class _Dp>
3929227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3930227825Stheraven        _Dp* __get_deleter() const _NOEXCEPT
3931227825Stheraven            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3932227825Stheraven#endif  // _LIBCPP_NO_RTTI
3933227825Stheraven
3934227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3935227825Stheraven
3936227825Stheraven    template<class ..._Args>
3937227825Stheraven        static
3938227825Stheraven        shared_ptr<_Tp>
3939227825Stheraven        make_shared(_Args&& ...__args);
3940227825Stheraven
3941227825Stheraven    template<class _Alloc, class ..._Args>
3942227825Stheraven        static
3943227825Stheraven        shared_ptr<_Tp>
3944227825Stheraven        allocate_shared(const _Alloc& __a, _Args&& ...__args);
3945227825Stheraven
3946227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
3947227825Stheraven
3948227825Stheraven    static shared_ptr<_Tp> make_shared();
3949227825Stheraven
3950227825Stheraven    template<class _A0>
3951227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&);
3952227825Stheraven
3953227825Stheraven    template<class _A0, class _A1>
3954227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3955227825Stheraven
3956227825Stheraven    template<class _A0, class _A1, class _A2>
3957227825Stheraven        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3958227825Stheraven
3959227825Stheraven    template<class _Alloc>
3960227825Stheraven        static shared_ptr<_Tp>
3961227825Stheraven        allocate_shared(const _Alloc& __a);
3962227825Stheraven
3963227825Stheraven    template<class _Alloc, class _A0>
3964227825Stheraven        static shared_ptr<_Tp>
3965227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0);
3966227825Stheraven
3967227825Stheraven    template<class _Alloc, class _A0, class _A1>
3968227825Stheraven        static shared_ptr<_Tp>
3969227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3970227825Stheraven
3971227825Stheraven    template<class _Alloc, class _A0, class _A1, class _A2>
3972227825Stheraven        static shared_ptr<_Tp>
3973227825Stheraven        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3974227825Stheraven
3975227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3976227825Stheraven
3977227825Stheravenprivate:
3978227825Stheraven
3979227825Stheraven    template <class _Yp>
3980227825Stheraven        _LIBCPP_INLINE_VISIBILITY
3981227825Stheraven        void
3982227825Stheraven        __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
3983227825Stheraven        {
3984227825Stheraven            if (__e)
3985227825Stheraven                __e->__weak_this_ = *this;
3986227825Stheraven        }
3987227825Stheraven
3988227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3989227825Stheraven    void __enable_weak_this(const void*) _NOEXCEPT {}
3990227825Stheraven
3991227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
3992227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
3993227825Stheraven};
3994227825Stheraven
3995227825Stheraventemplate<class _Tp>
3996227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
3997227825Stheravenshared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3998227825Stheraven    : __ptr_(0),
3999227825Stheraven      __cntrl_(0)
4000227825Stheraven{
4001227825Stheraven}
4002227825Stheraven
4003227825Stheraventemplate<class _Tp>
4004227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4005227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4006227825Stheraven    : __ptr_(0),
4007227825Stheraven      __cntrl_(0)
4008227825Stheraven{
4009227825Stheraven}
4010227825Stheraven
4011227825Stheraventemplate<class _Tp>
4012232924Stheraventemplate<class _Yp, class>
4013227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p)
4014227825Stheraven    : __ptr_(__p)
4015227825Stheraven{
4016227825Stheraven    unique_ptr<_Yp> __hold(__p);
4017227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4018227825Stheraven    __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4019227825Stheraven    __hold.release();
4020227825Stheraven    __enable_weak_this(__p);
4021227825Stheraven}
4022227825Stheraven
4023227825Stheraventemplate<class _Tp>
4024232924Stheraventemplate<class _Yp, class _Dp, class>
4025227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
4026227825Stheraven    : __ptr_(__p)
4027227825Stheraven{
4028227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4029227825Stheraven    try
4030227825Stheraven    {
4031227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4032227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4033227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4034227825Stheraven        __enable_weak_this(__p);
4035227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4036227825Stheraven    }
4037227825Stheraven    catch (...)
4038227825Stheraven    {
4039227825Stheraven        __d(__p);
4040227825Stheraven        throw;
4041227825Stheraven    }
4042227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4043227825Stheraven}
4044227825Stheraven
4045227825Stheraventemplate<class _Tp>
4046227825Stheraventemplate<class _Dp>
4047227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4048227825Stheraven    : __ptr_(0)
4049227825Stheraven{
4050227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4051227825Stheraven    try
4052227825Stheraven    {
4053227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4054227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4055227825Stheraven        __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4056227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4057227825Stheraven    }
4058227825Stheraven    catch (...)
4059227825Stheraven    {
4060227825Stheraven        __d(__p);
4061227825Stheraven        throw;
4062227825Stheraven    }
4063227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4064227825Stheraven}
4065227825Stheraven
4066227825Stheraventemplate<class _Tp>
4067232924Stheraventemplate<class _Yp, class _Dp, class _Alloc, class>
4068227825Stheravenshared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
4069227825Stheraven    : __ptr_(__p)
4070227825Stheraven{
4071227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4072227825Stheraven    try
4073227825Stheraven    {
4074227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4075227825Stheraven        typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4076227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4077227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4078227825Stheraven        _A2 __a2(__a);
4079227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4080227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4081227825Stheraven        __cntrl_ = __hold2.release();
4082227825Stheraven        __enable_weak_this(__p);
4083227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4084227825Stheraven    }
4085227825Stheraven    catch (...)
4086227825Stheraven    {
4087227825Stheraven        __d(__p);
4088227825Stheraven        throw;
4089227825Stheraven    }
4090227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4091227825Stheraven}
4092227825Stheraven
4093227825Stheraventemplate<class _Tp>
4094227825Stheraventemplate<class _Dp, class _Alloc>
4095227825Stheravenshared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4096227825Stheraven    : __ptr_(0)
4097227825Stheraven{
4098227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4099227825Stheraven    try
4100227825Stheraven    {
4101227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4102227825Stheraven        typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4103227825Stheraven        typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4104227825Stheraven        typedef __allocator_destructor<_A2> _D2;
4105227825Stheraven        _A2 __a2(__a);
4106227825Stheraven        unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4107227825Stheraven        ::new(__hold2.get()) _CntrlBlk(__p, __d, __a);
4108227825Stheraven        __cntrl_ = __hold2.release();
4109227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
4110227825Stheraven    }
4111227825Stheraven    catch (...)
4112227825Stheraven    {
4113227825Stheraven        __d(__p);
4114227825Stheraven        throw;
4115227825Stheraven    }
4116227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
4117227825Stheraven}
4118227825Stheraven
4119227825Stheraventemplate<class _Tp>
4120227825Stheraventemplate<class _Yp>
4121227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4122227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4123227825Stheraven    : __ptr_(__p),
4124227825Stheraven      __cntrl_(__r.__cntrl_)
4125227825Stheraven{
4126227825Stheraven    if (__cntrl_)
4127227825Stheraven        __cntrl_->__add_shared();
4128227825Stheraven}
4129227825Stheraven
4130227825Stheraventemplate<class _Tp>
4131227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4132227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4133227825Stheraven    : __ptr_(__r.__ptr_),
4134227825Stheraven      __cntrl_(__r.__cntrl_)
4135227825Stheraven{
4136227825Stheraven    if (__cntrl_)
4137227825Stheraven        __cntrl_->__add_shared();
4138227825Stheraven}
4139227825Stheraven
4140227825Stheraventemplate<class _Tp>
4141227825Stheraventemplate<class _Yp>
4142227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4143227825Stheravenshared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4144227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4145227825Stheraven         _NOEXCEPT
4146227825Stheraven    : __ptr_(__r.__ptr_),
4147227825Stheraven      __cntrl_(__r.__cntrl_)
4148227825Stheraven{
4149227825Stheraven    if (__cntrl_)
4150227825Stheraven        __cntrl_->__add_shared();
4151227825Stheraven}
4152227825Stheraven
4153227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4154227825Stheraven
4155227825Stheraventemplate<class _Tp>
4156227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4157227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4158227825Stheraven    : __ptr_(__r.__ptr_),
4159227825Stheraven      __cntrl_(__r.__cntrl_)
4160227825Stheraven{
4161227825Stheraven    __r.__ptr_ = 0;
4162227825Stheraven    __r.__cntrl_ = 0;
4163227825Stheraven}
4164227825Stheraven
4165227825Stheraventemplate<class _Tp>
4166227825Stheraventemplate<class _Yp>
4167227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4168227825Stheravenshared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4169227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
4170227825Stheraven         _NOEXCEPT
4171227825Stheraven    : __ptr_(__r.__ptr_),
4172227825Stheraven      __cntrl_(__r.__cntrl_)
4173227825Stheraven{
4174227825Stheraven    __r.__ptr_ = 0;
4175227825Stheraven    __r.__cntrl_ = 0;
4176227825Stheraven}
4177227825Stheraven
4178227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4179227825Stheraven
4180227825Stheraventemplate<class _Tp>
4181232924Stheraventemplate<class _Yp, class>
4182227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4183227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
4184227825Stheraven#else
4185227825Stheravenshared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
4186227825Stheraven#endif
4187227825Stheraven    : __ptr_(__r.get())
4188227825Stheraven{
4189227825Stheraven    typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4190227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4191227825Stheraven    __enable_weak_this(__r.get());
4192227825Stheraven    __r.release();
4193227825Stheraven}
4194227825Stheraven
4195227825Stheraventemplate<class _Tp>
4196232924Stheraventemplate <class _Yp, class _Dp, class>
4197227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4198227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4199227825Stheraven#else
4200227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4201227825Stheraven#endif
4202227825Stheraven           typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type)
4203227825Stheraven    : __ptr_(__r.get())
4204227825Stheraven{
4205227825Stheraven    typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4206227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4207227825Stheraven    __enable_weak_this(__r.get());
4208227825Stheraven    __r.release();
4209227825Stheraven}
4210227825Stheraven
4211227825Stheraventemplate<class _Tp>
4212232924Stheraventemplate <class _Yp, class _Dp, class>
4213227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4214227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4215227825Stheraven#else
4216227825Stheravenshared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4217227825Stheraven#endif
4218227825Stheraven           typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type)
4219227825Stheraven    : __ptr_(__r.get())
4220227825Stheraven{
4221227825Stheraven    typedef __shared_ptr_pointer<_Yp*,
4222227825Stheraven                                 reference_wrapper<typename remove_reference<_Dp>::type>,
4223227825Stheraven                                 allocator<_Yp> > _CntrlBlk;
4224227825Stheraven    __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4225227825Stheraven    __enable_weak_this(__r.get());
4226227825Stheraven    __r.release();
4227227825Stheraven}
4228227825Stheraven
4229227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4230227825Stheraven
4231227825Stheraventemplate<class _Tp>
4232227825Stheraventemplate<class ..._Args>
4233227825Stheravenshared_ptr<_Tp>
4234227825Stheravenshared_ptr<_Tp>::make_shared(_Args&& ...__args)
4235227825Stheraven{
4236227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4237227825Stheraven    typedef allocator<_CntrlBlk> _A2;
4238227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4239227825Stheraven    _A2 __a2;
4240227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4241227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4242227825Stheraven    shared_ptr<_Tp> __r;
4243227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4244227825Stheraven    __r.__cntrl_ = __hold2.release();
4245227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4246227825Stheraven    return __r;
4247227825Stheraven}
4248227825Stheraven
4249227825Stheraventemplate<class _Tp>
4250227825Stheraventemplate<class _Alloc, class ..._Args>
4251227825Stheravenshared_ptr<_Tp>
4252227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4253227825Stheraven{
4254227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4255227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _A2;
4256227825Stheraven    typedef __allocator_destructor<_A2> _D2;
4257227825Stheraven    _A2 __a2(__a);
4258227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4259227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4260227825Stheraven    shared_ptr<_Tp> __r;
4261227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4262227825Stheraven    __r.__cntrl_ = __hold2.release();
4263227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4264227825Stheraven    return __r;
4265227825Stheraven}
4266227825Stheraven
4267227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4268227825Stheraven
4269227825Stheraventemplate<class _Tp>
4270227825Stheravenshared_ptr<_Tp>
4271227825Stheravenshared_ptr<_Tp>::make_shared()
4272227825Stheraven{
4273227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4274227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4275227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4276227825Stheraven    _Alloc2 __alloc2;
4277227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4278227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2);
4279227825Stheraven    shared_ptr<_Tp> __r;
4280227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4281227825Stheraven    __r.__cntrl_ = __hold2.release();
4282227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4283227825Stheraven    return __r;
4284227825Stheraven}
4285227825Stheraven
4286227825Stheraventemplate<class _Tp>
4287227825Stheraventemplate<class _A0>
4288227825Stheravenshared_ptr<_Tp>
4289227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0)
4290227825Stheraven{
4291227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4292227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4293227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4294227825Stheraven    _Alloc2 __alloc2;
4295227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4296227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4297227825Stheraven    shared_ptr<_Tp> __r;
4298227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4299227825Stheraven    __r.__cntrl_ = __hold2.release();
4300227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4301227825Stheraven    return __r;
4302227825Stheraven}
4303227825Stheraven
4304227825Stheraventemplate<class _Tp>
4305227825Stheraventemplate<class _A0, class _A1>
4306227825Stheravenshared_ptr<_Tp>
4307227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4308227825Stheraven{
4309227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4310227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4311227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4312227825Stheraven    _Alloc2 __alloc2;
4313227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4314227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4315227825Stheraven    shared_ptr<_Tp> __r;
4316227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4317227825Stheraven    __r.__cntrl_ = __hold2.release();
4318227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4319227825Stheraven    return __r;
4320227825Stheraven}
4321227825Stheraven
4322227825Stheraventemplate<class _Tp>
4323227825Stheraventemplate<class _A0, class _A1, class _A2>
4324227825Stheravenshared_ptr<_Tp>
4325227825Stheravenshared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4326227825Stheraven{
4327227825Stheraven    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4328227825Stheraven    typedef allocator<_CntrlBlk> _Alloc2;
4329227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4330227825Stheraven    _Alloc2 __alloc2;
4331227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4332227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4333227825Stheraven    shared_ptr<_Tp> __r;
4334227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4335227825Stheraven    __r.__cntrl_ = __hold2.release();
4336227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4337227825Stheraven    return __r;
4338227825Stheraven}
4339227825Stheraven
4340227825Stheraventemplate<class _Tp>
4341227825Stheraventemplate<class _Alloc>
4342227825Stheravenshared_ptr<_Tp>
4343227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4344227825Stheraven{
4345227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4346227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4347227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4348227825Stheraven    _Alloc2 __alloc2(__a);
4349227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4350227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a);
4351227825Stheraven    shared_ptr<_Tp> __r;
4352227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4353227825Stheraven    __r.__cntrl_ = __hold2.release();
4354227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4355227825Stheraven    return __r;
4356227825Stheraven}
4357227825Stheraven
4358227825Stheraventemplate<class _Tp>
4359227825Stheraventemplate<class _Alloc, class _A0>
4360227825Stheravenshared_ptr<_Tp>
4361227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4362227825Stheraven{
4363227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4364227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4365227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4366227825Stheraven    _Alloc2 __alloc2(__a);
4367227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4368227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0);
4369227825Stheraven    shared_ptr<_Tp> __r;
4370227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4371227825Stheraven    __r.__cntrl_ = __hold2.release();
4372227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4373227825Stheraven    return __r;
4374227825Stheraven}
4375227825Stheraven
4376227825Stheraventemplate<class _Tp>
4377227825Stheraventemplate<class _Alloc, class _A0, class _A1>
4378227825Stheravenshared_ptr<_Tp>
4379227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4380227825Stheraven{
4381227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4382227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4383227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4384227825Stheraven    _Alloc2 __alloc2(__a);
4385227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4386227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1);
4387227825Stheraven    shared_ptr<_Tp> __r;
4388227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4389227825Stheraven    __r.__cntrl_ = __hold2.release();
4390227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4391227825Stheraven    return __r;
4392227825Stheraven}
4393227825Stheraven
4394227825Stheraventemplate<class _Tp>
4395227825Stheraventemplate<class _Alloc, class _A0, class _A1, class _A2>
4396227825Stheravenshared_ptr<_Tp>
4397227825Stheravenshared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4398227825Stheraven{
4399227825Stheraven    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4400227825Stheraven    typedef typename _Alloc::template rebind<_CntrlBlk>::other _Alloc2;
4401227825Stheraven    typedef __allocator_destructor<_Alloc2> _D2;
4402227825Stheraven    _Alloc2 __alloc2(__a);
4403227825Stheraven    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4404227825Stheraven    ::new(__hold2.get()) _CntrlBlk(__a, __a0, __a1, __a2);
4405227825Stheraven    shared_ptr<_Tp> __r;
4406227825Stheraven    __r.__ptr_ = __hold2.get()->get();
4407227825Stheraven    __r.__cntrl_ = __hold2.release();
4408227825Stheraven    __r.__enable_weak_this(__r.__ptr_);
4409227825Stheraven    return __r;
4410227825Stheraven}
4411227825Stheraven
4412227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4413227825Stheraven
4414227825Stheraventemplate<class _Tp>
4415227825Stheravenshared_ptr<_Tp>::~shared_ptr()
4416227825Stheraven{
4417227825Stheraven    if (__cntrl_)
4418227825Stheraven        __cntrl_->__release_shared();
4419227825Stheraven}
4420227825Stheraven
4421227825Stheraventemplate<class _Tp>
4422227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4423227825Stheravenshared_ptr<_Tp>&
4424227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4425227825Stheraven{
4426227825Stheraven    shared_ptr(__r).swap(*this);
4427227825Stheraven    return *this;
4428227825Stheraven}
4429227825Stheraven
4430227825Stheraventemplate<class _Tp>
4431227825Stheraventemplate<class _Yp>
4432227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4433232924Stheraventypename enable_if
4434232924Stheraven<
4435232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4436232924Stheraven    shared_ptr<_Tp>&
4437232924Stheraven>::type
4438227825Stheravenshared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4439227825Stheraven{
4440227825Stheraven    shared_ptr(__r).swap(*this);
4441227825Stheraven    return *this;
4442227825Stheraven}
4443227825Stheraven
4444227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4445227825Stheraven
4446227825Stheraventemplate<class _Tp>
4447227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4448227825Stheravenshared_ptr<_Tp>&
4449227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4450227825Stheraven{
4451227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4452227825Stheraven    return *this;
4453227825Stheraven}
4454227825Stheraven
4455227825Stheraventemplate<class _Tp>
4456227825Stheraventemplate<class _Yp>
4457227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4458232924Stheraventypename enable_if
4459232924Stheraven<
4460232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4461232924Stheraven    shared_ptr<_Tp>&
4462232924Stheraven>::type
4463227825Stheravenshared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4464227825Stheraven{
4465227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4466227825Stheraven    return *this;
4467227825Stheraven}
4468227825Stheraven
4469227825Stheraventemplate<class _Tp>
4470227825Stheraventemplate<class _Yp>
4471227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4472232924Stheraventypename enable_if
4473232924Stheraven<
4474232924Stheraven    !is_array<_Yp>::value &&
4475232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4476232924Stheraven    shared_ptr<_Tp>&
4477232924Stheraven>::type
4478227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4479227825Stheraven{
4480227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4481227825Stheraven    return *this;
4482227825Stheraven}
4483227825Stheraven
4484227825Stheraventemplate<class _Tp>
4485227825Stheraventemplate <class _Yp, class _Dp>
4486227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4487232924Stheraventypename enable_if
4488232924Stheraven<
4489232924Stheraven    !is_array<_Yp>::value &&
4490232924Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4491232924Stheraven    shared_ptr<_Tp>&
4492232924Stheraven>::type
4493227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4494227825Stheraven{
4495227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4496227825Stheraven    return *this;
4497227825Stheraven}
4498227825Stheraven
4499227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4500227825Stheraven
4501227825Stheraventemplate<class _Tp>
4502227825Stheraventemplate<class _Yp>
4503227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4504232924Stheraventypename enable_if
4505232924Stheraven<
4506232924Stheraven    !is_array<_Yp>::value &&
4507232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4508232924Stheraven    shared_ptr<_Tp>&
4509232924Stheraven>::type
4510227825Stheravenshared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4511227825Stheraven{
4512227825Stheraven    shared_ptr(__r).swap(*this);
4513227825Stheraven    return *this;
4514227825Stheraven}
4515227825Stheraven
4516227825Stheraventemplate<class _Tp>
4517227825Stheraventemplate <class _Yp, class _Dp>
4518227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4519232924Stheraventypename enable_if
4520232924Stheraven<
4521232924Stheraven    !is_array<_Yp>::value &&
4522232924Stheraven    is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4523232924Stheraven    shared_ptr<_Tp>&
4524232924Stheraven>::type
4525227825Stheravenshared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4526227825Stheraven{
4527227825Stheraven    shared_ptr(_VSTD::move(__r)).swap(*this);
4528227825Stheraven    return *this;
4529227825Stheraven}
4530227825Stheraven
4531227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4532227825Stheraven
4533227825Stheraventemplate<class _Tp>
4534227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4535227825Stheravenvoid
4536227825Stheravenshared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4537227825Stheraven{
4538227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
4539227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
4540227825Stheraven}
4541227825Stheraven
4542227825Stheraventemplate<class _Tp>
4543227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4544227825Stheravenvoid
4545227825Stheravenshared_ptr<_Tp>::reset() _NOEXCEPT
4546227825Stheraven{
4547227825Stheraven    shared_ptr().swap(*this);
4548227825Stheraven}
4549227825Stheraven
4550227825Stheraventemplate<class _Tp>
4551227825Stheraventemplate<class _Yp>
4552227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4553232924Stheraventypename enable_if
4554232924Stheraven<
4555232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4556232924Stheraven    void
4557232924Stheraven>::type
4558227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p)
4559227825Stheraven{
4560227825Stheraven    shared_ptr(__p).swap(*this);
4561227825Stheraven}
4562227825Stheraven
4563227825Stheraventemplate<class _Tp>
4564227825Stheraventemplate<class _Yp, class _Dp>
4565227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4566232924Stheraventypename enable_if
4567232924Stheraven<
4568232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4569232924Stheraven    void
4570232924Stheraven>::type
4571227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4572227825Stheraven{
4573227825Stheraven    shared_ptr(__p, __d).swap(*this);
4574227825Stheraven}
4575227825Stheraven
4576227825Stheraventemplate<class _Tp>
4577227825Stheraventemplate<class _Yp, class _Dp, class _Alloc>
4578227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4579232924Stheraventypename enable_if
4580232924Stheraven<
4581232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
4582232924Stheraven    void
4583232924Stheraven>::type
4584227825Stheravenshared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4585227825Stheraven{
4586227825Stheraven    shared_ptr(__p, __d, __a).swap(*this);
4587227825Stheraven}
4588227825Stheraven
4589227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
4590227825Stheraven
4591227825Stheraventemplate<class _Tp, class ..._Args>
4592227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4593232924Stheraventypename enable_if
4594232924Stheraven<
4595232924Stheraven    !is_array<_Tp>::value,
4596232924Stheraven    shared_ptr<_Tp>
4597232924Stheraven>::type
4598227825Stheravenmake_shared(_Args&& ...__args)
4599227825Stheraven{
4600227825Stheraven    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4601227825Stheraven}
4602227825Stheraven
4603227825Stheraventemplate<class _Tp, class _Alloc, class ..._Args>
4604227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4605232924Stheraventypename enable_if
4606232924Stheraven<
4607232924Stheraven    !is_array<_Tp>::value,
4608232924Stheraven    shared_ptr<_Tp>
4609232924Stheraven>::type
4610227825Stheravenallocate_shared(const _Alloc& __a, _Args&& ...__args)
4611227825Stheraven{
4612227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4613227825Stheraven}
4614227825Stheraven
4615227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
4616227825Stheraven
4617227825Stheraventemplate<class _Tp>
4618227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4619227825Stheravenshared_ptr<_Tp>
4620227825Stheravenmake_shared()
4621227825Stheraven{
4622227825Stheraven    return shared_ptr<_Tp>::make_shared();
4623227825Stheraven}
4624227825Stheraven
4625227825Stheraventemplate<class _Tp, class _A0>
4626227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4627227825Stheravenshared_ptr<_Tp>
4628227825Stheravenmake_shared(_A0& __a0)
4629227825Stheraven{
4630227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0);
4631227825Stheraven}
4632227825Stheraven
4633227825Stheraventemplate<class _Tp, class _A0, class _A1>
4634227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4635227825Stheravenshared_ptr<_Tp>
4636227825Stheravenmake_shared(_A0& __a0, _A1& __a1)
4637227825Stheraven{
4638227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1);
4639227825Stheraven}
4640227825Stheraven
4641227825Stheraventemplate<class _Tp, class _A0, class _A1, class _A2>
4642227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4643227825Stheravenshared_ptr<_Tp>
4644227825Stheravenmake_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4645227825Stheraven{
4646227825Stheraven    return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4647227825Stheraven}
4648227825Stheraven
4649227825Stheraventemplate<class _Tp, class _Alloc>
4650227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4651227825Stheravenshared_ptr<_Tp>
4652227825Stheravenallocate_shared(const _Alloc& __a)
4653227825Stheraven{
4654227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a);
4655227825Stheraven}
4656227825Stheraven
4657227825Stheraventemplate<class _Tp, class _Alloc, class _A0>
4658227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4659227825Stheravenshared_ptr<_Tp>
4660227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0)
4661227825Stheraven{
4662227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4663227825Stheraven}
4664227825Stheraven
4665227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1>
4666227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4667227825Stheravenshared_ptr<_Tp>
4668227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4669227825Stheraven{
4670227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4671227825Stheraven}
4672227825Stheraven
4673227825Stheraventemplate<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4674227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4675227825Stheravenshared_ptr<_Tp>
4676227825Stheravenallocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4677227825Stheraven{
4678227825Stheraven    return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4679227825Stheraven}
4680227825Stheraven
4681227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
4682227825Stheraven
4683227825Stheraventemplate<class _Tp, class _Up>
4684227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4685227825Stheravenbool
4686227825Stheravenoperator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4687227825Stheraven{
4688227825Stheraven    return __x.get() == __y.get();
4689227825Stheraven}
4690227825Stheraven
4691227825Stheraventemplate<class _Tp, class _Up>
4692227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4693227825Stheravenbool
4694227825Stheravenoperator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4695227825Stheraven{
4696227825Stheraven    return !(__x == __y);
4697227825Stheraven}
4698227825Stheraven
4699227825Stheraventemplate<class _Tp, class _Up>
4700227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4701227825Stheravenbool
4702227825Stheravenoperator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4703227825Stheraven{
4704232924Stheraven    typedef typename common_type<_Tp*, _Up*>::type _V;
4705232924Stheraven    return less<_V>()(__x.get(), __y.get());
4706227825Stheraven}
4707227825Stheraven
4708232924Stheraventemplate<class _Tp, class _Up>
4709232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4710232924Stheravenbool
4711232924Stheravenoperator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4712232924Stheraven{
4713232924Stheraven    return __y < __x;
4714232924Stheraven}
4715232924Stheraven
4716232924Stheraventemplate<class _Tp, class _Up>
4717232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4718232924Stheravenbool
4719232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4720232924Stheraven{
4721232924Stheraven    return !(__y < __x);
4722232924Stheraven}
4723232924Stheraven
4724232924Stheraventemplate<class _Tp, class _Up>
4725232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4726232924Stheravenbool
4727232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4728232924Stheraven{
4729232924Stheraven    return !(__x < __y);
4730232924Stheraven}
4731232924Stheraven
4732227825Stheraventemplate<class _Tp>
4733227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4734232924Stheravenbool
4735232924Stheravenoperator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4736232924Stheraven{
4737232924Stheraven    return !__x;
4738232924Stheraven}
4739232924Stheraven
4740232924Stheraventemplate<class _Tp>
4741232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4742232924Stheravenbool
4743232924Stheravenoperator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4744232924Stheraven{
4745232924Stheraven    return !__x;
4746232924Stheraven}
4747232924Stheraven
4748232924Stheraventemplate<class _Tp>
4749232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4750232924Stheravenbool
4751232924Stheravenoperator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4752232924Stheraven{
4753232924Stheraven    return static_cast<bool>(__x);
4754232924Stheraven}
4755232924Stheraven
4756232924Stheraventemplate<class _Tp>
4757232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4758232924Stheravenbool
4759232924Stheravenoperator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4760232924Stheraven{
4761232924Stheraven    return static_cast<bool>(__x);
4762232924Stheraven}
4763232924Stheraven
4764232924Stheraventemplate<class _Tp>
4765232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4766232924Stheravenbool
4767232924Stheravenoperator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4768232924Stheraven{
4769232924Stheraven    return less<_Tp*>()(__x.get(), nullptr);
4770232924Stheraven}
4771232924Stheraven
4772232924Stheraventemplate<class _Tp>
4773232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4774232924Stheravenbool
4775232924Stheravenoperator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4776232924Stheraven{
4777232924Stheraven    return less<_Tp*>()(nullptr, __x.get());
4778232924Stheraven}
4779232924Stheraven
4780232924Stheraventemplate<class _Tp>
4781232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4782232924Stheravenbool
4783232924Stheravenoperator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4784232924Stheraven{
4785232924Stheraven    return nullptr < __x;
4786232924Stheraven}
4787232924Stheraven
4788232924Stheraventemplate<class _Tp>
4789232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4790232924Stheravenbool
4791232924Stheravenoperator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4792232924Stheraven{
4793232924Stheraven    return __x < nullptr;
4794232924Stheraven}
4795232924Stheraven
4796232924Stheraventemplate<class _Tp>
4797232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4798232924Stheravenbool
4799232924Stheravenoperator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4800232924Stheraven{
4801232924Stheraven    return !(nullptr < __x);
4802232924Stheraven}
4803232924Stheraven
4804232924Stheraventemplate<class _Tp>
4805232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4806232924Stheravenbool
4807232924Stheravenoperator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4808232924Stheraven{
4809232924Stheraven    return !(__x < nullptr);
4810232924Stheraven}
4811232924Stheraven
4812232924Stheraventemplate<class _Tp>
4813232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4814232924Stheravenbool
4815232924Stheravenoperator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4816232924Stheraven{
4817232924Stheraven    return !(__x < nullptr);
4818232924Stheraven}
4819232924Stheraven
4820232924Stheraventemplate<class _Tp>
4821232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4822232924Stheravenbool
4823232924Stheravenoperator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4824232924Stheraven{
4825232924Stheraven    return !(nullptr < __x);
4826232924Stheraven}
4827232924Stheraven
4828232924Stheraventemplate<class _Tp>
4829232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
4830227825Stheravenvoid
4831227825Stheravenswap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4832227825Stheraven{
4833227825Stheraven    __x.swap(__y);
4834227825Stheraven}
4835227825Stheraven
4836227825Stheraventemplate<class _Tp, class _Up>
4837227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4838232924Stheraventypename enable_if
4839232924Stheraven<
4840232924Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4841232924Stheraven    shared_ptr<_Tp>
4842232924Stheraven>::type
4843227825Stheravenstatic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4844227825Stheraven{
4845227825Stheraven    return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4846227825Stheraven}
4847227825Stheraven
4848227825Stheraventemplate<class _Tp, class _Up>
4849227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4850232924Stheraventypename enable_if
4851232924Stheraven<
4852232924Stheraven    !is_array<_Tp>::value && !is_array<_Up>::value,
4853232924Stheraven    shared_ptr<_Tp>
4854232924Stheraven>::type
4855227825Stheravendynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4856227825Stheraven{
4857227825Stheraven    _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4858227825Stheraven    return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4859227825Stheraven}
4860227825Stheraven
4861227825Stheraventemplate<class _Tp, class _Up>
4862232924Stheraventypename enable_if
4863232924Stheraven<
4864232924Stheraven    is_array<_Tp>::value == is_array<_Up>::value,
4865232924Stheraven    shared_ptr<_Tp>
4866232924Stheraven>::type
4867227825Stheravenconst_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4868227825Stheraven{
4869232924Stheraven    typedef typename remove_extent<_Tp>::type _RTp;
4870232924Stheraven    return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4871227825Stheraven}
4872227825Stheraven
4873227825Stheraven#ifndef _LIBCPP_NO_RTTI
4874227825Stheraven
4875227825Stheraventemplate<class _Dp, class _Tp>
4876227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4877227825Stheraven_Dp*
4878227825Stheravenget_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4879227825Stheraven{
4880227825Stheraven    return __p.template __get_deleter<_Dp>();
4881227825Stheraven}
4882227825Stheraven
4883227825Stheraven#endif  // _LIBCPP_NO_RTTI
4884227825Stheraven
4885227825Stheraventemplate<class _Tp>
4886227825Stheravenclass _LIBCPP_VISIBLE weak_ptr
4887227825Stheraven{
4888227825Stheravenpublic:
4889227825Stheraven    typedef _Tp element_type;
4890227825Stheravenprivate:
4891227825Stheraven    element_type*        __ptr_;
4892227825Stheraven    __shared_weak_count* __cntrl_;
4893227825Stheraven
4894227825Stheravenpublic:
4895227825Stheraven    weak_ptr() _NOEXCEPT;
4896227825Stheraven    template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
4897227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4898227825Stheraven                        _NOEXCEPT;
4899227825Stheraven    weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4900227825Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
4901227825Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4902227825Stheraven                         _NOEXCEPT;
4903227825Stheraven
4904232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4905232924Stheraven    weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4906232924Stheraven    template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4907232924Stheraven                   typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4908232924Stheraven                         _NOEXCEPT;
4909232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4910227825Stheraven    ~weak_ptr();
4911227825Stheraven
4912227825Stheraven    weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4913232924Stheraven    template<class _Yp>
4914232924Stheraven        typename enable_if
4915232924Stheraven        <
4916232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4917232924Stheraven            weak_ptr&
4918232924Stheraven        >::type
4919232924Stheraven        operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4920227825Stheraven
4921232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4922232924Stheraven
4923232924Stheraven    weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4924232924Stheraven    template<class _Yp>
4925232924Stheraven        typename enable_if
4926232924Stheraven        <
4927232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4928232924Stheraven            weak_ptr&
4929232924Stheraven        >::type
4930232924Stheraven        operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4931232924Stheraven
4932232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4933232924Stheraven
4934232924Stheraven    template<class _Yp>
4935232924Stheraven        typename enable_if
4936232924Stheraven        <
4937232924Stheraven            is_convertible<_Yp*, element_type*>::value,
4938232924Stheraven            weak_ptr&
4939232924Stheraven        >::type
4940232924Stheraven        operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4941232924Stheraven
4942227825Stheraven    void swap(weak_ptr& __r) _NOEXCEPT;
4943227825Stheraven    void reset() _NOEXCEPT;
4944227825Stheraven
4945227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4946227825Stheraven    long use_count() const _NOEXCEPT
4947227825Stheraven        {return __cntrl_ ? __cntrl_->use_count() : 0;}
4948227825Stheraven    _LIBCPP_INLINE_VISIBILITY
4949227825Stheraven    bool expired() const _NOEXCEPT
4950227825Stheraven        {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4951227825Stheraven    shared_ptr<_Tp> lock() const _NOEXCEPT;
4952227825Stheraven    template<class _Up>
4953227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4954227825Stheraven        bool owner_before(const shared_ptr<_Up>& __r) const
4955227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
4956227825Stheraven    template<class _Up>
4957227825Stheraven        _LIBCPP_INLINE_VISIBILITY
4958227825Stheraven        bool owner_before(const weak_ptr<_Up>& __r) const
4959227825Stheraven        {return __cntrl_ < __r.__cntrl_;}
4960227825Stheraven
4961227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE weak_ptr;
4962227825Stheraven    template <class _Up> friend class _LIBCPP_VISIBLE shared_ptr;
4963227825Stheraven};
4964227825Stheraven
4965227825Stheraventemplate<class _Tp>
4966227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4967227825Stheravenweak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4968227825Stheraven    : __ptr_(0),
4969227825Stheraven      __cntrl_(0)
4970227825Stheraven{
4971227825Stheraven}
4972227825Stheraven
4973227825Stheraventemplate<class _Tp>
4974227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4975227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
4976227825Stheraven    : __ptr_(__r.__ptr_),
4977227825Stheraven      __cntrl_(__r.__cntrl_)
4978227825Stheraven{
4979227825Stheraven    if (__cntrl_)
4980227825Stheraven        __cntrl_->__add_weak();
4981227825Stheraven}
4982227825Stheraven
4983227825Stheraventemplate<class _Tp>
4984227825Stheraventemplate<class _Yp>
4985227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4986227825Stheravenweak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
4987227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4988227825Stheraven                         _NOEXCEPT
4989227825Stheraven    : __ptr_(__r.__ptr_),
4990227825Stheraven      __cntrl_(__r.__cntrl_)
4991227825Stheraven{
4992227825Stheraven    if (__cntrl_)
4993227825Stheraven        __cntrl_->__add_weak();
4994227825Stheraven}
4995227825Stheraven
4996227825Stheraventemplate<class _Tp>
4997227825Stheraventemplate<class _Yp>
4998227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
4999227825Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5000227825Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5001227825Stheraven         _NOEXCEPT
5002227825Stheraven    : __ptr_(__r.__ptr_),
5003227825Stheraven      __cntrl_(__r.__cntrl_)
5004227825Stheraven{
5005227825Stheraven    if (__cntrl_)
5006227825Stheraven        __cntrl_->__add_weak();
5007227825Stheraven}
5008227825Stheraven
5009232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5010232924Stheraven
5011227825Stheraventemplate<class _Tp>
5012232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5013232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5014232924Stheraven    : __ptr_(__r.__ptr_),
5015232924Stheraven      __cntrl_(__r.__cntrl_)
5016232924Stheraven{
5017232924Stheraven    __r.__ptr_ = 0;
5018232924Stheraven    __r.__cntrl_ = 0;
5019232924Stheraven}
5020232924Stheraven
5021232924Stheraventemplate<class _Tp>
5022232924Stheraventemplate<class _Yp>
5023232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5024232924Stheravenweak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5025232924Stheraven                        typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5026232924Stheraven         _NOEXCEPT
5027232924Stheraven    : __ptr_(__r.__ptr_),
5028232924Stheraven      __cntrl_(__r.__cntrl_)
5029232924Stheraven{
5030232924Stheraven    __r.__ptr_ = 0;
5031232924Stheraven    __r.__cntrl_ = 0;
5032232924Stheraven}
5033232924Stheraven
5034232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5035232924Stheraven
5036232924Stheraventemplate<class _Tp>
5037227825Stheravenweak_ptr<_Tp>::~weak_ptr()
5038227825Stheraven{
5039227825Stheraven    if (__cntrl_)
5040227825Stheraven        __cntrl_->__release_weak();
5041227825Stheraven}
5042227825Stheraven
5043227825Stheraventemplate<class _Tp>
5044227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5045227825Stheravenweak_ptr<_Tp>&
5046227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5047227825Stheraven{
5048227825Stheraven    weak_ptr(__r).swap(*this);
5049227825Stheraven    return *this;
5050227825Stheraven}
5051227825Stheraven
5052227825Stheraventemplate<class _Tp>
5053227825Stheraventemplate<class _Yp>
5054227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5055232924Stheraventypename enable_if
5056232924Stheraven<
5057232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5058232924Stheraven    weak_ptr<_Tp>&
5059232924Stheraven>::type
5060227825Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5061227825Stheraven{
5062227825Stheraven    weak_ptr(__r).swap(*this);
5063227825Stheraven    return *this;
5064227825Stheraven}
5065227825Stheraven
5066232924Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5067232924Stheraven
5068227825Stheraventemplate<class _Tp>
5069232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5070232924Stheravenweak_ptr<_Tp>&
5071232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5072232924Stheraven{
5073232924Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5074232924Stheraven    return *this;
5075232924Stheraven}
5076232924Stheraven
5077232924Stheraventemplate<class _Tp>
5078227825Stheraventemplate<class _Yp>
5079227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5080232924Stheraventypename enable_if
5081232924Stheraven<
5082232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5083232924Stheraven    weak_ptr<_Tp>&
5084232924Stheraven>::type
5085232924Stheravenweak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5086232924Stheraven{
5087232924Stheraven    weak_ptr(_VSTD::move(__r)).swap(*this);
5088232924Stheraven    return *this;
5089232924Stheraven}
5090232924Stheraven
5091232924Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5092232924Stheraven
5093232924Stheraventemplate<class _Tp>
5094232924Stheraventemplate<class _Yp>
5095232924Stheraveninline _LIBCPP_INLINE_VISIBILITY
5096232924Stheraventypename enable_if
5097232924Stheraven<
5098232924Stheraven    is_convertible<_Yp*, _Tp*>::value,
5099232924Stheraven    weak_ptr<_Tp>&
5100232924Stheraven>::type
5101227825Stheravenweak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5102227825Stheraven{
5103227825Stheraven    weak_ptr(__r).swap(*this);
5104227825Stheraven    return *this;
5105227825Stheraven}
5106227825Stheraven
5107227825Stheraventemplate<class _Tp>
5108227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5109227825Stheravenvoid
5110227825Stheravenweak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5111227825Stheraven{
5112227825Stheraven    _VSTD::swap(__ptr_, __r.__ptr_);
5113227825Stheraven    _VSTD::swap(__cntrl_, __r.__cntrl_);
5114227825Stheraven}
5115227825Stheraven
5116227825Stheraventemplate<class _Tp>
5117227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5118227825Stheravenvoid
5119227825Stheravenswap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5120227825Stheraven{
5121227825Stheraven    __x.swap(__y);
5122227825Stheraven}
5123227825Stheraven
5124227825Stheraventemplate<class _Tp>
5125227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5126227825Stheravenvoid
5127227825Stheravenweak_ptr<_Tp>::reset() _NOEXCEPT
5128227825Stheraven{
5129227825Stheraven    weak_ptr().swap(*this);
5130227825Stheraven}
5131227825Stheraven
5132227825Stheraventemplate<class _Tp>
5133227825Stheraventemplate<class _Yp>
5134227825Stheravenshared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5135227825Stheraven                            typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5136227825Stheraven    : __ptr_(__r.__ptr_),
5137227825Stheraven      __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5138227825Stheraven{
5139227825Stheraven    if (__cntrl_ == 0)
5140227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
5141227825Stheraven        throw bad_weak_ptr();
5142227825Stheraven#else
5143227825Stheraven        assert(!"bad_weak_ptr");
5144227825Stheraven#endif
5145227825Stheraven}
5146227825Stheraven
5147227825Stheraventemplate<class _Tp>
5148227825Stheravenshared_ptr<_Tp>
5149227825Stheravenweak_ptr<_Tp>::lock() const _NOEXCEPT
5150227825Stheraven{
5151227825Stheraven    shared_ptr<_Tp> __r;
5152227825Stheraven    __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5153227825Stheraven    if (__r.__cntrl_)
5154227825Stheraven        __r.__ptr_ = __ptr_;
5155227825Stheraven    return __r;
5156227825Stheraven}
5157227825Stheraven
5158227825Stheraventemplate <class _Tp> struct owner_less;
5159227825Stheraven
5160227825Stheraventemplate <class _Tp>
5161227825Stheravenstruct _LIBCPP_VISIBLE owner_less<shared_ptr<_Tp> >
5162227825Stheraven    : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5163227825Stheraven{
5164227825Stheraven    typedef bool result_type;
5165227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5166227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5167227825Stheraven        {return __x.owner_before(__y);}
5168227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5169227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5170227825Stheraven        {return __x.owner_before(__y);}
5171227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5172227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5173227825Stheraven        {return __x.owner_before(__y);}
5174227825Stheraven};
5175227825Stheraven
5176227825Stheraventemplate <class _Tp>
5177227825Stheravenstruct _LIBCPP_VISIBLE owner_less<weak_ptr<_Tp> >
5178227825Stheraven    : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5179227825Stheraven{
5180227825Stheraven    typedef bool result_type;
5181227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5182227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5183227825Stheraven        {return __x.owner_before(__y);}
5184227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5185227825Stheraven    bool operator()(shared_ptr<_Tp> const& __x,   weak_ptr<_Tp> const& __y) const
5186227825Stheraven        {return __x.owner_before(__y);}
5187227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5188227825Stheraven    bool operator()(  weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5189227825Stheraven        {return __x.owner_before(__y);}
5190227825Stheraven};
5191227825Stheraven
5192227825Stheraventemplate<class _Tp>
5193227825Stheravenclass _LIBCPP_VISIBLE enable_shared_from_this
5194227825Stheraven{
5195227825Stheraven    mutable weak_ptr<_Tp> __weak_this_;
5196227825Stheravenprotected:
5197227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5198227825Stheraven    enable_shared_from_this() _NOEXCEPT {}
5199227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5200227825Stheraven    enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5201227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5202227825Stheraven    enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5203227825Stheraven        {return *this;}
5204227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5205227825Stheraven    ~enable_shared_from_this() {}
5206227825Stheravenpublic:
5207227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5208227825Stheraven    shared_ptr<_Tp> shared_from_this()
5209227825Stheraven        {return shared_ptr<_Tp>(__weak_this_);}
5210227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5211227825Stheraven    shared_ptr<_Tp const> shared_from_this() const
5212227825Stheraven        {return shared_ptr<const _Tp>(__weak_this_);}
5213227825Stheraven
5214227825Stheraven    template <class _Up> friend class shared_ptr;
5215227825Stheraven};
5216227825Stheraven
5217227825Stheraventemplate <class _Tp>
5218227825Stheravenstruct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
5219227825Stheraven{
5220227825Stheraven    typedef shared_ptr<_Tp>      argument_type;
5221227825Stheraven    typedef size_t               result_type;
5222227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5223227825Stheraven    result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5224227825Stheraven    {
5225227825Stheraven        return hash<_Tp*>()(__ptr.get());
5226227825Stheraven    }
5227227825Stheraven};
5228227825Stheraven
5229232924Stheraventemplate<class _CharT, class _Traits, class _Yp>
5230227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5231227825Stheravenbasic_ostream<_CharT, _Traits>&
5232232924Stheravenoperator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5233227825Stheraven
5234227825Stheraven//enum class
5235227825Stheravenstruct _LIBCPP_VISIBLE pointer_safety
5236227825Stheraven{
5237227825Stheraven    enum _
5238227825Stheraven    {
5239227825Stheraven        relaxed,
5240227825Stheraven        preferred,
5241227825Stheraven        strict
5242227825Stheraven    };
5243227825Stheraven
5244227825Stheraven    _ __v_;
5245227825Stheraven
5246227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5247227825Stheraven    pointer_safety(_ __v) : __v_(__v) {}
5248227825Stheraven    _LIBCPP_INLINE_VISIBILITY
5249227825Stheraven    operator int() const {return __v_;}
5250227825Stheraven};
5251227825Stheraven
5252227825Stheravenvoid declare_reachable(void* __p);
5253227825Stheravenvoid declare_no_pointers(char* __p, size_t __n);
5254227825Stheravenvoid undeclare_no_pointers(char* __p, size_t __n);
5255227825Stheravenpointer_safety get_pointer_safety() _NOEXCEPT;
5256227825Stheravenvoid* __undeclare_reachable(void* __p);
5257227825Stheraven
5258227825Stheraventemplate <class _Tp>
5259227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
5260227825Stheraven_Tp*
5261227825Stheravenundeclare_reachable(_Tp* __p)
5262227825Stheraven{
5263227825Stheraven    return static_cast<_Tp*>(__undeclare_reachable(__p));
5264227825Stheraven}
5265227825Stheraven
5266227825Stheravenvoid* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5267227825Stheraven
5268227825Stheraven_LIBCPP_END_NAMESPACE_STD
5269227825Stheraven
5270227825Stheraven#endif  // _LIBCPP_MEMORY
5271