blob: 4e3a6f814f1ff3d512e644c2c4e2002b99a130fa [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;
Marshall Clowbf0460e2015-05-31 03:13:31 +00001524 if (_Np > 0)
Marshall Clow56523ff2015-06-02 13:04:18 +00001525 {
Marshall Clowbf0460e2015-05-31 03:13:31 +00001526 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Marshall Clow56523ff2015-06-02 13:04:18 +00001527 __begin2 += _Np;
1528 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001529 }
1530
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001531 template <class _Iter, class _Ptr>
1532 _LIBCPP_INLINE_VISIBILITY
1533 static
1534 void
1535 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1536 {
1537 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1538 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1539 }
1540
1541 template <class _Tp>
1542 _LIBCPP_INLINE_VISIBILITY
1543 static
1544 typename enable_if
1545 <
1546 (is_same<allocator_type, allocator<_Tp> >::value
1547 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1548 is_trivially_move_constructible<_Tp>::value,
1549 void
1550 >::type
1551 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1552 {
1553 typedef typename remove_const<_Tp>::type _Vp;
1554 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clowbf0460e2015-05-31 03:13:31 +00001555 if (_Np > 0)
Marshall Clow56523ff2015-06-02 13:04:18 +00001556 {
Marshall Clowbf0460e2015-05-31 03:13:31 +00001557 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
Marshall Clow56523ff2015-06-02 13:04:18 +00001558 __begin2 += _Np;
1559 }
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001560 }
1561
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001562 template <class _Ptr>
1563 _LIBCPP_INLINE_VISIBILITY
1564 static
1565 void
1566 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1567 {
1568 while (__end1 != __begin1)
Howard Hinnantf619e232013-01-11 20:36:59 +00001569 {
1570 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1571 --__end2;
1572 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001573 }
1574
1575 template <class _Tp>
1576 _LIBCPP_INLINE_VISIBILITY
1577 static
1578 typename enable_if
1579 <
1580 (is_same<allocator_type, allocator<_Tp> >::value
1581 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1582 is_trivially_move_constructible<_Tp>::value,
1583 void
1584 >::type
1585 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1586 {
1587 ptrdiff_t _Np = __end1 - __begin1;
1588 __end2 -= _Np;
Marshall Clowbf0460e2015-05-31 03:13:31 +00001589 if (_Np > 0)
1590 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001591 }
1592
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593private:
1594
Howard Hinnant82894812010-09-22 16:48:34 +00001595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 static pointer allocate(allocator_type& __a, size_type __n,
1597 const_void_pointer __hint, true_type)
1598 {return __a.allocate(__n, __hint);}
Howard Hinnant82894812010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001600 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnantec3773c2011-12-01 20:21:04 +00001601 const_void_pointer, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602 {return __a.allocate(__n);}
1603
1604#ifndef _LIBCPP_HAS_NO_VARIADICS
1605 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001608 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1612 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001613 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001615#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616
1617 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1620 {__a.destroy(__p);}
1621 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 static void __destroy(false_type, allocator_type&, _Tp* __p)
1624 {
1625 __p->~_Tp();
1626 }
1627
Howard Hinnant82894812010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 static size_type __max_size(true_type, const allocator_type& __a)
1630 {return __a.max_size();}
Howard Hinnant82894812010-09-22 16:48:34 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632 static size_type __max_size(false_type, const allocator_type&)
1633 {return numeric_limits<size_type>::max();}
1634
Howard Hinnant82894812010-09-22 16:48:34 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 static allocator_type
1637 select_on_container_copy_construction(true_type, const allocator_type& __a)
1638 {return __a.select_on_container_copy_construction();}
Howard Hinnant82894812010-09-22 16:48:34 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 static allocator_type
1641 select_on_container_copy_construction(false_type, const allocator_type& __a)
1642 {return __a;}
1643};
1644
Marshall Clow66302c62015-04-07 05:21:38 +00001645template <class _Traits, class _Tp>
1646struct __rebind_alloc_helper
1647{
1648#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Marshall Clow0ad232a2015-05-10 13:59:45 +00001649 typedef typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow66302c62015-04-07 05:21:38 +00001650#else
1651 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1652#endif
1653};
1654
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655// allocator
1656
1657template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001658class _LIBCPP_TYPE_VIS_ONLY allocator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659{
1660public:
1661 typedef size_t size_type;
1662 typedef ptrdiff_t difference_type;
1663 typedef _Tp* pointer;
1664 typedef const _Tp* const_pointer;
1665 typedef _Tp& reference;
1666 typedef const _Tp& const_reference;
1667 typedef _Tp value_type;
1668
Howard Hinnant18884f42011-06-02 21:38:57 +00001669 typedef true_type propagate_on_container_move_assignment;
1670
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1672
Howard Hinnant1694d232011-05-28 14:41:13 +00001673 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1674 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1675 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001676 {return _VSTD::addressof(__x);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001677 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001678 {return _VSTD::addressof(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001680 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant1694d232011-05-28 14:41:13 +00001681 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001682 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001683 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1684 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001685#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001686 template <class _Up, class... _Args>
1687 _LIBCPP_INLINE_VISIBILITY
1688 void
1689 construct(_Up* __p, _Args&&... __args)
1690 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001691 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001693#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694 _LIBCPP_INLINE_VISIBILITY
1695 void
1696 construct(pointer __p)
1697 {
1698 ::new((void*)__p) _Tp();
1699 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001700# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001701
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 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, _A0& __a0)
1706 {
1707 ::new((void*)__p) _Tp(__a0);
1708 }
1709 template <class _A0>
1710 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001711 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 construct(pointer __p, const _A0& __a0)
1713 {
1714 ::new((void*)__p) _Tp(__a0);
1715 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001716# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717 template <class _A0, class _A1>
1718 _LIBCPP_INLINE_VISIBILITY
1719 void
1720 construct(pointer __p, _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, const _A0& __a0, _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, _A0& __a0, const _A1& __a1)
1735 {
1736 ::new((void*)__p) _Tp(__a0, __a1);
1737 }
1738 template <class _A0, class _A1>
1739 _LIBCPP_INLINE_VISIBILITY
1740 void
1741 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1742 {
1743 ::new((void*)__p) _Tp(__a0, __a1);
1744 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001745#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1747};
1748
Howard Hinnant57199402012-01-02 17:56:02 +00001749template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001750class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00001751{
1752public:
1753 typedef size_t size_type;
1754 typedef ptrdiff_t difference_type;
1755 typedef const _Tp* pointer;
1756 typedef const _Tp* const_pointer;
1757 typedef const _Tp& reference;
1758 typedef const _Tp& const_reference;
Howard Hinnant9360e9f2013-06-07 01:56:37 +00001759 typedef const _Tp value_type;
Howard Hinnant57199402012-01-02 17:56:02 +00001760
1761 typedef true_type propagate_on_container_move_assignment;
1762
1763 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1764
1765 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1766 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1767 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1768 {return _VSTD::addressof(__x);}
1769 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001770 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant57199402012-01-02 17:56:02 +00001771 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001772 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant57199402012-01-02 17:56:02 +00001773 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1774 {return size_type(~0) / sizeof(_Tp);}
1775#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1776 template <class _Up, class... _Args>
1777 _LIBCPP_INLINE_VISIBILITY
1778 void
1779 construct(_Up* __p, _Args&&... __args)
1780 {
1781 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1782 }
1783#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1784 _LIBCPP_INLINE_VISIBILITY
1785 void
1786 construct(pointer __p)
1787 {
1788 ::new((void*)__p) _Tp();
1789 }
1790# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001791
Howard Hinnant57199402012-01-02 17:56:02 +00001792 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, _A0& __a0)
1796 {
1797 ::new((void*)__p) _Tp(__a0);
1798 }
1799 template <class _A0>
1800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001801 void
Howard Hinnant57199402012-01-02 17:56:02 +00001802 construct(pointer __p, const _A0& __a0)
1803 {
1804 ::new((void*)__p) _Tp(__a0);
1805 }
Howard Hinnant57199402012-01-02 17:56:02 +00001806# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1807 template <class _A0, class _A1>
1808 _LIBCPP_INLINE_VISIBILITY
1809 void
1810 construct(pointer __p, _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, const _A0& __a0, _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, _A0& __a0, const _A1& __a1)
1825 {
1826 ::new((void*)__p) _Tp(__a0, __a1);
1827 }
1828 template <class _A0, class _A1>
1829 _LIBCPP_INLINE_VISIBILITY
1830 void
1831 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1832 {
1833 ::new((void*)__p) _Tp(__a0, __a1);
1834 }
1835#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1836 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1837};
1838
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839template <class _Tp, class _Up>
1840inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001841bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842
1843template <class _Tp, class _Up>
1844inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001845bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846
1847template <class _OutputIterator, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001848class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849 : public iterator<output_iterator_tag,
1850 _Tp, // purposefully not C++03
1851 ptrdiff_t, // purposefully not C++03
1852 _Tp*, // purposefully not C++03
1853 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1854{
1855private:
1856 _OutputIterator __x_;
1857public:
1858 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1859 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1860 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1861 {::new(&*__x_) _Tp(__element); return *this;}
1862 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1863 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1864 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowdbaf7a02015-05-10 13:14:08 +00001865#if _LIBCPP_STD_VER >= 14
1866 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1867#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868};
1869
1870template <class _Tp>
1871pair<_Tp*, ptrdiff_t>
Howard Hinnant1694d232011-05-28 14:41:13 +00001872get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873{
1874 pair<_Tp*, ptrdiff_t> __r(0, 0);
1875 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1876 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1877 / sizeof(_Tp);
1878 if (__n > __m)
1879 __n = __m;
1880 while (__n > 0)
1881 {
1882 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1883 if (__r.first)
1884 {
1885 __r.second = __n;
1886 break;
1887 }
1888 __n /= 2;
1889 }
1890 return __r;
1891}
1892
1893template <class _Tp>
1894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001895void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896
1897template <class _Tp>
1898struct auto_ptr_ref
1899{
1900 _Tp* __ptr_;
1901};
1902
1903template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001904class _LIBCPP_TYPE_VIS_ONLY auto_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001905{
1906private:
1907 _Tp* __ptr_;
1908public:
1909 typedef _Tp element_type;
1910
1911 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1912 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1913 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1914 : __ptr_(__p.release()) {}
1915 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1916 {reset(__p.release()); return *this;}
1917 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1918 {reset(__p.release()); return *this;}
1919 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1920 {reset(__p.__ptr_); return *this;}
1921 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1922
1923 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1924 {return *__ptr_;}
1925 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1926 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1927 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1928 {
1929 _Tp* __t = __ptr_;
1930 __ptr_ = 0;
1931 return __t;
1932 }
1933 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1934 {
1935 if (__ptr_ != __p)
1936 delete __ptr_;
1937 __ptr_ = __p;
1938 }
1939
1940 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1941 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1942 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1943 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1944 {return auto_ptr<_Up>(release());}
1945};
1946
1947template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001948class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949{
1950public:
1951 typedef void element_type;
1952};
1953
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1955 typename remove_cv<_T2>::type>::value,
Howard Hinnantd4cf2152011-12-11 20:31:33 +00001956 bool = is_empty<_T1>::value
1957#if __has_feature(is_final)
1958 && !__is_final(_T1)
1959#endif
1960 ,
1961 bool = is_empty<_T2>::value
1962#if __has_feature(is_final)
1963 && !__is_final(_T2)
1964#endif
1965 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966struct __libcpp_compressed_pair_switch;
1967
1968template <class _T1, class _T2, bool IsSame>
1969struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1970
1971template <class _T1, class _T2, bool IsSame>
1972struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1973
1974template <class _T1, class _T2, bool IsSame>
1975struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1976
1977template <class _T1, class _T2>
1978struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1979
1980template <class _T1, class _T2>
1981struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1982
1983template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1984class __libcpp_compressed_pair_imp;
1985
1986template <class _T1, class _T2>
1987class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1988{
1989private:
1990 _T1 __first_;
1991 _T2 __second_;
1992public:
1993 typedef _T1 _T1_param;
1994 typedef _T2 _T2_param;
1995
1996 typedef typename remove_reference<_T1>::type& _T1_reference;
1997 typedef typename remove_reference<_T2>::type& _T2_reference;
1998
1999 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2000 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2001
2002 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002003 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002004 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002005 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002006 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002008 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002010#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002011
2012 _LIBCPP_INLINE_VISIBILITY
2013 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2014 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2015 is_nothrow_copy_constructible<_T2>::value)
2016 : __first_(__p.first()),
2017 __second_(__p.second()) {}
2018
2019 _LIBCPP_INLINE_VISIBILITY
2020 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2021 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2022 is_nothrow_copy_assignable<_T2>::value)
2023 {
2024 __first_ = __p.first();
2025 __second_ = __p.second();
2026 return *this;
2027 }
2028
Howard Hinnant61aa6012011-07-01 19:24:36 +00002029 _LIBCPP_INLINE_VISIBILITY
2030 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002031 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2032 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002033 : __first_(_VSTD::forward<_T1>(__p.first())),
2034 __second_(_VSTD::forward<_T2>(__p.second())) {}
2035
2036 _LIBCPP_INLINE_VISIBILITY
2037 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2038 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2039 is_nothrow_move_assignable<_T2>::value)
2040 {
2041 __first_ = _VSTD::forward<_T1>(__p.first());
2042 __second_ = _VSTD::forward<_T2>(__p.second());
2043 return *this;
2044 }
2045
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002046#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002047
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002048#ifndef _LIBCPP_HAS_NO_VARIADICS
2049
2050 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2051 _LIBCPP_INLINE_VISIBILITY
2052 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2053 tuple<_Args1...> __first_args,
2054 tuple<_Args2...> __second_args,
2055 __tuple_indices<_I1...>,
2056 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002057 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2058 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002059 {}
2060
2061#endif // _LIBCPP_HAS_NO_VARIADICS
2062
Howard Hinnant1694d232011-05-28 14:41:13 +00002063 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2064 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065
Howard Hinnant1694d232011-05-28 14:41:13 +00002066 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2067 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068
2069 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002070 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002071 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002073 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074 swap(__first_, __x.__first_);
2075 swap(__second_, __x.__second_);
2076 }
2077};
2078
2079template <class _T1, class _T2>
2080class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2081 : private _T1
2082{
2083private:
2084 _T2 __second_;
2085public:
2086 typedef _T1 _T1_param;
2087 typedef _T2 _T2_param;
2088
2089 typedef _T1& _T1_reference;
2090 typedef typename remove_reference<_T2>::type& _T2_reference;
2091
2092 typedef const _T1& _T1_const_reference;
2093 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2094
2095 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002096 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002097 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002098 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002099 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002101 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002103#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002104
2105 _LIBCPP_INLINE_VISIBILITY
2106 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2107 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2108 is_nothrow_copy_constructible<_T2>::value)
2109 : _T1(__p.first()), __second_(__p.second()) {}
2110
2111 _LIBCPP_INLINE_VISIBILITY
2112 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2113 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2114 is_nothrow_copy_assignable<_T2>::value)
2115 {
2116 _T1::operator=(__p.first());
2117 __second_ = __p.second();
2118 return *this;
2119 }
2120
Howard Hinnant61aa6012011-07-01 19:24:36 +00002121 _LIBCPP_INLINE_VISIBILITY
2122 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002123 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2124 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002125 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002126
2127 _LIBCPP_INLINE_VISIBILITY
2128 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2129 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2130 is_nothrow_move_assignable<_T2>::value)
2131 {
2132 _T1::operator=(_VSTD::move(__p.first()));
2133 __second_ = _VSTD::forward<_T2>(__p.second());
2134 return *this;
2135 }
2136
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002137#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002138
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002139#ifndef _LIBCPP_HAS_NO_VARIADICS
2140
2141 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2142 _LIBCPP_INLINE_VISIBILITY
2143 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2144 tuple<_Args1...> __first_args,
2145 tuple<_Args2...> __second_args,
2146 __tuple_indices<_I1...>,
2147 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002148 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2149 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002150 {}
2151
2152#endif // _LIBCPP_HAS_NO_VARIADICS
2153
Howard Hinnant1694d232011-05-28 14:41:13 +00002154 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2155 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156
Howard Hinnant1694d232011-05-28 14:41:13 +00002157 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2158 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159
2160 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002161 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002162 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002164 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165 swap(__second_, __x.__second_);
2166 }
2167};
2168
2169template <class _T1, class _T2>
2170class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2171 : private _T2
2172{
2173private:
2174 _T1 __first_;
2175public:
2176 typedef _T1 _T1_param;
2177 typedef _T2 _T2_param;
2178
2179 typedef typename remove_reference<_T1>::type& _T1_reference;
2180 typedef _T2& _T2_reference;
2181
2182 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2183 typedef const _T2& _T2_const_reference;
2184
2185 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2186 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002187 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002189 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant1694d232011-05-28 14:41:13 +00002191 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2192 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002193 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002195#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002196
2197 _LIBCPP_INLINE_VISIBILITY
2198 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2199 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2200 is_nothrow_copy_constructible<_T2>::value)
2201 : _T2(__p.second()), __first_(__p.first()) {}
2202
2203 _LIBCPP_INLINE_VISIBILITY
2204 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2205 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2206 is_nothrow_copy_assignable<_T2>::value)
2207 {
2208 _T2::operator=(__p.second());
2209 __first_ = __p.first();
2210 return *this;
2211 }
2212
Howard Hinnant61aa6012011-07-01 19:24:36 +00002213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002215 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2216 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002217 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002218
2219 _LIBCPP_INLINE_VISIBILITY
2220 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2221 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2222 is_nothrow_move_assignable<_T2>::value)
2223 {
2224 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2225 __first_ = _VSTD::move(__p.first());
2226 return *this;
2227 }
2228
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002229#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002230
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002231#ifndef _LIBCPP_HAS_NO_VARIADICS
2232
2233 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2234 _LIBCPP_INLINE_VISIBILITY
2235 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2236 tuple<_Args1...> __first_args,
2237 tuple<_Args2...> __second_args,
2238 __tuple_indices<_I1...>,
2239 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002240 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2241 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002242
2243 {}
2244
2245#endif // _LIBCPP_HAS_NO_VARIADICS
2246
Howard Hinnant1694d232011-05-28 14:41:13 +00002247 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2248 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002249
Howard Hinnant1694d232011-05-28 14:41:13 +00002250 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2251 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252
2253 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002254 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002255 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002257 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258 swap(__first_, __x.__first_);
2259 }
2260};
2261
2262template <class _T1, class _T2>
2263class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2264 : private _T1,
2265 private _T2
2266{
2267public:
2268 typedef _T1 _T1_param;
2269 typedef _T2 _T2_param;
2270
2271 typedef _T1& _T1_reference;
2272 typedef _T2& _T2_reference;
2273
2274 typedef const _T1& _T1_const_reference;
2275 typedef const _T2& _T2_const_reference;
2276
2277 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2278 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002279 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002281 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002283 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002284
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002285#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002286
2287 _LIBCPP_INLINE_VISIBILITY
2288 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2289 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2290 is_nothrow_copy_constructible<_T2>::value)
2291 : _T1(__p.first()), _T2(__p.second()) {}
2292
2293 _LIBCPP_INLINE_VISIBILITY
2294 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2295 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2296 is_nothrow_copy_assignable<_T2>::value)
2297 {
2298 _T1::operator=(__p.first());
2299 _T2::operator=(__p.second());
2300 return *this;
2301 }
2302
Howard Hinnant61aa6012011-07-01 19:24:36 +00002303 _LIBCPP_INLINE_VISIBILITY
2304 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002305 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2306 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002307 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002308
2309 _LIBCPP_INLINE_VISIBILITY
2310 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2311 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2312 is_nothrow_move_assignable<_T2>::value)
2313 {
2314 _T1::operator=(_VSTD::move(__p.first()));
2315 _T2::operator=(_VSTD::move(__p.second()));
2316 return *this;
2317 }
2318
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002319#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002320
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002321#ifndef _LIBCPP_HAS_NO_VARIADICS
2322
2323 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2324 _LIBCPP_INLINE_VISIBILITY
2325 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2326 tuple<_Args1...> __first_args,
2327 tuple<_Args2...> __second_args,
2328 __tuple_indices<_I1...>,
2329 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002330 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2331 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002332 {}
2333
2334#endif // _LIBCPP_HAS_NO_VARIADICS
2335
Howard Hinnant1694d232011-05-28 14:41:13 +00002336 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2337 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338
Howard Hinnant1694d232011-05-28 14:41:13 +00002339 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2340 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341
Howard Hinnantec3773c2011-12-01 20:21:04 +00002342 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant1694d232011-05-28 14:41:13 +00002343 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002344 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345 {
2346 }
2347};
2348
2349template <class _T1, class _T2>
2350class __compressed_pair
2351 : private __libcpp_compressed_pair_imp<_T1, _T2>
2352{
2353 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2354public:
2355 typedef typename base::_T1_param _T1_param;
2356 typedef typename base::_T2_param _T2_param;
2357
2358 typedef typename base::_T1_reference _T1_reference;
2359 typedef typename base::_T2_reference _T2_reference;
2360
2361 typedef typename base::_T1_const_reference _T1_const_reference;
2362 typedef typename base::_T2_const_reference _T2_const_reference;
2363
2364 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002365 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002366 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002367 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002368 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002369 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002370 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002372#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002373
2374 _LIBCPP_INLINE_VISIBILITY
2375 __compressed_pair(const __compressed_pair& __p)
2376 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2377 is_nothrow_copy_constructible<_T2>::value)
2378 : base(__p) {}
2379
2380 _LIBCPP_INLINE_VISIBILITY
2381 __compressed_pair& operator=(const __compressed_pair& __p)
2382 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2383 is_nothrow_copy_assignable<_T2>::value)
2384 {
2385 base::operator=(__p);
2386 return *this;
2387 }
2388
Howard Hinnant61aa6012011-07-01 19:24:36 +00002389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002390 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002391 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2392 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002393 : base(_VSTD::move(__p)) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002394
2395 _LIBCPP_INLINE_VISIBILITY
2396 __compressed_pair& operator=(__compressed_pair&& __p)
2397 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2398 is_nothrow_move_assignable<_T2>::value)
2399 {
2400 base::operator=(_VSTD::move(__p));
2401 return *this;
2402 }
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002403
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002404#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002405
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002406#ifndef _LIBCPP_HAS_NO_VARIADICS
2407
2408 template <class... _Args1, class... _Args2>
2409 _LIBCPP_INLINE_VISIBILITY
2410 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2411 tuple<_Args2...> __second_args)
Howard Hinnant57199402012-01-02 17:56:02 +00002412 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002413 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2414 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2415 {}
2416
2417#endif // _LIBCPP_HAS_NO_VARIADICS
2418
Howard Hinnant1694d232011-05-28 14:41:13 +00002419 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2420 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002421
Howard Hinnant1694d232011-05-28 14:41:13 +00002422 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2423 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002424
Howard Hinnant1694d232011-05-28 14:41:13 +00002425 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2426 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002427 __is_nothrow_swappable<_T2>::value)
Howard Hinnant1694d232011-05-28 14:41:13 +00002428 {base::swap(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002429};
2430
2431template <class _T1, class _T2>
2432inline _LIBCPP_INLINE_VISIBILITY
2433void
2434swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant1694d232011-05-28 14:41:13 +00002435 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002436 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437 {__x.swap(__y);}
2438
Howard Hinnant57199402012-01-02 17:56:02 +00002439// __same_or_less_cv_qualified
2440
2441template <class _Ptr1, class _Ptr2,
2442 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2443 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2444 >::value
2445 >
2446struct __same_or_less_cv_qualified_imp
2447 : is_convertible<_Ptr1, _Ptr2> {};
2448
2449template <class _Ptr1, class _Ptr2>
2450struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2451 : false_type {};
2452
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002453template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2454 is_same<_Ptr1, _Ptr2>::value ||
2455 __has_element_type<_Ptr1>::value>
Howard Hinnant57199402012-01-02 17:56:02 +00002456struct __same_or_less_cv_qualified
2457 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2458
2459template <class _Ptr1, class _Ptr2>
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002460struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant57199402012-01-02 17:56:02 +00002461 : false_type {};
2462
2463// default_delete
2464
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002465template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002466struct _LIBCPP_TYPE_VIS_ONLY default_delete
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002467{
Howard Hinnant46e94932012-07-07 20:56:04 +00002468#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2469 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2470#else
2471 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2472#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 template <class _Up>
2474 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant1694d232011-05-28 14:41:13 +00002475 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2476 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477 {
2478 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002479 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480 delete __ptr;
2481 }
2482};
2483
2484template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002485struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002486{
Howard Hinnant8e843502011-12-18 21:19:44 +00002487public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002488#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2489 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2490#else
2491 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2492#endif
Howard Hinnant8e843502011-12-18 21:19:44 +00002493 template <class _Up>
2494 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant57199402012-01-02 17:56:02 +00002495 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant8e843502011-12-18 21:19:44 +00002496 template <class _Up>
2497 _LIBCPP_INLINE_VISIBILITY
2498 void operator() (_Up* __ptr,
Howard Hinnant57199402012-01-02 17:56:02 +00002499 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002500 {
2501 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002502 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002503 delete [] __ptr;
2504 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505};
2506
2507template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002508class _LIBCPP_TYPE_VIS_ONLY unique_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509{
2510public:
2511 typedef _Tp element_type;
2512 typedef _Dp deleter_type;
2513 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2514private:
2515 __compressed_pair<pointer, deleter_type> __ptr_;
2516
Howard Hinnant57199402012-01-02 17:56:02 +00002517#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518 unique_ptr(unique_ptr&);
2519 template <class _Up, class _Ep>
2520 unique_ptr(unique_ptr<_Up, _Ep>&);
2521 unique_ptr& operator=(unique_ptr&);
2522 template <class _Up, class _Ep>
2523 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002524#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002525
2526 struct __nat {int __for_bool_;};
2527
2528 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2529 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2530public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002531 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 : __ptr_(pointer())
2533 {
2534 static_assert(!is_pointer<deleter_type>::value,
2535 "unique_ptr constructed with null function pointer deleter");
2536 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002537 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538 : __ptr_(pointer())
2539 {
2540 static_assert(!is_pointer<deleter_type>::value,
2541 "unique_ptr constructed with null function pointer deleter");
2542 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002543 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002544 : __ptr_(_VSTD::move(__p))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002545 {
2546 static_assert(!is_pointer<deleter_type>::value,
2547 "unique_ptr constructed with null function pointer deleter");
2548 }
2549
Howard Hinnant73d21a42010-09-04 23:28:19 +00002550#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002551 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2552 is_reference<deleter_type>::value,
2553 deleter_type,
2554 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002555 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002556 : __ptr_(__p, __d) {}
2557
2558 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002559 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002560 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002561 {
2562 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2563 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002564 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002565 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002566 template <class _Up, class _Ep>
2567 _LIBCPP_INLINE_VISIBILITY
2568 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2569 typename enable_if
2570 <
2571 !is_array<_Up>::value &&
2572 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2573 is_convertible<_Ep, deleter_type>::value &&
2574 (
2575 !is_reference<deleter_type>::value ||
2576 is_same<deleter_type, _Ep>::value
2577 ),
2578 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002579 >::type = __nat()) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002580 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002581
2582 template <class _Up>
2583 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2584 typename enable_if<
2585 is_convertible<_Up*, _Tp*>::value &&
2586 is_same<_Dp, default_delete<_Tp> >::value,
2587 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002588 >::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589 : __ptr_(__p.release())
2590 {
2591 }
2592
Howard Hinnant1694d232011-05-28 14:41:13 +00002593 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002594 {
2595 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002596 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002597 return *this;
2598 }
2599
2600 template <class _Up, class _Ep>
2601 _LIBCPP_INLINE_VISIBILITY
2602 typename enable_if
2603 <
Howard Hinnant57199402012-01-02 17:56:02 +00002604 !is_array<_Up>::value &&
2605 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2606 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607 unique_ptr&
2608 >::type
Howard Hinnant1694d232011-05-28 14:41:13 +00002609 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 {
2611 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002612 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002613 return *this;
2614 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002615#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616
2617 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2618 {
2619 return __rv<unique_ptr>(*this);
2620 }
2621
2622 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002623 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002624
2625 template <class _Up, class _Ep>
2626 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2627 {
2628 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002629 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002630 return *this;
2631 }
2632
2633 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002634 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002635
2636 template <class _Up>
2637 _LIBCPP_INLINE_VISIBILITY
2638 typename enable_if<
2639 is_convertible<_Up*, _Tp*>::value &&
2640 is_same<_Dp, default_delete<_Tp> >::value,
2641 unique_ptr&
2642 >::type
2643 operator=(auto_ptr<_Up> __p)
2644 {reset(__p.release()); return *this;}
2645
Howard Hinnant73d21a42010-09-04 23:28:19 +00002646#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2648
Howard Hinnant1694d232011-05-28 14:41:13 +00002649 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002650 {
2651 reset();
2652 return *this;
2653 }
2654
2655 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2656 {return *__ptr_.first();}
Howard Hinnant1694d232011-05-28 14:41:13 +00002657 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2658 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2659 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2660 {return __ptr_.second();}
2661 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2662 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002663 _LIBCPP_INLINE_VISIBILITY
2664 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2665 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666
Howard Hinnant1694d232011-05-28 14:41:13 +00002667 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 {
2669 pointer __t = __ptr_.first();
2670 __ptr_.first() = pointer();
2671 return __t;
2672 }
2673
Howard Hinnant1694d232011-05-28 14:41:13 +00002674 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002675 {
2676 pointer __tmp = __ptr_.first();
2677 __ptr_.first() = __p;
2678 if (__tmp)
2679 __ptr_.second()(__tmp);
2680 }
2681
Howard Hinnant1694d232011-05-28 14:41:13 +00002682 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2683 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684};
2685
2686template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002687class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002688{
2689public:
2690 typedef _Tp element_type;
2691 typedef _Dp deleter_type;
2692 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2693private:
2694 __compressed_pair<pointer, deleter_type> __ptr_;
2695
Howard Hinnant57199402012-01-02 17:56:02 +00002696#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002697 unique_ptr(unique_ptr&);
2698 template <class _Up>
2699 unique_ptr(unique_ptr<_Up>&);
2700 unique_ptr& operator=(unique_ptr&);
2701 template <class _Up>
2702 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002703#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002704
2705 struct __nat {int __for_bool_;};
2706
2707 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2708 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2709public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002710 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002711 : __ptr_(pointer())
2712 {
2713 static_assert(!is_pointer<deleter_type>::value,
2714 "unique_ptr constructed with null function pointer deleter");
2715 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002716 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002717 : __ptr_(pointer())
2718 {
2719 static_assert(!is_pointer<deleter_type>::value,
2720 "unique_ptr constructed with null function pointer deleter");
2721 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002722#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002723 template <class _Pp>
2724 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2725 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002726 : __ptr_(__p)
2727 {
2728 static_assert(!is_pointer<deleter_type>::value,
2729 "unique_ptr constructed with null function pointer deleter");
2730 }
2731
Logan Chiene1678a12014-01-31 09:30:46 +00002732 template <class _Pp>
Howard Hinnant99968442011-11-29 18:15:50 +00002733 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734 is_reference<deleter_type>::value,
2735 deleter_type,
Logan Chiene1678a12014-01-31 09:30:46 +00002736 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2737 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002738 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739 : __ptr_(__p, __d) {}
2740
2741 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2742 is_reference<deleter_type>::value,
2743 deleter_type,
2744 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002745 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746 : __ptr_(pointer(), __d) {}
2747
Logan Chiene1678a12014-01-31 09:30:46 +00002748 template <class _Pp>
2749 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2750 typename remove_reference<deleter_type>::type&& __d,
2751 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002752 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002753 : __ptr_(__p, _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
2758 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002759 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002760 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761 {
2762 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2763 }
2764
Howard Hinnant1694d232011-05-28 14:41:13 +00002765 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002766 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767
Howard Hinnant1694d232011-05-28 14:41:13 +00002768 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769 {
2770 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002771 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002772 return *this;
2773 }
Howard Hinnant8e843502011-12-18 21:19:44 +00002774
2775 template <class _Up, class _Ep>
2776 _LIBCPP_INLINE_VISIBILITY
2777 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2778 typename enable_if
2779 <
2780 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002781 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant8e843502011-12-18 21:19:44 +00002782 && is_convertible<_Ep, deleter_type>::value &&
2783 (
2784 !is_reference<deleter_type>::value ||
2785 is_same<deleter_type, _Ep>::value
2786 ),
2787 __nat
2788 >::type = __nat()
2789 ) _NOEXCEPT
2790 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2791
2792
2793 template <class _Up, class _Ep>
2794 _LIBCPP_INLINE_VISIBILITY
2795 typename enable_if
2796 <
2797 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002798 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2799 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant8e843502011-12-18 21:19:44 +00002800 unique_ptr&
2801 >::type
2802 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2803 {
2804 reset(__u.release());
2805 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2806 return *this;
2807 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002808#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002809
2810 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2811 : __ptr_(__p)
2812 {
2813 static_assert(!is_pointer<deleter_type>::value,
2814 "unique_ptr constructed with null function pointer deleter");
2815 }
2816
2817 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002818 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002819
2820 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002821 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002822
2823 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2824 {
2825 return __rv<unique_ptr>(*this);
2826 }
2827
2828 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002829 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830
2831 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2832 {
2833 reset(__u->release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002834 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 return *this;
2836 }
2837
Howard Hinnant73d21a42010-09-04 23:28:19 +00002838#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002839 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2840
Howard Hinnant1694d232011-05-28 14:41:13 +00002841 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002842 {
2843 reset();
2844 return *this;
2845 }
2846
2847 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2848 {return __ptr_.first()[__i];}
Howard Hinnant1694d232011-05-28 14:41:13 +00002849 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2850 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2851 {return __ptr_.second();}
2852 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2853 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002854 _LIBCPP_INLINE_VISIBILITY
2855 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2856 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857
Howard Hinnant1694d232011-05-28 14:41:13 +00002858 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859 {
2860 pointer __t = __ptr_.first();
2861 __ptr_.first() = pointer();
2862 return __t;
2863 }
2864
Howard Hinnant73d21a42010-09-04 23:28:19 +00002865#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002866 template <class _Pp>
2867 _LIBCPP_INLINE_VISIBILITY
2868 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2869 reset(_Pp __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870 {
2871 pointer __tmp = __ptr_.first();
2872 __ptr_.first() = __p;
2873 if (__tmp)
2874 __ptr_.second()(__tmp);
2875 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002876 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _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 Hinnant1694d232011-05-28 14:41:13 +00002883 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002884 {
2885 pointer __tmp = __ptr_.first();
2886 __ptr_.first() = nullptr;
2887 if (__tmp)
2888 __ptr_.second()(__tmp);
2889 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002890#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2892 {
2893 pointer __tmp = __ptr_.first();
2894 __ptr_.first() = __p;
2895 if (__tmp)
2896 __ptr_.second()(__tmp);
2897 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002898#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899
2900 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2901private:
Howard Hinnant324bb032010-08-22 00:02:43 +00002902
Howard Hinnant73d21a42010-09-04 23:28:19 +00002903#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002904 template <class _Up>
2905 explicit unique_ptr(_Up);
2906 template <class _Up>
2907 unique_ptr(_Up __u,
2908 typename conditional<
2909 is_reference<deleter_type>::value,
2910 deleter_type,
2911 typename add_lvalue_reference<const deleter_type>::type>::type,
2912 typename enable_if
2913 <
2914 is_convertible<_Up, pointer>::value,
2915 __nat
2916 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00002917#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002918};
2919
2920template <class _Tp, class _Dp>
2921inline _LIBCPP_INLINE_VISIBILITY
2922void
Howard Hinnant1694d232011-05-28 14:41:13 +00002923swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002924
2925template <class _T1, class _D1, class _T2, class _D2>
2926inline _LIBCPP_INLINE_VISIBILITY
2927bool
2928operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2929
2930template <class _T1, class _D1, class _T2, class _D2>
2931inline _LIBCPP_INLINE_VISIBILITY
2932bool
2933operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2934
2935template <class _T1, class _D1, class _T2, class _D2>
2936inline _LIBCPP_INLINE_VISIBILITY
2937bool
Howard Hinnant3fadda32012-02-21 21:02:58 +00002938operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2939{
2940 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2941 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselier8492cd82015-02-05 23:01:40 +00002942 typedef typename common_type<_P1, _P2>::type _Vp;
2943 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00002944}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002945
2946template <class _T1, class _D1, class _T2, class _D2>
2947inline _LIBCPP_INLINE_VISIBILITY
2948bool
2949operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2950
2951template <class _T1, class _D1, class _T2, class _D2>
2952inline _LIBCPP_INLINE_VISIBILITY
2953bool
2954operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2955
2956template <class _T1, class _D1, class _T2, class _D2>
2957inline _LIBCPP_INLINE_VISIBILITY
2958bool
2959operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2960
Howard Hinnant3fadda32012-02-21 21:02:58 +00002961template <class _T1, class _D1>
2962inline _LIBCPP_INLINE_VISIBILITY
2963bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002964operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002965{
2966 return !__x;
2967}
2968
2969template <class _T1, class _D1>
2970inline _LIBCPP_INLINE_VISIBILITY
2971bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002972operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002973{
2974 return !__x;
2975}
2976
2977template <class _T1, class _D1>
2978inline _LIBCPP_INLINE_VISIBILITY
2979bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002980operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002981{
2982 return static_cast<bool>(__x);
2983}
2984
2985template <class _T1, class _D1>
2986inline _LIBCPP_INLINE_VISIBILITY
2987bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002988operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002989{
2990 return static_cast<bool>(__x);
2991}
2992
2993template <class _T1, class _D1>
2994inline _LIBCPP_INLINE_VISIBILITY
2995bool
2996operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2997{
2998 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2999 return less<_P1>()(__x.get(), nullptr);
3000}
3001
3002template <class _T1, class _D1>
3003inline _LIBCPP_INLINE_VISIBILITY
3004bool
3005operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3006{
3007 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3008 return less<_P1>()(nullptr, __x.get());
3009}
3010
3011template <class _T1, class _D1>
3012inline _LIBCPP_INLINE_VISIBILITY
3013bool
3014operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3015{
3016 return nullptr < __x;
3017}
3018
3019template <class _T1, class _D1>
3020inline _LIBCPP_INLINE_VISIBILITY
3021bool
3022operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3023{
3024 return __x < nullptr;
3025}
3026
3027template <class _T1, class _D1>
3028inline _LIBCPP_INLINE_VISIBILITY
3029bool
3030operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3031{
3032 return !(nullptr < __x);
3033}
3034
3035template <class _T1, class _D1>
3036inline _LIBCPP_INLINE_VISIBILITY
3037bool
3038operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3039{
3040 return !(__x < nullptr);
3041}
3042
3043template <class _T1, class _D1>
3044inline _LIBCPP_INLINE_VISIBILITY
3045bool
3046operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3047{
3048 return !(__x < nullptr);
3049}
3050
3051template <class _T1, class _D1>
3052inline _LIBCPP_INLINE_VISIBILITY
3053bool
3054operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3055{
3056 return !(nullptr < __x);
3057}
3058
Howard Hinnant87073e42012-05-01 15:37:54 +00003059#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3060
3061template <class _Tp, class _Dp>
3062inline _LIBCPP_INLINE_VISIBILITY
3063unique_ptr<_Tp, _Dp>
3064move(unique_ptr<_Tp, _Dp>& __t)
3065{
3066 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3067}
3068
3069#endif
3070
Marshall Clowfd7481e2013-07-01 18:16:03 +00003071#if _LIBCPP_STD_VER > 11
3072
3073template<class _Tp>
3074struct __unique_if
3075{
3076 typedef unique_ptr<_Tp> __unique_single;
3077};
3078
3079template<class _Tp>
3080struct __unique_if<_Tp[]>
3081{
3082 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3083};
3084
3085template<class _Tp, size_t _Np>
3086struct __unique_if<_Tp[_Np]>
3087{
3088 typedef void __unique_array_known_bound;
3089};
3090
3091template<class _Tp, class... _Args>
Marshall Clowfb551102013-07-02 20:06:09 +00003092inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003093typename __unique_if<_Tp>::__unique_single
3094make_unique(_Args&&... __args)
3095{
3096 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3097}
3098
3099template<class _Tp>
Marshall Clowfb551102013-07-02 20:06:09 +00003100inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003101typename __unique_if<_Tp>::__unique_array_unknown_bound
3102make_unique(size_t __n)
3103{
3104 typedef typename remove_extent<_Tp>::type _Up;
3105 return unique_ptr<_Tp>(new _Up[__n]());
3106}
3107
3108template<class _Tp, class... _Args>
3109 typename __unique_if<_Tp>::__unique_array_known_bound
3110 make_unique(_Args&&...) = delete;
3111
3112#endif // _LIBCPP_STD_VER > 11
3113
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00003114template <class _Tp> struct hash;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003115
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003116template <class _Size>
3117inline _LIBCPP_INLINE_VISIBILITY
3118_Size
3119__loadword(const void* __p)
3120{
3121 _Size __r;
3122 std::memcpy(&__r, __p, sizeof(__r));
3123 return __r;
3124}
3125
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003126// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3127// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3128// multiplication, which can be very slow on 32-bit systems.
Howard Hinnant40c13d32011-12-05 00:08:45 +00003129template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003130struct __murmur2_or_cityhash;
Howard Hinnant40c13d32011-12-05 00:08:45 +00003131
3132template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003133struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003134{
3135 _Size operator()(const void* __key, _Size __len);
3136};
3137
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003138// murmur2
Howard Hinnant40c13d32011-12-05 00:08:45 +00003139template <class _Size>
3140_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003141__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003142{
3143 const _Size __m = 0x5bd1e995;
3144 const _Size __r = 24;
3145 _Size __h = __len;
3146 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3147 for (; __len >= 4; __data += 4, __len -= 4)
3148 {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003149 _Size __k = __loadword<_Size>(__data);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003150 __k *= __m;
3151 __k ^= __k >> __r;
3152 __k *= __m;
3153 __h *= __m;
3154 __h ^= __k;
3155 }
3156 switch (__len)
3157 {
3158 case 3:
3159 __h ^= __data[2] << 16;
3160 case 2:
3161 __h ^= __data[1] << 8;
3162 case 1:
3163 __h ^= __data[0];
3164 __h *= __m;
3165 }
3166 __h ^= __h >> 13;
3167 __h *= __m;
3168 __h ^= __h >> 15;
3169 return __h;
3170}
3171
3172template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003173struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003174{
3175 _Size operator()(const void* __key, _Size __len);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003176
3177 private:
3178 // Some primes between 2^63 and 2^64.
3179 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3180 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3181 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3182 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3183
3184 static _Size __rotate(_Size __val, int __shift) {
3185 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3186 }
3187
3188 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3189 return (__val >> __shift) | (__val << (64 - __shift));
3190 }
3191
3192 static _Size __shift_mix(_Size __val) {
3193 return __val ^ (__val >> 47);
3194 }
3195
3196 static _Size __hash_len_16(_Size __u, _Size __v) {
3197 const _Size __mul = 0x9ddfea08eb382d69ULL;
3198 _Size __a = (__u ^ __v) * __mul;
3199 __a ^= (__a >> 47);
3200 _Size __b = (__v ^ __a) * __mul;
3201 __b ^= (__b >> 47);
3202 __b *= __mul;
3203 return __b;
3204 }
3205
3206 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3207 if (__len > 8) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003208 const _Size __a = __loadword<_Size>(__s);
3209 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003210 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3211 }
3212 if (__len >= 4) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003213 const uint32_t __a = __loadword<uint32_t>(__s);
3214 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003215 return __hash_len_16(__len + (__a << 3), __b);
3216 }
3217 if (__len > 0) {
3218 const unsigned char __a = __s[0];
3219 const unsigned char __b = __s[__len >> 1];
3220 const unsigned char __c = __s[__len - 1];
3221 const uint32_t __y = static_cast<uint32_t>(__a) +
3222 (static_cast<uint32_t>(__b) << 8);
3223 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3224 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3225 }
3226 return __k2;
3227 }
3228
3229 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003230 const _Size __a = __loadword<_Size>(__s) * __k1;
3231 const _Size __b = __loadword<_Size>(__s + 8);
3232 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3233 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003234 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3235 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3236 }
3237
3238 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3239 // Callers do best to use "random-looking" values for a and b.
3240 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3241 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3242 __a += __w;
3243 __b = __rotate(__b + __a + __z, 21);
3244 const _Size __c = __a;
3245 __a += __x;
3246 __a += __y;
3247 __b += __rotate(__a, 44);
3248 return pair<_Size, _Size>(__a + __z, __b + __c);
3249 }
3250
3251 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3252 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3253 const char* __s, _Size __a, _Size __b) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003254 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3255 __loadword<_Size>(__s + 8),
3256 __loadword<_Size>(__s + 16),
3257 __loadword<_Size>(__s + 24),
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003258 __a,
3259 __b);
3260 }
3261
3262 // Return an 8-byte hash for 33 to 64 bytes.
3263 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003264 _Size __z = __loadword<_Size>(__s + 24);
3265 _Size __a = __loadword<_Size>(__s) +
3266 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003267 _Size __b = __rotate(__a + __z, 52);
3268 _Size __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003269 __a += __loadword<_Size>(__s + 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003270 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003271 __a += __loadword<_Size>(__s + 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003272 _Size __vf = __a + __z;
3273 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003274 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3275 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003276 __b = __rotate(__a + __z, 52);
3277 __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003278 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003279 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003280 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003281 _Size __wf = __a + __z;
3282 _Size __ws = __b + __rotate(__a, 31) + __c;
3283 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3284 return __shift_mix(__r * __k0 + __vs) * __k2;
3285 }
Howard Hinnant40c13d32011-12-05 00:08:45 +00003286};
3287
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003288// cityhash64
Howard Hinnant40c13d32011-12-05 00:08:45 +00003289template <class _Size>
3290_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003291__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003292{
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003293 const char* __s = static_cast<const char*>(__key);
3294 if (__len <= 32) {
3295 if (__len <= 16) {
3296 return __hash_len_0_to_16(__s, __len);
3297 } else {
3298 return __hash_len_17_to_32(__s, __len);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003299 }
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003300 } else if (__len <= 64) {
3301 return __hash_len_33_to_64(__s, __len);
3302 }
3303
3304 // For strings over 64 bytes we hash the end first, and then as we
3305 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003306 _Size __x = __loadword<_Size>(__s + __len - 40);
3307 _Size __y = __loadword<_Size>(__s + __len - 16) +
3308 __loadword<_Size>(__s + __len - 56);
3309 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3310 __loadword<_Size>(__s + __len - 24));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003311 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3312 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003313 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003314
3315 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3316 __len = (__len - 1) & ~static_cast<_Size>(63);
3317 do {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003318 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3319 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003320 __x ^= __w.second;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003321 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003322 __z = __rotate(__z + __w.first, 33) * __k1;
3323 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3324 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003325 __y + __loadword<_Size>(__s + 16));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003326 std::swap(__z, __x);
3327 __s += 64;
3328 __len -= 64;
3329 } while (__len != 0);
3330 return __hash_len_16(
3331 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3332 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003333}
3334
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003335template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3336struct __scalar_hash;
3337
3338template <class _Tp>
3339struct __scalar_hash<_Tp, 0>
3340 : public unary_function<_Tp, size_t>
Howard Hinnant21aefc32010-06-03 16:42:57 +00003341{
Howard Hinnant82894812010-09-22 16:48:34 +00003342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003343 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003344 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003345 union
3346 {
3347 _Tp __t;
3348 size_t __a;
3349 } __u;
3350 __u.__a = 0;
3351 __u.__t = __v;
3352 return __u.__a;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003353 }
3354};
3355
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003356template <class _Tp>
3357struct __scalar_hash<_Tp, 1>
3358 : public unary_function<_Tp, size_t>
3359{
3360 _LIBCPP_INLINE_VISIBILITY
3361 size_t operator()(_Tp __v) const _NOEXCEPT
3362 {
3363 union
3364 {
3365 _Tp __t;
3366 size_t __a;
3367 } __u;
3368 __u.__t = __v;
3369 return __u.__a;
3370 }
3371};
3372
3373template <class _Tp>
3374struct __scalar_hash<_Tp, 2>
3375 : public unary_function<_Tp, size_t>
3376{
3377 _LIBCPP_INLINE_VISIBILITY
3378 size_t operator()(_Tp __v) const _NOEXCEPT
3379 {
3380 union
3381 {
3382 _Tp __t;
3383 struct
3384 {
3385 size_t __a;
3386 size_t __b;
3387 };
3388 } __u;
3389 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003390 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003391 }
3392};
3393
3394template <class _Tp>
3395struct __scalar_hash<_Tp, 3>
3396 : public unary_function<_Tp, size_t>
3397{
3398 _LIBCPP_INLINE_VISIBILITY
3399 size_t operator()(_Tp __v) const _NOEXCEPT
3400 {
3401 union
3402 {
3403 _Tp __t;
3404 struct
3405 {
3406 size_t __a;
3407 size_t __b;
3408 size_t __c;
3409 };
3410 } __u;
3411 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003412 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003413 }
3414};
3415
3416template <class _Tp>
3417struct __scalar_hash<_Tp, 4>
3418 : public unary_function<_Tp, size_t>
3419{
3420 _LIBCPP_INLINE_VISIBILITY
3421 size_t operator()(_Tp __v) const _NOEXCEPT
3422 {
3423 union
3424 {
3425 _Tp __t;
3426 struct
3427 {
3428 size_t __a;
3429 size_t __b;
3430 size_t __c;
3431 size_t __d;
3432 };
3433 } __u;
3434 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003435 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003436 }
3437};
3438
3439template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003440struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003441 : public unary_function<_Tp*, size_t>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003442{
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003443 _LIBCPP_INLINE_VISIBILITY
3444 size_t operator()(_Tp* __v) const _NOEXCEPT
3445 {
3446 union
3447 {
3448 _Tp* __t;
3449 size_t __a;
3450 } __u;
3451 __u.__t = __v;
3452 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3453 }
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003454};
3455
Howard Hinnant21aefc32010-06-03 16:42:57 +00003456template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003457struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00003458{
3459 typedef unique_ptr<_Tp, _Dp> argument_type;
3460 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00003461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003462 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003463 {
3464 typedef typename argument_type::pointer pointer;
3465 return hash<pointer>()(__ptr.get());
3466 }
3467};
3468
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469struct __destruct_n
3470{
3471private:
3472 size_t size;
3473
3474 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003475 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3477
3478 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003479 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003480 {}
3481
Howard Hinnant1694d232011-05-28 14:41:13 +00003482 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483 {++size;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003484 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485 {}
3486
Howard Hinnant1694d232011-05-28 14:41:13 +00003487 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488 {size = __s;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003489 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490 {}
3491public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003492 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3493 : size(__s) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494
3495 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003496 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003497 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498
3499 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003500 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003501 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003502
3503 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003504 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003505 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003506};
3507
3508template <class _Alloc>
3509class __allocator_destructor
3510{
3511 typedef allocator_traits<_Alloc> __alloc_traits;
3512public:
3513 typedef typename __alloc_traits::pointer pointer;
3514 typedef typename __alloc_traits::size_type size_type;
3515private:
3516 _Alloc& __alloc_;
3517 size_type __s_;
3518public:
3519 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant1694d232011-05-28 14:41:13 +00003520 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003521 : __alloc_(__a), __s_(__s) {}
Howard Hinnant82894812010-09-22 16:48:34 +00003522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003523 void operator()(pointer __p) _NOEXCEPT
3524 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003525};
3526
3527template <class _InputIterator, class _ForwardIterator>
3528_ForwardIterator
3529uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3530{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003532#ifndef _LIBCPP_NO_EXCEPTIONS
3533 _ForwardIterator __s = __r;
3534 try
3535 {
3536#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003537 for (; __f != __l; ++__f, (void) ++__r)
3538 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant8292d742011-12-29 17:45:35 +00003539#ifndef _LIBCPP_NO_EXCEPTIONS
3540 }
3541 catch (...)
3542 {
3543 for (; __s != __r; ++__s)
3544 __s->~value_type();
3545 throw;
3546 }
3547#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003548 return __r;
3549}
3550
3551template <class _InputIterator, class _Size, class _ForwardIterator>
3552_ForwardIterator
3553uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3554{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003555 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003556#ifndef _LIBCPP_NO_EXCEPTIONS
3557 _ForwardIterator __s = __r;
3558 try
3559 {
3560#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003561 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3562 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant8292d742011-12-29 17:45:35 +00003563#ifndef _LIBCPP_NO_EXCEPTIONS
3564 }
3565 catch (...)
3566 {
3567 for (; __s != __r; ++__s)
3568 __s->~value_type();
3569 throw;
3570 }
3571#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572 return __r;
3573}
3574
3575template <class _ForwardIterator, class _Tp>
3576void
3577uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3578{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003580#ifndef _LIBCPP_NO_EXCEPTIONS
3581 _ForwardIterator __s = __f;
3582 try
3583 {
3584#endif
3585 for (; __f != __l; ++__f)
Marshall Clow5dce73d2015-05-19 15:01:48 +00003586 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant8292d742011-12-29 17:45:35 +00003587#ifndef _LIBCPP_NO_EXCEPTIONS
3588 }
3589 catch (...)
3590 {
3591 for (; __s != __f; ++__s)
3592 __s->~value_type();
3593 throw;
3594 }
3595#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596}
3597
3598template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003599_ForwardIterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3601{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003602 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003603#ifndef _LIBCPP_NO_EXCEPTIONS
3604 _ForwardIterator __s = __f;
3605 try
3606 {
3607#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003608 for (; __n > 0; ++__f, (void) --__n)
3609 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant8292d742011-12-29 17:45:35 +00003610#ifndef _LIBCPP_NO_EXCEPTIONS
3611 }
3612 catch (...)
3613 {
3614 for (; __s != __f; ++__s)
3615 __s->~value_type();
3616 throw;
3617 }
3618#endif
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003619 return __f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003620}
3621
Howard Hinnant82894812010-09-22 16:48:34 +00003622class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003623 : public std::exception
3624{
3625public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003626 virtual ~bad_weak_ptr() _NOEXCEPT;
3627 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628};
3629
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003630template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003632class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633{
3634 __shared_count(const __shared_count&);
3635 __shared_count& operator=(const __shared_count&);
3636
3637protected:
3638 long __shared_owners_;
3639 virtual ~__shared_count();
3640private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003641 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642
3643public:
Howard Hinnant82894812010-09-22 16:48:34 +00003644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003645 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003646 : __shared_owners_(__refs) {}
3647
Howard Hinnant1694d232011-05-28 14:41:13 +00003648 void __add_shared() _NOEXCEPT;
3649 bool __release_shared() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003651 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652};
3653
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003654class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003655 : private __shared_count
3656{
3657 long __shared_weak_owners_;
3658
3659public:
Howard Hinnant82894812010-09-22 16:48:34 +00003660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003661 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662 : __shared_count(__refs),
3663 __shared_weak_owners_(__refs) {}
3664protected:
3665 virtual ~__shared_weak_count();
3666
3667public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003668 void __add_shared() _NOEXCEPT;
3669 void __add_weak() _NOEXCEPT;
3670 void __release_shared() _NOEXCEPT;
3671 void __release_weak() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003673 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3674 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003675
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003676 // Define the function out only if we build static libc++ without RTTI.
3677 // Otherwise we may break clients who need to compile their projects with
3678 // -fno-rtti and yet link against a libc++.dylib compiled
3679 // without -fno-rtti.
3680#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant1694d232011-05-28 14:41:13 +00003681 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003682#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003684 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003685};
3686
3687template <class _Tp, class _Dp, class _Alloc>
3688class __shared_ptr_pointer
3689 : public __shared_weak_count
3690{
3691 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3692public:
Howard Hinnant82894812010-09-22 16:48:34 +00003693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003695 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003696
Howard Hinnantd4444702010-08-11 17:04:31 +00003697#ifndef _LIBCPP_NO_RTTI
Howard Hinnant1694d232011-05-28 14:41:13 +00003698 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnantd4444702010-08-11 17:04:31 +00003699#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700
3701private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003702 virtual void __on_zero_shared() _NOEXCEPT;
3703 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704};
3705
Howard Hinnantd4444702010-08-11 17:04:31 +00003706#ifndef _LIBCPP_NO_RTTI
3707
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003708template <class _Tp, class _Dp, class _Alloc>
3709const void*
Howard Hinnant1694d232011-05-28 14:41:13 +00003710__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711{
Marshall Clow4b3ca8c2014-11-17 19:05:50 +00003712 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713}
3714
Howard Hinnant324bb032010-08-22 00:02:43 +00003715#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00003716
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003717template <class _Tp, class _Dp, class _Alloc>
3718void
Howard Hinnant1694d232011-05-28 14:41:13 +00003719__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720{
3721 __data_.first().second()(__data_.first().first());
3722 __data_.first().second().~_Dp();
3723}
3724
3725template <class _Tp, class _Dp, class _Alloc>
3726void
Howard Hinnant1694d232011-05-28 14:41:13 +00003727__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003728{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003729 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3730 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003731 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3732
Eric Fiselier8492cd82015-02-05 23:01:40 +00003733 _Al __a(__data_.second());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003734 __data_.second().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003735 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003736}
3737
3738template <class _Tp, class _Alloc>
3739class __shared_ptr_emplace
3740 : public __shared_weak_count
3741{
3742 __compressed_pair<_Alloc, _Tp> __data_;
3743public:
3744#ifndef _LIBCPP_HAS_NO_VARIADICS
3745
Howard Hinnant82894812010-09-22 16:48:34 +00003746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003747 __shared_ptr_emplace(_Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003748 : __data_(_VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003749
3750 template <class ..._Args>
Howard Hinnant82894812010-09-22 16:48:34 +00003751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00003753 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3754 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003755
3756#else // _LIBCPP_HAS_NO_VARIADICS
3757
Howard Hinnant82894812010-09-22 16:48:34 +00003758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003759 __shared_ptr_emplace(_Alloc __a)
3760 : __data_(__a) {}
3761
3762 template <class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00003763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003764 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3765 : __data_(__a, _Tp(__a0)) {}
3766
3767 template <class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00003768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003769 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3770 : __data_(__a, _Tp(__a0, __a1)) {}
3771
3772 template <class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00003773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003774 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3775 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3776
3777#endif // _LIBCPP_HAS_NO_VARIADICS
3778
3779private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003780 virtual void __on_zero_shared() _NOEXCEPT;
3781 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003782public:
Howard Hinnant82894812010-09-22 16:48:34 +00003783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003784 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003785};
3786
3787template <class _Tp, class _Alloc>
3788void
Howard Hinnant1694d232011-05-28 14:41:13 +00003789__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003790{
3791 __data_.second().~_Tp();
3792}
3793
3794template <class _Tp, class _Alloc>
3795void
Howard Hinnant1694d232011-05-28 14:41:13 +00003796__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003798 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3799 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003800 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselier8492cd82015-02-05 23:01:40 +00003801 _Al __a(__data_.first());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802 __data_.first().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003803 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003804}
3805
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003806template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003807
3808template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003809class _LIBCPP_TYPE_VIS_ONLY shared_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003810{
Howard Hinnant324bb032010-08-22 00:02:43 +00003811public:
3812 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003813private:
3814 element_type* __ptr_;
3815 __shared_weak_count* __cntrl_;
3816
3817 struct __nat {int __for_bool_;};
3818public:
Howard Hinnant46e94932012-07-07 20:56:04 +00003819 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3820 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiene1678a12014-01-31 09:30:46 +00003821 template<class _Yp>
3822 explicit shared_ptr(_Yp* __p,
3823 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3824 template<class _Yp, class _Dp>
3825 shared_ptr(_Yp* __p, _Dp __d,
3826 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3827 template<class _Yp, class _Dp, class _Alloc>
3828 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3829 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3831 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Howard Hinnant1694d232011-05-28 14:41:13 +00003832 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3833 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834 template<class _Yp>
3835 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003836 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3837 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003838#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003839 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003841 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3842 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003843#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant324bb032010-08-22 00:02:43 +00003845 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003846#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003847 template<class _Yp>
3848 shared_ptr(auto_ptr<_Yp>&& __r,
3849 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant324bb032010-08-22 00:02:43 +00003850#else
Logan Chiene1678a12014-01-31 09:30:46 +00003851 template<class _Yp>
3852 shared_ptr(auto_ptr<_Yp> __r,
3853 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +00003855#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003856 template <class _Yp, class _Dp>
3857 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3858 typename enable_if
3859 <
3860 !is_lvalue_reference<_Dp>::value &&
3861 !is_array<_Yp>::value &&
3862 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3863 __nat
3864 >::type = __nat());
3865 template <class _Yp, class _Dp>
3866 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3867 typename enable_if
3868 <
3869 is_lvalue_reference<_Dp>::value &&
3870 !is_array<_Yp>::value &&
3871 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3872 __nat
3873 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003874#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003875 template <class _Yp, class _Dp>
3876 shared_ptr(unique_ptr<_Yp, _Dp>,
3877 typename enable_if
3878 <
3879 !is_lvalue_reference<_Dp>::value &&
3880 !is_array<_Yp>::value &&
3881 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3882 __nat
3883 >::type = __nat());
3884 template <class _Yp, class _Dp>
3885 shared_ptr(unique_ptr<_Yp, _Dp>,
3886 typename enable_if
3887 <
3888 is_lvalue_reference<_Dp>::value &&
3889 !is_array<_Yp>::value &&
3890 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3891 __nat
3892 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003893#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894
3895 ~shared_ptr();
3896
Howard Hinnant1694d232011-05-28 14:41:13 +00003897 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003898 template<class _Yp>
3899 typename enable_if
3900 <
3901 is_convertible<_Yp*, element_type*>::value,
3902 shared_ptr&
3903 >::type
3904 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003905#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003906 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003907 template<class _Yp>
3908 typename enable_if
3909 <
3910 is_convertible<_Yp*, element_type*>::value,
3911 shared_ptr<_Tp>&
3912 >::type
3913 operator=(shared_ptr<_Yp>&& __r);
3914 template<class _Yp>
3915 typename enable_if
3916 <
3917 !is_array<_Yp>::value &&
3918 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00003919 shared_ptr
3920 >::type&
Howard Hinnant57199402012-01-02 17:56:02 +00003921 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003922#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003923 template<class _Yp>
3924 typename enable_if
3925 <
3926 !is_array<_Yp>::value &&
3927 is_convertible<_Yp*, element_type*>::value,
3928 shared_ptr&
3929 >::type
3930 operator=(auto_ptr<_Yp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931#endif
Howard Hinnant57199402012-01-02 17:56:02 +00003932 template <class _Yp, class _Dp>
3933 typename enable_if
3934 <
3935 !is_array<_Yp>::value &&
3936 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3937 shared_ptr&
3938 >::type
Howard Hinnant73d21a42010-09-04 23:28:19 +00003939#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003940 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003941#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003942 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943#endif
3944
Howard Hinnant1694d232011-05-28 14:41:13 +00003945 void swap(shared_ptr& __r) _NOEXCEPT;
3946 void reset() _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003947 template<class _Yp>
3948 typename enable_if
3949 <
3950 is_convertible<_Yp*, element_type*>::value,
3951 void
3952 >::type
3953 reset(_Yp* __p);
3954 template<class _Yp, class _Dp>
3955 typename enable_if
3956 <
3957 is_convertible<_Yp*, element_type*>::value,
3958 void
3959 >::type
3960 reset(_Yp* __p, _Dp __d);
3961 template<class _Yp, class _Dp, class _Alloc>
3962 typename enable_if
3963 <
3964 is_convertible<_Yp*, element_type*>::value,
3965 void
3966 >::type
3967 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003968
Howard Hinnant82894812010-09-22 16:48:34 +00003969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003970 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003972 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3973 {return *__ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003975 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003977 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00003978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003979 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant82894812010-09-22 16:48:34 +00003980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00003981 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnant99968442011-11-29 18:15:50 +00003982 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003984 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant99968442011-11-29 18:15:50 +00003986 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003988 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003990 _LIBCPP_INLINE_VISIBILITY
3991 bool
3992 __owner_equivalent(const shared_ptr& __p) const
3993 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003994
Howard Hinnantd4444702010-08-11 17:04:31 +00003995#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003996 template <class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00003997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003998 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003999 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant324bb032010-08-22 00:02:43 +00004000#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004001
4002#ifndef _LIBCPP_HAS_NO_VARIADICS
4003
4004 template<class ..._Args>
4005 static
4006 shared_ptr<_Tp>
4007 make_shared(_Args&& ...__args);
4008
4009 template<class _Alloc, class ..._Args>
4010 static
4011 shared_ptr<_Tp>
4012 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4013
4014#else // _LIBCPP_HAS_NO_VARIADICS
4015
4016 static shared_ptr<_Tp> make_shared();
4017
4018 template<class _A0>
4019 static shared_ptr<_Tp> make_shared(_A0&);
4020
4021 template<class _A0, class _A1>
4022 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4023
4024 template<class _A0, class _A1, class _A2>
4025 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4026
4027 template<class _Alloc>
4028 static shared_ptr<_Tp>
4029 allocate_shared(const _Alloc& __a);
4030
4031 template<class _Alloc, class _A0>
4032 static shared_ptr<_Tp>
4033 allocate_shared(const _Alloc& __a, _A0& __a0);
4034
4035 template<class _Alloc, class _A0, class _A1>
4036 static shared_ptr<_Tp>
4037 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4038
4039 template<class _Alloc, class _A0, class _A1, class _A2>
4040 static shared_ptr<_Tp>
4041 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4042
4043#endif // _LIBCPP_HAS_NO_VARIADICS
4044
4045private:
4046
4047 template <class _Yp>
Howard Hinnant82894812010-09-22 16:48:34 +00004048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004049 void
Marshall Clowfc3a3ff2015-05-27 20:36:14 +00004050 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004051 {
4052 if (__e)
4053 __e->__weak_this_ = *this;
4054 }
4055
Howard Hinnant82894812010-09-22 16:48:34 +00004056 _LIBCPP_INLINE_VISIBILITY
Marshall Clow60784f62015-05-27 22:44:47 +00004057 void __enable_weak_this(const volatile void*) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004058
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004059 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4060 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004061};
4062
4063template<class _Tp>
4064inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004065_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004066shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067 : __ptr_(0),
4068 __cntrl_(0)
4069{
4070}
4071
4072template<class _Tp>
4073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004074_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004075shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004076 : __ptr_(0),
4077 __cntrl_(0)
4078{
4079}
4080
4081template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004082template<class _Yp>
4083shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4084 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004085 : __ptr_(__p)
4086{
4087 unique_ptr<_Yp> __hold(__p);
4088 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4089 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4090 __hold.release();
4091 __enable_weak_this(__p);
4092}
4093
4094template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004095template<class _Yp, class _Dp>
4096shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4097 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004098 : __ptr_(__p)
4099{
4100#ifndef _LIBCPP_NO_EXCEPTIONS
4101 try
4102 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004103#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4105 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4106 __enable_weak_this(__p);
4107#ifndef _LIBCPP_NO_EXCEPTIONS
4108 }
4109 catch (...)
4110 {
4111 __d(__p);
4112 throw;
4113 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004114#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004115}
4116
4117template<class _Tp>
4118template<class _Dp>
4119shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4120 : __ptr_(0)
4121{
4122#ifndef _LIBCPP_NO_EXCEPTIONS
4123 try
4124 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004125#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004126 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4127 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4128#ifndef _LIBCPP_NO_EXCEPTIONS
4129 }
4130 catch (...)
4131 {
4132 __d(__p);
4133 throw;
4134 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004135#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004136}
4137
4138template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004139template<class _Yp, class _Dp, class _Alloc>
4140shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4141 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004142 : __ptr_(__p)
4143{
4144#ifndef _LIBCPP_NO_EXCEPTIONS
4145 try
4146 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004147#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004148 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004149 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004150 typedef __allocator_destructor<_A2> _D2;
4151 _A2 __a2(__a);
4152 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004153 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4154 _CntrlBlk(__p, __d, __a);
4155 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004156 __enable_weak_this(__p);
4157#ifndef _LIBCPP_NO_EXCEPTIONS
4158 }
4159 catch (...)
4160 {
4161 __d(__p);
4162 throw;
4163 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004164#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004165}
4166
4167template<class _Tp>
4168template<class _Dp, class _Alloc>
4169shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4170 : __ptr_(0)
4171{
4172#ifndef _LIBCPP_NO_EXCEPTIONS
4173 try
4174 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004175#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004176 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004177 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004178 typedef __allocator_destructor<_A2> _D2;
4179 _A2 __a2(__a);
4180 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004181 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4182 _CntrlBlk(__p, __d, __a);
4183 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004184#ifndef _LIBCPP_NO_EXCEPTIONS
4185 }
4186 catch (...)
4187 {
4188 __d(__p);
4189 throw;
4190 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004191#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004192}
4193
4194template<class _Tp>
4195template<class _Yp>
4196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004197shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004198 : __ptr_(__p),
4199 __cntrl_(__r.__cntrl_)
4200{
4201 if (__cntrl_)
4202 __cntrl_->__add_shared();
4203}
4204
4205template<class _Tp>
4206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004207shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004208 : __ptr_(__r.__ptr_),
4209 __cntrl_(__r.__cntrl_)
4210{
4211 if (__cntrl_)
4212 __cntrl_->__add_shared();
4213}
4214
4215template<class _Tp>
4216template<class _Yp>
4217inline _LIBCPP_INLINE_VISIBILITY
4218shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4219 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004220 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004221 : __ptr_(__r.__ptr_),
4222 __cntrl_(__r.__cntrl_)
4223{
4224 if (__cntrl_)
4225 __cntrl_->__add_shared();
4226}
4227
Howard Hinnant73d21a42010-09-04 23:28:19 +00004228#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004229
4230template<class _Tp>
4231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004232shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004233 : __ptr_(__r.__ptr_),
4234 __cntrl_(__r.__cntrl_)
4235{
4236 __r.__ptr_ = 0;
4237 __r.__cntrl_ = 0;
4238}
4239
4240template<class _Tp>
4241template<class _Yp>
4242inline _LIBCPP_INLINE_VISIBILITY
4243shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4244 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004245 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004246 : __ptr_(__r.__ptr_),
4247 __cntrl_(__r.__cntrl_)
4248{
4249 __r.__ptr_ = 0;
4250 __r.__cntrl_ = 0;
4251}
4252
Howard Hinnant73d21a42010-09-04 23:28:19 +00004253#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004254
4255template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004256template<class _Yp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004257#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00004258shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004259#else
Logan Chiene1678a12014-01-31 09:30:46 +00004260shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004261#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004262 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004263 : __ptr_(__r.get())
4264{
4265 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4266 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4267 __enable_weak_this(__r.get());
4268 __r.release();
4269}
4270
4271template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004272template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004273#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004274shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4275#else
4276shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4277#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004278 typename enable_if
4279 <
4280 !is_lvalue_reference<_Dp>::value &&
4281 !is_array<_Yp>::value &&
4282 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4283 __nat
4284 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004285 : __ptr_(__r.get())
4286{
Marshall Clow0ad232a2015-05-10 13:59:45 +00004287#if _LIBCPP_STD_VER > 11
4288 if (__ptr_ == nullptr)
4289 __cntrl_ = nullptr;
4290 else
4291#endif
4292 {
4293 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4294 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4295 __enable_weak_this(__r.get());
4296 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004297 __r.release();
4298}
4299
4300template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004301template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004302#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004303shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4304#else
4305shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4306#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004307 typename enable_if
4308 <
4309 is_lvalue_reference<_Dp>::value &&
4310 !is_array<_Yp>::value &&
4311 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4312 __nat
4313 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004314 : __ptr_(__r.get())
4315{
Marshall Clow0ad232a2015-05-10 13:59:45 +00004316#if _LIBCPP_STD_VER > 11
4317 if (__ptr_ == nullptr)
4318 __cntrl_ = nullptr;
4319 else
4320#endif
4321 {
4322 typedef __shared_ptr_pointer<_Yp*,
4323 reference_wrapper<typename remove_reference<_Dp>::type>,
4324 allocator<_Yp> > _CntrlBlk;
4325 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4326 __enable_weak_this(__r.get());
4327 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004328 __r.release();
4329}
4330
4331#ifndef _LIBCPP_HAS_NO_VARIADICS
4332
4333template<class _Tp>
4334template<class ..._Args>
4335shared_ptr<_Tp>
4336shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4337{
4338 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4339 typedef allocator<_CntrlBlk> _A2;
4340 typedef __allocator_destructor<_A2> _D2;
4341 _A2 __a2;
4342 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00004343 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004344 shared_ptr<_Tp> __r;
4345 __r.__ptr_ = __hold2.get()->get();
4346 __r.__cntrl_ = __hold2.release();
4347 __r.__enable_weak_this(__r.__ptr_);
4348 return __r;
4349}
4350
4351template<class _Tp>
4352template<class _Alloc, class ..._Args>
4353shared_ptr<_Tp>
4354shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4355{
4356 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004357 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004358 typedef __allocator_destructor<_A2> _D2;
4359 _A2 __a2(__a);
4360 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004361 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4362 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004363 shared_ptr<_Tp> __r;
4364 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004365 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004366 __r.__enable_weak_this(__r.__ptr_);
4367 return __r;
4368}
4369
4370#else // _LIBCPP_HAS_NO_VARIADICS
4371
4372template<class _Tp>
4373shared_ptr<_Tp>
4374shared_ptr<_Tp>::make_shared()
4375{
4376 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4377 typedef allocator<_CntrlBlk> _Alloc2;
4378 typedef __allocator_destructor<_Alloc2> _D2;
4379 _Alloc2 __alloc2;
4380 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4381 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4382 shared_ptr<_Tp> __r;
4383 __r.__ptr_ = __hold2.get()->get();
4384 __r.__cntrl_ = __hold2.release();
4385 __r.__enable_weak_this(__r.__ptr_);
4386 return __r;
4387}
4388
4389template<class _Tp>
4390template<class _A0>
4391shared_ptr<_Tp>
4392shared_ptr<_Tp>::make_shared(_A0& __a0)
4393{
4394 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4395 typedef allocator<_CntrlBlk> _Alloc2;
4396 typedef __allocator_destructor<_Alloc2> _D2;
4397 _Alloc2 __alloc2;
4398 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4399 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4400 shared_ptr<_Tp> __r;
4401 __r.__ptr_ = __hold2.get()->get();
4402 __r.__cntrl_ = __hold2.release();
4403 __r.__enable_weak_this(__r.__ptr_);
4404 return __r;
4405}
4406
4407template<class _Tp>
4408template<class _A0, class _A1>
4409shared_ptr<_Tp>
4410shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4411{
4412 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4413 typedef allocator<_CntrlBlk> _Alloc2;
4414 typedef __allocator_destructor<_Alloc2> _D2;
4415 _Alloc2 __alloc2;
4416 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4417 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4418 shared_ptr<_Tp> __r;
4419 __r.__ptr_ = __hold2.get()->get();
4420 __r.__cntrl_ = __hold2.release();
4421 __r.__enable_weak_this(__r.__ptr_);
4422 return __r;
4423}
4424
4425template<class _Tp>
4426template<class _A0, class _A1, class _A2>
4427shared_ptr<_Tp>
4428shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4429{
4430 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4431 typedef allocator<_CntrlBlk> _Alloc2;
4432 typedef __allocator_destructor<_Alloc2> _D2;
4433 _Alloc2 __alloc2;
4434 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4435 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4436 shared_ptr<_Tp> __r;
4437 __r.__ptr_ = __hold2.get()->get();
4438 __r.__cntrl_ = __hold2.release();
4439 __r.__enable_weak_this(__r.__ptr_);
4440 return __r;
4441}
4442
4443template<class _Tp>
4444template<class _Alloc>
4445shared_ptr<_Tp>
4446shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4447{
4448 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004449 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004450 typedef __allocator_destructor<_Alloc2> _D2;
4451 _Alloc2 __alloc2(__a);
4452 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004453 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4454 _CntrlBlk(__a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004455 shared_ptr<_Tp> __r;
4456 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004457 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004458 __r.__enable_weak_this(__r.__ptr_);
4459 return __r;
4460}
4461
4462template<class _Tp>
4463template<class _Alloc, class _A0>
4464shared_ptr<_Tp>
4465shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4466{
4467 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004468 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004469 typedef __allocator_destructor<_Alloc2> _D2;
4470 _Alloc2 __alloc2(__a);
4471 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004472 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4473 _CntrlBlk(__a, __a0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004474 shared_ptr<_Tp> __r;
4475 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004476 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004477 __r.__enable_weak_this(__r.__ptr_);
4478 return __r;
4479}
4480
4481template<class _Tp>
4482template<class _Alloc, class _A0, class _A1>
4483shared_ptr<_Tp>
4484shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4485{
4486 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004487 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004488 typedef __allocator_destructor<_Alloc2> _D2;
4489 _Alloc2 __alloc2(__a);
4490 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004491 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4492 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004493 shared_ptr<_Tp> __r;
4494 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004495 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004496 __r.__enable_weak_this(__r.__ptr_);
4497 return __r;
4498}
4499
4500template<class _Tp>
4501template<class _Alloc, class _A0, class _A1, class _A2>
4502shared_ptr<_Tp>
4503shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4504{
4505 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004506 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004507 typedef __allocator_destructor<_Alloc2> _D2;
4508 _Alloc2 __alloc2(__a);
4509 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004510 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4511 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004512 shared_ptr<_Tp> __r;
4513 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004514 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004515 __r.__enable_weak_this(__r.__ptr_);
4516 return __r;
4517}
4518
4519#endif // _LIBCPP_HAS_NO_VARIADICS
4520
4521template<class _Tp>
4522shared_ptr<_Tp>::~shared_ptr()
4523{
4524 if (__cntrl_)
4525 __cntrl_->__release_shared();
4526}
4527
4528template<class _Tp>
4529inline _LIBCPP_INLINE_VISIBILITY
4530shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004531shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004532{
4533 shared_ptr(__r).swap(*this);
4534 return *this;
4535}
4536
4537template<class _Tp>
4538template<class _Yp>
4539inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004540typename enable_if
4541<
4542 is_convertible<_Yp*, _Tp*>::value,
4543 shared_ptr<_Tp>&
4544>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004545shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004546{
4547 shared_ptr(__r).swap(*this);
4548 return *this;
4549}
4550
Howard Hinnant73d21a42010-09-04 23:28:19 +00004551#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004552
4553template<class _Tp>
4554inline _LIBCPP_INLINE_VISIBILITY
4555shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004556shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004557{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004558 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004559 return *this;
4560}
4561
4562template<class _Tp>
4563template<class _Yp>
4564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004565typename enable_if
4566<
4567 is_convertible<_Yp*, _Tp*>::value,
4568 shared_ptr<_Tp>&
4569>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004570shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4571{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004572 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004573 return *this;
4574}
4575
4576template<class _Tp>
4577template<class _Yp>
4578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004579typename enable_if
4580<
4581 !is_array<_Yp>::value &&
4582 is_convertible<_Yp*, _Tp*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00004583 shared_ptr<_Tp>
4584>::type&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004585shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4586{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004587 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004588 return *this;
4589}
4590
4591template<class _Tp>
4592template <class _Yp, class _Dp>
4593inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004594typename enable_if
4595<
4596 !is_array<_Yp>::value &&
4597 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4598 shared_ptr<_Tp>&
4599>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004600shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4601{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004602 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004603 return *this;
4604}
4605
Howard Hinnant73d21a42010-09-04 23:28:19 +00004606#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004607
4608template<class _Tp>
4609template<class _Yp>
4610inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004611typename enable_if
4612<
4613 !is_array<_Yp>::value &&
4614 is_convertible<_Yp*, _Tp*>::value,
4615 shared_ptr<_Tp>&
4616>::type
Howard Hinnant324bb032010-08-22 00:02:43 +00004617shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004618{
4619 shared_ptr(__r).swap(*this);
4620 return *this;
4621}
4622
4623template<class _Tp>
4624template <class _Yp, class _Dp>
4625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004626typename enable_if
4627<
4628 !is_array<_Yp>::value &&
4629 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4630 shared_ptr<_Tp>&
4631>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004632shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4633{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004634 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004635 return *this;
4636}
4637
Howard Hinnant73d21a42010-09-04 23:28:19 +00004638#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004639
4640template<class _Tp>
4641inline _LIBCPP_INLINE_VISIBILITY
4642void
Howard Hinnant1694d232011-05-28 14:41:13 +00004643shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004644{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004645 _VSTD::swap(__ptr_, __r.__ptr_);
4646 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004647}
4648
4649template<class _Tp>
4650inline _LIBCPP_INLINE_VISIBILITY
4651void
Howard Hinnant1694d232011-05-28 14:41:13 +00004652shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004653{
4654 shared_ptr().swap(*this);
4655}
4656
4657template<class _Tp>
4658template<class _Yp>
4659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004660typename enable_if
4661<
4662 is_convertible<_Yp*, _Tp*>::value,
4663 void
4664>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004665shared_ptr<_Tp>::reset(_Yp* __p)
4666{
4667 shared_ptr(__p).swap(*this);
4668}
4669
4670template<class _Tp>
4671template<class _Yp, class _Dp>
4672inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004673typename enable_if
4674<
4675 is_convertible<_Yp*, _Tp*>::value,
4676 void
4677>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004678shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4679{
4680 shared_ptr(__p, __d).swap(*this);
4681}
4682
4683template<class _Tp>
4684template<class _Yp, class _Dp, class _Alloc>
4685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004686typename enable_if
4687<
4688 is_convertible<_Yp*, _Tp*>::value,
4689 void
4690>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004691shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4692{
4693 shared_ptr(__p, __d, __a).swap(*this);
4694}
4695
4696#ifndef _LIBCPP_HAS_NO_VARIADICS
4697
Howard Hinnant324bb032010-08-22 00:02:43 +00004698template<class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004699inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004700typename enable_if
4701<
4702 !is_array<_Tp>::value,
4703 shared_ptr<_Tp>
4704>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004705make_shared(_Args&& ...__args)
4706{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004707 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004708}
4709
Howard Hinnant324bb032010-08-22 00:02:43 +00004710template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004711inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004712typename enable_if
4713<
4714 !is_array<_Tp>::value,
4715 shared_ptr<_Tp>
4716>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004717allocate_shared(const _Alloc& __a, _Args&& ...__args)
4718{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004719 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004720}
4721
4722#else // _LIBCPP_HAS_NO_VARIADICS
4723
4724template<class _Tp>
4725inline _LIBCPP_INLINE_VISIBILITY
4726shared_ptr<_Tp>
4727make_shared()
4728{
4729 return shared_ptr<_Tp>::make_shared();
4730}
4731
4732template<class _Tp, class _A0>
4733inline _LIBCPP_INLINE_VISIBILITY
4734shared_ptr<_Tp>
4735make_shared(_A0& __a0)
4736{
4737 return shared_ptr<_Tp>::make_shared(__a0);
4738}
4739
4740template<class _Tp, class _A0, class _A1>
4741inline _LIBCPP_INLINE_VISIBILITY
4742shared_ptr<_Tp>
4743make_shared(_A0& __a0, _A1& __a1)
4744{
4745 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4746}
4747
Howard Hinnant324bb032010-08-22 00:02:43 +00004748template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004749inline _LIBCPP_INLINE_VISIBILITY
4750shared_ptr<_Tp>
4751make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4752{
4753 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4754}
4755
4756template<class _Tp, class _Alloc>
4757inline _LIBCPP_INLINE_VISIBILITY
4758shared_ptr<_Tp>
4759allocate_shared(const _Alloc& __a)
4760{
4761 return shared_ptr<_Tp>::allocate_shared(__a);
4762}
4763
4764template<class _Tp, class _Alloc, class _A0>
4765inline _LIBCPP_INLINE_VISIBILITY
4766shared_ptr<_Tp>
4767allocate_shared(const _Alloc& __a, _A0& __a0)
4768{
4769 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4770}
4771
4772template<class _Tp, class _Alloc, class _A0, class _A1>
4773inline _LIBCPP_INLINE_VISIBILITY
4774shared_ptr<_Tp>
4775allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4776{
4777 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4778}
4779
4780template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4781inline _LIBCPP_INLINE_VISIBILITY
4782shared_ptr<_Tp>
4783allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4784{
4785 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4786}
4787
4788#endif // _LIBCPP_HAS_NO_VARIADICS
4789
4790template<class _Tp, class _Up>
4791inline _LIBCPP_INLINE_VISIBILITY
4792bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004793operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004794{
4795 return __x.get() == __y.get();
4796}
4797
4798template<class _Tp, class _Up>
4799inline _LIBCPP_INLINE_VISIBILITY
4800bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004801operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004802{
4803 return !(__x == __y);
4804}
4805
4806template<class _Tp, class _Up>
4807inline _LIBCPP_INLINE_VISIBILITY
4808bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004809operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004810{
Eric Fiselier8492cd82015-02-05 23:01:40 +00004811 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4812 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00004813}
4814
4815template<class _Tp, class _Up>
4816inline _LIBCPP_INLINE_VISIBILITY
4817bool
4818operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4819{
4820 return __y < __x;
4821}
4822
4823template<class _Tp, class _Up>
4824inline _LIBCPP_INLINE_VISIBILITY
4825bool
4826operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4827{
4828 return !(__y < __x);
4829}
4830
4831template<class _Tp, class _Up>
4832inline _LIBCPP_INLINE_VISIBILITY
4833bool
4834operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4835{
4836 return !(__x < __y);
4837}
4838
4839template<class _Tp>
4840inline _LIBCPP_INLINE_VISIBILITY
4841bool
4842operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4843{
4844 return !__x;
4845}
4846
4847template<class _Tp>
4848inline _LIBCPP_INLINE_VISIBILITY
4849bool
4850operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4851{
4852 return !__x;
4853}
4854
4855template<class _Tp>
4856inline _LIBCPP_INLINE_VISIBILITY
4857bool
4858operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4859{
4860 return static_cast<bool>(__x);
4861}
4862
4863template<class _Tp>
4864inline _LIBCPP_INLINE_VISIBILITY
4865bool
4866operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4867{
4868 return static_cast<bool>(__x);
4869}
4870
4871template<class _Tp>
4872inline _LIBCPP_INLINE_VISIBILITY
4873bool
4874operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4875{
4876 return less<_Tp*>()(__x.get(), nullptr);
4877}
4878
4879template<class _Tp>
4880inline _LIBCPP_INLINE_VISIBILITY
4881bool
4882operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4883{
4884 return less<_Tp*>()(nullptr, __x.get());
4885}
4886
4887template<class _Tp>
4888inline _LIBCPP_INLINE_VISIBILITY
4889bool
4890operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4891{
4892 return nullptr < __x;
4893}
4894
4895template<class _Tp>
4896inline _LIBCPP_INLINE_VISIBILITY
4897bool
4898operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4899{
4900 return __x < nullptr;
4901}
4902
4903template<class _Tp>
4904inline _LIBCPP_INLINE_VISIBILITY
4905bool
4906operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4907{
4908 return !(nullptr < __x);
4909}
4910
4911template<class _Tp>
4912inline _LIBCPP_INLINE_VISIBILITY
4913bool
4914operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4915{
4916 return !(__x < nullptr);
4917}
4918
4919template<class _Tp>
4920inline _LIBCPP_INLINE_VISIBILITY
4921bool
4922operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4923{
4924 return !(__x < nullptr);
4925}
4926
4927template<class _Tp>
4928inline _LIBCPP_INLINE_VISIBILITY
4929bool
4930operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4931{
4932 return !(nullptr < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004933}
4934
4935template<class _Tp>
4936inline _LIBCPP_INLINE_VISIBILITY
4937void
Howard Hinnant1694d232011-05-28 14:41:13 +00004938swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004939{
4940 __x.swap(__y);
4941}
4942
4943template<class _Tp, class _Up>
4944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004945typename enable_if
4946<
4947 !is_array<_Tp>::value && !is_array<_Up>::value,
4948 shared_ptr<_Tp>
4949>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004950static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004951{
4952 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4953}
4954
4955template<class _Tp, class _Up>
4956inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004957typename enable_if
4958<
4959 !is_array<_Tp>::value && !is_array<_Up>::value,
4960 shared_ptr<_Tp>
4961>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004962dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004963{
4964 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4965 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4966}
4967
4968template<class _Tp, class _Up>
Howard Hinnant57199402012-01-02 17:56:02 +00004969typename enable_if
4970<
4971 is_array<_Tp>::value == is_array<_Up>::value,
4972 shared_ptr<_Tp>
4973>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004974const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004975{
Howard Hinnant57199402012-01-02 17:56:02 +00004976 typedef typename remove_extent<_Tp>::type _RTp;
4977 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004978}
4979
Howard Hinnantd4444702010-08-11 17:04:31 +00004980#ifndef _LIBCPP_NO_RTTI
4981
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004982template<class _Dp, class _Tp>
4983inline _LIBCPP_INLINE_VISIBILITY
4984_Dp*
Howard Hinnant1694d232011-05-28 14:41:13 +00004985get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004986{
4987 return __p.template __get_deleter<_Dp>();
4988}
4989
Howard Hinnant324bb032010-08-22 00:02:43 +00004990#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00004991
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004992template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004993class _LIBCPP_TYPE_VIS_ONLY weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004994{
Howard Hinnant324bb032010-08-22 00:02:43 +00004995public:
4996 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004997private:
4998 element_type* __ptr_;
4999 __shared_weak_count* __cntrl_;
5000
Howard Hinnant324bb032010-08-22 00:02:43 +00005001public:
Howard Hinnant46e94932012-07-07 20:56:04 +00005002 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005003 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00005004 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5005 _NOEXCEPT;
5006 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005007 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00005008 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5009 _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005010
Howard Hinnant57199402012-01-02 17:56:02 +00005011#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5012 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5013 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
5014 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5015 _NOEXCEPT;
5016#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant324bb032010-08-22 00:02:43 +00005017 ~weak_ptr();
5018
Howard Hinnant1694d232011-05-28 14:41:13 +00005019 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00005020 template<class _Yp>
5021 typename enable_if
5022 <
5023 is_convertible<_Yp*, element_type*>::value,
5024 weak_ptr&
5025 >::type
5026 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5027
5028#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5029
5030 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5031 template<class _Yp>
5032 typename enable_if
5033 <
5034 is_convertible<_Yp*, element_type*>::value,
5035 weak_ptr&
5036 >::type
5037 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5038
5039#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5040
5041 template<class _Yp>
5042 typename enable_if
5043 <
5044 is_convertible<_Yp*, element_type*>::value,
5045 weak_ptr&
5046 >::type
5047 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005048
Howard Hinnant1694d232011-05-28 14:41:13 +00005049 void swap(weak_ptr& __r) _NOEXCEPT;
5050 void reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005051
Howard Hinnant82894812010-09-22 16:48:34 +00005052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005053 long use_count() const _NOEXCEPT
5054 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00005055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005056 bool expired() const _NOEXCEPT
5057 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5058 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00005059 template<class _Up>
5060 _LIBCPP_INLINE_VISIBILITY
5061 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005062 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant82894812010-09-22 16:48:34 +00005063 template<class _Up>
5064 _LIBCPP_INLINE_VISIBILITY
5065 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005066 {return __cntrl_ < __r.__cntrl_;}
5067
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005068 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5069 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005070};
5071
5072template<class _Tp>
5073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00005074_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005075weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005076 : __ptr_(0),
5077 __cntrl_(0)
5078{
5079}
5080
5081template<class _Tp>
5082inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005083weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005084 : __ptr_(__r.__ptr_),
5085 __cntrl_(__r.__cntrl_)
5086{
5087 if (__cntrl_)
5088 __cntrl_->__add_weak();
5089}
5090
5091template<class _Tp>
5092template<class _Yp>
5093inline _LIBCPP_INLINE_VISIBILITY
5094weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005095 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005096 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005097 : __ptr_(__r.__ptr_),
5098 __cntrl_(__r.__cntrl_)
5099{
5100 if (__cntrl_)
5101 __cntrl_->__add_weak();
5102}
5103
5104template<class _Tp>
5105template<class _Yp>
5106inline _LIBCPP_INLINE_VISIBILITY
5107weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005108 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005109 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005110 : __ptr_(__r.__ptr_),
5111 __cntrl_(__r.__cntrl_)
5112{
5113 if (__cntrl_)
5114 __cntrl_->__add_weak();
5115}
5116
Howard Hinnant57199402012-01-02 17:56:02 +00005117#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5118
5119template<class _Tp>
5120inline _LIBCPP_INLINE_VISIBILITY
5121weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5122 : __ptr_(__r.__ptr_),
5123 __cntrl_(__r.__cntrl_)
5124{
5125 __r.__ptr_ = 0;
5126 __r.__cntrl_ = 0;
5127}
5128
5129template<class _Tp>
5130template<class _Yp>
5131inline _LIBCPP_INLINE_VISIBILITY
5132weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5133 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5134 _NOEXCEPT
5135 : __ptr_(__r.__ptr_),
5136 __cntrl_(__r.__cntrl_)
5137{
5138 __r.__ptr_ = 0;
5139 __r.__cntrl_ = 0;
5140}
5141
5142#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5143
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005144template<class _Tp>
5145weak_ptr<_Tp>::~weak_ptr()
5146{
5147 if (__cntrl_)
5148 __cntrl_->__release_weak();
5149}
5150
5151template<class _Tp>
5152inline _LIBCPP_INLINE_VISIBILITY
5153weak_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00005154weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005155{
5156 weak_ptr(__r).swap(*this);
5157 return *this;
5158}
5159
5160template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005161template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005163typename enable_if
5164<
5165 is_convertible<_Yp*, _Tp*>::value,
5166 weak_ptr<_Tp>&
5167>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005168weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005169{
5170 weak_ptr(__r).swap(*this);
5171 return *this;
5172}
5173
Howard Hinnant57199402012-01-02 17:56:02 +00005174#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5175
5176template<class _Tp>
5177inline _LIBCPP_INLINE_VISIBILITY
5178weak_ptr<_Tp>&
5179weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5180{
5181 weak_ptr(_VSTD::move(__r)).swap(*this);
5182 return *this;
5183}
5184
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005185template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005186template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005187inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005188typename enable_if
5189<
5190 is_convertible<_Yp*, _Tp*>::value,
5191 weak_ptr<_Tp>&
5192>::type
5193weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5194{
5195 weak_ptr(_VSTD::move(__r)).swap(*this);
5196 return *this;
5197}
5198
5199#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5200
5201template<class _Tp>
5202template<class _Yp>
5203inline _LIBCPP_INLINE_VISIBILITY
5204typename enable_if
5205<
5206 is_convertible<_Yp*, _Tp*>::value,
5207 weak_ptr<_Tp>&
5208>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005209weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005210{
5211 weak_ptr(__r).swap(*this);
5212 return *this;
5213}
5214
5215template<class _Tp>
5216inline _LIBCPP_INLINE_VISIBILITY
5217void
Howard Hinnant1694d232011-05-28 14:41:13 +00005218weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005219{
Howard Hinnant0949eed2011-06-30 21:18:19 +00005220 _VSTD::swap(__ptr_, __r.__ptr_);
5221 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005222}
5223
5224template<class _Tp>
5225inline _LIBCPP_INLINE_VISIBILITY
5226void
Howard Hinnant1694d232011-05-28 14:41:13 +00005227swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005228{
5229 __x.swap(__y);
5230}
5231
5232template<class _Tp>
5233inline _LIBCPP_INLINE_VISIBILITY
5234void
Howard Hinnant1694d232011-05-28 14:41:13 +00005235weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005236{
5237 weak_ptr().swap(*this);
5238}
5239
5240template<class _Tp>
5241template<class _Yp>
5242shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5243 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5244 : __ptr_(__r.__ptr_),
5245 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5246{
5247 if (__cntrl_ == 0)
5248#ifndef _LIBCPP_NO_EXCEPTIONS
5249 throw bad_weak_ptr();
5250#else
5251 assert(!"bad_weak_ptr");
5252#endif
5253}
5254
5255template<class _Tp>
5256shared_ptr<_Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00005257weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005258{
5259 shared_ptr<_Tp> __r;
5260 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5261 if (__r.__cntrl_)
5262 __r.__ptr_ = __ptr_;
5263 return __r;
5264}
5265
Howard Hinnant324bb032010-08-22 00:02:43 +00005266template <class _Tp> struct owner_less;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005267
5268template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005269struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005270 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant324bb032010-08-22 00:02:43 +00005271{
5272 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005273 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005274 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5275 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005277 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5278 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005280 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5281 {return __x.owner_before(__y);}
Howard Hinnant324bb032010-08-22 00:02:43 +00005282};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005283
5284template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005285struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005286 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5287{
Howard Hinnant324bb032010-08-22 00:02:43 +00005288 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005290 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5291 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005293 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5294 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005296 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5297 {return __x.owner_before(__y);}
5298};
5299
5300template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005301class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005302{
5303 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant324bb032010-08-22 00:02:43 +00005304protected:
Howard Hinnant46e94932012-07-07 20:56:04 +00005305 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005306 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005308 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005310 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5311 {return *this;}
Howard Hinnant82894812010-09-22 16:48:34 +00005312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005313 ~enable_shared_from_this() {}
Howard Hinnant324bb032010-08-22 00:02:43 +00005314public:
Howard Hinnant82894812010-09-22 16:48:34 +00005315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005316 shared_ptr<_Tp> shared_from_this()
5317 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant82894812010-09-22 16:48:34 +00005318 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005319 shared_ptr<_Tp const> shared_from_this() const
5320 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005321
5322 template <class _Up> friend class shared_ptr;
5323};
5324
Howard Hinnant21aefc32010-06-03 16:42:57 +00005325template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005326struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00005327{
5328 typedef shared_ptr<_Tp> argument_type;
5329 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005331 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00005332 {
5333 return hash<_Tp*>()(__ptr.get());
5334 }
5335};
5336
Howard Hinnant99968442011-11-29 18:15:50 +00005337template<class _CharT, class _Traits, class _Yp>
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005338inline _LIBCPP_INLINE_VISIBILITY
5339basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00005340operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005341
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005342#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005343
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005344class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005345{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005346 void* __lx;
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005347public:
5348 void lock() _NOEXCEPT;
5349 void unlock() _NOEXCEPT;
5350
5351private:
5352 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5353 __sp_mut(const __sp_mut&);
5354 __sp_mut& operator=(const __sp_mut&);
5355
Howard Hinnant83eade62013-03-06 23:30:19 +00005356 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005357};
5358
Howard Hinnant83eade62013-03-06 23:30:19 +00005359_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005360
5361template <class _Tp>
5362inline _LIBCPP_INLINE_VISIBILITY
5363bool
5364atomic_is_lock_free(const shared_ptr<_Tp>*)
5365{
5366 return false;
5367}
5368
5369template <class _Tp>
5370shared_ptr<_Tp>
5371atomic_load(const shared_ptr<_Tp>* __p)
5372{
5373 __sp_mut& __m = __get_sp_mut(__p);
5374 __m.lock();
5375 shared_ptr<_Tp> __q = *__p;
5376 __m.unlock();
5377 return __q;
5378}
5379
5380template <class _Tp>
5381inline _LIBCPP_INLINE_VISIBILITY
5382shared_ptr<_Tp>
5383atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5384{
5385 return atomic_load(__p);
5386}
5387
5388template <class _Tp>
5389void
5390atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5391{
5392 __sp_mut& __m = __get_sp_mut(__p);
5393 __m.lock();
5394 __p->swap(__r);
5395 __m.unlock();
5396}
5397
5398template <class _Tp>
5399inline _LIBCPP_INLINE_VISIBILITY
5400void
5401atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5402{
5403 atomic_store(__p, __r);
5404}
5405
5406template <class _Tp>
5407shared_ptr<_Tp>
5408atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5409{
5410 __sp_mut& __m = __get_sp_mut(__p);
5411 __m.lock();
5412 __p->swap(__r);
5413 __m.unlock();
5414 return __r;
5415}
5416
5417template <class _Tp>
5418inline _LIBCPP_INLINE_VISIBILITY
5419shared_ptr<_Tp>
5420atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5421{
5422 return atomic_exchange(__p, __r);
5423}
5424
5425template <class _Tp>
5426bool
5427atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5428{
5429 __sp_mut& __m = __get_sp_mut(__p);
5430 __m.lock();
5431 if (__p->__owner_equivalent(*__v))
5432 {
5433 *__p = __w;
5434 __m.unlock();
5435 return true;
5436 }
5437 *__v = *__p;
5438 __m.unlock();
5439 return false;
5440}
5441
5442template <class _Tp>
5443inline _LIBCPP_INLINE_VISIBILITY
5444bool
5445atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5446{
5447 return atomic_compare_exchange_strong(__p, __v, __w);
5448}
5449
5450template <class _Tp>
5451inline _LIBCPP_INLINE_VISIBILITY
5452bool
5453atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5454 shared_ptr<_Tp> __w, memory_order, memory_order)
5455{
5456 return atomic_compare_exchange_strong(__p, __v, __w);
5457}
5458
5459template <class _Tp>
5460inline _LIBCPP_INLINE_VISIBILITY
5461bool
5462atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5463 shared_ptr<_Tp> __w, memory_order, memory_order)
5464{
5465 return atomic_compare_exchange_weak(__p, __v, __w);
5466}
5467
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005468#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005469
Howard Hinnant324bb032010-08-22 00:02:43 +00005470//enum class
Howard Hinnant83eade62013-03-06 23:30:19 +00005471struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005472{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005473 enum __lx
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005474 {
5475 relaxed,
5476 preferred,
5477 strict
5478 };
5479
Howard Hinnant9c0df142012-10-30 19:06:59 +00005480 __lx __v_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005481
Howard Hinnant82894812010-09-22 16:48:34 +00005482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9c0df142012-10-30 19:06:59 +00005483 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant82894812010-09-22 16:48:34 +00005484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005485 operator int() const {return __v_;}
5486};
5487
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005488_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5489_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5490_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5491_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5492_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005493
5494template <class _Tp>
5495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00005496_Tp*
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005497undeclare_reachable(_Tp* __p)
5498{
5499 return static_cast<_Tp*>(__undeclare_reachable(__p));
5500}
5501
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005502_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005503
5504_LIBCPP_END_NAMESPACE_STD
5505
5506#endif // _LIBCPP_MEMORY