blob: 3f7ea1a2b04f3c7337cf8f30994c0053ed4026ae [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MEMORY
12#define _LIBCPP_MEMORY
13
14/*
15 memory synopsis
16
17namespace std
18{
19
20struct allocator_arg_t { };
21constexpr allocator_arg_t allocator_arg = allocator_arg_t();
22
23template <class T, class Alloc> struct uses_allocator;
24
25template <class Ptr>
26struct pointer_traits
27{
28 typedef Ptr pointer;
29 typedef <details> element_type;
30 typedef <details> difference_type;
Howard Hinnant324bb032010-08-22 00:02:43 +000031
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000032 template <class U> using rebind = <details>;
Howard Hinnant324bb032010-08-22 00:02:43 +000033
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034 static pointer pointer_to(<details>);
35};
36
Howard Hinnant1694d232011-05-28 14:41:13 +000037template <class T>
38struct pointer_traits<T*>
39{
40 typedef T* pointer;
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
43
44 template <class U> using rebind = U*;
45
46 static pointer pointer_to(<details>) noexcept;
47};
48
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049template <class Alloc>
50struct allocator_traits
51{
52 typedef Alloc allocator_type;
53 typedef typename allocator_type::value_type
54 value_type;
55
56 typedef Alloc::pointer | value_type* pointer;
57 typedef Alloc::const_pointer
58 | pointer_traits<pointer>::rebind<const value_type>
59 const_pointer;
60 typedef Alloc::void_pointer
61 | pointer_traits<pointer>::rebind<void>
62 void_pointer;
63 typedef Alloc::const_void_pointer
64 | pointer_traits<pointer>::rebind<const void>
65 const_void_pointer;
66 typedef Alloc::difference_type
Howard Hinnant47761072010-11-18 01:40:00 +000067 | pointer_traits<pointer>::difference_type
68 difference_type;
69 typedef Alloc::size_type
70 | make_unsigned<difference_type>::type
71 size_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072 typedef Alloc::propagate_on_container_copy_assignment
73 | false_type propagate_on_container_copy_assignment;
74 typedef Alloc::propagate_on_container_move_assignment
75 | false_type propagate_on_container_move_assignment;
76 typedef Alloc::propagate_on_container_swap
77 | false_type propagate_on_container_swap;
78
79 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
80 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
81
82 static pointer allocate(allocator_type& a, size_type n);
83 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
84
Howard Hinnant1694d232011-05-28 14:41:13 +000085 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000086
87 template <class T, class... Args>
88 static void construct(allocator_type& a, T* p, Args&&... args);
89
90 template <class T>
91 static void destroy(allocator_type& a, T* p);
92
Marshall Clow08b4f3f2013-08-27 20:22:15 +000093 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094
95 static allocator_type
96 select_on_container_copy_construction(const allocator_type& a);
97};
98
99template <>
100class allocator<void>
101{
102public:
103 typedef void* pointer;
104 typedef const void* const_pointer;
105 typedef void value_type;
106
107 template <class _Up> struct rebind {typedef allocator<_Up> other;};
108};
109
110template <class T>
111class allocator
112{
113public:
114 typedef size_t size_type;
115 typedef ptrdiff_t difference_type;
116 typedef T* pointer;
117 typedef const T* const_pointer;
118 typedef typename add_lvalue_reference<T>::type reference;
119 typedef typename add_lvalue_reference<const T>::type const_reference;
120 typedef T value_type;
121
122 template <class U> struct rebind {typedef allocator<U> other;};
123
Howard Hinnant1694d232011-05-28 14:41:13 +0000124 allocator() noexcept;
125 allocator(const allocator&) noexcept;
126 template <class U> allocator(const allocator<U>&) noexcept;
127 ~allocator();
128 pointer address(reference x) const noexcept;
129 const_pointer address(const_reference x) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000130 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant1694d232011-05-28 14:41:13 +0000131 void deallocate(pointer p, size_type n) noexcept;
132 size_type max_size() const noexcept;
133 template<class U, class... Args>
134 void construct(U* p, Args&&... args);
135 template <class U>
136 void destroy(U* p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137};
138
139template <class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000140bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
142template <class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000143bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
145template <class OutputIterator, class T>
146class raw_storage_iterator
147 : public iterator<output_iterator_tag,
148 T, // purposefully not C++03
149 ptrdiff_t, // purposefully not C++03
150 T*, // purposefully not C++03
151 raw_storage_iterator&> // purposefully not C++03
152{
153public:
154 explicit raw_storage_iterator(OutputIterator x);
155 raw_storage_iterator& operator*();
156 raw_storage_iterator& operator=(const T& element);
157 raw_storage_iterator& operator++();
158 raw_storage_iterator operator++(int);
159};
160
Howard Hinnant1694d232011-05-28 14:41:13 +0000161template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
162template <class T> void return_temporary_buffer(T* p) noexcept;
163
164template <class T> T* addressof(T& r) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000165
166template <class InputIterator, class ForwardIterator>
167ForwardIterator
168uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
169
Howard Hinnant1694d232011-05-28 14:41:13 +0000170template <class InputIterator, class Size, class ForwardIterator>
171ForwardIterator
172uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
173
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000174template <class ForwardIterator, class T>
175void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
176
177template <class ForwardIterator, class Size, class T>
Howard Hinnant2f6a6272010-11-18 16:13:03 +0000178ForwardIterator
179uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180
181template <class Y> struct auto_ptr_ref {};
182
183template<class X>
184class auto_ptr
185{
186public:
187 typedef X element_type;
188
189 explicit auto_ptr(X* p =0) throw();
190 auto_ptr(auto_ptr&) throw();
191 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
192 auto_ptr& operator=(auto_ptr&) throw();
193 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
194 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
195 ~auto_ptr() throw();
196
197 typename add_lvalue_reference<X>::type operator*() const throw();
198 X* operator->() const throw();
199 X* get() const throw();
200 X* release() throw();
201 void reset(X* p =0) throw();
202
203 auto_ptr(auto_ptr_ref<X>) throw();
204 template<class Y> operator auto_ptr_ref<Y>() throw();
205 template<class Y> operator auto_ptr<Y>() throw();
206};
207
Howard Hinnante92c3d72010-08-19 18:39:17 +0000208template <class T>
209struct default_delete
210{
Howard Hinnant1694d232011-05-28 14:41:13 +0000211 constexpr default_delete() noexcept = default;
212 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000213
Howard Hinnant1694d232011-05-28 14:41:13 +0000214 void operator()(T*) const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000215};
216
217template <class T>
218struct default_delete<T[]>
219{
Howard Hinnant1694d232011-05-28 14:41:13 +0000220 constexpr default_delete() noexcept = default;
221 void operator()(T*) const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000222 template <class U> void operator()(U*) const = delete;
223};
224
Howard Hinnante92c3d72010-08-19 18:39:17 +0000225template <class T, class D = default_delete<T>>
226class unique_ptr
227{
228public:
229 typedef see below pointer;
230 typedef T element_type;
231 typedef D deleter_type;
232
233 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000234 constexpr unique_ptr() noexcept;
235 explicit unique_ptr(pointer p) noexcept;
236 unique_ptr(pointer p, see below d1) noexcept;
237 unique_ptr(pointer p, see below d2) noexcept;
238 unique_ptr(unique_ptr&& u) noexcept;
239 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnante92c3d72010-08-19 18:39:17 +0000240 template <class U, class E>
Howard Hinnant1694d232011-05-28 14:41:13 +0000241 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000242 template <class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000243 unique_ptr(auto_ptr<U>&& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000244
245 // destructor
246 ~unique_ptr();
247
248 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000249 unique_ptr& operator=(unique_ptr&& u) noexcept;
250 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
251 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000252
253 // observers
254 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant1694d232011-05-28 14:41:13 +0000255 pointer operator->() const noexcept;
256 pointer get() const noexcept;
257 deleter_type& get_deleter() noexcept;
258 const deleter_type& get_deleter() const noexcept;
259 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000260
261 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000262 pointer release() noexcept;
263 void reset(pointer p = pointer()) noexcept;
264 void swap(unique_ptr& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000265};
266
267template <class T, class D>
268class unique_ptr<T[], D>
269{
270public:
271 typedef implementation-defined pointer;
272 typedef T element_type;
273 typedef D deleter_type;
274
275 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000276 constexpr unique_ptr() noexcept;
277 explicit unique_ptr(pointer p) noexcept;
278 unique_ptr(pointer p, see below d) noexcept;
279 unique_ptr(pointer p, see below d) noexcept;
280 unique_ptr(unique_ptr&& u) noexcept;
281 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnante92c3d72010-08-19 18:39:17 +0000282
283 // destructor
Howard Hinnant324bb032010-08-22 00:02:43 +0000284 ~unique_ptr();
Howard Hinnante92c3d72010-08-19 18:39:17 +0000285
286 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000287 unique_ptr& operator=(unique_ptr&& u) noexcept;
288 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000289
290 // observers
291 T& operator[](size_t i) const;
Howard Hinnant1694d232011-05-28 14:41:13 +0000292 pointer get() const noexcept;
293 deleter_type& get_deleter() noexcept;
294 const deleter_type& get_deleter() const noexcept;
295 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000296
297 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000298 pointer release() noexcept;
299 void reset(pointer p = pointer()) noexcept;
300 void reset(nullptr_t) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000301 template <class U> void reset(U) = delete;
Howard Hinnant1694d232011-05-28 14:41:13 +0000302 void swap(unique_ptr& u) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000303};
304
305template <class T, class D>
Howard Hinnant1694d232011-05-28 14:41:13 +0000306 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000307
308template <class T1, class D1, class T2, class D2>
309 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
310template <class T1, class D1, class T2, class D2>
311 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
312template <class T1, class D1, class T2, class D2>
313 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
314template <class T1, class D1, class T2, class D2>
315 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
316template <class T1, class D1, class T2, class D2>
317 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
318template <class T1, class D1, class T2, class D2>
319 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
320
Howard Hinnant1694d232011-05-28 14:41:13 +0000321template <class T, class D>
322 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
323template <class T, class D>
324 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
325template <class T, class D>
326 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
327template <class T, class D>
328 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
329
330template <class T, class D>
331 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
332template <class T, class D>
333 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
334template <class T, class D>
335 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
336template <class T, class D>
337 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
338template <class T, class D>
339 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
340template <class T, class D>
341 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
342template <class T, class D>
343 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
344template <class T, class D>
345 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
346
Howard Hinnante92c3d72010-08-19 18:39:17 +0000347class bad_weak_ptr
348 : public std::exception
349{
Howard Hinnant1694d232011-05-28 14:41:13 +0000350 bad_weak_ptr() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000351};
352
Marshall Clowfd7481e2013-07-01 18:16:03 +0000353template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
354template<class T> unique_ptr<T> make_unique(size_t n); // C++14
355template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
356
Howard Hinnante92c3d72010-08-19 18:39:17 +0000357template<class T>
358class shared_ptr
359{
360public:
361 typedef T element_type;
362
363 // constructors:
Howard Hinnant1694d232011-05-28 14:41:13 +0000364 constexpr shared_ptr() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000365 template<class Y> explicit shared_ptr(Y* p);
366 template<class Y, class D> shared_ptr(Y* p, D d);
367 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
368 template <class D> shared_ptr(nullptr_t p, D d);
369 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant1694d232011-05-28 14:41:13 +0000370 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
371 shared_ptr(const shared_ptr& r) noexcept;
372 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
373 shared_ptr(shared_ptr&& r) noexcept;
374 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000375 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
376 template<class Y> shared_ptr(auto_ptr<Y>&& r);
377 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
378 shared_ptr(nullptr_t) : shared_ptr() { }
379
380 // destructor:
381 ~shared_ptr();
382
383 // assignment:
Howard Hinnant1694d232011-05-28 14:41:13 +0000384 shared_ptr& operator=(const shared_ptr& r) noexcept;
385 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
386 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000387 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
388 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
389 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
390
391 // modifiers:
Howard Hinnant1694d232011-05-28 14:41:13 +0000392 void swap(shared_ptr& r) noexcept;
393 void reset() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000394 template<class Y> void reset(Y* p);
395 template<class Y, class D> void reset(Y* p, D d);
396 template<class Y, class D, class A> void reset(Y* p, D d, A a);
397
Howard Hinnant1694d232011-05-28 14:41:13 +0000398 // observers:
399 T* get() const noexcept;
400 T& operator*() const noexcept;
401 T* operator->() const noexcept;
402 long use_count() const noexcept;
403 bool unique() const noexcept;
404 explicit operator bool() const noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000405 template<class U> bool owner_before(shared_ptr<U> const& b) const;
406 template<class U> bool owner_before(weak_ptr<U> const& b) const;
407};
408
409// shared_ptr comparisons:
410template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000411 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000412template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000413 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000414template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000415 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000416template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000417 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000418template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000419 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000420template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000421 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
422
423template <class T>
424 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
425template <class T>
426 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
427template <class T>
428 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
429template <class T>
430 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
431template <class T>
432 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
433template <class T>
434bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
435template <class T>
436 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
437template <class T>
438 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
439template <class T>
440 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
441template <class T>
442 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
443template <class T>
444 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
445template <class T>
446 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000447
448// shared_ptr specialized algorithms:
Howard Hinnant1694d232011-05-28 14:41:13 +0000449template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000450
451// shared_ptr casts:
452template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000453 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000454template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000455 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000456template<class T, class U>
Howard Hinnant1694d232011-05-28 14:41:13 +0000457 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000458
459// shared_ptr I/O:
460template<class E, class T, class Y>
461 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
462
463// shared_ptr get_deleter:
Howard Hinnant1694d232011-05-28 14:41:13 +0000464template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000465
466template<class T, class... Args>
467 shared_ptr<T> make_shared(Args&&... args);
468template<class T, class A, class... Args>
469 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
470
471template<class T>
472class weak_ptr
473{
474public:
475 typedef T element_type;
476
477 // constructors
Howard Hinnant1694d232011-05-28 14:41:13 +0000478 constexpr weak_ptr() noexcept;
479 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
480 weak_ptr(weak_ptr const& r) noexcept;
481 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Marshall Clow23ef1512014-03-05 03:12:04 +0000482 weak_ptr(weak_ptr&& r) noexcept; // C++14
483 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnante92c3d72010-08-19 18:39:17 +0000484
485 // destructor
486 ~weak_ptr();
487
488 // assignment
Howard Hinnant1694d232011-05-28 14:41:13 +0000489 weak_ptr& operator=(weak_ptr const& r) noexcept;
490 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
491 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Marshall Clow23ef1512014-03-05 03:12:04 +0000492 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
493 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnante92c3d72010-08-19 18:39:17 +0000494
495 // modifiers
Howard Hinnant1694d232011-05-28 14:41:13 +0000496 void swap(weak_ptr& r) noexcept;
497 void reset() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000498
499 // observers
Howard Hinnant1694d232011-05-28 14:41:13 +0000500 long use_count() const noexcept;
501 bool expired() const noexcept;
502 shared_ptr<T> lock() const noexcept;
Marshall Clow1b5f3ad2013-09-03 14:37:50 +0000503 template<class U> bool owner_before(shared_ptr<U> const& b) const;
504 template<class U> bool owner_before(weak_ptr<U> const& b) const;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000505};
506
507// weak_ptr specialized algorithms:
Howard Hinnant1694d232011-05-28 14:41:13 +0000508template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000509
510// class owner_less:
511template<class T> struct owner_less;
512
513template<class T>
514struct owner_less<shared_ptr<T>>
515 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
516{
517 typedef bool result_type;
518 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
519 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
520 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
521};
522
523template<class T>
524struct owner_less<weak_ptr<T>>
525 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
526{
527 typedef bool result_type;
528 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
529 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
530 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
531};
532
533template<class T>
534class enable_shared_from_this
535{
536protected:
Howard Hinnant1694d232011-05-28 14:41:13 +0000537 constexpr enable_shared_from_this() noexcept;
538 enable_shared_from_this(enable_shared_from_this const&) noexcept;
539 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000540 ~enable_shared_from_this();
541public:
542 shared_ptr<T> shared_from_this();
543 shared_ptr<T const> shared_from_this() const;
544};
545
546template<class T>
547 bool atomic_is_lock_free(const shared_ptr<T>* p);
548template<class T>
549 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
550template<class T>
551 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
552template<class T>
553 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
554template<class T>
555 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
556template<class T>
557 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
558template<class T>
559 shared_ptr<T>
560 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
561template<class T>
562 bool
563 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
564template<class T>
565 bool
566 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
567template<class T>
568 bool
569 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
570 shared_ptr<T> w, memory_order success,
571 memory_order failure);
572template<class T>
573 bool
574 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
575 shared_ptr<T> w, memory_order success,
576 memory_order failure);
577// Hash support
578template <class T> struct hash;
579template <class T, class D> struct hash<unique_ptr<T, D> >;
580template <class T> struct hash<shared_ptr<T> >;
581
582// Pointer safety
583enum class pointer_safety { relaxed, preferred, strict };
584void declare_reachable(void *p);
585template <class T> T *undeclare_reachable(T *p);
586void declare_no_pointers(char *p, size_t n);
587void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant1694d232011-05-28 14:41:13 +0000588pointer_safety get_pointer_safety() noexcept;
Howard Hinnante92c3d72010-08-19 18:39:17 +0000589
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
591
592} // std
593
594*/
595
596#include <__config>
597#include <type_traits>
598#include <typeinfo>
599#include <cstddef>
600#include <cstdint>
601#include <new>
602#include <utility>
603#include <limits>
604#include <iterator>
605#include <__functional_base>
Howard Hinnant464aa5c2011-07-18 15:51:59 +0000606#include <iosfwd>
Howard Hinnant6cc99fa2011-12-19 17:58:44 +0000607#include <tuple>
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +0000608#include <cstring>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609#if defined(_LIBCPP_NO_EXCEPTIONS)
610 #include <cassert>
611#endif
612
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +0000613#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +0000614# include <atomic>
615#endif
616
Howard Hinnant66c6f972011-11-29 16:45:27 +0000617#include <__undef_min_max>
Saleem Abdulrasoolf1b30c42015-02-13 22:15:32 +0000618#include <__undef___deallocate>
Howard Hinnant66c6f972011-11-29 16:45:27 +0000619
Howard Hinnant08e17472011-10-17 20:05:10 +0000620#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000622#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623
624_LIBCPP_BEGIN_NAMESPACE_STD
625
Howard Hinnanta4e87ab2013-08-08 18:38:55 +0000626// addressof moved to <__functional_base>
Douglas Gregor35d2fcf2011-06-22 22:17:44 +0000627
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628template <class _Tp> class allocator;
629
630template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000631class _LIBCPP_TYPE_VIS_ONLY allocator<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632{
633public:
634 typedef void* pointer;
635 typedef const void* const_pointer;
636 typedef void value_type;
637
638 template <class _Up> struct rebind {typedef allocator<_Up> other;};
639};
640
Howard Hinnanta1877872012-01-19 23:15:22 +0000641template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000642class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
Howard Hinnanta1877872012-01-19 23:15:22 +0000643{
644public:
645 typedef const void* pointer;
646 typedef const void* const_pointer;
647 typedef const void value_type;
648
649 template <class _Up> struct rebind {typedef allocator<_Up> other;};
650};
651
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652// pointer_traits
653
654template <class _Tp>
655struct __has_element_type
656{
657private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000658 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 template <class _Up> static __two __test(...);
660 template <class _Up> static char __test(typename _Up::element_type* = 0);
661public:
662 static const bool value = sizeof(__test<_Tp>(0)) == 1;
663};
664
665template <class _Ptr, bool = __has_element_type<_Ptr>::value>
666struct __pointer_traits_element_type;
667
668template <class _Ptr>
669struct __pointer_traits_element_type<_Ptr, true>
670{
671 typedef typename _Ptr::element_type type;
672};
673
674#ifndef _LIBCPP_HAS_NO_VARIADICS
675
676template <template <class, class...> class _Sp, class _Tp, class ..._Args>
677struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
678{
679 typedef typename _Sp<_Tp, _Args...>::element_type type;
680};
681
682template <template <class, class...> class _Sp, class _Tp, class ..._Args>
683struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
684{
685 typedef _Tp type;
686};
687
Howard Hinnant324bb032010-08-22 00:02:43 +0000688#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689
690template <template <class> class _Sp, class _Tp>
691struct __pointer_traits_element_type<_Sp<_Tp>, true>
692{
693 typedef typename _Sp<_Tp>::element_type type;
694};
695
696template <template <class> class _Sp, class _Tp>
697struct __pointer_traits_element_type<_Sp<_Tp>, false>
698{
699 typedef _Tp type;
700};
701
702template <template <class, class> class _Sp, class _Tp, class _A0>
703struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
704{
705 typedef typename _Sp<_Tp, _A0>::element_type type;
706};
707
708template <template <class, class> class _Sp, class _Tp, class _A0>
709struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
710{
711 typedef _Tp type;
712};
713
714template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
715struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
716{
717 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
718};
719
720template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
721struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
722{
723 typedef _Tp type;
724};
725
726template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
727 class _A1, class _A2>
728struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
729{
730 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
731};
732
733template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
734 class _A1, class _A2>
735struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
736{
737 typedef _Tp type;
738};
739
Howard Hinnant324bb032010-08-22 00:02:43 +0000740#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741
742template <class _Tp>
743struct __has_difference_type
744{
745private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000746 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 template <class _Up> static __two __test(...);
748 template <class _Up> static char __test(typename _Up::difference_type* = 0);
749public:
750 static const bool value = sizeof(__test<_Tp>(0)) == 1;
751};
752
753template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
754struct __pointer_traits_difference_type
755{
756 typedef ptrdiff_t type;
757};
758
759template <class _Ptr>
760struct __pointer_traits_difference_type<_Ptr, true>
761{
762 typedef typename _Ptr::difference_type type;
763};
764
765template <class _Tp, class _Up>
766struct __has_rebind
767{
768private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000769 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 template <class _Xp> static __two __test(...);
771 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
772public:
773 static const bool value = sizeof(__test<_Tp>(0)) == 1;
774};
775
776template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
777struct __pointer_traits_rebind
778{
779#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
780 typedef typename _Tp::template rebind<_Up> type;
781#else
782 typedef typename _Tp::template rebind<_Up>::other type;
783#endif
784};
785
786#ifndef _LIBCPP_HAS_NO_VARIADICS
787
788template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
789struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
790{
791#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
792 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
793#else
794 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
795#endif
796};
797
798template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
799struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
800{
801 typedef _Sp<_Up, _Args...> type;
802};
803
Howard Hinnant324bb032010-08-22 00:02:43 +0000804#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000805
806template <template <class> class _Sp, class _Tp, class _Up>
807struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
808{
809#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
810 typedef typename _Sp<_Tp>::template rebind<_Up> type;
811#else
812 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
813#endif
814};
815
816template <template <class> class _Sp, class _Tp, class _Up>
817struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
818{
819 typedef _Sp<_Up> type;
820};
821
822template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
823struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
824{
825#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
826 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
827#else
828 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
829#endif
830};
831
832template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
833struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
834{
835 typedef _Sp<_Up, _A0> type;
836};
837
838template <template <class, class, class> class _Sp, class _Tp, class _A0,
839 class _A1, class _Up>
840struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
841{
842#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
843 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
844#else
845 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
846#endif
847};
848
849template <template <class, class, class> class _Sp, class _Tp, class _A0,
850 class _A1, class _Up>
851struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
852{
853 typedef _Sp<_Up, _A0, _A1> type;
854};
855
856template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
857 class _A1, class _A2, class _Up>
858struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
859{
860#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
861 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
862#else
863 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
864#endif
865};
866
867template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
868 class _A1, class _A2, class _Up>
869struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
870{
871 typedef _Sp<_Up, _A0, _A1, _A2> type;
872};
873
Howard Hinnant324bb032010-08-22 00:02:43 +0000874#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875
876template <class _Ptr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000877struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878{
879 typedef _Ptr pointer;
880 typedef typename __pointer_traits_element_type<pointer>::type element_type;
881 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
882
883#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant6b41c602011-05-11 20:21:19 +0000884 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000885#else
886 template <class _Up> struct rebind
887 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Howard Hinnant324bb032010-08-22 00:02:43 +0000888#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889
890private:
891 struct __nat {};
892public:
Howard Hinnant82894812010-09-22 16:48:34 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 static pointer pointer_to(typename conditional<is_void<element_type>::value,
895 __nat, element_type>::type& __r)
896 {return pointer::pointer_to(__r);}
897};
898
899template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000900struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901{
902 typedef _Tp* pointer;
903 typedef _Tp element_type;
904 typedef ptrdiff_t difference_type;
905
906#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
907 template <class _Up> using rebind = _Up*;
908#else
909 template <class _Up> struct rebind {typedef _Up* other;};
910#endif
911
912private:
913 struct __nat {};
914public:
Howard Hinnant82894812010-09-22 16:48:34 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant1694d232011-05-28 14:41:13 +0000917 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +0000918 {return _VSTD::addressof(__r);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000919};
920
921// allocator_traits
922
923namespace __has_pointer_type_imp
924{
Howard Hinnant81277582013-09-21 01:45:05 +0000925 template <class _Up> static __two __test(...);
926 template <class _Up> static char __test(typename _Up::pointer* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927}
928
929template <class _Tp>
930struct __has_pointer_type
Howard Hinnant81277582013-09-21 01:45:05 +0000931 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932{
933};
934
935namespace __pointer_type_imp
936{
937
938template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
939struct __pointer_type
940{
941 typedef typename _Dp::pointer type;
942};
943
944template <class _Tp, class _Dp>
945struct __pointer_type<_Tp, _Dp, false>
946{
947 typedef _Tp* type;
948};
949
Howard Hinnant47761072010-11-18 01:40:00 +0000950} // __pointer_type_imp
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951
952template <class _Tp, class _Dp>
953struct __pointer_type
954{
955 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
956};
957
958template <class _Tp>
959struct __has_const_pointer
960{
961private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000962 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000963 template <class _Up> static __two __test(...);
964 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
965public:
966 static const bool value = sizeof(__test<_Tp>(0)) == 1;
967};
968
969template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
970struct __const_pointer
971{
972 typedef typename _Alloc::const_pointer type;
973};
974
975template <class _Tp, class _Ptr, class _Alloc>
976struct __const_pointer<_Tp, _Ptr, _Alloc, false>
977{
978#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
979 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
980#else
981 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
982#endif
983};
984
985template <class _Tp>
986struct __has_void_pointer
987{
988private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000989 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 template <class _Up> static __two __test(...);
991 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
992public:
993 static const bool value = sizeof(__test<_Tp>(0)) == 1;
994};
995
996template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
997struct __void_pointer
998{
999 typedef typename _Alloc::void_pointer type;
1000};
1001
1002template <class _Ptr, class _Alloc>
1003struct __void_pointer<_Ptr, _Alloc, false>
1004{
1005#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1006 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1007#else
1008 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1009#endif
1010};
1011
1012template <class _Tp>
1013struct __has_const_void_pointer
1014{
1015private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001016 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017 template <class _Up> static __two __test(...);
1018 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1019public:
1020 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1021};
1022
1023template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1024struct __const_void_pointer
1025{
1026 typedef typename _Alloc::const_void_pointer type;
1027};
1028
1029template <class _Ptr, class _Alloc>
1030struct __const_void_pointer<_Ptr, _Alloc, false>
1031{
1032#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1033 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1034#else
1035 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1036#endif
1037};
1038
Howard Hinnant99968442011-11-29 18:15:50 +00001039template <class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001041_Tp*
1042__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043{
1044 return __p;
1045}
1046
1047template <class _Pointer>
1048inline _LIBCPP_INLINE_VISIBILITY
1049typename pointer_traits<_Pointer>::element_type*
Howard Hinnant1694d232011-05-28 14:41:13 +00001050__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001052 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053}
1054
1055template <class _Tp>
1056struct __has_size_type
1057{
1058private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001059 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060 template <class _Up> static __two __test(...);
1061 template <class _Up> static char __test(typename _Up::size_type* = 0);
1062public:
1063 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1064};
1065
Howard Hinnant47761072010-11-18 01:40:00 +00001066template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067struct __size_type
1068{
Howard Hinnant47761072010-11-18 01:40:00 +00001069 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070};
1071
Howard Hinnant47761072010-11-18 01:40:00 +00001072template <class _Alloc, class _DiffType>
1073struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001074{
1075 typedef typename _Alloc::size_type type;
1076};
1077
1078template <class _Tp>
1079struct __has_propagate_on_container_copy_assignment
1080{
1081private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001082 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083 template <class _Up> static __two __test(...);
1084 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1085public:
1086 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1087};
1088
1089template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1090struct __propagate_on_container_copy_assignment
1091{
1092 typedef false_type type;
1093};
1094
1095template <class _Alloc>
1096struct __propagate_on_container_copy_assignment<_Alloc, true>
1097{
1098 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1099};
1100
1101template <class _Tp>
1102struct __has_propagate_on_container_move_assignment
1103{
1104private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001105 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 template <class _Up> static __two __test(...);
1107 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1108public:
1109 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1110};
1111
1112template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1113struct __propagate_on_container_move_assignment
1114{
1115 typedef false_type type;
1116};
1117
1118template <class _Alloc>
1119struct __propagate_on_container_move_assignment<_Alloc, true>
1120{
1121 typedef typename _Alloc::propagate_on_container_move_assignment type;
1122};
1123
1124template <class _Tp>
1125struct __has_propagate_on_container_swap
1126{
1127private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001128 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 template <class _Up> static __two __test(...);
1130 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1131public:
1132 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1133};
1134
1135template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1136struct __propagate_on_container_swap
1137{
1138 typedef false_type type;
1139};
1140
1141template <class _Alloc>
1142struct __propagate_on_container_swap<_Alloc, true>
1143{
1144 typedef typename _Alloc::propagate_on_container_swap type;
1145};
1146
1147template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1148struct __has_rebind_other
1149{
1150private:
Howard Hinnant9c0df142012-10-30 19:06:59 +00001151 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152 template <class _Xp> static __two __test(...);
1153 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1154public:
1155 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1156};
1157
1158template <class _Tp, class _Up>
1159struct __has_rebind_other<_Tp, _Up, false>
1160{
1161 static const bool value = false;
1162};
1163
1164template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1165struct __allocator_traits_rebind
1166{
1167 typedef typename _Tp::template rebind<_Up>::other type;
1168};
1169
1170#ifndef _LIBCPP_HAS_NO_VARIADICS
1171
1172template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1173struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1174{
1175 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1176};
1177
1178template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1179struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1180{
1181 typedef _Alloc<_Up, _Args...> type;
1182};
1183
Howard Hinnant324bb032010-08-22 00:02:43 +00001184#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185
1186template <template <class> class _Alloc, class _Tp, class _Up>
1187struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1188{
1189 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1190};
1191
1192template <template <class> class _Alloc, class _Tp, class _Up>
1193struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1194{
1195 typedef _Alloc<_Up> type;
1196};
1197
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1199struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1200{
1201 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1202};
1203
1204template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1205struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1206{
1207 typedef _Alloc<_Up, _A0> type;
1208};
1209
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1211 class _A1, class _Up>
1212struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1213{
1214 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1215};
1216
1217template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1218 class _A1, class _Up>
1219struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1220{
1221 typedef _Alloc<_Up, _A0, _A1> type;
1222};
1223
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1225 class _A1, class _A2, class _Up>
1226struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1227{
1228 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1229};
1230
1231template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1232 class _A1, class _A2, class _Up>
1233struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1234{
1235 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1236};
1237
Howard Hinnant324bb032010-08-22 00:02:43 +00001238#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001239
1240#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1241
1242template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1243auto
1244__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1245 -> decltype(__a.allocate(__sz, __p), true_type());
1246
1247template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1248auto
1249__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1250 -> false_type;
1251
1252template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1253struct __has_allocate_hint
1254 : integral_constant<bool,
1255 is_same<
1256 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1257 declval<_SizeType>(),
1258 declval<_ConstVoidPtr>())),
1259 true_type>::value>
1260{
1261};
1262
Howard Hinnant324bb032010-08-22 00:02:43 +00001263#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264
1265template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1266struct __has_allocate_hint
1267 : true_type
1268{
1269};
1270
Howard Hinnant324bb032010-08-22 00:02:43 +00001271#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001272
Howard Hinnant23369ee2011-07-29 21:35:53 +00001273#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274
1275template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnant0949eed2011-06-30 21:18:19 +00001276decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1277 _VSTD::declval<_Args>()...),
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278 true_type())
1279__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1280
1281template <class _Alloc, class _Pointer, class ..._Args>
1282false_type
1283__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1284
1285template <class _Alloc, class _Pointer, class ..._Args>
1286struct __has_construct
1287 : integral_constant<bool,
1288 is_same<
1289 decltype(__has_construct_test(declval<_Alloc>(),
1290 declval<_Pointer>(),
1291 declval<_Args>()...)),
1292 true_type>::value>
1293{
1294};
1295
1296template <class _Alloc, class _Pointer>
1297auto
1298__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1299 -> decltype(__a.destroy(__p), true_type());
1300
1301template <class _Alloc, class _Pointer>
1302auto
1303__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1304 -> false_type;
1305
1306template <class _Alloc, class _Pointer>
1307struct __has_destroy
1308 : integral_constant<bool,
1309 is_same<
1310 decltype(__has_destroy_test(declval<_Alloc>(),
1311 declval<_Pointer>())),
1312 true_type>::value>
1313{
1314};
1315
1316template <class _Alloc>
1317auto
1318__has_max_size_test(_Alloc&& __a)
1319 -> decltype(__a.max_size(), true_type());
1320
1321template <class _Alloc>
1322auto
1323__has_max_size_test(const volatile _Alloc& __a)
1324 -> false_type;
1325
1326template <class _Alloc>
1327struct __has_max_size
1328 : integral_constant<bool,
1329 is_same<
1330 decltype(__has_max_size_test(declval<_Alloc&>())),
1331 true_type>::value>
1332{
1333};
1334
1335template <class _Alloc>
1336auto
1337__has_select_on_container_copy_construction_test(_Alloc&& __a)
1338 -> decltype(__a.select_on_container_copy_construction(), true_type());
1339
1340template <class _Alloc>
1341auto
1342__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1343 -> false_type;
1344
1345template <class _Alloc>
1346struct __has_select_on_container_copy_construction
1347 : integral_constant<bool,
1348 is_same<
1349 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1350 true_type>::value>
1351{
1352};
1353
Howard Hinnant324bb032010-08-22 00:02:43 +00001354#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355
1356#ifndef _LIBCPP_HAS_NO_VARIADICS
1357
1358template <class _Alloc, class _Pointer, class ..._Args>
1359struct __has_construct
1360 : false_type
1361{
1362};
1363
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001364#else // _LIBCPP_HAS_NO_VARIADICS
1365
1366template <class _Alloc, class _Pointer, class _Args>
1367struct __has_construct
1368 : false_type
1369{
1370};
1371
Howard Hinnant324bb032010-08-22 00:02:43 +00001372#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373
1374template <class _Alloc, class _Pointer>
1375struct __has_destroy
1376 : false_type
1377{
1378};
1379
1380template <class _Alloc>
1381struct __has_max_size
1382 : true_type
1383{
1384};
1385
1386template <class _Alloc>
1387struct __has_select_on_container_copy_construction
1388 : false_type
1389{
1390};
1391
Howard Hinnant324bb032010-08-22 00:02:43 +00001392#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393
Howard Hinnant47761072010-11-18 01:40:00 +00001394template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1395struct __alloc_traits_difference_type
1396{
1397 typedef typename pointer_traits<_Ptr>::difference_type type;
1398};
1399
1400template <class _Alloc, class _Ptr>
1401struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1402{
1403 typedef typename _Alloc::difference_type type;
1404};
1405
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406template <class _Alloc>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001407struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408{
1409 typedef _Alloc allocator_type;
1410 typedef typename allocator_type::value_type value_type;
1411
1412 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1413 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1414 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1415 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1416
Howard Hinnant47761072010-11-18 01:40:00 +00001417 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1418 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419
1420 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1421 propagate_on_container_copy_assignment;
1422 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1423 propagate_on_container_move_assignment;
1424 typedef typename __propagate_on_container_swap<allocator_type>::type
1425 propagate_on_container_swap;
1426
1427#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1428 template <class _Tp> using rebind_alloc =
Howard Hinnant6b41c602011-05-11 20:21:19 +00001429 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Howard Hinnant324bb032010-08-22 00:02:43 +00001431#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 template <class _Tp> struct rebind_alloc
1433 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1434 template <class _Tp> struct rebind_traits
1435 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Howard Hinnant324bb032010-08-22 00:02:43 +00001436#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437
Howard Hinnant82894812010-09-22 16:48:34 +00001438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439 static pointer allocate(allocator_type& __a, size_type __n)
1440 {return __a.allocate(__n);}
Howard Hinnant82894812010-09-22 16:48:34 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1443 {return allocate(__a, __n, __hint,
1444 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1445
Howard Hinnant82894812010-09-22 16:48:34 +00001446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001447 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448 {__a.deallocate(__p, __n);}
1449
1450#ifndef _LIBCPP_HAS_NO_VARIADICS
1451 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow3f5579f2014-11-11 19:22:33 +00001454 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00001455 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant324bb032010-08-22 00:02:43 +00001456#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459 static void construct(allocator_type& __a, _Tp* __p)
1460 {
1461 ::new ((void*)__p) _Tp();
1462 }
1463 template <class _Tp, class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00001464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1466 {
1467 ::new ((void*)__p) _Tp(__a0);
1468 }
1469 template <class _Tp, class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00001470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1472 const _A1& __a1)
1473 {
1474 ::new ((void*)__p) _Tp(__a0, __a1);
1475 }
1476 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00001477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1479 const _A1& __a1, const _A2& __a2)
1480 {
1481 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1482 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001483#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484
1485 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 static void destroy(allocator_type& __a, _Tp* __p)
1488 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1489
Howard Hinnant82894812010-09-22 16:48:34 +00001490 _LIBCPP_INLINE_VISIBILITY
Marshall Clow08b4f3f2013-08-27 20:22:15 +00001491 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001492 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1493
Howard Hinnant82894812010-09-22 16:48:34 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495 static allocator_type
1496 select_on_container_copy_construction(const allocator_type& __a)
1497 {return select_on_container_copy_construction(
1498 __has_select_on_container_copy_construction<const allocator_type>(),
1499 __a);}
1500
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001501 template <class _Ptr>
1502 _LIBCPP_INLINE_VISIBILITY
1503 static
1504 void
1505 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1506 {
1507 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1508 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1509 }
1510
1511 template <class _Tp>
1512 _LIBCPP_INLINE_VISIBILITY
1513 static
1514 typename enable_if
1515 <
1516 (is_same<allocator_type, allocator<_Tp> >::value
1517 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1518 is_trivially_move_constructible<_Tp>::value,
1519 void
1520 >::type
1521 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1522 {
1523 ptrdiff_t _Np = __end1 - __begin1;
1524 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1525 __begin2 += _Np;
1526 }
1527
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001528 template <class _Iter, class _Ptr>
1529 _LIBCPP_INLINE_VISIBILITY
1530 static
1531 void
1532 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1533 {
1534 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1535 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1536 }
1537
1538 template <class _Tp>
1539 _LIBCPP_INLINE_VISIBILITY
1540 static
1541 typename enable_if
1542 <
1543 (is_same<allocator_type, allocator<_Tp> >::value
1544 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1545 is_trivially_move_constructible<_Tp>::value,
1546 void
1547 >::type
1548 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1549 {
1550 typedef typename remove_const<_Tp>::type _Vp;
1551 ptrdiff_t _Np = __end1 - __begin1;
1552 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1553 __begin2 += _Np;
1554 }
1555
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001556 template <class _Ptr>
1557 _LIBCPP_INLINE_VISIBILITY
1558 static
1559 void
1560 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1561 {
1562 while (__end1 != __begin1)
Howard Hinnantf619e232013-01-11 20:36:59 +00001563 {
1564 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1565 --__end2;
1566 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001567 }
1568
1569 template <class _Tp>
1570 _LIBCPP_INLINE_VISIBILITY
1571 static
1572 typename enable_if
1573 <
1574 (is_same<allocator_type, allocator<_Tp> >::value
1575 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1576 is_trivially_move_constructible<_Tp>::value,
1577 void
1578 >::type
1579 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1580 {
1581 ptrdiff_t _Np = __end1 - __begin1;
1582 __end2 -= _Np;
1583 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1584 }
1585
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586private:
1587
Howard Hinnant82894812010-09-22 16:48:34 +00001588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 static pointer allocate(allocator_type& __a, size_type __n,
1590 const_void_pointer __hint, true_type)
1591 {return __a.allocate(__n, __hint);}
Howard Hinnant82894812010-09-22 16:48:34 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnantec3773c2011-12-01 20:21:04 +00001594 const_void_pointer, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 {return __a.allocate(__n);}
1596
1597#ifndef _LIBCPP_HAS_NO_VARIADICS
1598 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001601 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1605 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001606 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001608#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609
1610 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1613 {__a.destroy(__p);}
1614 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 static void __destroy(false_type, allocator_type&, _Tp* __p)
1617 {
1618 __p->~_Tp();
1619 }
1620
Howard Hinnant82894812010-09-22 16:48:34 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622 static size_type __max_size(true_type, const allocator_type& __a)
1623 {return __a.max_size();}
Howard Hinnant82894812010-09-22 16:48:34 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 static size_type __max_size(false_type, const allocator_type&)
1626 {return numeric_limits<size_type>::max();}
1627
Howard Hinnant82894812010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 static allocator_type
1630 select_on_container_copy_construction(true_type, const allocator_type& __a)
1631 {return __a.select_on_container_copy_construction();}
Howard Hinnant82894812010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633 static allocator_type
1634 select_on_container_copy_construction(false_type, const allocator_type& __a)
1635 {return __a;}
1636};
1637
Marshall Clow66302c62015-04-07 05:21:38 +00001638template <class _Traits, class _Tp>
1639struct __rebind_alloc_helper
1640{
1641#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1642 typedef typename _Traits::template rebind_alloc<_Tp> type;
1643#else
1644 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1645#endif
1646};
1647
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648// allocator
1649
1650template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001651class _LIBCPP_TYPE_VIS_ONLY allocator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001652{
1653public:
1654 typedef size_t size_type;
1655 typedef ptrdiff_t difference_type;
1656 typedef _Tp* pointer;
1657 typedef const _Tp* const_pointer;
1658 typedef _Tp& reference;
1659 typedef const _Tp& const_reference;
1660 typedef _Tp value_type;
1661
Howard Hinnant18884f42011-06-02 21:38:57 +00001662 typedef true_type propagate_on_container_move_assignment;
1663
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1665
Howard Hinnant1694d232011-05-28 14:41:13 +00001666 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1667 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1668 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001669 {return _VSTD::addressof(__x);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001670 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001671 {return _VSTD::addressof(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001673 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant1694d232011-05-28 14:41:13 +00001674 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001675 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001676 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1677 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001678#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679 template <class _Up, class... _Args>
1680 _LIBCPP_INLINE_VISIBILITY
1681 void
1682 construct(_Up* __p, _Args&&... __args)
1683 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001684 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001686#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687 _LIBCPP_INLINE_VISIBILITY
1688 void
1689 construct(pointer __p)
1690 {
1691 ::new((void*)__p) _Tp();
1692 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001693# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001694
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695 template <class _A0>
1696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001697 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 construct(pointer __p, _A0& __a0)
1699 {
1700 ::new((void*)__p) _Tp(__a0);
1701 }
1702 template <class _A0>
1703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001704 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705 construct(pointer __p, const _A0& __a0)
1706 {
1707 ::new((void*)__p) _Tp(__a0);
1708 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001709# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710 template <class _A0, class _A1>
1711 _LIBCPP_INLINE_VISIBILITY
1712 void
1713 construct(pointer __p, _A0& __a0, _A1& __a1)
1714 {
1715 ::new((void*)__p) _Tp(__a0, __a1);
1716 }
1717 template <class _A0, class _A1>
1718 _LIBCPP_INLINE_VISIBILITY
1719 void
1720 construct(pointer __p, const _A0& __a0, _A1& __a1)
1721 {
1722 ::new((void*)__p) _Tp(__a0, __a1);
1723 }
1724 template <class _A0, class _A1>
1725 _LIBCPP_INLINE_VISIBILITY
1726 void
1727 construct(pointer __p, _A0& __a0, const _A1& __a1)
1728 {
1729 ::new((void*)__p) _Tp(__a0, __a1);
1730 }
1731 template <class _A0, class _A1>
1732 _LIBCPP_INLINE_VISIBILITY
1733 void
1734 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1735 {
1736 ::new((void*)__p) _Tp(__a0, __a1);
1737 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001738#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1740};
1741
Howard Hinnant57199402012-01-02 17:56:02 +00001742template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001743class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00001744{
1745public:
1746 typedef size_t size_type;
1747 typedef ptrdiff_t difference_type;
1748 typedef const _Tp* pointer;
1749 typedef const _Tp* const_pointer;
1750 typedef const _Tp& reference;
1751 typedef const _Tp& const_reference;
Howard Hinnant9360e9f2013-06-07 01:56:37 +00001752 typedef const _Tp value_type;
Howard Hinnant57199402012-01-02 17:56:02 +00001753
1754 typedef true_type propagate_on_container_move_assignment;
1755
1756 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1757
1758 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1759 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1760 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1761 {return _VSTD::addressof(__x);}
1762 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001763 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant57199402012-01-02 17:56:02 +00001764 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001765 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant57199402012-01-02 17:56:02 +00001766 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1767 {return size_type(~0) / sizeof(_Tp);}
1768#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1769 template <class _Up, class... _Args>
1770 _LIBCPP_INLINE_VISIBILITY
1771 void
1772 construct(_Up* __p, _Args&&... __args)
1773 {
1774 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1775 }
1776#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1777 _LIBCPP_INLINE_VISIBILITY
1778 void
1779 construct(pointer __p)
1780 {
1781 ::new((void*)__p) _Tp();
1782 }
1783# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001784
Howard Hinnant57199402012-01-02 17:56:02 +00001785 template <class _A0>
1786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001787 void
Howard Hinnant57199402012-01-02 17:56:02 +00001788 construct(pointer __p, _A0& __a0)
1789 {
1790 ::new((void*)__p) _Tp(__a0);
1791 }
1792 template <class _A0>
1793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001794 void
Howard Hinnant57199402012-01-02 17:56:02 +00001795 construct(pointer __p, const _A0& __a0)
1796 {
1797 ::new((void*)__p) _Tp(__a0);
1798 }
Howard Hinnant57199402012-01-02 17:56:02 +00001799# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1800 template <class _A0, class _A1>
1801 _LIBCPP_INLINE_VISIBILITY
1802 void
1803 construct(pointer __p, _A0& __a0, _A1& __a1)
1804 {
1805 ::new((void*)__p) _Tp(__a0, __a1);
1806 }
1807 template <class _A0, class _A1>
1808 _LIBCPP_INLINE_VISIBILITY
1809 void
1810 construct(pointer __p, const _A0& __a0, _A1& __a1)
1811 {
1812 ::new((void*)__p) _Tp(__a0, __a1);
1813 }
1814 template <class _A0, class _A1>
1815 _LIBCPP_INLINE_VISIBILITY
1816 void
1817 construct(pointer __p, _A0& __a0, const _A1& __a1)
1818 {
1819 ::new((void*)__p) _Tp(__a0, __a1);
1820 }
1821 template <class _A0, class _A1>
1822 _LIBCPP_INLINE_VISIBILITY
1823 void
1824 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1825 {
1826 ::new((void*)__p) _Tp(__a0, __a1);
1827 }
1828#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1829 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1830};
1831
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832template <class _Tp, class _Up>
1833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001834bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835
1836template <class _Tp, class _Up>
1837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001838bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839
1840template <class _OutputIterator, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001841class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 : public iterator<output_iterator_tag,
1843 _Tp, // purposefully not C++03
1844 ptrdiff_t, // purposefully not C++03
1845 _Tp*, // purposefully not C++03
1846 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1847{
1848private:
1849 _OutputIterator __x_;
1850public:
1851 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1852 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1853 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1854 {::new(&*__x_) _Tp(__element); return *this;}
1855 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1856 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1857 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowdbaf7a02015-05-10 13:14:08 +00001858#if _LIBCPP_STD_VER >= 14
1859 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1860#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861};
1862
1863template <class _Tp>
1864pair<_Tp*, ptrdiff_t>
Howard Hinnant1694d232011-05-28 14:41:13 +00001865get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866{
1867 pair<_Tp*, ptrdiff_t> __r(0, 0);
1868 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1869 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1870 / sizeof(_Tp);
1871 if (__n > __m)
1872 __n = __m;
1873 while (__n > 0)
1874 {
1875 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1876 if (__r.first)
1877 {
1878 __r.second = __n;
1879 break;
1880 }
1881 __n /= 2;
1882 }
1883 return __r;
1884}
1885
1886template <class _Tp>
1887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001888void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889
1890template <class _Tp>
1891struct auto_ptr_ref
1892{
1893 _Tp* __ptr_;
1894};
1895
1896template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001897class _LIBCPP_TYPE_VIS_ONLY auto_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898{
1899private:
1900 _Tp* __ptr_;
1901public:
1902 typedef _Tp element_type;
1903
1904 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1905 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1906 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1907 : __ptr_(__p.release()) {}
1908 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1909 {reset(__p.release()); return *this;}
1910 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1911 {reset(__p.release()); return *this;}
1912 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1913 {reset(__p.__ptr_); return *this;}
1914 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1915
1916 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1917 {return *__ptr_;}
1918 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1919 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1920 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1921 {
1922 _Tp* __t = __ptr_;
1923 __ptr_ = 0;
1924 return __t;
1925 }
1926 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1927 {
1928 if (__ptr_ != __p)
1929 delete __ptr_;
1930 __ptr_ = __p;
1931 }
1932
1933 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1934 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1935 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1936 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1937 {return auto_ptr<_Up>(release());}
1938};
1939
1940template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001941class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942{
1943public:
1944 typedef void element_type;
1945};
1946
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001947template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1948 typename remove_cv<_T2>::type>::value,
Howard Hinnantd4cf2152011-12-11 20:31:33 +00001949 bool = is_empty<_T1>::value
1950#if __has_feature(is_final)
1951 && !__is_final(_T1)
1952#endif
1953 ,
1954 bool = is_empty<_T2>::value
1955#if __has_feature(is_final)
1956 && !__is_final(_T2)
1957#endif
1958 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959struct __libcpp_compressed_pair_switch;
1960
1961template <class _T1, class _T2, bool IsSame>
1962struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1963
1964template <class _T1, class _T2, bool IsSame>
1965struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1966
1967template <class _T1, class _T2, bool IsSame>
1968struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1969
1970template <class _T1, class _T2>
1971struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1972
1973template <class _T1, class _T2>
1974struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1975
1976template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1977class __libcpp_compressed_pair_imp;
1978
1979template <class _T1, class _T2>
1980class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1981{
1982private:
1983 _T1 __first_;
1984 _T2 __second_;
1985public:
1986 typedef _T1 _T1_param;
1987 typedef _T2 _T2_param;
1988
1989 typedef typename remove_reference<_T1>::type& _T1_reference;
1990 typedef typename remove_reference<_T2>::type& _T2_reference;
1991
1992 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1993 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1994
1995 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00001996 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001997 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00001998 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001999 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002001 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002003#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002004
2005 _LIBCPP_INLINE_VISIBILITY
2006 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2007 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2008 is_nothrow_copy_constructible<_T2>::value)
2009 : __first_(__p.first()),
2010 __second_(__p.second()) {}
2011
2012 _LIBCPP_INLINE_VISIBILITY
2013 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2014 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2015 is_nothrow_copy_assignable<_T2>::value)
2016 {
2017 __first_ = __p.first();
2018 __second_ = __p.second();
2019 return *this;
2020 }
2021
Howard Hinnant61aa6012011-07-01 19:24:36 +00002022 _LIBCPP_INLINE_VISIBILITY
2023 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002024 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2025 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002026 : __first_(_VSTD::forward<_T1>(__p.first())),
2027 __second_(_VSTD::forward<_T2>(__p.second())) {}
2028
2029 _LIBCPP_INLINE_VISIBILITY
2030 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2031 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2032 is_nothrow_move_assignable<_T2>::value)
2033 {
2034 __first_ = _VSTD::forward<_T1>(__p.first());
2035 __second_ = _VSTD::forward<_T2>(__p.second());
2036 return *this;
2037 }
2038
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002039#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002040
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002041#ifndef _LIBCPP_HAS_NO_VARIADICS
2042
2043 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2044 _LIBCPP_INLINE_VISIBILITY
2045 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2046 tuple<_Args1...> __first_args,
2047 tuple<_Args2...> __second_args,
2048 __tuple_indices<_I1...>,
2049 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002050 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2051 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002052 {}
2053
2054#endif // _LIBCPP_HAS_NO_VARIADICS
2055
Howard Hinnant1694d232011-05-28 14:41:13 +00002056 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2057 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058
Howard Hinnant1694d232011-05-28 14:41:13 +00002059 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2060 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061
2062 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002063 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002064 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002066 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067 swap(__first_, __x.__first_);
2068 swap(__second_, __x.__second_);
2069 }
2070};
2071
2072template <class _T1, class _T2>
2073class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2074 : private _T1
2075{
2076private:
2077 _T2 __second_;
2078public:
2079 typedef _T1 _T1_param;
2080 typedef _T2 _T2_param;
2081
2082 typedef _T1& _T1_reference;
2083 typedef typename remove_reference<_T2>::type& _T2_reference;
2084
2085 typedef const _T1& _T1_const_reference;
2086 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2087
2088 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002089 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002090 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002091 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002092 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002094 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002096#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002097
2098 _LIBCPP_INLINE_VISIBILITY
2099 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2100 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2101 is_nothrow_copy_constructible<_T2>::value)
2102 : _T1(__p.first()), __second_(__p.second()) {}
2103
2104 _LIBCPP_INLINE_VISIBILITY
2105 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2106 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2107 is_nothrow_copy_assignable<_T2>::value)
2108 {
2109 _T1::operator=(__p.first());
2110 __second_ = __p.second();
2111 return *this;
2112 }
2113
Howard Hinnant61aa6012011-07-01 19:24:36 +00002114 _LIBCPP_INLINE_VISIBILITY
2115 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002116 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2117 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002118 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002119
2120 _LIBCPP_INLINE_VISIBILITY
2121 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2122 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2123 is_nothrow_move_assignable<_T2>::value)
2124 {
2125 _T1::operator=(_VSTD::move(__p.first()));
2126 __second_ = _VSTD::forward<_T2>(__p.second());
2127 return *this;
2128 }
2129
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002130#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002131
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002132#ifndef _LIBCPP_HAS_NO_VARIADICS
2133
2134 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2135 _LIBCPP_INLINE_VISIBILITY
2136 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2137 tuple<_Args1...> __first_args,
2138 tuple<_Args2...> __second_args,
2139 __tuple_indices<_I1...>,
2140 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002141 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2142 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002143 {}
2144
2145#endif // _LIBCPP_HAS_NO_VARIADICS
2146
Howard Hinnant1694d232011-05-28 14:41:13 +00002147 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2148 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149
Howard Hinnant1694d232011-05-28 14:41:13 +00002150 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2151 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152
2153 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002154 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002155 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002157 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002158 swap(__second_, __x.__second_);
2159 }
2160};
2161
2162template <class _T1, class _T2>
2163class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2164 : private _T2
2165{
2166private:
2167 _T1 __first_;
2168public:
2169 typedef _T1 _T1_param;
2170 typedef _T2 _T2_param;
2171
2172 typedef typename remove_reference<_T1>::type& _T1_reference;
2173 typedef _T2& _T2_reference;
2174
2175 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2176 typedef const _T2& _T2_const_reference;
2177
2178 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2179 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002180 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002182 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant1694d232011-05-28 14:41:13 +00002184 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2185 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002186 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002188#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002189
2190 _LIBCPP_INLINE_VISIBILITY
2191 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2192 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2193 is_nothrow_copy_constructible<_T2>::value)
2194 : _T2(__p.second()), __first_(__p.first()) {}
2195
2196 _LIBCPP_INLINE_VISIBILITY
2197 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2198 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2199 is_nothrow_copy_assignable<_T2>::value)
2200 {
2201 _T2::operator=(__p.second());
2202 __first_ = __p.first();
2203 return *this;
2204 }
2205
Howard Hinnant61aa6012011-07-01 19:24:36 +00002206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002208 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2209 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002210 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002211
2212 _LIBCPP_INLINE_VISIBILITY
2213 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2214 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2215 is_nothrow_move_assignable<_T2>::value)
2216 {
2217 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2218 __first_ = _VSTD::move(__p.first());
2219 return *this;
2220 }
2221
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002222#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002223
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002224#ifndef _LIBCPP_HAS_NO_VARIADICS
2225
2226 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2227 _LIBCPP_INLINE_VISIBILITY
2228 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2229 tuple<_Args1...> __first_args,
2230 tuple<_Args2...> __second_args,
2231 __tuple_indices<_I1...>,
2232 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002233 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2234 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002235
2236 {}
2237
2238#endif // _LIBCPP_HAS_NO_VARIADICS
2239
Howard Hinnant1694d232011-05-28 14:41:13 +00002240 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2241 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242
Howard Hinnant1694d232011-05-28 14:41:13 +00002243 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2244 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245
2246 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002247 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002248 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002249 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002250 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002251 swap(__first_, __x.__first_);
2252 }
2253};
2254
2255template <class _T1, class _T2>
2256class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2257 : private _T1,
2258 private _T2
2259{
2260public:
2261 typedef _T1 _T1_param;
2262 typedef _T2 _T2_param;
2263
2264 typedef _T1& _T1_reference;
2265 typedef _T2& _T2_reference;
2266
2267 typedef const _T1& _T1_const_reference;
2268 typedef const _T2& _T2_const_reference;
2269
2270 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2271 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002272 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002273 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002274 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002275 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002276 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002277
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002278#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002279
2280 _LIBCPP_INLINE_VISIBILITY
2281 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2282 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2283 is_nothrow_copy_constructible<_T2>::value)
2284 : _T1(__p.first()), _T2(__p.second()) {}
2285
2286 _LIBCPP_INLINE_VISIBILITY
2287 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2288 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2289 is_nothrow_copy_assignable<_T2>::value)
2290 {
2291 _T1::operator=(__p.first());
2292 _T2::operator=(__p.second());
2293 return *this;
2294 }
2295
Howard Hinnant61aa6012011-07-01 19:24:36 +00002296 _LIBCPP_INLINE_VISIBILITY
2297 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002298 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2299 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002300 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002301
2302 _LIBCPP_INLINE_VISIBILITY
2303 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2304 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2305 is_nothrow_move_assignable<_T2>::value)
2306 {
2307 _T1::operator=(_VSTD::move(__p.first()));
2308 _T2::operator=(_VSTD::move(__p.second()));
2309 return *this;
2310 }
2311
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002312#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002313
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002314#ifndef _LIBCPP_HAS_NO_VARIADICS
2315
2316 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2317 _LIBCPP_INLINE_VISIBILITY
2318 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2319 tuple<_Args1...> __first_args,
2320 tuple<_Args2...> __second_args,
2321 __tuple_indices<_I1...>,
2322 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002323 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2324 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002325 {}
2326
2327#endif // _LIBCPP_HAS_NO_VARIADICS
2328
Howard Hinnant1694d232011-05-28 14:41:13 +00002329 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2330 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331
Howard Hinnant1694d232011-05-28 14:41:13 +00002332 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2333 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334
Howard Hinnantec3773c2011-12-01 20:21:04 +00002335 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant1694d232011-05-28 14:41:13 +00002336 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002337 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338 {
2339 }
2340};
2341
2342template <class _T1, class _T2>
2343class __compressed_pair
2344 : private __libcpp_compressed_pair_imp<_T1, _T2>
2345{
2346 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2347public:
2348 typedef typename base::_T1_param _T1_param;
2349 typedef typename base::_T2_param _T2_param;
2350
2351 typedef typename base::_T1_reference _T1_reference;
2352 typedef typename base::_T2_reference _T2_reference;
2353
2354 typedef typename base::_T1_const_reference _T1_const_reference;
2355 typedef typename base::_T2_const_reference _T2_const_reference;
2356
2357 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002358 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002359 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002360 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002361 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002362 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002363 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002365#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002366
2367 _LIBCPP_INLINE_VISIBILITY
2368 __compressed_pair(const __compressed_pair& __p)
2369 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2370 is_nothrow_copy_constructible<_T2>::value)
2371 : base(__p) {}
2372
2373 _LIBCPP_INLINE_VISIBILITY
2374 __compressed_pair& operator=(const __compressed_pair& __p)
2375 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2376 is_nothrow_copy_assignable<_T2>::value)
2377 {
2378 base::operator=(__p);
2379 return *this;
2380 }
2381
Howard Hinnant61aa6012011-07-01 19:24:36 +00002382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002384 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2385 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002386 : base(_VSTD::move(__p)) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002387
2388 _LIBCPP_INLINE_VISIBILITY
2389 __compressed_pair& operator=(__compressed_pair&& __p)
2390 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2391 is_nothrow_move_assignable<_T2>::value)
2392 {
2393 base::operator=(_VSTD::move(__p));
2394 return *this;
2395 }
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002396
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002397#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002398
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002399#ifndef _LIBCPP_HAS_NO_VARIADICS
2400
2401 template <class... _Args1, class... _Args2>
2402 _LIBCPP_INLINE_VISIBILITY
2403 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2404 tuple<_Args2...> __second_args)
Howard Hinnant57199402012-01-02 17:56:02 +00002405 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002406 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2407 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2408 {}
2409
2410#endif // _LIBCPP_HAS_NO_VARIADICS
2411
Howard Hinnant1694d232011-05-28 14:41:13 +00002412 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2413 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414
Howard Hinnant1694d232011-05-28 14:41:13 +00002415 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2416 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417
Howard Hinnant1694d232011-05-28 14:41:13 +00002418 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2419 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002420 __is_nothrow_swappable<_T2>::value)
Howard Hinnant1694d232011-05-28 14:41:13 +00002421 {base::swap(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422};
2423
2424template <class _T1, class _T2>
2425inline _LIBCPP_INLINE_VISIBILITY
2426void
2427swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant1694d232011-05-28 14:41:13 +00002428 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002429 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430 {__x.swap(__y);}
2431
Howard Hinnant57199402012-01-02 17:56:02 +00002432// __same_or_less_cv_qualified
2433
2434template <class _Ptr1, class _Ptr2,
2435 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2436 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2437 >::value
2438 >
2439struct __same_or_less_cv_qualified_imp
2440 : is_convertible<_Ptr1, _Ptr2> {};
2441
2442template <class _Ptr1, class _Ptr2>
2443struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2444 : false_type {};
2445
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002446template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2447 is_same<_Ptr1, _Ptr2>::value ||
2448 __has_element_type<_Ptr1>::value>
Howard Hinnant57199402012-01-02 17:56:02 +00002449struct __same_or_less_cv_qualified
2450 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2451
2452template <class _Ptr1, class _Ptr2>
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002453struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant57199402012-01-02 17:56:02 +00002454 : false_type {};
2455
2456// default_delete
2457
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002458template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002459struct _LIBCPP_TYPE_VIS_ONLY default_delete
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002460{
Howard Hinnant46e94932012-07-07 20:56:04 +00002461#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2462 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2463#else
2464 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2465#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002466 template <class _Up>
2467 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant1694d232011-05-28 14:41:13 +00002468 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2469 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 {
2471 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002472 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 delete __ptr;
2474 }
2475};
2476
2477template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002478struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479{
Howard Hinnant8e843502011-12-18 21:19:44 +00002480public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002481#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2483#else
2484 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2485#endif
Howard Hinnant8e843502011-12-18 21:19:44 +00002486 template <class _Up>
2487 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant57199402012-01-02 17:56:02 +00002488 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant8e843502011-12-18 21:19:44 +00002489 template <class _Up>
2490 _LIBCPP_INLINE_VISIBILITY
2491 void operator() (_Up* __ptr,
Howard Hinnant57199402012-01-02 17:56:02 +00002492 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 {
2494 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002495 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 delete [] __ptr;
2497 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002498};
2499
2500template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002501class _LIBCPP_TYPE_VIS_ONLY unique_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502{
2503public:
2504 typedef _Tp element_type;
2505 typedef _Dp deleter_type;
2506 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2507private:
2508 __compressed_pair<pointer, deleter_type> __ptr_;
2509
Howard Hinnant57199402012-01-02 17:56:02 +00002510#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002511 unique_ptr(unique_ptr&);
2512 template <class _Up, class _Ep>
2513 unique_ptr(unique_ptr<_Up, _Ep>&);
2514 unique_ptr& operator=(unique_ptr&);
2515 template <class _Up, class _Ep>
2516 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002517#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518
2519 struct __nat {int __for_bool_;};
2520
2521 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2522 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2523public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002524 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002525 : __ptr_(pointer())
2526 {
2527 static_assert(!is_pointer<deleter_type>::value,
2528 "unique_ptr constructed with null function pointer deleter");
2529 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002530 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002531 : __ptr_(pointer())
2532 {
2533 static_assert(!is_pointer<deleter_type>::value,
2534 "unique_ptr constructed with null function pointer deleter");
2535 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002536 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002537 : __ptr_(_VSTD::move(__p))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538 {
2539 static_assert(!is_pointer<deleter_type>::value,
2540 "unique_ptr constructed with null function pointer deleter");
2541 }
2542
Howard Hinnant73d21a42010-09-04 23:28:19 +00002543#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2545 is_reference<deleter_type>::value,
2546 deleter_type,
2547 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002548 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549 : __ptr_(__p, __d) {}
2550
2551 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002552 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002553 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554 {
2555 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2556 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002557 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002558 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559 template <class _Up, class _Ep>
2560 _LIBCPP_INLINE_VISIBILITY
2561 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2562 typename enable_if
2563 <
2564 !is_array<_Up>::value &&
2565 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2566 is_convertible<_Ep, deleter_type>::value &&
2567 (
2568 !is_reference<deleter_type>::value ||
2569 is_same<deleter_type, _Ep>::value
2570 ),
2571 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002572 >::type = __nat()) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002573 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002574
2575 template <class _Up>
2576 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2577 typename enable_if<
2578 is_convertible<_Up*, _Tp*>::value &&
2579 is_same<_Dp, default_delete<_Tp> >::value,
2580 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002581 >::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582 : __ptr_(__p.release())
2583 {
2584 }
2585
Howard Hinnant1694d232011-05-28 14:41:13 +00002586 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587 {
2588 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002589 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002590 return *this;
2591 }
2592
2593 template <class _Up, class _Ep>
2594 _LIBCPP_INLINE_VISIBILITY
2595 typename enable_if
2596 <
Howard Hinnant57199402012-01-02 17:56:02 +00002597 !is_array<_Up>::value &&
2598 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2599 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 unique_ptr&
2601 >::type
Howard Hinnant1694d232011-05-28 14:41:13 +00002602 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 {
2604 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002605 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002606 return *this;
2607 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002608#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002609
2610 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2611 {
2612 return __rv<unique_ptr>(*this);
2613 }
2614
2615 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002616 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002617
2618 template <class _Up, class _Ep>
2619 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2620 {
2621 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002622 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 return *this;
2624 }
2625
2626 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002627 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002628
2629 template <class _Up>
2630 _LIBCPP_INLINE_VISIBILITY
2631 typename enable_if<
2632 is_convertible<_Up*, _Tp*>::value &&
2633 is_same<_Dp, default_delete<_Tp> >::value,
2634 unique_ptr&
2635 >::type
2636 operator=(auto_ptr<_Up> __p)
2637 {reset(__p.release()); return *this;}
2638
Howard Hinnant73d21a42010-09-04 23:28:19 +00002639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002640 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2641
Howard Hinnant1694d232011-05-28 14:41:13 +00002642 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002643 {
2644 reset();
2645 return *this;
2646 }
2647
2648 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2649 {return *__ptr_.first();}
Howard Hinnant1694d232011-05-28 14:41:13 +00002650 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2651 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2652 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2653 {return __ptr_.second();}
2654 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2655 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002656 _LIBCPP_INLINE_VISIBILITY
2657 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2658 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002659
Howard Hinnant1694d232011-05-28 14:41:13 +00002660 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661 {
2662 pointer __t = __ptr_.first();
2663 __ptr_.first() = pointer();
2664 return __t;
2665 }
2666
Howard Hinnant1694d232011-05-28 14:41:13 +00002667 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 {
2669 pointer __tmp = __ptr_.first();
2670 __ptr_.first() = __p;
2671 if (__tmp)
2672 __ptr_.second()(__tmp);
2673 }
2674
Howard Hinnant1694d232011-05-28 14:41:13 +00002675 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2676 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677};
2678
2679template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002680class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002681{
2682public:
2683 typedef _Tp element_type;
2684 typedef _Dp deleter_type;
2685 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2686private:
2687 __compressed_pair<pointer, deleter_type> __ptr_;
2688
Howard Hinnant57199402012-01-02 17:56:02 +00002689#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002690 unique_ptr(unique_ptr&);
2691 template <class _Up>
2692 unique_ptr(unique_ptr<_Up>&);
2693 unique_ptr& operator=(unique_ptr&);
2694 template <class _Up>
2695 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002696#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697
2698 struct __nat {int __for_bool_;};
2699
2700 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2701 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2702public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002703 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704 : __ptr_(pointer())
2705 {
2706 static_assert(!is_pointer<deleter_type>::value,
2707 "unique_ptr constructed with null function pointer deleter");
2708 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002709 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710 : __ptr_(pointer())
2711 {
2712 static_assert(!is_pointer<deleter_type>::value,
2713 "unique_ptr constructed with null function pointer deleter");
2714 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002715#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002716 template <class _Pp>
2717 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2718 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002719 : __ptr_(__p)
2720 {
2721 static_assert(!is_pointer<deleter_type>::value,
2722 "unique_ptr constructed with null function pointer deleter");
2723 }
2724
Logan Chiene1678a12014-01-31 09:30:46 +00002725 template <class _Pp>
Howard Hinnant99968442011-11-29 18:15:50 +00002726 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727 is_reference<deleter_type>::value,
2728 deleter_type,
Logan Chiene1678a12014-01-31 09:30:46 +00002729 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2730 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002731 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002732 : __ptr_(__p, __d) {}
2733
2734 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2735 is_reference<deleter_type>::value,
2736 deleter_type,
2737 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002738 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739 : __ptr_(pointer(), __d) {}
2740
Logan Chiene1678a12014-01-31 09:30:46 +00002741 template <class _Pp>
2742 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2743 typename remove_reference<deleter_type>::type&& __d,
2744 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002745 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002746 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002747 {
2748 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2749 }
2750
2751 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002752 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002753 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754 {
2755 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2756 }
2757
Howard Hinnant1694d232011-05-28 14:41:13 +00002758 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002759 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002760
Howard Hinnant1694d232011-05-28 14:41:13 +00002761 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002762 {
2763 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002764 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765 return *this;
2766 }
Howard Hinnant8e843502011-12-18 21:19:44 +00002767
2768 template <class _Up, class _Ep>
2769 _LIBCPP_INLINE_VISIBILITY
2770 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2771 typename enable_if
2772 <
2773 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002774 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant8e843502011-12-18 21:19:44 +00002775 && is_convertible<_Ep, deleter_type>::value &&
2776 (
2777 !is_reference<deleter_type>::value ||
2778 is_same<deleter_type, _Ep>::value
2779 ),
2780 __nat
2781 >::type = __nat()
2782 ) _NOEXCEPT
2783 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2784
2785
2786 template <class _Up, class _Ep>
2787 _LIBCPP_INLINE_VISIBILITY
2788 typename enable_if
2789 <
2790 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002791 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2792 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant8e843502011-12-18 21:19:44 +00002793 unique_ptr&
2794 >::type
2795 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2796 {
2797 reset(__u.release());
2798 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2799 return *this;
2800 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002801#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002802
2803 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2804 : __ptr_(__p)
2805 {
2806 static_assert(!is_pointer<deleter_type>::value,
2807 "unique_ptr constructed with null function pointer deleter");
2808 }
2809
2810 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002811 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002812
2813 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002814 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815
2816 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2817 {
2818 return __rv<unique_ptr>(*this);
2819 }
2820
2821 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002822 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002823
2824 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2825 {
2826 reset(__u->release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002827 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002828 return *this;
2829 }
2830
Howard Hinnant73d21a42010-09-04 23:28:19 +00002831#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2833
Howard Hinnant1694d232011-05-28 14:41:13 +00002834 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 {
2836 reset();
2837 return *this;
2838 }
2839
2840 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2841 {return __ptr_.first()[__i];}
Howard Hinnant1694d232011-05-28 14:41:13 +00002842 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2843 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2844 {return __ptr_.second();}
2845 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2846 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002847 _LIBCPP_INLINE_VISIBILITY
2848 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2849 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002850
Howard Hinnant1694d232011-05-28 14:41:13 +00002851 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852 {
2853 pointer __t = __ptr_.first();
2854 __ptr_.first() = pointer();
2855 return __t;
2856 }
2857
Howard Hinnant73d21a42010-09-04 23:28:19 +00002858#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002859 template <class _Pp>
2860 _LIBCPP_INLINE_VISIBILITY
2861 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2862 reset(_Pp __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002863 {
2864 pointer __tmp = __ptr_.first();
2865 __ptr_.first() = __p;
2866 if (__tmp)
2867 __ptr_.second()(__tmp);
2868 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002869 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870 {
2871 pointer __tmp = __ptr_.first();
2872 __ptr_.first() = nullptr;
2873 if (__tmp)
2874 __ptr_.second()(__tmp);
2875 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002876 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002877 {
2878 pointer __tmp = __ptr_.first();
2879 __ptr_.first() = nullptr;
2880 if (__tmp)
2881 __ptr_.second()(__tmp);
2882 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002883#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002884 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2885 {
2886 pointer __tmp = __ptr_.first();
2887 __ptr_.first() = __p;
2888 if (__tmp)
2889 __ptr_.second()(__tmp);
2890 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002891#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892
2893 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2894private:
Howard Hinnant324bb032010-08-22 00:02:43 +00002895
Howard Hinnant73d21a42010-09-04 23:28:19 +00002896#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897 template <class _Up>
2898 explicit unique_ptr(_Up);
2899 template <class _Up>
2900 unique_ptr(_Up __u,
2901 typename conditional<
2902 is_reference<deleter_type>::value,
2903 deleter_type,
2904 typename add_lvalue_reference<const deleter_type>::type>::type,
2905 typename enable_if
2906 <
2907 is_convertible<_Up, pointer>::value,
2908 __nat
2909 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00002910#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911};
2912
2913template <class _Tp, class _Dp>
2914inline _LIBCPP_INLINE_VISIBILITY
2915void
Howard Hinnant1694d232011-05-28 14:41:13 +00002916swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917
2918template <class _T1, class _D1, class _T2, class _D2>
2919inline _LIBCPP_INLINE_VISIBILITY
2920bool
2921operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2922
2923template <class _T1, class _D1, class _T2, class _D2>
2924inline _LIBCPP_INLINE_VISIBILITY
2925bool
2926operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2927
2928template <class _T1, class _D1, class _T2, class _D2>
2929inline _LIBCPP_INLINE_VISIBILITY
2930bool
Howard Hinnant3fadda32012-02-21 21:02:58 +00002931operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2932{
2933 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2934 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselier8492cd82015-02-05 23:01:40 +00002935 typedef typename common_type<_P1, _P2>::type _Vp;
2936 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00002937}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938
2939template <class _T1, class _D1, class _T2, class _D2>
2940inline _LIBCPP_INLINE_VISIBILITY
2941bool
2942operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2943
2944template <class _T1, class _D1, class _T2, class _D2>
2945inline _LIBCPP_INLINE_VISIBILITY
2946bool
2947operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2948
2949template <class _T1, class _D1, class _T2, class _D2>
2950inline _LIBCPP_INLINE_VISIBILITY
2951bool
2952operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2953
Howard Hinnant3fadda32012-02-21 21:02:58 +00002954template <class _T1, class _D1>
2955inline _LIBCPP_INLINE_VISIBILITY
2956bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002957operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002958{
2959 return !__x;
2960}
2961
2962template <class _T1, class _D1>
2963inline _LIBCPP_INLINE_VISIBILITY
2964bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002965operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002966{
2967 return !__x;
2968}
2969
2970template <class _T1, class _D1>
2971inline _LIBCPP_INLINE_VISIBILITY
2972bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002973operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002974{
2975 return static_cast<bool>(__x);
2976}
2977
2978template <class _T1, class _D1>
2979inline _LIBCPP_INLINE_VISIBILITY
2980bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002981operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002982{
2983 return static_cast<bool>(__x);
2984}
2985
2986template <class _T1, class _D1>
2987inline _LIBCPP_INLINE_VISIBILITY
2988bool
2989operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2990{
2991 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2992 return less<_P1>()(__x.get(), nullptr);
2993}
2994
2995template <class _T1, class _D1>
2996inline _LIBCPP_INLINE_VISIBILITY
2997bool
2998operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2999{
3000 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3001 return less<_P1>()(nullptr, __x.get());
3002}
3003
3004template <class _T1, class _D1>
3005inline _LIBCPP_INLINE_VISIBILITY
3006bool
3007operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3008{
3009 return nullptr < __x;
3010}
3011
3012template <class _T1, class _D1>
3013inline _LIBCPP_INLINE_VISIBILITY
3014bool
3015operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3016{
3017 return __x < nullptr;
3018}
3019
3020template <class _T1, class _D1>
3021inline _LIBCPP_INLINE_VISIBILITY
3022bool
3023operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3024{
3025 return !(nullptr < __x);
3026}
3027
3028template <class _T1, class _D1>
3029inline _LIBCPP_INLINE_VISIBILITY
3030bool
3031operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3032{
3033 return !(__x < nullptr);
3034}
3035
3036template <class _T1, class _D1>
3037inline _LIBCPP_INLINE_VISIBILITY
3038bool
3039operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3040{
3041 return !(__x < nullptr);
3042}
3043
3044template <class _T1, class _D1>
3045inline _LIBCPP_INLINE_VISIBILITY
3046bool
3047operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3048{
3049 return !(nullptr < __x);
3050}
3051
Howard Hinnant87073e42012-05-01 15:37:54 +00003052#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3053
3054template <class _Tp, class _Dp>
3055inline _LIBCPP_INLINE_VISIBILITY
3056unique_ptr<_Tp, _Dp>
3057move(unique_ptr<_Tp, _Dp>& __t)
3058{
3059 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3060}
3061
3062#endif
3063
Marshall Clowfd7481e2013-07-01 18:16:03 +00003064#if _LIBCPP_STD_VER > 11
3065
3066template<class _Tp>
3067struct __unique_if
3068{
3069 typedef unique_ptr<_Tp> __unique_single;
3070};
3071
3072template<class _Tp>
3073struct __unique_if<_Tp[]>
3074{
3075 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3076};
3077
3078template<class _Tp, size_t _Np>
3079struct __unique_if<_Tp[_Np]>
3080{
3081 typedef void __unique_array_known_bound;
3082};
3083
3084template<class _Tp, class... _Args>
Marshall Clowfb551102013-07-02 20:06:09 +00003085inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003086typename __unique_if<_Tp>::__unique_single
3087make_unique(_Args&&... __args)
3088{
3089 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3090}
3091
3092template<class _Tp>
Marshall Clowfb551102013-07-02 20:06:09 +00003093inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003094typename __unique_if<_Tp>::__unique_array_unknown_bound
3095make_unique(size_t __n)
3096{
3097 typedef typename remove_extent<_Tp>::type _Up;
3098 return unique_ptr<_Tp>(new _Up[__n]());
3099}
3100
3101template<class _Tp, class... _Args>
3102 typename __unique_if<_Tp>::__unique_array_known_bound
3103 make_unique(_Args&&...) = delete;
3104
3105#endif // _LIBCPP_STD_VER > 11
3106
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00003107template <class _Tp> struct hash;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003108
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003109template <class _Size>
3110inline _LIBCPP_INLINE_VISIBILITY
3111_Size
3112__loadword(const void* __p)
3113{
3114 _Size __r;
3115 std::memcpy(&__r, __p, sizeof(__r));
3116 return __r;
3117}
3118
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003119// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3120// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3121// multiplication, which can be very slow on 32-bit systems.
Howard Hinnant40c13d32011-12-05 00:08:45 +00003122template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003123struct __murmur2_or_cityhash;
Howard Hinnant40c13d32011-12-05 00:08:45 +00003124
3125template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003126struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003127{
3128 _Size operator()(const void* __key, _Size __len);
3129};
3130
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003131// murmur2
Howard Hinnant40c13d32011-12-05 00:08:45 +00003132template <class _Size>
3133_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003134__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003135{
3136 const _Size __m = 0x5bd1e995;
3137 const _Size __r = 24;
3138 _Size __h = __len;
3139 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3140 for (; __len >= 4; __data += 4, __len -= 4)
3141 {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003142 _Size __k = __loadword<_Size>(__data);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003143 __k *= __m;
3144 __k ^= __k >> __r;
3145 __k *= __m;
3146 __h *= __m;
3147 __h ^= __k;
3148 }
3149 switch (__len)
3150 {
3151 case 3:
3152 __h ^= __data[2] << 16;
3153 case 2:
3154 __h ^= __data[1] << 8;
3155 case 1:
3156 __h ^= __data[0];
3157 __h *= __m;
3158 }
3159 __h ^= __h >> 13;
3160 __h *= __m;
3161 __h ^= __h >> 15;
3162 return __h;
3163}
3164
3165template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003166struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003167{
3168 _Size operator()(const void* __key, _Size __len);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003169
3170 private:
3171 // Some primes between 2^63 and 2^64.
3172 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3173 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3174 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3175 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3176
3177 static _Size __rotate(_Size __val, int __shift) {
3178 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3179 }
3180
3181 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3182 return (__val >> __shift) | (__val << (64 - __shift));
3183 }
3184
3185 static _Size __shift_mix(_Size __val) {
3186 return __val ^ (__val >> 47);
3187 }
3188
3189 static _Size __hash_len_16(_Size __u, _Size __v) {
3190 const _Size __mul = 0x9ddfea08eb382d69ULL;
3191 _Size __a = (__u ^ __v) * __mul;
3192 __a ^= (__a >> 47);
3193 _Size __b = (__v ^ __a) * __mul;
3194 __b ^= (__b >> 47);
3195 __b *= __mul;
3196 return __b;
3197 }
3198
3199 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3200 if (__len > 8) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003201 const _Size __a = __loadword<_Size>(__s);
3202 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003203 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3204 }
3205 if (__len >= 4) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003206 const uint32_t __a = __loadword<uint32_t>(__s);
3207 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003208 return __hash_len_16(__len + (__a << 3), __b);
3209 }
3210 if (__len > 0) {
3211 const unsigned char __a = __s[0];
3212 const unsigned char __b = __s[__len >> 1];
3213 const unsigned char __c = __s[__len - 1];
3214 const uint32_t __y = static_cast<uint32_t>(__a) +
3215 (static_cast<uint32_t>(__b) << 8);
3216 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3217 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3218 }
3219 return __k2;
3220 }
3221
3222 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003223 const _Size __a = __loadword<_Size>(__s) * __k1;
3224 const _Size __b = __loadword<_Size>(__s + 8);
3225 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3226 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003227 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3228 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3229 }
3230
3231 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3232 // Callers do best to use "random-looking" values for a and b.
3233 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3234 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3235 __a += __w;
3236 __b = __rotate(__b + __a + __z, 21);
3237 const _Size __c = __a;
3238 __a += __x;
3239 __a += __y;
3240 __b += __rotate(__a, 44);
3241 return pair<_Size, _Size>(__a + __z, __b + __c);
3242 }
3243
3244 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3245 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3246 const char* __s, _Size __a, _Size __b) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003247 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3248 __loadword<_Size>(__s + 8),
3249 __loadword<_Size>(__s + 16),
3250 __loadword<_Size>(__s + 24),
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003251 __a,
3252 __b);
3253 }
3254
3255 // Return an 8-byte hash for 33 to 64 bytes.
3256 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003257 _Size __z = __loadword<_Size>(__s + 24);
3258 _Size __a = __loadword<_Size>(__s) +
3259 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003260 _Size __b = __rotate(__a + __z, 52);
3261 _Size __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003262 __a += __loadword<_Size>(__s + 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003263 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003264 __a += __loadword<_Size>(__s + 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003265 _Size __vf = __a + __z;
3266 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003267 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3268 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003269 __b = __rotate(__a + __z, 52);
3270 __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003271 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003272 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003273 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003274 _Size __wf = __a + __z;
3275 _Size __ws = __b + __rotate(__a, 31) + __c;
3276 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3277 return __shift_mix(__r * __k0 + __vs) * __k2;
3278 }
Howard Hinnant40c13d32011-12-05 00:08:45 +00003279};
3280
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003281// cityhash64
Howard Hinnant40c13d32011-12-05 00:08:45 +00003282template <class _Size>
3283_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003284__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003285{
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003286 const char* __s = static_cast<const char*>(__key);
3287 if (__len <= 32) {
3288 if (__len <= 16) {
3289 return __hash_len_0_to_16(__s, __len);
3290 } else {
3291 return __hash_len_17_to_32(__s, __len);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003292 }
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003293 } else if (__len <= 64) {
3294 return __hash_len_33_to_64(__s, __len);
3295 }
3296
3297 // For strings over 64 bytes we hash the end first, and then as we
3298 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003299 _Size __x = __loadword<_Size>(__s + __len - 40);
3300 _Size __y = __loadword<_Size>(__s + __len - 16) +
3301 __loadword<_Size>(__s + __len - 56);
3302 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3303 __loadword<_Size>(__s + __len - 24));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003304 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3305 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003306 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003307
3308 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3309 __len = (__len - 1) & ~static_cast<_Size>(63);
3310 do {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003311 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3312 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003313 __x ^= __w.second;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003314 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003315 __z = __rotate(__z + __w.first, 33) * __k1;
3316 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3317 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003318 __y + __loadword<_Size>(__s + 16));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003319 std::swap(__z, __x);
3320 __s += 64;
3321 __len -= 64;
3322 } while (__len != 0);
3323 return __hash_len_16(
3324 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3325 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003326}
3327
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003328template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3329struct __scalar_hash;
3330
3331template <class _Tp>
3332struct __scalar_hash<_Tp, 0>
3333 : public unary_function<_Tp, size_t>
Howard Hinnant21aefc32010-06-03 16:42:57 +00003334{
Howard Hinnant82894812010-09-22 16:48:34 +00003335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003336 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003337 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003338 union
3339 {
3340 _Tp __t;
3341 size_t __a;
3342 } __u;
3343 __u.__a = 0;
3344 __u.__t = __v;
3345 return __u.__a;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003346 }
3347};
3348
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003349template <class _Tp>
3350struct __scalar_hash<_Tp, 1>
3351 : public unary_function<_Tp, size_t>
3352{
3353 _LIBCPP_INLINE_VISIBILITY
3354 size_t operator()(_Tp __v) const _NOEXCEPT
3355 {
3356 union
3357 {
3358 _Tp __t;
3359 size_t __a;
3360 } __u;
3361 __u.__t = __v;
3362 return __u.__a;
3363 }
3364};
3365
3366template <class _Tp>
3367struct __scalar_hash<_Tp, 2>
3368 : public unary_function<_Tp, size_t>
3369{
3370 _LIBCPP_INLINE_VISIBILITY
3371 size_t operator()(_Tp __v) const _NOEXCEPT
3372 {
3373 union
3374 {
3375 _Tp __t;
3376 struct
3377 {
3378 size_t __a;
3379 size_t __b;
3380 };
3381 } __u;
3382 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003383 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003384 }
3385};
3386
3387template <class _Tp>
3388struct __scalar_hash<_Tp, 3>
3389 : public unary_function<_Tp, size_t>
3390{
3391 _LIBCPP_INLINE_VISIBILITY
3392 size_t operator()(_Tp __v) const _NOEXCEPT
3393 {
3394 union
3395 {
3396 _Tp __t;
3397 struct
3398 {
3399 size_t __a;
3400 size_t __b;
3401 size_t __c;
3402 };
3403 } __u;
3404 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003405 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003406 }
3407};
3408
3409template <class _Tp>
3410struct __scalar_hash<_Tp, 4>
3411 : public unary_function<_Tp, size_t>
3412{
3413 _LIBCPP_INLINE_VISIBILITY
3414 size_t operator()(_Tp __v) const _NOEXCEPT
3415 {
3416 union
3417 {
3418 _Tp __t;
3419 struct
3420 {
3421 size_t __a;
3422 size_t __b;
3423 size_t __c;
3424 size_t __d;
3425 };
3426 } __u;
3427 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003428 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003429 }
3430};
3431
3432template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003433struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003434 : public unary_function<_Tp*, size_t>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003435{
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003436 _LIBCPP_INLINE_VISIBILITY
3437 size_t operator()(_Tp* __v) const _NOEXCEPT
3438 {
3439 union
3440 {
3441 _Tp* __t;
3442 size_t __a;
3443 } __u;
3444 __u.__t = __v;
3445 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3446 }
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003447};
3448
Howard Hinnant21aefc32010-06-03 16:42:57 +00003449template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003450struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00003451{
3452 typedef unique_ptr<_Tp, _Dp> argument_type;
3453 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00003454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003455 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003456 {
3457 typedef typename argument_type::pointer pointer;
3458 return hash<pointer>()(__ptr.get());
3459 }
3460};
3461
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462struct __destruct_n
3463{
3464private:
3465 size_t size;
3466
3467 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003468 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3470
3471 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003472 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473 {}
3474
Howard Hinnant1694d232011-05-28 14:41:13 +00003475 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476 {++size;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003477 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478 {}
3479
Howard Hinnant1694d232011-05-28 14:41:13 +00003480 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481 {size = __s;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003482 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483 {}
3484public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003485 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3486 : size(__s) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003487
3488 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003489 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003490 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003491
3492 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003493 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003494 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003495
3496 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003497 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003498 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003499};
3500
3501template <class _Alloc>
3502class __allocator_destructor
3503{
3504 typedef allocator_traits<_Alloc> __alloc_traits;
3505public:
3506 typedef typename __alloc_traits::pointer pointer;
3507 typedef typename __alloc_traits::size_type size_type;
3508private:
3509 _Alloc& __alloc_;
3510 size_type __s_;
3511public:
3512 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant1694d232011-05-28 14:41:13 +00003513 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514 : __alloc_(__a), __s_(__s) {}
Howard Hinnant82894812010-09-22 16:48:34 +00003515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003516 void operator()(pointer __p) _NOEXCEPT
3517 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518};
3519
3520template <class _InputIterator, class _ForwardIterator>
3521_ForwardIterator
3522uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3523{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003525#ifndef _LIBCPP_NO_EXCEPTIONS
3526 _ForwardIterator __s = __r;
3527 try
3528 {
3529#endif
3530 for (; __f != __l; ++__f, ++__r)
3531 ::new(&*__r) value_type(*__f);
3532#ifndef _LIBCPP_NO_EXCEPTIONS
3533 }
3534 catch (...)
3535 {
3536 for (; __s != __r; ++__s)
3537 __s->~value_type();
3538 throw;
3539 }
3540#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003541 return __r;
3542}
3543
3544template <class _InputIterator, class _Size, class _ForwardIterator>
3545_ForwardIterator
3546uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3547{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003548 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003549#ifndef _LIBCPP_NO_EXCEPTIONS
3550 _ForwardIterator __s = __r;
3551 try
3552 {
3553#endif
3554 for (; __n > 0; ++__f, ++__r, --__n)
3555 ::new(&*__r) value_type(*__f);
3556#ifndef _LIBCPP_NO_EXCEPTIONS
3557 }
3558 catch (...)
3559 {
3560 for (; __s != __r; ++__s)
3561 __s->~value_type();
3562 throw;
3563 }
3564#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003565 return __r;
3566}
3567
3568template <class _ForwardIterator, class _Tp>
3569void
3570uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3571{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003573#ifndef _LIBCPP_NO_EXCEPTIONS
3574 _ForwardIterator __s = __f;
3575 try
3576 {
3577#endif
3578 for (; __f != __l; ++__f)
3579 ::new(&*__f) value_type(__x);
3580#ifndef _LIBCPP_NO_EXCEPTIONS
3581 }
3582 catch (...)
3583 {
3584 for (; __s != __f; ++__s)
3585 __s->~value_type();
3586 throw;
3587 }
3588#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589}
3590
3591template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003592_ForwardIterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3594{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003595 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003596#ifndef _LIBCPP_NO_EXCEPTIONS
3597 _ForwardIterator __s = __f;
3598 try
3599 {
3600#endif
3601 for (; __n > 0; ++__f, --__n)
3602 ::new(&*__f) value_type(__x);
3603#ifndef _LIBCPP_NO_EXCEPTIONS
3604 }
3605 catch (...)
3606 {
3607 for (; __s != __f; ++__s)
3608 __s->~value_type();
3609 throw;
3610 }
3611#endif
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003612 return __f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613}
3614
Howard Hinnant82894812010-09-22 16:48:34 +00003615class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003616 : public std::exception
3617{
3618public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003619 virtual ~bad_weak_ptr() _NOEXCEPT;
3620 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621};
3622
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003623template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003625class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626{
3627 __shared_count(const __shared_count&);
3628 __shared_count& operator=(const __shared_count&);
3629
3630protected:
3631 long __shared_owners_;
3632 virtual ~__shared_count();
3633private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003634 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003635
3636public:
Howard Hinnant82894812010-09-22 16:48:34 +00003637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003638 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003639 : __shared_owners_(__refs) {}
3640
Howard Hinnant1694d232011-05-28 14:41:13 +00003641 void __add_shared() _NOEXCEPT;
3642 bool __release_shared() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003644 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645};
3646
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003647class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648 : private __shared_count
3649{
3650 long __shared_weak_owners_;
3651
3652public:
Howard Hinnant82894812010-09-22 16:48:34 +00003653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003654 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655 : __shared_count(__refs),
3656 __shared_weak_owners_(__refs) {}
3657protected:
3658 virtual ~__shared_weak_count();
3659
3660public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003661 void __add_shared() _NOEXCEPT;
3662 void __add_weak() _NOEXCEPT;
3663 void __release_shared() _NOEXCEPT;
3664 void __release_weak() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003666 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3667 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003669 // Define the function out only if we build static libc++ without RTTI.
3670 // Otherwise we may break clients who need to compile their projects with
3671 // -fno-rtti and yet link against a libc++.dylib compiled
3672 // without -fno-rtti.
3673#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant1694d232011-05-28 14:41:13 +00003674 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003675#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003676private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003677 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678};
3679
3680template <class _Tp, class _Dp, class _Alloc>
3681class __shared_ptr_pointer
3682 : public __shared_weak_count
3683{
3684 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3685public:
Howard Hinnant82894812010-09-22 16:48:34 +00003686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003687 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003688 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689
Howard Hinnantd4444702010-08-11 17:04:31 +00003690#ifndef _LIBCPP_NO_RTTI
Howard Hinnant1694d232011-05-28 14:41:13 +00003691 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnantd4444702010-08-11 17:04:31 +00003692#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693
3694private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003695 virtual void __on_zero_shared() _NOEXCEPT;
3696 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003697};
3698
Howard Hinnantd4444702010-08-11 17:04:31 +00003699#ifndef _LIBCPP_NO_RTTI
3700
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701template <class _Tp, class _Dp, class _Alloc>
3702const void*
Howard Hinnant1694d232011-05-28 14:41:13 +00003703__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704{
Marshall Clow4b3ca8c2014-11-17 19:05:50 +00003705 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003706}
3707
Howard Hinnant324bb032010-08-22 00:02:43 +00003708#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00003709
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710template <class _Tp, class _Dp, class _Alloc>
3711void
Howard Hinnant1694d232011-05-28 14:41:13 +00003712__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713{
3714 __data_.first().second()(__data_.first().first());
3715 __data_.first().second().~_Dp();
3716}
3717
3718template <class _Tp, class _Dp, class _Alloc>
3719void
Howard Hinnant1694d232011-05-28 14:41:13 +00003720__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003721{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003722 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3723 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003724 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3725
Eric Fiselier8492cd82015-02-05 23:01:40 +00003726 _Al __a(__data_.second());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003727 __data_.second().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003728 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003729}
3730
3731template <class _Tp, class _Alloc>
3732class __shared_ptr_emplace
3733 : public __shared_weak_count
3734{
3735 __compressed_pair<_Alloc, _Tp> __data_;
3736public:
3737#ifndef _LIBCPP_HAS_NO_VARIADICS
3738
Howard Hinnant82894812010-09-22 16:48:34 +00003739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740 __shared_ptr_emplace(_Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003741 : __data_(_VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742
3743 template <class ..._Args>
Howard Hinnant82894812010-09-22 16:48:34 +00003744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00003746 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3747 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748
3749#else // _LIBCPP_HAS_NO_VARIADICS
3750
Howard Hinnant82894812010-09-22 16:48:34 +00003751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752 __shared_ptr_emplace(_Alloc __a)
3753 : __data_(__a) {}
3754
3755 template <class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00003756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003757 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3758 : __data_(__a, _Tp(__a0)) {}
3759
3760 template <class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00003761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003762 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3763 : __data_(__a, _Tp(__a0, __a1)) {}
3764
3765 template <class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00003766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003767 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3768 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3769
3770#endif // _LIBCPP_HAS_NO_VARIADICS
3771
3772private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003773 virtual void __on_zero_shared() _NOEXCEPT;
3774 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003775public:
Howard Hinnant82894812010-09-22 16:48:34 +00003776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003777 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003778};
3779
3780template <class _Tp, class _Alloc>
3781void
Howard Hinnant1694d232011-05-28 14:41:13 +00003782__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003783{
3784 __data_.second().~_Tp();
3785}
3786
3787template <class _Tp, class _Alloc>
3788void
Howard Hinnant1694d232011-05-28 14:41:13 +00003789__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003790{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003791 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3792 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003793 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselier8492cd82015-02-05 23:01:40 +00003794 _Al __a(__data_.first());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003795 __data_.first().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003796 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797}
3798
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003799template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003800
3801template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003802class _LIBCPP_TYPE_VIS_ONLY shared_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803{
Howard Hinnant324bb032010-08-22 00:02:43 +00003804public:
3805 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806private:
3807 element_type* __ptr_;
3808 __shared_weak_count* __cntrl_;
3809
3810 struct __nat {int __for_bool_;};
3811public:
Howard Hinnant46e94932012-07-07 20:56:04 +00003812 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3813 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiene1678a12014-01-31 09:30:46 +00003814 template<class _Yp>
3815 explicit shared_ptr(_Yp* __p,
3816 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3817 template<class _Yp, class _Dp>
3818 shared_ptr(_Yp* __p, _Dp __d,
3819 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3820 template<class _Yp, class _Dp, class _Alloc>
3821 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3822 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003823 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3824 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Howard Hinnant1694d232011-05-28 14:41:13 +00003825 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3826 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827 template<class _Yp>
3828 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003829 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3830 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003831#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003832 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003834 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3835 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003836#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant324bb032010-08-22 00:02:43 +00003838 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003839#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003840 template<class _Yp>
3841 shared_ptr(auto_ptr<_Yp>&& __r,
3842 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant324bb032010-08-22 00:02:43 +00003843#else
Logan Chiene1678a12014-01-31 09:30:46 +00003844 template<class _Yp>
3845 shared_ptr(auto_ptr<_Yp> __r,
3846 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +00003848#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003849 template <class _Yp, class _Dp>
3850 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3851 typename enable_if
3852 <
3853 !is_lvalue_reference<_Dp>::value &&
3854 !is_array<_Yp>::value &&
3855 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3856 __nat
3857 >::type = __nat());
3858 template <class _Yp, class _Dp>
3859 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3860 typename enable_if
3861 <
3862 is_lvalue_reference<_Dp>::value &&
3863 !is_array<_Yp>::value &&
3864 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3865 __nat
3866 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003867#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003868 template <class _Yp, class _Dp>
3869 shared_ptr(unique_ptr<_Yp, _Dp>,
3870 typename enable_if
3871 <
3872 !is_lvalue_reference<_Dp>::value &&
3873 !is_array<_Yp>::value &&
3874 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3875 __nat
3876 >::type = __nat());
3877 template <class _Yp, class _Dp>
3878 shared_ptr(unique_ptr<_Yp, _Dp>,
3879 typename enable_if
3880 <
3881 is_lvalue_reference<_Dp>::value &&
3882 !is_array<_Yp>::value &&
3883 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3884 __nat
3885 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003886#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887
3888 ~shared_ptr();
3889
Howard Hinnant1694d232011-05-28 14:41:13 +00003890 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003891 template<class _Yp>
3892 typename enable_if
3893 <
3894 is_convertible<_Yp*, element_type*>::value,
3895 shared_ptr&
3896 >::type
3897 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003898#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003899 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003900 template<class _Yp>
3901 typename enable_if
3902 <
3903 is_convertible<_Yp*, element_type*>::value,
3904 shared_ptr<_Tp>&
3905 >::type
3906 operator=(shared_ptr<_Yp>&& __r);
3907 template<class _Yp>
3908 typename enable_if
3909 <
3910 !is_array<_Yp>::value &&
3911 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00003912 shared_ptr
3913 >::type&
Howard Hinnant57199402012-01-02 17:56:02 +00003914 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003915#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003916 template<class _Yp>
3917 typename enable_if
3918 <
3919 !is_array<_Yp>::value &&
3920 is_convertible<_Yp*, element_type*>::value,
3921 shared_ptr&
3922 >::type
3923 operator=(auto_ptr<_Yp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003924#endif
Howard Hinnant57199402012-01-02 17:56:02 +00003925 template <class _Yp, class _Dp>
3926 typename enable_if
3927 <
3928 !is_array<_Yp>::value &&
3929 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3930 shared_ptr&
3931 >::type
Howard Hinnant73d21a42010-09-04 23:28:19 +00003932#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003933 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003934#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003935 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003936#endif
3937
Howard Hinnant1694d232011-05-28 14:41:13 +00003938 void swap(shared_ptr& __r) _NOEXCEPT;
3939 void reset() _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003940 template<class _Yp>
3941 typename enable_if
3942 <
3943 is_convertible<_Yp*, element_type*>::value,
3944 void
3945 >::type
3946 reset(_Yp* __p);
3947 template<class _Yp, class _Dp>
3948 typename enable_if
3949 <
3950 is_convertible<_Yp*, element_type*>::value,
3951 void
3952 >::type
3953 reset(_Yp* __p, _Dp __d);
3954 template<class _Yp, class _Dp, class _Alloc>
3955 typename enable_if
3956 <
3957 is_convertible<_Yp*, element_type*>::value,
3958 void
3959 >::type
3960 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003961
Howard Hinnant82894812010-09-22 16:48:34 +00003962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003963 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003965 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3966 {return *__ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003968 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003970 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00003971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003972 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant82894812010-09-22 16:48:34 +00003973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00003974 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnant99968442011-11-29 18:15:50 +00003975 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003977 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant99968442011-11-29 18:15:50 +00003979 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003981 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003982 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003983 _LIBCPP_INLINE_VISIBILITY
3984 bool
3985 __owner_equivalent(const shared_ptr& __p) const
3986 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003987
Howard Hinnantd4444702010-08-11 17:04:31 +00003988#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989 template <class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00003990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003991 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant324bb032010-08-22 00:02:43 +00003993#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003994
3995#ifndef _LIBCPP_HAS_NO_VARIADICS
3996
3997 template<class ..._Args>
3998 static
3999 shared_ptr<_Tp>
4000 make_shared(_Args&& ...__args);
4001
4002 template<class _Alloc, class ..._Args>
4003 static
4004 shared_ptr<_Tp>
4005 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4006
4007#else // _LIBCPP_HAS_NO_VARIADICS
4008
4009 static shared_ptr<_Tp> make_shared();
4010
4011 template<class _A0>
4012 static shared_ptr<_Tp> make_shared(_A0&);
4013
4014 template<class _A0, class _A1>
4015 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4016
4017 template<class _A0, class _A1, class _A2>
4018 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4019
4020 template<class _Alloc>
4021 static shared_ptr<_Tp>
4022 allocate_shared(const _Alloc& __a);
4023
4024 template<class _Alloc, class _A0>
4025 static shared_ptr<_Tp>
4026 allocate_shared(const _Alloc& __a, _A0& __a0);
4027
4028 template<class _Alloc, class _A0, class _A1>
4029 static shared_ptr<_Tp>
4030 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4031
4032 template<class _Alloc, class _A0, class _A1, class _A2>
4033 static shared_ptr<_Tp>
4034 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4035
4036#endif // _LIBCPP_HAS_NO_VARIADICS
4037
4038private:
4039
4040 template <class _Yp>
Howard Hinnant82894812010-09-22 16:48:34 +00004041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004042 void
Howard Hinnant1694d232011-05-28 14:41:13 +00004043 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004044 {
4045 if (__e)
4046 __e->__weak_this_ = *this;
4047 }
4048
Howard Hinnant82894812010-09-22 16:48:34 +00004049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004050 void __enable_weak_this(const void*) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004051
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004052 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4053 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054};
4055
4056template<class _Tp>
4057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004058_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004059shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004060 : __ptr_(0),
4061 __cntrl_(0)
4062{
4063}
4064
4065template<class _Tp>
4066inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004067_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004068shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004069 : __ptr_(0),
4070 __cntrl_(0)
4071{
4072}
4073
4074template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004075template<class _Yp>
4076shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4077 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004078 : __ptr_(__p)
4079{
4080 unique_ptr<_Yp> __hold(__p);
4081 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4082 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4083 __hold.release();
4084 __enable_weak_this(__p);
4085}
4086
4087template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004088template<class _Yp, class _Dp>
4089shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4090 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091 : __ptr_(__p)
4092{
4093#ifndef _LIBCPP_NO_EXCEPTIONS
4094 try
4095 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004096#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004097 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4098 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4099 __enable_weak_this(__p);
4100#ifndef _LIBCPP_NO_EXCEPTIONS
4101 }
4102 catch (...)
4103 {
4104 __d(__p);
4105 throw;
4106 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004107#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004108}
4109
4110template<class _Tp>
4111template<class _Dp>
4112shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4113 : __ptr_(0)
4114{
4115#ifndef _LIBCPP_NO_EXCEPTIONS
4116 try
4117 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004118#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004119 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4120 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4121#ifndef _LIBCPP_NO_EXCEPTIONS
4122 }
4123 catch (...)
4124 {
4125 __d(__p);
4126 throw;
4127 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004128#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004129}
4130
4131template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004132template<class _Yp, class _Dp, class _Alloc>
4133shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4134 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004135 : __ptr_(__p)
4136{
4137#ifndef _LIBCPP_NO_EXCEPTIONS
4138 try
4139 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004140#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004141 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004142 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004143 typedef __allocator_destructor<_A2> _D2;
4144 _A2 __a2(__a);
4145 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004146 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4147 _CntrlBlk(__p, __d, __a);
4148 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004149 __enable_weak_this(__p);
4150#ifndef _LIBCPP_NO_EXCEPTIONS
4151 }
4152 catch (...)
4153 {
4154 __d(__p);
4155 throw;
4156 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004157#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004158}
4159
4160template<class _Tp>
4161template<class _Dp, class _Alloc>
4162shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4163 : __ptr_(0)
4164{
4165#ifndef _LIBCPP_NO_EXCEPTIONS
4166 try
4167 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004168#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004169 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004170 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004171 typedef __allocator_destructor<_A2> _D2;
4172 _A2 __a2(__a);
4173 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004174 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4175 _CntrlBlk(__p, __d, __a);
4176 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177#ifndef _LIBCPP_NO_EXCEPTIONS
4178 }
4179 catch (...)
4180 {
4181 __d(__p);
4182 throw;
4183 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004184#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004185}
4186
4187template<class _Tp>
4188template<class _Yp>
4189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004190shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004191 : __ptr_(__p),
4192 __cntrl_(__r.__cntrl_)
4193{
4194 if (__cntrl_)
4195 __cntrl_->__add_shared();
4196}
4197
4198template<class _Tp>
4199inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004200shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004201 : __ptr_(__r.__ptr_),
4202 __cntrl_(__r.__cntrl_)
4203{
4204 if (__cntrl_)
4205 __cntrl_->__add_shared();
4206}
4207
4208template<class _Tp>
4209template<class _Yp>
4210inline _LIBCPP_INLINE_VISIBILITY
4211shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4212 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004213 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004214 : __ptr_(__r.__ptr_),
4215 __cntrl_(__r.__cntrl_)
4216{
4217 if (__cntrl_)
4218 __cntrl_->__add_shared();
4219}
4220
Howard Hinnant73d21a42010-09-04 23:28:19 +00004221#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004222
4223template<class _Tp>
4224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004225shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004226 : __ptr_(__r.__ptr_),
4227 __cntrl_(__r.__cntrl_)
4228{
4229 __r.__ptr_ = 0;
4230 __r.__cntrl_ = 0;
4231}
4232
4233template<class _Tp>
4234template<class _Yp>
4235inline _LIBCPP_INLINE_VISIBILITY
4236shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4237 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004238 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004239 : __ptr_(__r.__ptr_),
4240 __cntrl_(__r.__cntrl_)
4241{
4242 __r.__ptr_ = 0;
4243 __r.__cntrl_ = 0;
4244}
4245
Howard Hinnant73d21a42010-09-04 23:28:19 +00004246#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004247
4248template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004249template<class _Yp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004250#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00004251shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004252#else
Logan Chiene1678a12014-01-31 09:30:46 +00004253shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004254#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004255 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004256 : __ptr_(__r.get())
4257{
4258 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4259 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4260 __enable_weak_this(__r.get());
4261 __r.release();
4262}
4263
4264template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004265template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004266#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004267shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4268#else
4269shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4270#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004271 typename enable_if
4272 <
4273 !is_lvalue_reference<_Dp>::value &&
4274 !is_array<_Yp>::value &&
4275 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4276 __nat
4277 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004278 : __ptr_(__r.get())
4279{
4280 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4281 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4282 __enable_weak_this(__r.get());
4283 __r.release();
4284}
4285
4286template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004287template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004288#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004289shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4290#else
4291shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4292#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004293 typename enable_if
4294 <
4295 is_lvalue_reference<_Dp>::value &&
4296 !is_array<_Yp>::value &&
4297 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4298 __nat
4299 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004300 : __ptr_(__r.get())
4301{
4302 typedef __shared_ptr_pointer<_Yp*,
4303 reference_wrapper<typename remove_reference<_Dp>::type>,
4304 allocator<_Yp> > _CntrlBlk;
4305 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4306 __enable_weak_this(__r.get());
4307 __r.release();
4308}
4309
4310#ifndef _LIBCPP_HAS_NO_VARIADICS
4311
4312template<class _Tp>
4313template<class ..._Args>
4314shared_ptr<_Tp>
4315shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4316{
4317 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4318 typedef allocator<_CntrlBlk> _A2;
4319 typedef __allocator_destructor<_A2> _D2;
4320 _A2 __a2;
4321 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00004322 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004323 shared_ptr<_Tp> __r;
4324 __r.__ptr_ = __hold2.get()->get();
4325 __r.__cntrl_ = __hold2.release();
4326 __r.__enable_weak_this(__r.__ptr_);
4327 return __r;
4328}
4329
4330template<class _Tp>
4331template<class _Alloc, class ..._Args>
4332shared_ptr<_Tp>
4333shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4334{
4335 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004336 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004337 typedef __allocator_destructor<_A2> _D2;
4338 _A2 __a2(__a);
4339 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004340 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4341 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004342 shared_ptr<_Tp> __r;
4343 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004344 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004345 __r.__enable_weak_this(__r.__ptr_);
4346 return __r;
4347}
4348
4349#else // _LIBCPP_HAS_NO_VARIADICS
4350
4351template<class _Tp>
4352shared_ptr<_Tp>
4353shared_ptr<_Tp>::make_shared()
4354{
4355 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4356 typedef allocator<_CntrlBlk> _Alloc2;
4357 typedef __allocator_destructor<_Alloc2> _D2;
4358 _Alloc2 __alloc2;
4359 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4360 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4361 shared_ptr<_Tp> __r;
4362 __r.__ptr_ = __hold2.get()->get();
4363 __r.__cntrl_ = __hold2.release();
4364 __r.__enable_weak_this(__r.__ptr_);
4365 return __r;
4366}
4367
4368template<class _Tp>
4369template<class _A0>
4370shared_ptr<_Tp>
4371shared_ptr<_Tp>::make_shared(_A0& __a0)
4372{
4373 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4374 typedef allocator<_CntrlBlk> _Alloc2;
4375 typedef __allocator_destructor<_Alloc2> _D2;
4376 _Alloc2 __alloc2;
4377 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4378 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4379 shared_ptr<_Tp> __r;
4380 __r.__ptr_ = __hold2.get()->get();
4381 __r.__cntrl_ = __hold2.release();
4382 __r.__enable_weak_this(__r.__ptr_);
4383 return __r;
4384}
4385
4386template<class _Tp>
4387template<class _A0, class _A1>
4388shared_ptr<_Tp>
4389shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4390{
4391 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4392 typedef allocator<_CntrlBlk> _Alloc2;
4393 typedef __allocator_destructor<_Alloc2> _D2;
4394 _Alloc2 __alloc2;
4395 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4396 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4397 shared_ptr<_Tp> __r;
4398 __r.__ptr_ = __hold2.get()->get();
4399 __r.__cntrl_ = __hold2.release();
4400 __r.__enable_weak_this(__r.__ptr_);
4401 return __r;
4402}
4403
4404template<class _Tp>
4405template<class _A0, class _A1, class _A2>
4406shared_ptr<_Tp>
4407shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4408{
4409 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4410 typedef allocator<_CntrlBlk> _Alloc2;
4411 typedef __allocator_destructor<_Alloc2> _D2;
4412 _Alloc2 __alloc2;
4413 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4414 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4415 shared_ptr<_Tp> __r;
4416 __r.__ptr_ = __hold2.get()->get();
4417 __r.__cntrl_ = __hold2.release();
4418 __r.__enable_weak_this(__r.__ptr_);
4419 return __r;
4420}
4421
4422template<class _Tp>
4423template<class _Alloc>
4424shared_ptr<_Tp>
4425shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4426{
4427 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004428 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004429 typedef __allocator_destructor<_Alloc2> _D2;
4430 _Alloc2 __alloc2(__a);
4431 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004432 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4433 _CntrlBlk(__a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004434 shared_ptr<_Tp> __r;
4435 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004436 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004437 __r.__enable_weak_this(__r.__ptr_);
4438 return __r;
4439}
4440
4441template<class _Tp>
4442template<class _Alloc, class _A0>
4443shared_ptr<_Tp>
4444shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4445{
4446 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004447 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004448 typedef __allocator_destructor<_Alloc2> _D2;
4449 _Alloc2 __alloc2(__a);
4450 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004451 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4452 _CntrlBlk(__a, __a0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004453 shared_ptr<_Tp> __r;
4454 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004455 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004456 __r.__enable_weak_this(__r.__ptr_);
4457 return __r;
4458}
4459
4460template<class _Tp>
4461template<class _Alloc, class _A0, class _A1>
4462shared_ptr<_Tp>
4463shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4464{
4465 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004466 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004467 typedef __allocator_destructor<_Alloc2> _D2;
4468 _Alloc2 __alloc2(__a);
4469 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004470 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4471 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004472 shared_ptr<_Tp> __r;
4473 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004474 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004475 __r.__enable_weak_this(__r.__ptr_);
4476 return __r;
4477}
4478
4479template<class _Tp>
4480template<class _Alloc, class _A0, class _A1, class _A2>
4481shared_ptr<_Tp>
4482shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4483{
4484 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004485 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004486 typedef __allocator_destructor<_Alloc2> _D2;
4487 _Alloc2 __alloc2(__a);
4488 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004489 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4490 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004491 shared_ptr<_Tp> __r;
4492 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004493 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004494 __r.__enable_weak_this(__r.__ptr_);
4495 return __r;
4496}
4497
4498#endif // _LIBCPP_HAS_NO_VARIADICS
4499
4500template<class _Tp>
4501shared_ptr<_Tp>::~shared_ptr()
4502{
4503 if (__cntrl_)
4504 __cntrl_->__release_shared();
4505}
4506
4507template<class _Tp>
4508inline _LIBCPP_INLINE_VISIBILITY
4509shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004510shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004511{
4512 shared_ptr(__r).swap(*this);
4513 return *this;
4514}
4515
4516template<class _Tp>
4517template<class _Yp>
4518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004519typename enable_if
4520<
4521 is_convertible<_Yp*, _Tp*>::value,
4522 shared_ptr<_Tp>&
4523>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004524shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004525{
4526 shared_ptr(__r).swap(*this);
4527 return *this;
4528}
4529
Howard Hinnant73d21a42010-09-04 23:28:19 +00004530#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004531
4532template<class _Tp>
4533inline _LIBCPP_INLINE_VISIBILITY
4534shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004535shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004536{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004537 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004538 return *this;
4539}
4540
4541template<class _Tp>
4542template<class _Yp>
4543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004544typename enable_if
4545<
4546 is_convertible<_Yp*, _Tp*>::value,
4547 shared_ptr<_Tp>&
4548>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004549shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4550{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004551 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004552 return *this;
4553}
4554
4555template<class _Tp>
4556template<class _Yp>
4557inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004558typename enable_if
4559<
4560 !is_array<_Yp>::value &&
4561 is_convertible<_Yp*, _Tp*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00004562 shared_ptr<_Tp>
4563>::type&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004564shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4565{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004566 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004567 return *this;
4568}
4569
4570template<class _Tp>
4571template <class _Yp, class _Dp>
4572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004573typename enable_if
4574<
4575 !is_array<_Yp>::value &&
4576 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4577 shared_ptr<_Tp>&
4578>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004579shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4580{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004581 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004582 return *this;
4583}
4584
Howard Hinnant73d21a42010-09-04 23:28:19 +00004585#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004586
4587template<class _Tp>
4588template<class _Yp>
4589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004590typename enable_if
4591<
4592 !is_array<_Yp>::value &&
4593 is_convertible<_Yp*, _Tp*>::value,
4594 shared_ptr<_Tp>&
4595>::type
Howard Hinnant324bb032010-08-22 00:02:43 +00004596shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004597{
4598 shared_ptr(__r).swap(*this);
4599 return *this;
4600}
4601
4602template<class _Tp>
4603template <class _Yp, class _Dp>
4604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004605typename enable_if
4606<
4607 !is_array<_Yp>::value &&
4608 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4609 shared_ptr<_Tp>&
4610>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004611shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4612{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004613 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004614 return *this;
4615}
4616
Howard Hinnant73d21a42010-09-04 23:28:19 +00004617#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004618
4619template<class _Tp>
4620inline _LIBCPP_INLINE_VISIBILITY
4621void
Howard Hinnant1694d232011-05-28 14:41:13 +00004622shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004623{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004624 _VSTD::swap(__ptr_, __r.__ptr_);
4625 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004626}
4627
4628template<class _Tp>
4629inline _LIBCPP_INLINE_VISIBILITY
4630void
Howard Hinnant1694d232011-05-28 14:41:13 +00004631shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004632{
4633 shared_ptr().swap(*this);
4634}
4635
4636template<class _Tp>
4637template<class _Yp>
4638inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004639typename enable_if
4640<
4641 is_convertible<_Yp*, _Tp*>::value,
4642 void
4643>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004644shared_ptr<_Tp>::reset(_Yp* __p)
4645{
4646 shared_ptr(__p).swap(*this);
4647}
4648
4649template<class _Tp>
4650template<class _Yp, class _Dp>
4651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004652typename enable_if
4653<
4654 is_convertible<_Yp*, _Tp*>::value,
4655 void
4656>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004657shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4658{
4659 shared_ptr(__p, __d).swap(*this);
4660}
4661
4662template<class _Tp>
4663template<class _Yp, class _Dp, class _Alloc>
4664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004665typename enable_if
4666<
4667 is_convertible<_Yp*, _Tp*>::value,
4668 void
4669>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004670shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4671{
4672 shared_ptr(__p, __d, __a).swap(*this);
4673}
4674
4675#ifndef _LIBCPP_HAS_NO_VARIADICS
4676
Howard Hinnant324bb032010-08-22 00:02:43 +00004677template<class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004678inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004679typename enable_if
4680<
4681 !is_array<_Tp>::value,
4682 shared_ptr<_Tp>
4683>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004684make_shared(_Args&& ...__args)
4685{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004686 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004687}
4688
Howard Hinnant324bb032010-08-22 00:02:43 +00004689template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004690inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004691typename enable_if
4692<
4693 !is_array<_Tp>::value,
4694 shared_ptr<_Tp>
4695>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004696allocate_shared(const _Alloc& __a, _Args&& ...__args)
4697{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004698 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004699}
4700
4701#else // _LIBCPP_HAS_NO_VARIADICS
4702
4703template<class _Tp>
4704inline _LIBCPP_INLINE_VISIBILITY
4705shared_ptr<_Tp>
4706make_shared()
4707{
4708 return shared_ptr<_Tp>::make_shared();
4709}
4710
4711template<class _Tp, class _A0>
4712inline _LIBCPP_INLINE_VISIBILITY
4713shared_ptr<_Tp>
4714make_shared(_A0& __a0)
4715{
4716 return shared_ptr<_Tp>::make_shared(__a0);
4717}
4718
4719template<class _Tp, class _A0, class _A1>
4720inline _LIBCPP_INLINE_VISIBILITY
4721shared_ptr<_Tp>
4722make_shared(_A0& __a0, _A1& __a1)
4723{
4724 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4725}
4726
Howard Hinnant324bb032010-08-22 00:02:43 +00004727template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004728inline _LIBCPP_INLINE_VISIBILITY
4729shared_ptr<_Tp>
4730make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4731{
4732 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4733}
4734
4735template<class _Tp, class _Alloc>
4736inline _LIBCPP_INLINE_VISIBILITY
4737shared_ptr<_Tp>
4738allocate_shared(const _Alloc& __a)
4739{
4740 return shared_ptr<_Tp>::allocate_shared(__a);
4741}
4742
4743template<class _Tp, class _Alloc, class _A0>
4744inline _LIBCPP_INLINE_VISIBILITY
4745shared_ptr<_Tp>
4746allocate_shared(const _Alloc& __a, _A0& __a0)
4747{
4748 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4749}
4750
4751template<class _Tp, class _Alloc, class _A0, class _A1>
4752inline _LIBCPP_INLINE_VISIBILITY
4753shared_ptr<_Tp>
4754allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4755{
4756 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4757}
4758
4759template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4760inline _LIBCPP_INLINE_VISIBILITY
4761shared_ptr<_Tp>
4762allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4763{
4764 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4765}
4766
4767#endif // _LIBCPP_HAS_NO_VARIADICS
4768
4769template<class _Tp, class _Up>
4770inline _LIBCPP_INLINE_VISIBILITY
4771bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004772operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004773{
4774 return __x.get() == __y.get();
4775}
4776
4777template<class _Tp, class _Up>
4778inline _LIBCPP_INLINE_VISIBILITY
4779bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004780operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004781{
4782 return !(__x == __y);
4783}
4784
4785template<class _Tp, class _Up>
4786inline _LIBCPP_INLINE_VISIBILITY
4787bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004788operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004789{
Eric Fiselier8492cd82015-02-05 23:01:40 +00004790 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4791 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00004792}
4793
4794template<class _Tp, class _Up>
4795inline _LIBCPP_INLINE_VISIBILITY
4796bool
4797operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4798{
4799 return __y < __x;
4800}
4801
4802template<class _Tp, class _Up>
4803inline _LIBCPP_INLINE_VISIBILITY
4804bool
4805operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4806{
4807 return !(__y < __x);
4808}
4809
4810template<class _Tp, class _Up>
4811inline _LIBCPP_INLINE_VISIBILITY
4812bool
4813operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4814{
4815 return !(__x < __y);
4816}
4817
4818template<class _Tp>
4819inline _LIBCPP_INLINE_VISIBILITY
4820bool
4821operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4822{
4823 return !__x;
4824}
4825
4826template<class _Tp>
4827inline _LIBCPP_INLINE_VISIBILITY
4828bool
4829operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4830{
4831 return !__x;
4832}
4833
4834template<class _Tp>
4835inline _LIBCPP_INLINE_VISIBILITY
4836bool
4837operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4838{
4839 return static_cast<bool>(__x);
4840}
4841
4842template<class _Tp>
4843inline _LIBCPP_INLINE_VISIBILITY
4844bool
4845operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4846{
4847 return static_cast<bool>(__x);
4848}
4849
4850template<class _Tp>
4851inline _LIBCPP_INLINE_VISIBILITY
4852bool
4853operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4854{
4855 return less<_Tp*>()(__x.get(), nullptr);
4856}
4857
4858template<class _Tp>
4859inline _LIBCPP_INLINE_VISIBILITY
4860bool
4861operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4862{
4863 return less<_Tp*>()(nullptr, __x.get());
4864}
4865
4866template<class _Tp>
4867inline _LIBCPP_INLINE_VISIBILITY
4868bool
4869operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4870{
4871 return nullptr < __x;
4872}
4873
4874template<class _Tp>
4875inline _LIBCPP_INLINE_VISIBILITY
4876bool
4877operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4878{
4879 return __x < nullptr;
4880}
4881
4882template<class _Tp>
4883inline _LIBCPP_INLINE_VISIBILITY
4884bool
4885operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4886{
4887 return !(nullptr < __x);
4888}
4889
4890template<class _Tp>
4891inline _LIBCPP_INLINE_VISIBILITY
4892bool
4893operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4894{
4895 return !(__x < nullptr);
4896}
4897
4898template<class _Tp>
4899inline _LIBCPP_INLINE_VISIBILITY
4900bool
4901operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4902{
4903 return !(__x < nullptr);
4904}
4905
4906template<class _Tp>
4907inline _LIBCPP_INLINE_VISIBILITY
4908bool
4909operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4910{
4911 return !(nullptr < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004912}
4913
4914template<class _Tp>
4915inline _LIBCPP_INLINE_VISIBILITY
4916void
Howard Hinnant1694d232011-05-28 14:41:13 +00004917swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004918{
4919 __x.swap(__y);
4920}
4921
4922template<class _Tp, class _Up>
4923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004924typename enable_if
4925<
4926 !is_array<_Tp>::value && !is_array<_Up>::value,
4927 shared_ptr<_Tp>
4928>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004929static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004930{
4931 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4932}
4933
4934template<class _Tp, class _Up>
4935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004936typename enable_if
4937<
4938 !is_array<_Tp>::value && !is_array<_Up>::value,
4939 shared_ptr<_Tp>
4940>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004941dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004942{
4943 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4944 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4945}
4946
4947template<class _Tp, class _Up>
Howard Hinnant57199402012-01-02 17:56:02 +00004948typename enable_if
4949<
4950 is_array<_Tp>::value == is_array<_Up>::value,
4951 shared_ptr<_Tp>
4952>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004953const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004954{
Howard Hinnant57199402012-01-02 17:56:02 +00004955 typedef typename remove_extent<_Tp>::type _RTp;
4956 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004957}
4958
Howard Hinnantd4444702010-08-11 17:04:31 +00004959#ifndef _LIBCPP_NO_RTTI
4960
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004961template<class _Dp, class _Tp>
4962inline _LIBCPP_INLINE_VISIBILITY
4963_Dp*
Howard Hinnant1694d232011-05-28 14:41:13 +00004964get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004965{
4966 return __p.template __get_deleter<_Dp>();
4967}
4968
Howard Hinnant324bb032010-08-22 00:02:43 +00004969#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00004970
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004971template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004972class _LIBCPP_TYPE_VIS_ONLY weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004973{
Howard Hinnant324bb032010-08-22 00:02:43 +00004974public:
4975 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004976private:
4977 element_type* __ptr_;
4978 __shared_weak_count* __cntrl_;
4979
Howard Hinnant324bb032010-08-22 00:02:43 +00004980public:
Howard Hinnant46e94932012-07-07 20:56:04 +00004981 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004982 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00004983 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4984 _NOEXCEPT;
4985 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004986 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00004987 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4988 _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00004989
Howard Hinnant57199402012-01-02 17:56:02 +00004990#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4991 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4992 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4993 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4994 _NOEXCEPT;
4995#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant324bb032010-08-22 00:02:43 +00004996 ~weak_ptr();
4997
Howard Hinnant1694d232011-05-28 14:41:13 +00004998 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00004999 template<class _Yp>
5000 typename enable_if
5001 <
5002 is_convertible<_Yp*, element_type*>::value,
5003 weak_ptr&
5004 >::type
5005 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5006
5007#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5008
5009 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5010 template<class _Yp>
5011 typename enable_if
5012 <
5013 is_convertible<_Yp*, element_type*>::value,
5014 weak_ptr&
5015 >::type
5016 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5017
5018#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5019
5020 template<class _Yp>
5021 typename enable_if
5022 <
5023 is_convertible<_Yp*, element_type*>::value,
5024 weak_ptr&
5025 >::type
5026 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005027
Howard Hinnant1694d232011-05-28 14:41:13 +00005028 void swap(weak_ptr& __r) _NOEXCEPT;
5029 void reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005030
Howard Hinnant82894812010-09-22 16:48:34 +00005031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005032 long use_count() const _NOEXCEPT
5033 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00005034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005035 bool expired() const _NOEXCEPT
5036 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5037 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00005038 template<class _Up>
5039 _LIBCPP_INLINE_VISIBILITY
5040 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005041 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant82894812010-09-22 16:48:34 +00005042 template<class _Up>
5043 _LIBCPP_INLINE_VISIBILITY
5044 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005045 {return __cntrl_ < __r.__cntrl_;}
5046
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005047 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5048 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005049};
5050
5051template<class _Tp>
5052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00005053_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005054weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005055 : __ptr_(0),
5056 __cntrl_(0)
5057{
5058}
5059
5060template<class _Tp>
5061inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005062weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005063 : __ptr_(__r.__ptr_),
5064 __cntrl_(__r.__cntrl_)
5065{
5066 if (__cntrl_)
5067 __cntrl_->__add_weak();
5068}
5069
5070template<class _Tp>
5071template<class _Yp>
5072inline _LIBCPP_INLINE_VISIBILITY
5073weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005074 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005075 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005076 : __ptr_(__r.__ptr_),
5077 __cntrl_(__r.__cntrl_)
5078{
5079 if (__cntrl_)
5080 __cntrl_->__add_weak();
5081}
5082
5083template<class _Tp>
5084template<class _Yp>
5085inline _LIBCPP_INLINE_VISIBILITY
5086weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005087 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005088 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005089 : __ptr_(__r.__ptr_),
5090 __cntrl_(__r.__cntrl_)
5091{
5092 if (__cntrl_)
5093 __cntrl_->__add_weak();
5094}
5095
Howard Hinnant57199402012-01-02 17:56:02 +00005096#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5097
5098template<class _Tp>
5099inline _LIBCPP_INLINE_VISIBILITY
5100weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5101 : __ptr_(__r.__ptr_),
5102 __cntrl_(__r.__cntrl_)
5103{
5104 __r.__ptr_ = 0;
5105 __r.__cntrl_ = 0;
5106}
5107
5108template<class _Tp>
5109template<class _Yp>
5110inline _LIBCPP_INLINE_VISIBILITY
5111weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5112 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5113 _NOEXCEPT
5114 : __ptr_(__r.__ptr_),
5115 __cntrl_(__r.__cntrl_)
5116{
5117 __r.__ptr_ = 0;
5118 __r.__cntrl_ = 0;
5119}
5120
5121#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5122
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005123template<class _Tp>
5124weak_ptr<_Tp>::~weak_ptr()
5125{
5126 if (__cntrl_)
5127 __cntrl_->__release_weak();
5128}
5129
5130template<class _Tp>
5131inline _LIBCPP_INLINE_VISIBILITY
5132weak_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00005133weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005134{
5135 weak_ptr(__r).swap(*this);
5136 return *this;
5137}
5138
5139template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005140template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005142typename enable_if
5143<
5144 is_convertible<_Yp*, _Tp*>::value,
5145 weak_ptr<_Tp>&
5146>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005147weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005148{
5149 weak_ptr(__r).swap(*this);
5150 return *this;
5151}
5152
Howard Hinnant57199402012-01-02 17:56:02 +00005153#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5154
5155template<class _Tp>
5156inline _LIBCPP_INLINE_VISIBILITY
5157weak_ptr<_Tp>&
5158weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5159{
5160 weak_ptr(_VSTD::move(__r)).swap(*this);
5161 return *this;
5162}
5163
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005164template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005165template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005166inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005167typename enable_if
5168<
5169 is_convertible<_Yp*, _Tp*>::value,
5170 weak_ptr<_Tp>&
5171>::type
5172weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5173{
5174 weak_ptr(_VSTD::move(__r)).swap(*this);
5175 return *this;
5176}
5177
5178#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5179
5180template<class _Tp>
5181template<class _Yp>
5182inline _LIBCPP_INLINE_VISIBILITY
5183typename enable_if
5184<
5185 is_convertible<_Yp*, _Tp*>::value,
5186 weak_ptr<_Tp>&
5187>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005188weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005189{
5190 weak_ptr(__r).swap(*this);
5191 return *this;
5192}
5193
5194template<class _Tp>
5195inline _LIBCPP_INLINE_VISIBILITY
5196void
Howard Hinnant1694d232011-05-28 14:41:13 +00005197weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005198{
Howard Hinnant0949eed2011-06-30 21:18:19 +00005199 _VSTD::swap(__ptr_, __r.__ptr_);
5200 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005201}
5202
5203template<class _Tp>
5204inline _LIBCPP_INLINE_VISIBILITY
5205void
Howard Hinnant1694d232011-05-28 14:41:13 +00005206swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005207{
5208 __x.swap(__y);
5209}
5210
5211template<class _Tp>
5212inline _LIBCPP_INLINE_VISIBILITY
5213void
Howard Hinnant1694d232011-05-28 14:41:13 +00005214weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005215{
5216 weak_ptr().swap(*this);
5217}
5218
5219template<class _Tp>
5220template<class _Yp>
5221shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5222 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5223 : __ptr_(__r.__ptr_),
5224 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5225{
5226 if (__cntrl_ == 0)
5227#ifndef _LIBCPP_NO_EXCEPTIONS
5228 throw bad_weak_ptr();
5229#else
5230 assert(!"bad_weak_ptr");
5231#endif
5232}
5233
5234template<class _Tp>
5235shared_ptr<_Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00005236weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005237{
5238 shared_ptr<_Tp> __r;
5239 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5240 if (__r.__cntrl_)
5241 __r.__ptr_ = __ptr_;
5242 return __r;
5243}
5244
Howard Hinnant324bb032010-08-22 00:02:43 +00005245template <class _Tp> struct owner_less;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005246
5247template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005248struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005249 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant324bb032010-08-22 00:02:43 +00005250{
5251 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005253 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5254 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005256 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5257 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005259 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5260 {return __x.owner_before(__y);}
Howard Hinnant324bb032010-08-22 00:02:43 +00005261};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005262
5263template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005264struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005265 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5266{
Howard Hinnant324bb032010-08-22 00:02:43 +00005267 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005269 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5270 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005272 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5273 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005275 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5276 {return __x.owner_before(__y);}
5277};
5278
5279template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005280class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005281{
5282 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant324bb032010-08-22 00:02:43 +00005283protected:
Howard Hinnant46e94932012-07-07 20:56:04 +00005284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005285 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005287 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005289 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5290 {return *this;}
Howard Hinnant82894812010-09-22 16:48:34 +00005291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005292 ~enable_shared_from_this() {}
Howard Hinnant324bb032010-08-22 00:02:43 +00005293public:
Howard Hinnant82894812010-09-22 16:48:34 +00005294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005295 shared_ptr<_Tp> shared_from_this()
5296 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant82894812010-09-22 16:48:34 +00005297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005298 shared_ptr<_Tp const> shared_from_this() const
5299 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005300
5301 template <class _Up> friend class shared_ptr;
5302};
5303
Howard Hinnant21aefc32010-06-03 16:42:57 +00005304template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005305struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00005306{
5307 typedef shared_ptr<_Tp> argument_type;
5308 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005310 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00005311 {
5312 return hash<_Tp*>()(__ptr.get());
5313 }
5314};
5315
Howard Hinnant99968442011-11-29 18:15:50 +00005316template<class _CharT, class _Traits, class _Yp>
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005317inline _LIBCPP_INLINE_VISIBILITY
5318basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00005319operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005320
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005321#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005322
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005323class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005324{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005325 void* __lx;
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005326public:
5327 void lock() _NOEXCEPT;
5328 void unlock() _NOEXCEPT;
5329
5330private:
5331 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5332 __sp_mut(const __sp_mut&);
5333 __sp_mut& operator=(const __sp_mut&);
5334
Howard Hinnant83eade62013-03-06 23:30:19 +00005335 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005336};
5337
Howard Hinnant83eade62013-03-06 23:30:19 +00005338_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005339
5340template <class _Tp>
5341inline _LIBCPP_INLINE_VISIBILITY
5342bool
5343atomic_is_lock_free(const shared_ptr<_Tp>*)
5344{
5345 return false;
5346}
5347
5348template <class _Tp>
5349shared_ptr<_Tp>
5350atomic_load(const shared_ptr<_Tp>* __p)
5351{
5352 __sp_mut& __m = __get_sp_mut(__p);
5353 __m.lock();
5354 shared_ptr<_Tp> __q = *__p;
5355 __m.unlock();
5356 return __q;
5357}
5358
5359template <class _Tp>
5360inline _LIBCPP_INLINE_VISIBILITY
5361shared_ptr<_Tp>
5362atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5363{
5364 return atomic_load(__p);
5365}
5366
5367template <class _Tp>
5368void
5369atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5370{
5371 __sp_mut& __m = __get_sp_mut(__p);
5372 __m.lock();
5373 __p->swap(__r);
5374 __m.unlock();
5375}
5376
5377template <class _Tp>
5378inline _LIBCPP_INLINE_VISIBILITY
5379void
5380atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5381{
5382 atomic_store(__p, __r);
5383}
5384
5385template <class _Tp>
5386shared_ptr<_Tp>
5387atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5388{
5389 __sp_mut& __m = __get_sp_mut(__p);
5390 __m.lock();
5391 __p->swap(__r);
5392 __m.unlock();
5393 return __r;
5394}
5395
5396template <class _Tp>
5397inline _LIBCPP_INLINE_VISIBILITY
5398shared_ptr<_Tp>
5399atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5400{
5401 return atomic_exchange(__p, __r);
5402}
5403
5404template <class _Tp>
5405bool
5406atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5407{
5408 __sp_mut& __m = __get_sp_mut(__p);
5409 __m.lock();
5410 if (__p->__owner_equivalent(*__v))
5411 {
5412 *__p = __w;
5413 __m.unlock();
5414 return true;
5415 }
5416 *__v = *__p;
5417 __m.unlock();
5418 return false;
5419}
5420
5421template <class _Tp>
5422inline _LIBCPP_INLINE_VISIBILITY
5423bool
5424atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5425{
5426 return atomic_compare_exchange_strong(__p, __v, __w);
5427}
5428
5429template <class _Tp>
5430inline _LIBCPP_INLINE_VISIBILITY
5431bool
5432atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5433 shared_ptr<_Tp> __w, memory_order, memory_order)
5434{
5435 return atomic_compare_exchange_strong(__p, __v, __w);
5436}
5437
5438template <class _Tp>
5439inline _LIBCPP_INLINE_VISIBILITY
5440bool
5441atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5442 shared_ptr<_Tp> __w, memory_order, memory_order)
5443{
5444 return atomic_compare_exchange_weak(__p, __v, __w);
5445}
5446
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005447#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005448
Howard Hinnant324bb032010-08-22 00:02:43 +00005449//enum class
Howard Hinnant83eade62013-03-06 23:30:19 +00005450struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005451{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005452 enum __lx
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005453 {
5454 relaxed,
5455 preferred,
5456 strict
5457 };
5458
Howard Hinnant9c0df142012-10-30 19:06:59 +00005459 __lx __v_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005460
Howard Hinnant82894812010-09-22 16:48:34 +00005461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9c0df142012-10-30 19:06:59 +00005462 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant82894812010-09-22 16:48:34 +00005463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005464 operator int() const {return __v_;}
5465};
5466
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005467_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5468_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5469_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5470_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5471_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005472
5473template <class _Tp>
5474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00005475_Tp*
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005476undeclare_reachable(_Tp* __p)
5477{
5478 return static_cast<_Tp*>(__undeclare_reachable(__p));
5479}
5480
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005481_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005482
5483_LIBCPP_END_NAMESPACE_STD
5484
5485#endif // _LIBCPP_MEMORY