blob: 6f3fdd53ec3a29da8e32ece5ef5eae17e0b44c6f [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)
1525 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001526 __begin2 += _Np;
1527 }
1528
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001529 template <class _Iter, class _Ptr>
1530 _LIBCPP_INLINE_VISIBILITY
1531 static
1532 void
1533 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1534 {
1535 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1536 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1537 }
1538
1539 template <class _Tp>
1540 _LIBCPP_INLINE_VISIBILITY
1541 static
1542 typename enable_if
1543 <
1544 (is_same<allocator_type, allocator<_Tp> >::value
1545 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1546 is_trivially_move_constructible<_Tp>::value,
1547 void
1548 >::type
1549 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1550 {
1551 typedef typename remove_const<_Tp>::type _Vp;
1552 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clowbf0460e2015-05-31 03:13:31 +00001553 if (_Np > 0)
1554 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
Eric Fiselier088ed9f2015-03-31 16:54:19 +00001555 __begin2 += _Np;
1556 }
1557
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001558 template <class _Ptr>
1559 _LIBCPP_INLINE_VISIBILITY
1560 static
1561 void
1562 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1563 {
1564 while (__end1 != __begin1)
Howard Hinnantf619e232013-01-11 20:36:59 +00001565 {
1566 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1567 --__end2;
1568 }
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001569 }
1570
1571 template <class _Tp>
1572 _LIBCPP_INLINE_VISIBILITY
1573 static
1574 typename enable_if
1575 <
1576 (is_same<allocator_type, allocator<_Tp> >::value
1577 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1578 is_trivially_move_constructible<_Tp>::value,
1579 void
1580 >::type
1581 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1582 {
1583 ptrdiff_t _Np = __end1 - __begin1;
1584 __end2 -= _Np;
Marshall Clowbf0460e2015-05-31 03:13:31 +00001585 if (_Np > 0)
1586 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantb0bfd9b2012-02-15 00:41:34 +00001587 }
1588
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589private:
1590
Howard Hinnant82894812010-09-22 16:48:34 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592 static pointer allocate(allocator_type& __a, size_type __n,
1593 const_void_pointer __hint, true_type)
1594 {return __a.allocate(__n, __hint);}
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,
Howard Hinnantec3773c2011-12-01 20:21:04 +00001597 const_void_pointer, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 {return __a.allocate(__n);}
1599
1600#ifndef _LIBCPP_HAS_NO_VARIADICS
1601 template <class _Tp, class... _Args>
Howard Hinnant82894812010-09-22 16:48:34 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001604 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 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(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1608 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001609 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001610 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001611#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612
1613 template <class _Tp>
Howard Hinnant82894812010-09-22 16:48:34 +00001614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1616 {__a.destroy(__p);}
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(false_type, allocator_type&, _Tp* __p)
1620 {
1621 __p->~_Tp();
1622 }
1623
Howard Hinnant82894812010-09-22 16:48:34 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 static size_type __max_size(true_type, const allocator_type& __a)
1626 {return __a.max_size();}
Howard Hinnant82894812010-09-22 16:48:34 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628 static size_type __max_size(false_type, const allocator_type&)
1629 {return numeric_limits<size_type>::max();}
1630
Howard Hinnant82894812010-09-22 16:48:34 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632 static allocator_type
1633 select_on_container_copy_construction(true_type, const allocator_type& __a)
1634 {return __a.select_on_container_copy_construction();}
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(false_type, const allocator_type& __a)
1638 {return __a;}
1639};
1640
Marshall Clow66302c62015-04-07 05:21:38 +00001641template <class _Traits, class _Tp>
1642struct __rebind_alloc_helper
1643{
1644#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Marshall Clow0ad232a2015-05-10 13:59:45 +00001645 typedef typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow66302c62015-04-07 05:21:38 +00001646#else
1647 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1648#endif
1649};
1650
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651// allocator
1652
1653template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001654class _LIBCPP_TYPE_VIS_ONLY allocator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655{
1656public:
1657 typedef size_t size_type;
1658 typedef ptrdiff_t difference_type;
1659 typedef _Tp* pointer;
1660 typedef const _Tp* const_pointer;
1661 typedef _Tp& reference;
1662 typedef const _Tp& const_reference;
1663 typedef _Tp value_type;
1664
Howard Hinnant18884f42011-06-02 21:38:57 +00001665 typedef true_type propagate_on_container_move_assignment;
1666
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1668
Howard Hinnant1694d232011-05-28 14:41:13 +00001669 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1670 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1671 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001672 {return _VSTD::addressof(__x);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001673 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00001674 {return _VSTD::addressof(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001676 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant1694d232011-05-28 14:41:13 +00001677 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001678 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant1694d232011-05-28 14:41:13 +00001679 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1680 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001681#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682 template <class _Up, class... _Args>
1683 _LIBCPP_INLINE_VISIBILITY
1684 void
1685 construct(_Up* __p, _Args&&... __args)
1686 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001687 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001689#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690 _LIBCPP_INLINE_VISIBILITY
1691 void
1692 construct(pointer __p)
1693 {
1694 ::new((void*)__p) _Tp();
1695 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001696# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001697
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 template <class _A0>
1699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001700 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001701 construct(pointer __p, _A0& __a0)
1702 {
1703 ::new((void*)__p) _Tp(__a0);
1704 }
1705 template <class _A0>
1706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001707 void
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001708 construct(pointer __p, const _A0& __a0)
1709 {
1710 ::new((void*)__p) _Tp(__a0);
1711 }
Michael J. Spencer626916f2010-12-10 19:47:54 +00001712# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713 template <class _A0, class _A1>
1714 _LIBCPP_INLINE_VISIBILITY
1715 void
1716 construct(pointer __p, _A0& __a0, _A1& __a1)
1717 {
1718 ::new((void*)__p) _Tp(__a0, __a1);
1719 }
1720 template <class _A0, class _A1>
1721 _LIBCPP_INLINE_VISIBILITY
1722 void
1723 construct(pointer __p, const _A0& __a0, _A1& __a1)
1724 {
1725 ::new((void*)__p) _Tp(__a0, __a1);
1726 }
1727 template <class _A0, class _A1>
1728 _LIBCPP_INLINE_VISIBILITY
1729 void
1730 construct(pointer __p, _A0& __a0, const _A1& __a1)
1731 {
1732 ::new((void*)__p) _Tp(__a0, __a1);
1733 }
1734 template <class _A0, class _A1>
1735 _LIBCPP_INLINE_VISIBILITY
1736 void
1737 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1738 {
1739 ::new((void*)__p) _Tp(__a0, __a1);
1740 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00001741#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1743};
1744
Howard Hinnant57199402012-01-02 17:56:02 +00001745template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001746class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
Howard Hinnant57199402012-01-02 17:56:02 +00001747{
1748public:
1749 typedef size_t size_type;
1750 typedef ptrdiff_t difference_type;
1751 typedef const _Tp* pointer;
1752 typedef const _Tp* const_pointer;
1753 typedef const _Tp& reference;
1754 typedef const _Tp& const_reference;
Howard Hinnant9360e9f2013-06-07 01:56:37 +00001755 typedef const _Tp value_type;
Howard Hinnant57199402012-01-02 17:56:02 +00001756
1757 typedef true_type propagate_on_container_move_assignment;
1758
1759 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1760
1761 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1762 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1763 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1764 {return _VSTD::addressof(__x);}
1765 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith73c1fce2014-06-04 19:54:15 +00001766 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant57199402012-01-02 17:56:02 +00001767 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith73c1fce2014-06-04 19:54:15 +00001768 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant57199402012-01-02 17:56:02 +00001769 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1770 {return size_type(~0) / sizeof(_Tp);}
1771#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1772 template <class _Up, class... _Args>
1773 _LIBCPP_INLINE_VISIBILITY
1774 void
1775 construct(_Up* __p, _Args&&... __args)
1776 {
1777 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1778 }
1779#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1780 _LIBCPP_INLINE_VISIBILITY
1781 void
1782 construct(pointer __p)
1783 {
1784 ::new((void*)__p) _Tp();
1785 }
1786# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant87073e42012-05-01 15:37:54 +00001787
Howard Hinnant57199402012-01-02 17:56:02 +00001788 template <class _A0>
1789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001790 void
Howard Hinnant57199402012-01-02 17:56:02 +00001791 construct(pointer __p, _A0& __a0)
1792 {
1793 ::new((void*)__p) _Tp(__a0);
1794 }
1795 template <class _A0>
1796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant87073e42012-05-01 15:37:54 +00001797 void
Howard Hinnant57199402012-01-02 17:56:02 +00001798 construct(pointer __p, const _A0& __a0)
1799 {
1800 ::new((void*)__p) _Tp(__a0);
1801 }
Howard Hinnant57199402012-01-02 17:56:02 +00001802# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1803 template <class _A0, class _A1>
1804 _LIBCPP_INLINE_VISIBILITY
1805 void
1806 construct(pointer __p, _A0& __a0, _A1& __a1)
1807 {
1808 ::new((void*)__p) _Tp(__a0, __a1);
1809 }
1810 template <class _A0, class _A1>
1811 _LIBCPP_INLINE_VISIBILITY
1812 void
1813 construct(pointer __p, const _A0& __a0, _A1& __a1)
1814 {
1815 ::new((void*)__p) _Tp(__a0, __a1);
1816 }
1817 template <class _A0, class _A1>
1818 _LIBCPP_INLINE_VISIBILITY
1819 void
1820 construct(pointer __p, _A0& __a0, const _A1& __a1)
1821 {
1822 ::new((void*)__p) _Tp(__a0, __a1);
1823 }
1824 template <class _A0, class _A1>
1825 _LIBCPP_INLINE_VISIBILITY
1826 void
1827 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1828 {
1829 ::new((void*)__p) _Tp(__a0, __a1);
1830 }
1831#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1832 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1833};
1834
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835template <class _Tp, class _Up>
1836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001837bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838
1839template <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 false;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842
1843template <class _OutputIterator, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001844class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845 : public iterator<output_iterator_tag,
1846 _Tp, // purposefully not C++03
1847 ptrdiff_t, // purposefully not C++03
1848 _Tp*, // purposefully not C++03
1849 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1850{
1851private:
1852 _OutputIterator __x_;
1853public:
1854 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1855 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1856 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1857 {::new(&*__x_) _Tp(__element); return *this;}
1858 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1859 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1860 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowdbaf7a02015-05-10 13:14:08 +00001861#if _LIBCPP_STD_VER >= 14
1862 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1863#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864};
1865
1866template <class _Tp>
1867pair<_Tp*, ptrdiff_t>
Howard Hinnant1694d232011-05-28 14:41:13 +00001868get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869{
1870 pair<_Tp*, ptrdiff_t> __r(0, 0);
1871 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1872 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1873 / sizeof(_Tp);
1874 if (__n > __m)
1875 __n = __m;
1876 while (__n > 0)
1877 {
1878 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1879 if (__r.first)
1880 {
1881 __r.second = __n;
1882 break;
1883 }
1884 __n /= 2;
1885 }
1886 return __r;
1887}
1888
1889template <class _Tp>
1890inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00001891void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001892
1893template <class _Tp>
1894struct auto_ptr_ref
1895{
1896 _Tp* __ptr_;
1897};
1898
1899template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001900class _LIBCPP_TYPE_VIS_ONLY auto_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901{
1902private:
1903 _Tp* __ptr_;
1904public:
1905 typedef _Tp element_type;
1906
1907 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1908 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1909 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1910 : __ptr_(__p.release()) {}
1911 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1912 {reset(__p.release()); return *this;}
1913 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1914 {reset(__p.release()); return *this;}
1915 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1916 {reset(__p.__ptr_); return *this;}
1917 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1918
1919 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1920 {return *__ptr_;}
1921 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1922 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1923 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1924 {
1925 _Tp* __t = __ptr_;
1926 __ptr_ = 0;
1927 return __t;
1928 }
1929 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1930 {
1931 if (__ptr_ != __p)
1932 delete __ptr_;
1933 __ptr_ = __p;
1934 }
1935
1936 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1937 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1938 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1939 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1940 {return auto_ptr<_Up>(release());}
1941};
1942
1943template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001944class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001945{
1946public:
1947 typedef void element_type;
1948};
1949
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1951 typename remove_cv<_T2>::type>::value,
Howard Hinnantd4cf2152011-12-11 20:31:33 +00001952 bool = is_empty<_T1>::value
1953#if __has_feature(is_final)
1954 && !__is_final(_T1)
1955#endif
1956 ,
1957 bool = is_empty<_T2>::value
1958#if __has_feature(is_final)
1959 && !__is_final(_T2)
1960#endif
1961 >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962struct __libcpp_compressed_pair_switch;
1963
1964template <class _T1, class _T2, bool IsSame>
1965struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1966
1967template <class _T1, class _T2, bool IsSame>
1968struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1969
1970template <class _T1, class _T2, bool IsSame>
1971struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1972
1973template <class _T1, class _T2>
1974struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1975
1976template <class _T1, class _T2>
1977struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1978
1979template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1980class __libcpp_compressed_pair_imp;
1981
1982template <class _T1, class _T2>
1983class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1984{
1985private:
1986 _T1 __first_;
1987 _T2 __second_;
1988public:
1989 typedef _T1 _T1_param;
1990 typedef _T2 _T2_param;
1991
1992 typedef typename remove_reference<_T1>::type& _T1_reference;
1993 typedef typename remove_reference<_T2>::type& _T2_reference;
1994
1995 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1996 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1997
1998 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00001999 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002000 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002001 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002002 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002004 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002006#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002007
2008 _LIBCPP_INLINE_VISIBILITY
2009 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2010 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2011 is_nothrow_copy_constructible<_T2>::value)
2012 : __first_(__p.first()),
2013 __second_(__p.second()) {}
2014
2015 _LIBCPP_INLINE_VISIBILITY
2016 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2017 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2018 is_nothrow_copy_assignable<_T2>::value)
2019 {
2020 __first_ = __p.first();
2021 __second_ = __p.second();
2022 return *this;
2023 }
2024
Howard Hinnant61aa6012011-07-01 19:24:36 +00002025 _LIBCPP_INLINE_VISIBILITY
2026 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002027 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2028 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002029 : __first_(_VSTD::forward<_T1>(__p.first())),
2030 __second_(_VSTD::forward<_T2>(__p.second())) {}
2031
2032 _LIBCPP_INLINE_VISIBILITY
2033 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2034 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2035 is_nothrow_move_assignable<_T2>::value)
2036 {
2037 __first_ = _VSTD::forward<_T1>(__p.first());
2038 __second_ = _VSTD::forward<_T2>(__p.second());
2039 return *this;
2040 }
2041
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002042#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002043
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002044#ifndef _LIBCPP_HAS_NO_VARIADICS
2045
2046 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2047 _LIBCPP_INLINE_VISIBILITY
2048 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2049 tuple<_Args1...> __first_args,
2050 tuple<_Args2...> __second_args,
2051 __tuple_indices<_I1...>,
2052 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002053 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2054 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002055 {}
2056
2057#endif // _LIBCPP_HAS_NO_VARIADICS
2058
Howard Hinnant1694d232011-05-28 14:41:13 +00002059 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2060 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061
Howard Hinnant1694d232011-05-28 14:41:13 +00002062 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2063 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002064
2065 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002066 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002067 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002069 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070 swap(__first_, __x.__first_);
2071 swap(__second_, __x.__second_);
2072 }
2073};
2074
2075template <class _T1, class _T2>
2076class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2077 : private _T1
2078{
2079private:
2080 _T2 __second_;
2081public:
2082 typedef _T1 _T1_param;
2083 typedef _T2 _T2_param;
2084
2085 typedef _T1& _T1_reference;
2086 typedef typename remove_reference<_T2>::type& _T2_reference;
2087
2088 typedef const _T1& _T1_const_reference;
2089 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2090
2091 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002092 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002093 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002094 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002095 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002097 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002099#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002100
2101 _LIBCPP_INLINE_VISIBILITY
2102 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2103 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2104 is_nothrow_copy_constructible<_T2>::value)
2105 : _T1(__p.first()), __second_(__p.second()) {}
2106
2107 _LIBCPP_INLINE_VISIBILITY
2108 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2109 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2110 is_nothrow_copy_assignable<_T2>::value)
2111 {
2112 _T1::operator=(__p.first());
2113 __second_ = __p.second();
2114 return *this;
2115 }
2116
Howard Hinnant61aa6012011-07-01 19:24:36 +00002117 _LIBCPP_INLINE_VISIBILITY
2118 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002119 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2120 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002121 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002122
2123 _LIBCPP_INLINE_VISIBILITY
2124 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2125 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2126 is_nothrow_move_assignable<_T2>::value)
2127 {
2128 _T1::operator=(_VSTD::move(__p.first()));
2129 __second_ = _VSTD::forward<_T2>(__p.second());
2130 return *this;
2131 }
2132
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002133#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002134
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002135#ifndef _LIBCPP_HAS_NO_VARIADICS
2136
2137 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2138 _LIBCPP_INLINE_VISIBILITY
2139 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2140 tuple<_Args1...> __first_args,
2141 tuple<_Args2...> __second_args,
2142 __tuple_indices<_I1...>,
2143 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002144 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2145 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002146 {}
2147
2148#endif // _LIBCPP_HAS_NO_VARIADICS
2149
Howard Hinnant1694d232011-05-28 14:41:13 +00002150 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2151 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152
Howard Hinnant1694d232011-05-28 14:41:13 +00002153 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2154 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155
2156 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002157 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002158 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002160 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 swap(__second_, __x.__second_);
2162 }
2163};
2164
2165template <class _T1, class _T2>
2166class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2167 : private _T2
2168{
2169private:
2170 _T1 __first_;
2171public:
2172 typedef _T1 _T1_param;
2173 typedef _T2 _T2_param;
2174
2175 typedef typename remove_reference<_T1>::type& _T1_reference;
2176 typedef _T2& _T2_reference;
2177
2178 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2179 typedef const _T2& _T2_const_reference;
2180
2181 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2182 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002183 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002185 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant1694d232011-05-28 14:41:13 +00002187 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2188 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002189 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002191#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002192
2193 _LIBCPP_INLINE_VISIBILITY
2194 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2195 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2196 is_nothrow_copy_constructible<_T2>::value)
2197 : _T2(__p.second()), __first_(__p.first()) {}
2198
2199 _LIBCPP_INLINE_VISIBILITY
2200 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2201 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2202 is_nothrow_copy_assignable<_T2>::value)
2203 {
2204 _T2::operator=(__p.second());
2205 __first_ = __p.first();
2206 return *this;
2207 }
2208
Howard Hinnant61aa6012011-07-01 19:24:36 +00002209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002210 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002211 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2212 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002213 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002214
2215 _LIBCPP_INLINE_VISIBILITY
2216 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2217 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2218 is_nothrow_move_assignable<_T2>::value)
2219 {
2220 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2221 __first_ = _VSTD::move(__p.first());
2222 return *this;
2223 }
2224
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002225#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002226
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002227#ifndef _LIBCPP_HAS_NO_VARIADICS
2228
2229 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2230 _LIBCPP_INLINE_VISIBILITY
2231 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2232 tuple<_Args1...> __first_args,
2233 tuple<_Args2...> __second_args,
2234 __tuple_indices<_I1...>,
2235 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002236 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2237 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002238
2239 {}
2240
2241#endif // _LIBCPP_HAS_NO_VARIADICS
2242
Howard Hinnant1694d232011-05-28 14:41:13 +00002243 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2244 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245
Howard Hinnant1694d232011-05-28 14:41:13 +00002246 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2247 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248
2249 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant1694d232011-05-28 14:41:13 +00002250 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002251 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002253 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 swap(__first_, __x.__first_);
2255 }
2256};
2257
2258template <class _T1, class _T2>
2259class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2260 : private _T1,
2261 private _T2
2262{
2263public:
2264 typedef _T1 _T1_param;
2265 typedef _T2 _T2_param;
2266
2267 typedef _T1& _T1_reference;
2268 typedef _T2& _T2_reference;
2269
2270 typedef const _T1& _T1_const_reference;
2271 typedef const _T2& _T2_const_reference;
2272
2273 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2274 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002275 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002277 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002279 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002281#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002282
2283 _LIBCPP_INLINE_VISIBILITY
2284 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2285 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2286 is_nothrow_copy_constructible<_T2>::value)
2287 : _T1(__p.first()), _T2(__p.second()) {}
2288
2289 _LIBCPP_INLINE_VISIBILITY
2290 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2291 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2292 is_nothrow_copy_assignable<_T2>::value)
2293 {
2294 _T1::operator=(__p.first());
2295 _T2::operator=(__p.second());
2296 return *this;
2297 }
2298
Howard Hinnant61aa6012011-07-01 19:24:36 +00002299 _LIBCPP_INLINE_VISIBILITY
2300 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002301 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2302 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002303 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002304
2305 _LIBCPP_INLINE_VISIBILITY
2306 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2307 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2308 is_nothrow_move_assignable<_T2>::value)
2309 {
2310 _T1::operator=(_VSTD::move(__p.first()));
2311 _T2::operator=(_VSTD::move(__p.second()));
2312 return *this;
2313 }
2314
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002315#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002316
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002317#ifndef _LIBCPP_HAS_NO_VARIADICS
2318
2319 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2320 _LIBCPP_INLINE_VISIBILITY
2321 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2322 tuple<_Args1...> __first_args,
2323 tuple<_Args2...> __second_args,
2324 __tuple_indices<_I1...>,
2325 __tuple_indices<_I2...>)
Marshall Clowba6dbf42014-06-24 00:46:19 +00002326 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2327 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002328 {}
2329
2330#endif // _LIBCPP_HAS_NO_VARIADICS
2331
Howard Hinnant1694d232011-05-28 14:41:13 +00002332 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2333 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334
Howard Hinnant1694d232011-05-28 14:41:13 +00002335 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2336 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337
Howard Hinnantec3773c2011-12-01 20:21:04 +00002338 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant1694d232011-05-28 14:41:13 +00002339 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002340 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341 {
2342 }
2343};
2344
2345template <class _T1, class _T2>
2346class __compressed_pair
2347 : private __libcpp_compressed_pair_imp<_T1, _T2>
2348{
2349 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2350public:
2351 typedef typename base::_T1_param _T1_param;
2352 typedef typename base::_T2_param _T2_param;
2353
2354 typedef typename base::_T1_reference _T1_reference;
2355 typedef typename base::_T2_reference _T2_reference;
2356
2357 typedef typename base::_T1_const_reference _T1_const_reference;
2358 typedef typename base::_T2_const_reference _T2_const_reference;
2359
2360 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant57199402012-01-02 17:56:02 +00002361 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002362 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant57199402012-01-02 17:56:02 +00002363 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002364 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002366 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002368#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant61aa6012011-07-01 19:24:36 +00002369
2370 _LIBCPP_INLINE_VISIBILITY
2371 __compressed_pair(const __compressed_pair& __p)
2372 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2373 is_nothrow_copy_constructible<_T2>::value)
2374 : base(__p) {}
2375
2376 _LIBCPP_INLINE_VISIBILITY
2377 __compressed_pair& operator=(const __compressed_pair& __p)
2378 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2379 is_nothrow_copy_assignable<_T2>::value)
2380 {
2381 base::operator=(__p);
2382 return *this;
2383 }
2384
Howard Hinnant61aa6012011-07-01 19:24:36 +00002385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant1694d232011-05-28 14:41:13 +00002387 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2388 is_nothrow_move_constructible<_T2>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002389 : base(_VSTD::move(__p)) {}
Howard Hinnant61aa6012011-07-01 19:24:36 +00002390
2391 _LIBCPP_INLINE_VISIBILITY
2392 __compressed_pair& operator=(__compressed_pair&& __p)
2393 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2394 is_nothrow_move_assignable<_T2>::value)
2395 {
2396 base::operator=(_VSTD::move(__p));
2397 return *this;
2398 }
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002399
Howard Hinnant3f81e9e2013-11-13 00:39:22 +00002400#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant8c238192013-05-06 16:58:36 +00002401
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002402#ifndef _LIBCPP_HAS_NO_VARIADICS
2403
2404 template <class... _Args1, class... _Args2>
2405 _LIBCPP_INLINE_VISIBILITY
2406 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2407 tuple<_Args2...> __second_args)
Howard Hinnant57199402012-01-02 17:56:02 +00002408 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00002409 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2410 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2411 {}
2412
2413#endif // _LIBCPP_HAS_NO_VARIADICS
2414
Howard Hinnant1694d232011-05-28 14:41:13 +00002415 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2416 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417
Howard Hinnant1694d232011-05-28 14:41:13 +00002418 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2419 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002420
Howard Hinnant1694d232011-05-28 14:41:13 +00002421 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2422 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002423 __is_nothrow_swappable<_T2>::value)
Howard Hinnant1694d232011-05-28 14:41:13 +00002424 {base::swap(__x);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425};
2426
2427template <class _T1, class _T2>
2428inline _LIBCPP_INLINE_VISIBILITY
2429void
2430swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant1694d232011-05-28 14:41:13 +00002431 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow394451d2014-06-30 15:35:09 +00002432 __is_nothrow_swappable<_T2>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002433 {__x.swap(__y);}
2434
Howard Hinnant57199402012-01-02 17:56:02 +00002435// __same_or_less_cv_qualified
2436
2437template <class _Ptr1, class _Ptr2,
2438 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2439 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2440 >::value
2441 >
2442struct __same_or_less_cv_qualified_imp
2443 : is_convertible<_Ptr1, _Ptr2> {};
2444
2445template <class _Ptr1, class _Ptr2>
2446struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2447 : false_type {};
2448
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002449template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2450 is_same<_Ptr1, _Ptr2>::value ||
2451 __has_element_type<_Ptr1>::value>
Howard Hinnant57199402012-01-02 17:56:02 +00002452struct __same_or_less_cv_qualified
2453 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2454
2455template <class _Ptr1, class _Ptr2>
Marshall Clow5f64a2b2014-04-26 05:19:48 +00002456struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant57199402012-01-02 17:56:02 +00002457 : false_type {};
2458
2459// default_delete
2460
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002462struct _LIBCPP_TYPE_VIS_ONLY default_delete
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002463{
Howard Hinnant46e94932012-07-07 20:56:04 +00002464#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2465 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2466#else
2467 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2468#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002469 template <class _Up>
2470 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant1694d232011-05-28 14:41:13 +00002471 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2472 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 {
2474 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002475 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476 delete __ptr;
2477 }
2478};
2479
2480template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002481struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002482{
Howard Hinnant8e843502011-12-18 21:19:44 +00002483public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002484#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2485 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2486#else
2487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2488#endif
Howard Hinnant8e843502011-12-18 21:19:44 +00002489 template <class _Up>
2490 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant57199402012-01-02 17:56:02 +00002491 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant8e843502011-12-18 21:19:44 +00002492 template <class _Up>
2493 _LIBCPP_INLINE_VISIBILITY
2494 void operator() (_Up* __ptr,
Howard Hinnant57199402012-01-02 17:56:02 +00002495 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 {
2497 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant05e7d242013-04-24 19:44:26 +00002498 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002499 delete [] __ptr;
2500 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002501};
2502
2503template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002504class _LIBCPP_TYPE_VIS_ONLY unique_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505{
2506public:
2507 typedef _Tp element_type;
2508 typedef _Dp deleter_type;
2509 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2510private:
2511 __compressed_pair<pointer, deleter_type> __ptr_;
2512
Howard Hinnant57199402012-01-02 17:56:02 +00002513#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002514 unique_ptr(unique_ptr&);
2515 template <class _Up, class _Ep>
2516 unique_ptr(unique_ptr<_Up, _Ep>&);
2517 unique_ptr& operator=(unique_ptr&);
2518 template <class _Up, class _Ep>
2519 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002520#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002521
2522 struct __nat {int __for_bool_;};
2523
2524 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2525 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2526public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002527 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528 : __ptr_(pointer())
2529 {
2530 static_assert(!is_pointer<deleter_type>::value,
2531 "unique_ptr constructed with null function pointer deleter");
2532 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002533 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002534 : __ptr_(pointer())
2535 {
2536 static_assert(!is_pointer<deleter_type>::value,
2537 "unique_ptr constructed with null function pointer deleter");
2538 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002539 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002540 : __ptr_(_VSTD::move(__p))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541 {
2542 static_assert(!is_pointer<deleter_type>::value,
2543 "unique_ptr constructed with null function pointer deleter");
2544 }
2545
Howard Hinnant73d21a42010-09-04 23:28:19 +00002546#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2548 is_reference<deleter_type>::value,
2549 deleter_type,
2550 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002551 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002552 : __ptr_(__p, __d) {}
2553
2554 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002555 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002556 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002557 {
2558 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2559 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002560 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002561 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562 template <class _Up, class _Ep>
2563 _LIBCPP_INLINE_VISIBILITY
2564 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2565 typename enable_if
2566 <
2567 !is_array<_Up>::value &&
2568 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2569 is_convertible<_Ep, deleter_type>::value &&
2570 (
2571 !is_reference<deleter_type>::value ||
2572 is_same<deleter_type, _Ep>::value
2573 ),
2574 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002575 >::type = __nat()) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002576 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002577
2578 template <class _Up>
2579 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2580 typename enable_if<
2581 is_convertible<_Up*, _Tp*>::value &&
2582 is_same<_Dp, default_delete<_Tp> >::value,
2583 __nat
Howard Hinnant1694d232011-05-28 14:41:13 +00002584 >::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585 : __ptr_(__p.release())
2586 {
2587 }
2588
Howard Hinnant1694d232011-05-28 14:41:13 +00002589 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002590 {
2591 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002592 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593 return *this;
2594 }
2595
2596 template <class _Up, class _Ep>
2597 _LIBCPP_INLINE_VISIBILITY
2598 typename enable_if
2599 <
Howard Hinnant57199402012-01-02 17:56:02 +00002600 !is_array<_Up>::value &&
2601 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2602 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002603 unique_ptr&
2604 >::type
Howard Hinnant1694d232011-05-28 14:41:13 +00002605 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002606 {
2607 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002608 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002609 return *this;
2610 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002611#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002612
2613 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2614 {
2615 return __rv<unique_ptr>(*this);
2616 }
2617
2618 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002619 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002620
2621 template <class _Up, class _Ep>
2622 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2623 {
2624 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002625 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 return *this;
2627 }
2628
2629 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002630 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002631
2632 template <class _Up>
2633 _LIBCPP_INLINE_VISIBILITY
2634 typename enable_if<
2635 is_convertible<_Up*, _Tp*>::value &&
2636 is_same<_Dp, default_delete<_Tp> >::value,
2637 unique_ptr&
2638 >::type
2639 operator=(auto_ptr<_Up> __p)
2640 {reset(__p.release()); return *this;}
2641
Howard Hinnant73d21a42010-09-04 23:28:19 +00002642#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002643 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2644
Howard Hinnant1694d232011-05-28 14:41:13 +00002645 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002646 {
2647 reset();
2648 return *this;
2649 }
2650
2651 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2652 {return *__ptr_.first();}
Howard Hinnant1694d232011-05-28 14:41:13 +00002653 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2654 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2655 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2656 {return __ptr_.second();}
2657 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2658 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002659 _LIBCPP_INLINE_VISIBILITY
2660 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2661 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662
Howard Hinnant1694d232011-05-28 14:41:13 +00002663 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002664 {
2665 pointer __t = __ptr_.first();
2666 __ptr_.first() = pointer();
2667 return __t;
2668 }
2669
Howard Hinnant1694d232011-05-28 14:41:13 +00002670 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002671 {
2672 pointer __tmp = __ptr_.first();
2673 __ptr_.first() = __p;
2674 if (__tmp)
2675 __ptr_.second()(__tmp);
2676 }
2677
Howard Hinnant1694d232011-05-28 14:41:13 +00002678 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2679 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680};
2681
2682template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002683class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684{
2685public:
2686 typedef _Tp element_type;
2687 typedef _Dp deleter_type;
2688 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2689private:
2690 __compressed_pair<pointer, deleter_type> __ptr_;
2691
Howard Hinnant57199402012-01-02 17:56:02 +00002692#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693 unique_ptr(unique_ptr&);
2694 template <class _Up>
2695 unique_ptr(unique_ptr<_Up>&);
2696 unique_ptr& operator=(unique_ptr&);
2697 template <class _Up>
2698 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant73d21a42010-09-04 23:28:19 +00002699#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700
2701 struct __nat {int __for_bool_;};
2702
2703 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2704 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2705public:
Howard Hinnant46e94932012-07-07 20:56:04 +00002706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002707 : __ptr_(pointer())
2708 {
2709 static_assert(!is_pointer<deleter_type>::value,
2710 "unique_ptr constructed with null function pointer deleter");
2711 }
Howard Hinnant46e94932012-07-07 20:56:04 +00002712 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002713 : __ptr_(pointer())
2714 {
2715 static_assert(!is_pointer<deleter_type>::value,
2716 "unique_ptr constructed with null function pointer deleter");
2717 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002718#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002719 template <class _Pp>
2720 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2721 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002722 : __ptr_(__p)
2723 {
2724 static_assert(!is_pointer<deleter_type>::value,
2725 "unique_ptr constructed with null function pointer deleter");
2726 }
2727
Logan Chiene1678a12014-01-31 09:30:46 +00002728 template <class _Pp>
Howard Hinnant99968442011-11-29 18:15:50 +00002729 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730 is_reference<deleter_type>::value,
2731 deleter_type,
Logan Chiene1678a12014-01-31 09:30:46 +00002732 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2733 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002734 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 : __ptr_(__p, __d) {}
2736
2737 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2738 is_reference<deleter_type>::value,
2739 deleter_type,
2740 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002741 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002742 : __ptr_(pointer(), __d) {}
2743
Logan Chiene1678a12014-01-31 09:30:46 +00002744 template <class _Pp>
2745 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2746 typename remove_reference<deleter_type>::type&& __d,
2747 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant1694d232011-05-28 14:41:13 +00002748 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002749 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750 {
2751 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2752 }
2753
2754 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant1694d232011-05-28 14:41:13 +00002755 _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002756 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002757 {
2758 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2759 }
2760
Howard Hinnant1694d232011-05-28 14:41:13 +00002761 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant0949eed2011-06-30 21:18:19 +00002762 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763
Howard Hinnant1694d232011-05-28 14:41:13 +00002764 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765 {
2766 reset(__u.release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002767 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002768 return *this;
2769 }
Howard Hinnant8e843502011-12-18 21:19:44 +00002770
2771 template <class _Up, class _Ep>
2772 _LIBCPP_INLINE_VISIBILITY
2773 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2774 typename enable_if
2775 <
2776 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002777 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant8e843502011-12-18 21:19:44 +00002778 && is_convertible<_Ep, deleter_type>::value &&
2779 (
2780 !is_reference<deleter_type>::value ||
2781 is_same<deleter_type, _Ep>::value
2782 ),
2783 __nat
2784 >::type = __nat()
2785 ) _NOEXCEPT
2786 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2787
2788
2789 template <class _Up, class _Ep>
2790 _LIBCPP_INLINE_VISIBILITY
2791 typename enable_if
2792 <
2793 is_array<_Up>::value &&
Howard Hinnant57199402012-01-02 17:56:02 +00002794 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2795 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant8e843502011-12-18 21:19:44 +00002796 unique_ptr&
2797 >::type
2798 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2799 {
2800 reset(__u.release());
2801 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2802 return *this;
2803 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002804#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002805
2806 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2807 : __ptr_(__p)
2808 {
2809 static_assert(!is_pointer<deleter_type>::value,
2810 "unique_ptr constructed with null function pointer deleter");
2811 }
2812
2813 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002814 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815
2816 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002817 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002818
2819 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2820 {
2821 return __rv<unique_ptr>(*this);
2822 }
2823
2824 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002825 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002826
2827 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2828 {
2829 reset(__u->release());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002830 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831 return *this;
2832 }
2833
Howard Hinnant73d21a42010-09-04 23:28:19 +00002834#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2836
Howard Hinnant1694d232011-05-28 14:41:13 +00002837 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002838 {
2839 reset();
2840 return *this;
2841 }
2842
2843 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2844 {return __ptr_.first()[__i];}
Howard Hinnant1694d232011-05-28 14:41:13 +00002845 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2846 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2847 {return __ptr_.second();}
2848 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2849 {return __ptr_.second();}
Howard Hinnant77861882012-02-21 21:46:43 +00002850 _LIBCPP_INLINE_VISIBILITY
2851 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2852 {return __ptr_.first() != nullptr;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002853
Howard Hinnant1694d232011-05-28 14:41:13 +00002854 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855 {
2856 pointer __t = __ptr_.first();
2857 __ptr_.first() = pointer();
2858 return __t;
2859 }
2860
Howard Hinnant73d21a42010-09-04 23:28:19 +00002861#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00002862 template <class _Pp>
2863 _LIBCPP_INLINE_VISIBILITY
2864 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2865 reset(_Pp __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 {
2867 pointer __tmp = __ptr_.first();
2868 __ptr_.first() = __p;
2869 if (__tmp)
2870 __ptr_.second()(__tmp);
2871 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002872 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 {
2874 pointer __tmp = __ptr_.first();
2875 __ptr_.first() = nullptr;
2876 if (__tmp)
2877 __ptr_.second()(__tmp);
2878 }
Howard Hinnant1694d232011-05-28 14:41:13 +00002879 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002880 {
2881 pointer __tmp = __ptr_.first();
2882 __ptr_.first() = nullptr;
2883 if (__tmp)
2884 __ptr_.second()(__tmp);
2885 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002886#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002887 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2888 {
2889 pointer __tmp = __ptr_.first();
2890 __ptr_.first() = __p;
2891 if (__tmp)
2892 __ptr_.second()(__tmp);
2893 }
Howard Hinnant73d21a42010-09-04 23:28:19 +00002894#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002895
2896 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2897private:
Howard Hinnant324bb032010-08-22 00:02:43 +00002898
Howard Hinnant73d21a42010-09-04 23:28:19 +00002899#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900 template <class _Up>
2901 explicit unique_ptr(_Up);
2902 template <class _Up>
2903 unique_ptr(_Up __u,
2904 typename conditional<
2905 is_reference<deleter_type>::value,
2906 deleter_type,
2907 typename add_lvalue_reference<const deleter_type>::type>::type,
2908 typename enable_if
2909 <
2910 is_convertible<_Up, pointer>::value,
2911 __nat
2912 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00002913#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914};
2915
2916template <class _Tp, class _Dp>
2917inline _LIBCPP_INLINE_VISIBILITY
2918void
Howard Hinnant1694d232011-05-28 14:41:13 +00002919swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920
2921template <class _T1, class _D1, class _T2, class _D2>
2922inline _LIBCPP_INLINE_VISIBILITY
2923bool
2924operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2925
2926template <class _T1, class _D1, class _T2, class _D2>
2927inline _LIBCPP_INLINE_VISIBILITY
2928bool
2929operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2930
2931template <class _T1, class _D1, class _T2, class _D2>
2932inline _LIBCPP_INLINE_VISIBILITY
2933bool
Howard Hinnant3fadda32012-02-21 21:02:58 +00002934operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2935{
2936 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2937 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselier8492cd82015-02-05 23:01:40 +00002938 typedef typename common_type<_P1, _P2>::type _Vp;
2939 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00002940}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941
2942template <class _T1, class _D1, class _T2, class _D2>
2943inline _LIBCPP_INLINE_VISIBILITY
2944bool
2945operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2946
2947template <class _T1, class _D1, class _T2, class _D2>
2948inline _LIBCPP_INLINE_VISIBILITY
2949bool
2950operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2951
2952template <class _T1, class _D1, class _T2, class _D2>
2953inline _LIBCPP_INLINE_VISIBILITY
2954bool
2955operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2956
Howard Hinnant3fadda32012-02-21 21:02:58 +00002957template <class _T1, class _D1>
2958inline _LIBCPP_INLINE_VISIBILITY
2959bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002960operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002961{
2962 return !__x;
2963}
2964
2965template <class _T1, class _D1>
2966inline _LIBCPP_INLINE_VISIBILITY
2967bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002968operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002969{
2970 return !__x;
2971}
2972
2973template <class _T1, class _D1>
2974inline _LIBCPP_INLINE_VISIBILITY
2975bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002976operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002977{
2978 return static_cast<bool>(__x);
2979}
2980
2981template <class _T1, class _D1>
2982inline _LIBCPP_INLINE_VISIBILITY
2983bool
Howard Hinnant46e94932012-07-07 20:56:04 +00002984operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant3fadda32012-02-21 21:02:58 +00002985{
2986 return static_cast<bool>(__x);
2987}
2988
2989template <class _T1, class _D1>
2990inline _LIBCPP_INLINE_VISIBILITY
2991bool
2992operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2993{
2994 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2995 return less<_P1>()(__x.get(), nullptr);
2996}
2997
2998template <class _T1, class _D1>
2999inline _LIBCPP_INLINE_VISIBILITY
3000bool
3001operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3002{
3003 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3004 return less<_P1>()(nullptr, __x.get());
3005}
3006
3007template <class _T1, class _D1>
3008inline _LIBCPP_INLINE_VISIBILITY
3009bool
3010operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3011{
3012 return nullptr < __x;
3013}
3014
3015template <class _T1, class _D1>
3016inline _LIBCPP_INLINE_VISIBILITY
3017bool
3018operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3019{
3020 return __x < nullptr;
3021}
3022
3023template <class _T1, class _D1>
3024inline _LIBCPP_INLINE_VISIBILITY
3025bool
3026operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3027{
3028 return !(nullptr < __x);
3029}
3030
3031template <class _T1, class _D1>
3032inline _LIBCPP_INLINE_VISIBILITY
3033bool
3034operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3035{
3036 return !(__x < nullptr);
3037}
3038
3039template <class _T1, class _D1>
3040inline _LIBCPP_INLINE_VISIBILITY
3041bool
3042operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3043{
3044 return !(__x < nullptr);
3045}
3046
3047template <class _T1, class _D1>
3048inline _LIBCPP_INLINE_VISIBILITY
3049bool
3050operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3051{
3052 return !(nullptr < __x);
3053}
3054
Howard Hinnant87073e42012-05-01 15:37:54 +00003055#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3056
3057template <class _Tp, class _Dp>
3058inline _LIBCPP_INLINE_VISIBILITY
3059unique_ptr<_Tp, _Dp>
3060move(unique_ptr<_Tp, _Dp>& __t)
3061{
3062 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3063}
3064
3065#endif
3066
Marshall Clowfd7481e2013-07-01 18:16:03 +00003067#if _LIBCPP_STD_VER > 11
3068
3069template<class _Tp>
3070struct __unique_if
3071{
3072 typedef unique_ptr<_Tp> __unique_single;
3073};
3074
3075template<class _Tp>
3076struct __unique_if<_Tp[]>
3077{
3078 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3079};
3080
3081template<class _Tp, size_t _Np>
3082struct __unique_if<_Tp[_Np]>
3083{
3084 typedef void __unique_array_known_bound;
3085};
3086
3087template<class _Tp, class... _Args>
Marshall Clowfb551102013-07-02 20:06:09 +00003088inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003089typename __unique_if<_Tp>::__unique_single
3090make_unique(_Args&&... __args)
3091{
3092 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3093}
3094
3095template<class _Tp>
Marshall Clowfb551102013-07-02 20:06:09 +00003096inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowfd7481e2013-07-01 18:16:03 +00003097typename __unique_if<_Tp>::__unique_array_unknown_bound
3098make_unique(size_t __n)
3099{
3100 typedef typename remove_extent<_Tp>::type _Up;
3101 return unique_ptr<_Tp>(new _Up[__n]());
3102}
3103
3104template<class _Tp, class... _Args>
3105 typename __unique_if<_Tp>::__unique_array_known_bound
3106 make_unique(_Args&&...) = delete;
3107
3108#endif // _LIBCPP_STD_VER > 11
3109
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00003110template <class _Tp> struct hash;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003111
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003112template <class _Size>
3113inline _LIBCPP_INLINE_VISIBILITY
3114_Size
3115__loadword(const void* __p)
3116{
3117 _Size __r;
3118 std::memcpy(&__r, __p, sizeof(__r));
3119 return __r;
3120}
3121
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003122// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3123// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3124// multiplication, which can be very slow on 32-bit systems.
Howard Hinnant40c13d32011-12-05 00:08:45 +00003125template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003126struct __murmur2_or_cityhash;
Howard Hinnant40c13d32011-12-05 00:08:45 +00003127
3128template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003129struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003130{
3131 _Size operator()(const void* __key, _Size __len);
3132};
3133
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003134// murmur2
Howard Hinnant40c13d32011-12-05 00:08:45 +00003135template <class _Size>
3136_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003137__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003138{
3139 const _Size __m = 0x5bd1e995;
3140 const _Size __r = 24;
3141 _Size __h = __len;
3142 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3143 for (; __len >= 4; __data += 4, __len -= 4)
3144 {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003145 _Size __k = __loadword<_Size>(__data);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003146 __k *= __m;
3147 __k ^= __k >> __r;
3148 __k *= __m;
3149 __h *= __m;
3150 __h ^= __k;
3151 }
3152 switch (__len)
3153 {
3154 case 3:
3155 __h ^= __data[2] << 16;
3156 case 2:
3157 __h ^= __data[1] << 8;
3158 case 1:
3159 __h ^= __data[0];
3160 __h *= __m;
3161 }
3162 __h ^= __h >> 13;
3163 __h *= __m;
3164 __h ^= __h >> 15;
3165 return __h;
3166}
3167
3168template <class _Size>
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003169struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnant40c13d32011-12-05 00:08:45 +00003170{
3171 _Size operator()(const void* __key, _Size __len);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003172
3173 private:
3174 // Some primes between 2^63 and 2^64.
3175 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3176 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3177 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3178 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3179
3180 static _Size __rotate(_Size __val, int __shift) {
3181 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3182 }
3183
3184 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3185 return (__val >> __shift) | (__val << (64 - __shift));
3186 }
3187
3188 static _Size __shift_mix(_Size __val) {
3189 return __val ^ (__val >> 47);
3190 }
3191
3192 static _Size __hash_len_16(_Size __u, _Size __v) {
3193 const _Size __mul = 0x9ddfea08eb382d69ULL;
3194 _Size __a = (__u ^ __v) * __mul;
3195 __a ^= (__a >> 47);
3196 _Size __b = (__v ^ __a) * __mul;
3197 __b ^= (__b >> 47);
3198 __b *= __mul;
3199 return __b;
3200 }
3201
3202 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3203 if (__len > 8) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003204 const _Size __a = __loadword<_Size>(__s);
3205 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003206 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3207 }
3208 if (__len >= 4) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003209 const uint32_t __a = __loadword<uint32_t>(__s);
3210 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003211 return __hash_len_16(__len + (__a << 3), __b);
3212 }
3213 if (__len > 0) {
3214 const unsigned char __a = __s[0];
3215 const unsigned char __b = __s[__len >> 1];
3216 const unsigned char __c = __s[__len - 1];
3217 const uint32_t __y = static_cast<uint32_t>(__a) +
3218 (static_cast<uint32_t>(__b) << 8);
3219 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3220 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3221 }
3222 return __k2;
3223 }
3224
3225 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003226 const _Size __a = __loadword<_Size>(__s) * __k1;
3227 const _Size __b = __loadword<_Size>(__s + 8);
3228 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3229 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003230 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3231 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3232 }
3233
3234 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3235 // Callers do best to use "random-looking" values for a and b.
3236 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3237 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3238 __a += __w;
3239 __b = __rotate(__b + __a + __z, 21);
3240 const _Size __c = __a;
3241 __a += __x;
3242 __a += __y;
3243 __b += __rotate(__a, 44);
3244 return pair<_Size, _Size>(__a + __z, __b + __c);
3245 }
3246
3247 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3248 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3249 const char* __s, _Size __a, _Size __b) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003250 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3251 __loadword<_Size>(__s + 8),
3252 __loadword<_Size>(__s + 16),
3253 __loadword<_Size>(__s + 24),
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003254 __a,
3255 __b);
3256 }
3257
3258 // Return an 8-byte hash for 33 to 64 bytes.
3259 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003260 _Size __z = __loadword<_Size>(__s + 24);
3261 _Size __a = __loadword<_Size>(__s) +
3262 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003263 _Size __b = __rotate(__a + __z, 52);
3264 _Size __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003265 __a += __loadword<_Size>(__s + 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003266 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003267 __a += __loadword<_Size>(__s + 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003268 _Size __vf = __a + __z;
3269 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003270 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3271 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003272 __b = __rotate(__a + __z, 52);
3273 __c = __rotate(__a, 37);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003274 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003275 __c += __rotate(__a, 7);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003276 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003277 _Size __wf = __a + __z;
3278 _Size __ws = __b + __rotate(__a, 31) + __c;
3279 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3280 return __shift_mix(__r * __k0 + __vs) * __k2;
3281 }
Howard Hinnant40c13d32011-12-05 00:08:45 +00003282};
3283
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003284// cityhash64
Howard Hinnant40c13d32011-12-05 00:08:45 +00003285template <class _Size>
3286_Size
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003287__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Howard Hinnant40c13d32011-12-05 00:08:45 +00003288{
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003289 const char* __s = static_cast<const char*>(__key);
3290 if (__len <= 32) {
3291 if (__len <= 16) {
3292 return __hash_len_0_to_16(__s, __len);
3293 } else {
3294 return __hash_len_17_to_32(__s, __len);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003295 }
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003296 } else if (__len <= 64) {
3297 return __hash_len_33_to_64(__s, __len);
3298 }
3299
3300 // For strings over 64 bytes we hash the end first, and then as we
3301 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003302 _Size __x = __loadword<_Size>(__s + __len - 40);
3303 _Size __y = __loadword<_Size>(__s + __len - 16) +
3304 __loadword<_Size>(__s + __len - 56);
3305 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3306 __loadword<_Size>(__s + __len - 24));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003307 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3308 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003309 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003310
3311 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3312 __len = (__len - 1) & ~static_cast<_Size>(63);
3313 do {
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003314 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3315 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003316 __x ^= __w.second;
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003317 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003318 __z = __rotate(__z + __w.first, 33) * __k1;
3319 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3320 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant24ae8f82013-07-03 17:39:28 +00003321 __y + __loadword<_Size>(__s + 16));
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003322 std::swap(__z, __x);
3323 __s += 64;
3324 __len -= 64;
3325 } while (__len != 0);
3326 return __hash_len_16(
3327 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3328 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnant40c13d32011-12-05 00:08:45 +00003329}
3330
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003331template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3332struct __scalar_hash;
3333
3334template <class _Tp>
3335struct __scalar_hash<_Tp, 0>
3336 : public unary_function<_Tp, size_t>
Howard Hinnant21aefc32010-06-03 16:42:57 +00003337{
Howard Hinnant82894812010-09-22 16:48:34 +00003338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003339 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003340 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003341 union
3342 {
3343 _Tp __t;
3344 size_t __a;
3345 } __u;
3346 __u.__a = 0;
3347 __u.__t = __v;
3348 return __u.__a;
Howard Hinnant21aefc32010-06-03 16:42:57 +00003349 }
3350};
3351
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003352template <class _Tp>
3353struct __scalar_hash<_Tp, 1>
3354 : public unary_function<_Tp, size_t>
3355{
3356 _LIBCPP_INLINE_VISIBILITY
3357 size_t operator()(_Tp __v) const _NOEXCEPT
3358 {
3359 union
3360 {
3361 _Tp __t;
3362 size_t __a;
3363 } __u;
3364 __u.__t = __v;
3365 return __u.__a;
3366 }
3367};
3368
3369template <class _Tp>
3370struct __scalar_hash<_Tp, 2>
3371 : public unary_function<_Tp, size_t>
3372{
3373 _LIBCPP_INLINE_VISIBILITY
3374 size_t operator()(_Tp __v) const _NOEXCEPT
3375 {
3376 union
3377 {
3378 _Tp __t;
3379 struct
3380 {
3381 size_t __a;
3382 size_t __b;
3383 };
3384 } __u;
3385 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003386 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003387 }
3388};
3389
3390template <class _Tp>
3391struct __scalar_hash<_Tp, 3>
3392 : public unary_function<_Tp, size_t>
3393{
3394 _LIBCPP_INLINE_VISIBILITY
3395 size_t operator()(_Tp __v) const _NOEXCEPT
3396 {
3397 union
3398 {
3399 _Tp __t;
3400 struct
3401 {
3402 size_t __a;
3403 size_t __b;
3404 size_t __c;
3405 };
3406 } __u;
3407 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003408 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003409 }
3410};
3411
3412template <class _Tp>
3413struct __scalar_hash<_Tp, 4>
3414 : public unary_function<_Tp, size_t>
3415{
3416 _LIBCPP_INLINE_VISIBILITY
3417 size_t operator()(_Tp __v) const _NOEXCEPT
3418 {
3419 union
3420 {
3421 _Tp __t;
3422 struct
3423 {
3424 size_t __a;
3425 size_t __b;
3426 size_t __c;
3427 size_t __d;
3428 };
3429 } __u;
3430 __u.__t = __v;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00003431 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003432 }
3433};
3434
3435template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003436struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003437 : public unary_function<_Tp*, size_t>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003438{
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003439 _LIBCPP_INLINE_VISIBILITY
3440 size_t operator()(_Tp* __v) const _NOEXCEPT
3441 {
3442 union
3443 {
3444 _Tp* __t;
3445 size_t __a;
3446 } __u;
3447 __u.__t = __v;
3448 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3449 }
Howard Hinnantcf2654b2011-12-03 21:11:36 +00003450};
3451
Howard Hinnant21aefc32010-06-03 16:42:57 +00003452template <class _Tp, class _Dp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003453struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00003454{
3455 typedef unique_ptr<_Tp, _Dp> argument_type;
3456 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00003457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003458 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00003459 {
3460 typedef typename argument_type::pointer pointer;
3461 return hash<pointer>()(__ptr.get());
3462 }
3463};
3464
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003465struct __destruct_n
3466{
3467private:
3468 size_t size;
3469
3470 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003471 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3473
3474 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003475 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476 {}
3477
Howard Hinnant1694d232011-05-28 14:41:13 +00003478 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479 {++size;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003480 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481 {}
3482
Howard Hinnant1694d232011-05-28 14:41:13 +00003483 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003484 {size = __s;}
Howard Hinnant1694d232011-05-28 14:41:13 +00003485 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486 {}
3487public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003488 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3489 : size(__s) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490
3491 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003492 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003493 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003494
3495 template <class _Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00003496 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003497 {__set(__s, 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 operator()(_Tp* __p) _NOEXCEPT
Howard Hinnant1468b662010-11-19 22:17:28 +00003501 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003502};
3503
3504template <class _Alloc>
3505class __allocator_destructor
3506{
3507 typedef allocator_traits<_Alloc> __alloc_traits;
3508public:
3509 typedef typename __alloc_traits::pointer pointer;
3510 typedef typename __alloc_traits::size_type size_type;
3511private:
3512 _Alloc& __alloc_;
3513 size_type __s_;
3514public:
3515 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant1694d232011-05-28 14:41:13 +00003516 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517 : __alloc_(__a), __s_(__s) {}
Howard Hinnant82894812010-09-22 16:48:34 +00003518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003519 void operator()(pointer __p) _NOEXCEPT
3520 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003521};
3522
3523template <class _InputIterator, class _ForwardIterator>
3524_ForwardIterator
3525uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3526{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003527 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003528#ifndef _LIBCPP_NO_EXCEPTIONS
3529 _ForwardIterator __s = __r;
3530 try
3531 {
3532#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003533 for (; __f != __l; ++__f, (void) ++__r)
3534 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant8292d742011-12-29 17:45:35 +00003535#ifndef _LIBCPP_NO_EXCEPTIONS
3536 }
3537 catch (...)
3538 {
3539 for (; __s != __r; ++__s)
3540 __s->~value_type();
3541 throw;
3542 }
3543#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003544 return __r;
3545}
3546
3547template <class _InputIterator, class _Size, class _ForwardIterator>
3548_ForwardIterator
3549uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3550{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003551 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003552#ifndef _LIBCPP_NO_EXCEPTIONS
3553 _ForwardIterator __s = __r;
3554 try
3555 {
3556#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003557 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3558 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant8292d742011-12-29 17:45:35 +00003559#ifndef _LIBCPP_NO_EXCEPTIONS
3560 }
3561 catch (...)
3562 {
3563 for (; __s != __r; ++__s)
3564 __s->~value_type();
3565 throw;
3566 }
3567#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003568 return __r;
3569}
3570
3571template <class _ForwardIterator, class _Tp>
3572void
3573uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3574{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003576#ifndef _LIBCPP_NO_EXCEPTIONS
3577 _ForwardIterator __s = __f;
3578 try
3579 {
3580#endif
3581 for (; __f != __l; ++__f)
Marshall Clow5dce73d2015-05-19 15:01:48 +00003582 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant8292d742011-12-29 17:45:35 +00003583#ifndef _LIBCPP_NO_EXCEPTIONS
3584 }
3585 catch (...)
3586 {
3587 for (; __s != __f; ++__s)
3588 __s->~value_type();
3589 throw;
3590 }
3591#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003592}
3593
3594template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003595_ForwardIterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3597{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003598 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant8292d742011-12-29 17:45:35 +00003599#ifndef _LIBCPP_NO_EXCEPTIONS
3600 _ForwardIterator __s = __f;
3601 try
3602 {
3603#endif
Marshall Clow5dce73d2015-05-19 15:01:48 +00003604 for (; __n > 0; ++__f, (void) --__n)
3605 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant8292d742011-12-29 17:45:35 +00003606#ifndef _LIBCPP_NO_EXCEPTIONS
3607 }
3608 catch (...)
3609 {
3610 for (; __s != __f; ++__s)
3611 __s->~value_type();
3612 throw;
3613 }
3614#endif
Howard Hinnant2f6a6272010-11-18 16:13:03 +00003615 return __f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003616}
3617
Howard Hinnant82894812010-09-22 16:48:34 +00003618class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619 : public std::exception
3620{
3621public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003622 virtual ~bad_weak_ptr() _NOEXCEPT;
3623 virtual const char* what() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003624};
3625
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003626template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003627
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003628class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629{
3630 __shared_count(const __shared_count&);
3631 __shared_count& operator=(const __shared_count&);
3632
3633protected:
3634 long __shared_owners_;
3635 virtual ~__shared_count();
3636private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003637 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638
3639public:
Howard Hinnant82894812010-09-22 16:48:34 +00003640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003641 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642 : __shared_owners_(__refs) {}
3643
Howard Hinnant1694d232011-05-28 14:41:13 +00003644 void __add_shared() _NOEXCEPT;
3645 bool __release_shared() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003647 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648};
3649
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003650class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003651 : private __shared_count
3652{
3653 long __shared_weak_owners_;
3654
3655public:
Howard Hinnant82894812010-09-22 16:48:34 +00003656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003657 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658 : __shared_count(__refs),
3659 __shared_weak_owners_(__refs) {}
3660protected:
3661 virtual ~__shared_weak_count();
3662
3663public:
Howard Hinnant1694d232011-05-28 14:41:13 +00003664 void __add_shared() _NOEXCEPT;
3665 void __add_weak() _NOEXCEPT;
3666 void __release_shared() _NOEXCEPT;
3667 void __release_weak() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00003668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003669 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3670 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003672 // Define the function out only if we build static libc++ without RTTI.
3673 // Otherwise we may break clients who need to compile their projects with
3674 // -fno-rtti and yet link against a libc++.dylib compiled
3675 // without -fno-rtti.
3676#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant1694d232011-05-28 14:41:13 +00003677 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant4a0e74f2013-02-25 15:50:36 +00003678#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003679private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003680 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681};
3682
3683template <class _Tp, class _Dp, class _Alloc>
3684class __shared_ptr_pointer
3685 : public __shared_weak_count
3686{
3687 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3688public:
Howard Hinnant82894812010-09-22 16:48:34 +00003689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003691 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003692
Howard Hinnantd4444702010-08-11 17:04:31 +00003693#ifndef _LIBCPP_NO_RTTI
Howard Hinnant1694d232011-05-28 14:41:13 +00003694 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnantd4444702010-08-11 17:04:31 +00003695#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003696
3697private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003698 virtual void __on_zero_shared() _NOEXCEPT;
3699 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700};
3701
Howard Hinnantd4444702010-08-11 17:04:31 +00003702#ifndef _LIBCPP_NO_RTTI
3703
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704template <class _Tp, class _Dp, class _Alloc>
3705const void*
Howard Hinnant1694d232011-05-28 14:41:13 +00003706__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003707{
Marshall Clow4b3ca8c2014-11-17 19:05:50 +00003708 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003709}
3710
Howard Hinnant324bb032010-08-22 00:02:43 +00003711#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00003712
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713template <class _Tp, class _Dp, class _Alloc>
3714void
Howard Hinnant1694d232011-05-28 14:41:13 +00003715__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716{
3717 __data_.first().second()(__data_.first().first());
3718 __data_.first().second().~_Dp();
3719}
3720
3721template <class _Tp, class _Dp, class _Alloc>
3722void
Howard Hinnant1694d232011-05-28 14:41:13 +00003723__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003724{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003725 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3726 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003727 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3728
Eric Fiselier8492cd82015-02-05 23:01:40 +00003729 _Al __a(__data_.second());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003730 __data_.second().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003731 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732}
3733
3734template <class _Tp, class _Alloc>
3735class __shared_ptr_emplace
3736 : public __shared_weak_count
3737{
3738 __compressed_pair<_Alloc, _Tp> __data_;
3739public:
3740#ifndef _LIBCPP_HAS_NO_VARIADICS
3741
Howard Hinnant82894812010-09-22 16:48:34 +00003742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003743 __shared_ptr_emplace(_Alloc __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +00003744 : __data_(_VSTD::move(__a)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745
3746 template <class ..._Args>
Howard Hinnant82894812010-09-22 16:48:34 +00003747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant6cc99fa2011-12-19 17:58:44 +00003749 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3750 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003751
3752#else // _LIBCPP_HAS_NO_VARIADICS
3753
Howard Hinnant82894812010-09-22 16:48:34 +00003754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003755 __shared_ptr_emplace(_Alloc __a)
3756 : __data_(__a) {}
3757
3758 template <class _A0>
Howard Hinnant82894812010-09-22 16:48:34 +00003759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003760 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3761 : __data_(__a, _Tp(__a0)) {}
3762
3763 template <class _A0, class _A1>
Howard Hinnant82894812010-09-22 16:48:34 +00003764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003765 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3766 : __data_(__a, _Tp(__a0, __a1)) {}
3767
3768 template <class _A0, class _A1, class _A2>
Howard Hinnant82894812010-09-22 16:48:34 +00003769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003770 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3771 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3772
3773#endif // _LIBCPP_HAS_NO_VARIADICS
3774
3775private:
Howard Hinnant1694d232011-05-28 14:41:13 +00003776 virtual void __on_zero_shared() _NOEXCEPT;
3777 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003778public:
Howard Hinnant82894812010-09-22 16:48:34 +00003779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003780 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003781};
3782
3783template <class _Tp, class _Alloc>
3784void
Howard Hinnant1694d232011-05-28 14:41:13 +00003785__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003786{
3787 __data_.second().~_Tp();
3788}
3789
3790template <class _Tp, class _Alloc>
3791void
Howard Hinnant1694d232011-05-28 14:41:13 +00003792__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793{
Eric Fiselier8492cd82015-02-05 23:01:40 +00003794 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3795 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003796 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselier8492cd82015-02-05 23:01:40 +00003797 _Al __a(__data_.first());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003798 __data_.first().~_Alloc();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00003799 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003800}
3801
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003802template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803
3804template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003805class _LIBCPP_TYPE_VIS_ONLY shared_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806{
Howard Hinnant324bb032010-08-22 00:02:43 +00003807public:
3808 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003809private:
3810 element_type* __ptr_;
3811 __shared_weak_count* __cntrl_;
3812
3813 struct __nat {int __for_bool_;};
3814public:
Howard Hinnant46e94932012-07-07 20:56:04 +00003815 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3816 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiene1678a12014-01-31 09:30:46 +00003817 template<class _Yp>
3818 explicit shared_ptr(_Yp* __p,
3819 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3820 template<class _Yp, class _Dp>
3821 shared_ptr(_Yp* __p, _Dp __d,
3822 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3823 template<class _Yp, class _Dp, class _Alloc>
3824 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3825 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003826 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3827 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Howard Hinnant1694d232011-05-28 14:41:13 +00003828 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3829 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830 template<class _Yp>
3831 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003832 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3833 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003834#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003835 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00003837 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3838 _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003839#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant324bb032010-08-22 00:02:43 +00003841 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003842#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003843 template<class _Yp>
3844 shared_ptr(auto_ptr<_Yp>&& __r,
3845 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant324bb032010-08-22 00:02:43 +00003846#else
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 Hinnantbc8d3f92010-05-11 19:42:16 +00003850#endif
Howard Hinnant73d21a42010-09-04 23:28:19 +00003851#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003852 template <class _Yp, class _Dp>
3853 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3854 typename enable_if
3855 <
3856 !is_lvalue_reference<_Dp>::value &&
3857 !is_array<_Yp>::value &&
3858 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3859 __nat
3860 >::type = __nat());
3861 template <class _Yp, class _Dp>
3862 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3863 typename enable_if
3864 <
3865 is_lvalue_reference<_Dp>::value &&
3866 !is_array<_Yp>::value &&
3867 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3868 __nat
3869 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003870#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00003871 template <class _Yp, class _Dp>
3872 shared_ptr(unique_ptr<_Yp, _Dp>,
3873 typename enable_if
3874 <
3875 !is_lvalue_reference<_Dp>::value &&
3876 !is_array<_Yp>::value &&
3877 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3878 __nat
3879 >::type = __nat());
3880 template <class _Yp, class _Dp>
3881 shared_ptr(unique_ptr<_Yp, _Dp>,
3882 typename enable_if
3883 <
3884 is_lvalue_reference<_Dp>::value &&
3885 !is_array<_Yp>::value &&
3886 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3887 __nat
3888 >::type = __nat());
Howard Hinnant73d21a42010-09-04 23:28:19 +00003889#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890
3891 ~shared_ptr();
3892
Howard Hinnant1694d232011-05-28 14:41:13 +00003893 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003894 template<class _Yp>
3895 typename enable_if
3896 <
3897 is_convertible<_Yp*, element_type*>::value,
3898 shared_ptr&
3899 >::type
3900 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant73d21a42010-09-04 23:28:19 +00003901#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant1694d232011-05-28 14:41:13 +00003902 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003903 template<class _Yp>
3904 typename enable_if
3905 <
3906 is_convertible<_Yp*, element_type*>::value,
3907 shared_ptr<_Tp>&
3908 >::type
3909 operator=(shared_ptr<_Yp>&& __r);
3910 template<class _Yp>
3911 typename enable_if
3912 <
3913 !is_array<_Yp>::value &&
3914 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00003915 shared_ptr
3916 >::type&
Howard Hinnant57199402012-01-02 17:56:02 +00003917 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003918#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003919 template<class _Yp>
3920 typename enable_if
3921 <
3922 !is_array<_Yp>::value &&
3923 is_convertible<_Yp*, element_type*>::value,
3924 shared_ptr&
3925 >::type
3926 operator=(auto_ptr<_Yp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003927#endif
Howard Hinnant57199402012-01-02 17:56:02 +00003928 template <class _Yp, class _Dp>
3929 typename enable_if
3930 <
3931 !is_array<_Yp>::value &&
3932 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3933 shared_ptr&
3934 >::type
Howard Hinnant73d21a42010-09-04 23:28:19 +00003935#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003936 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant73d21a42010-09-04 23:28:19 +00003937#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant57199402012-01-02 17:56:02 +00003938 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939#endif
3940
Howard Hinnant1694d232011-05-28 14:41:13 +00003941 void swap(shared_ptr& __r) _NOEXCEPT;
3942 void reset() _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00003943 template<class _Yp>
3944 typename enable_if
3945 <
3946 is_convertible<_Yp*, element_type*>::value,
3947 void
3948 >::type
3949 reset(_Yp* __p);
3950 template<class _Yp, class _Dp>
3951 typename enable_if
3952 <
3953 is_convertible<_Yp*, element_type*>::value,
3954 void
3955 >::type
3956 reset(_Yp* __p, _Dp __d);
3957 template<class _Yp, class _Dp, class _Alloc>
3958 typename enable_if
3959 <
3960 is_convertible<_Yp*, element_type*>::value,
3961 void
3962 >::type
3963 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003964
Howard Hinnant82894812010-09-22 16:48:34 +00003965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003966 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003968 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3969 {return *__ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003971 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant82894812010-09-22 16:48:34 +00003972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003973 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00003974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003975 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant82894812010-09-22 16:48:34 +00003976 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00003977 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnant99968442011-11-29 18:15:50 +00003978 template <class _Up>
Howard Hinnant82894812010-09-22 16:48:34 +00003979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00003980 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981 {return __cntrl_ < __p.__cntrl_;}
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(weak_ptr<_Up> const& __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant5fec82d2012-07-30 01:40:57 +00003986 _LIBCPP_INLINE_VISIBILITY
3987 bool
3988 __owner_equivalent(const shared_ptr& __p) const
3989 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003990
Howard Hinnantd4444702010-08-11 17:04:31 +00003991#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003992 template <class _Dp>
Howard Hinnant82894812010-09-22 16:48:34 +00003993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00003994 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003995 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant324bb032010-08-22 00:02:43 +00003996#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003997
3998#ifndef _LIBCPP_HAS_NO_VARIADICS
3999
4000 template<class ..._Args>
4001 static
4002 shared_ptr<_Tp>
4003 make_shared(_Args&& ...__args);
4004
4005 template<class _Alloc, class ..._Args>
4006 static
4007 shared_ptr<_Tp>
4008 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4009
4010#else // _LIBCPP_HAS_NO_VARIADICS
4011
4012 static shared_ptr<_Tp> make_shared();
4013
4014 template<class _A0>
4015 static shared_ptr<_Tp> make_shared(_A0&);
4016
4017 template<class _A0, class _A1>
4018 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4019
4020 template<class _A0, class _A1, class _A2>
4021 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4022
4023 template<class _Alloc>
4024 static shared_ptr<_Tp>
4025 allocate_shared(const _Alloc& __a);
4026
4027 template<class _Alloc, class _A0>
4028 static shared_ptr<_Tp>
4029 allocate_shared(const _Alloc& __a, _A0& __a0);
4030
4031 template<class _Alloc, class _A0, class _A1>
4032 static shared_ptr<_Tp>
4033 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4034
4035 template<class _Alloc, class _A0, class _A1, class _A2>
4036 static shared_ptr<_Tp>
4037 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4038
4039#endif // _LIBCPP_HAS_NO_VARIADICS
4040
4041private:
4042
4043 template <class _Yp>
Howard Hinnant82894812010-09-22 16:48:34 +00004044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004045 void
Marshall Clowfc3a3ff2015-05-27 20:36:14 +00004046 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004047 {
4048 if (__e)
4049 __e->__weak_this_ = *this;
4050 }
4051
Howard Hinnant82894812010-09-22 16:48:34 +00004052 _LIBCPP_INLINE_VISIBILITY
Marshall Clow60784f62015-05-27 22:44:47 +00004053 void __enable_weak_this(const volatile void*) _NOEXCEPT {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004055 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4056 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004057};
4058
4059template<class _Tp>
4060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004061_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004062shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004063 : __ptr_(0),
4064 __cntrl_(0)
4065{
4066}
4067
4068template<class _Tp>
4069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00004070_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00004071shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004072 : __ptr_(0),
4073 __cntrl_(0)
4074{
4075}
4076
4077template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004078template<class _Yp>
4079shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4080 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004081 : __ptr_(__p)
4082{
4083 unique_ptr<_Yp> __hold(__p);
4084 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4085 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4086 __hold.release();
4087 __enable_weak_this(__p);
4088}
4089
4090template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004091template<class _Yp, class _Dp>
4092shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4093 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004094 : __ptr_(__p)
4095{
4096#ifndef _LIBCPP_NO_EXCEPTIONS
4097 try
4098 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004099#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004100 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4101 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4102 __enable_weak_this(__p);
4103#ifndef _LIBCPP_NO_EXCEPTIONS
4104 }
4105 catch (...)
4106 {
4107 __d(__p);
4108 throw;
4109 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004110#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004111}
4112
4113template<class _Tp>
4114template<class _Dp>
4115shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4116 : __ptr_(0)
4117{
4118#ifndef _LIBCPP_NO_EXCEPTIONS
4119 try
4120 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004121#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004122 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4123 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4124#ifndef _LIBCPP_NO_EXCEPTIONS
4125 }
4126 catch (...)
4127 {
4128 __d(__p);
4129 throw;
4130 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004131#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004132}
4133
4134template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004135template<class _Yp, class _Dp, class _Alloc>
4136shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4137 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004138 : __ptr_(__p)
4139{
4140#ifndef _LIBCPP_NO_EXCEPTIONS
4141 try
4142 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004143#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004144 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004145 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004146 typedef __allocator_destructor<_A2> _D2;
4147 _A2 __a2(__a);
4148 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004149 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4150 _CntrlBlk(__p, __d, __a);
4151 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004152 __enable_weak_this(__p);
4153#ifndef _LIBCPP_NO_EXCEPTIONS
4154 }
4155 catch (...)
4156 {
4157 __d(__p);
4158 throw;
4159 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004160#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004161}
4162
4163template<class _Tp>
4164template<class _Dp, class _Alloc>
4165shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4166 : __ptr_(0)
4167{
4168#ifndef _LIBCPP_NO_EXCEPTIONS
4169 try
4170 {
Howard Hinnant324bb032010-08-22 00:02:43 +00004171#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004172 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004173 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004174 typedef __allocator_destructor<_A2> _D2;
4175 _A2 __a2(__a);
4176 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004177 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4178 _CntrlBlk(__p, __d, __a);
4179 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004180#ifndef _LIBCPP_NO_EXCEPTIONS
4181 }
4182 catch (...)
4183 {
4184 __d(__p);
4185 throw;
4186 }
Howard Hinnant324bb032010-08-22 00:02:43 +00004187#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004188}
4189
4190template<class _Tp>
4191template<class _Yp>
4192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004193shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004194 : __ptr_(__p),
4195 __cntrl_(__r.__cntrl_)
4196{
4197 if (__cntrl_)
4198 __cntrl_->__add_shared();
4199}
4200
4201template<class _Tp>
4202inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004203shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004204 : __ptr_(__r.__ptr_),
4205 __cntrl_(__r.__cntrl_)
4206{
4207 if (__cntrl_)
4208 __cntrl_->__add_shared();
4209}
4210
4211template<class _Tp>
4212template<class _Yp>
4213inline _LIBCPP_INLINE_VISIBILITY
4214shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4215 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004216 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004217 : __ptr_(__r.__ptr_),
4218 __cntrl_(__r.__cntrl_)
4219{
4220 if (__cntrl_)
4221 __cntrl_->__add_shared();
4222}
4223
Howard Hinnant73d21a42010-09-04 23:28:19 +00004224#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004225
4226template<class _Tp>
4227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00004228shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004229 : __ptr_(__r.__ptr_),
4230 __cntrl_(__r.__cntrl_)
4231{
4232 __r.__ptr_ = 0;
4233 __r.__cntrl_ = 0;
4234}
4235
4236template<class _Tp>
4237template<class _Yp>
4238inline _LIBCPP_INLINE_VISIBILITY
4239shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4240 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00004241 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004242 : __ptr_(__r.__ptr_),
4243 __cntrl_(__r.__cntrl_)
4244{
4245 __r.__ptr_ = 0;
4246 __r.__cntrl_ = 0;
4247}
4248
Howard Hinnant73d21a42010-09-04 23:28:19 +00004249#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004250
4251template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004252template<class _Yp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004253#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiene1678a12014-01-31 09:30:46 +00004254shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004255#else
Logan Chiene1678a12014-01-31 09:30:46 +00004256shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004257#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004258 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004259 : __ptr_(__r.get())
4260{
4261 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4262 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4263 __enable_weak_this(__r.get());
4264 __r.release();
4265}
4266
4267template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004268template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004269#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004270shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4271#else
4272shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4273#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004274 typename enable_if
4275 <
4276 !is_lvalue_reference<_Dp>::value &&
4277 !is_array<_Yp>::value &&
4278 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4279 __nat
4280 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004281 : __ptr_(__r.get())
4282{
Marshall Clow0ad232a2015-05-10 13:59:45 +00004283#if _LIBCPP_STD_VER > 11
4284 if (__ptr_ == nullptr)
4285 __cntrl_ = nullptr;
4286 else
4287#endif
4288 {
4289 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4290 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4291 __enable_weak_this(__r.get());
4292 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004293 __r.release();
4294}
4295
4296template<class _Tp>
Logan Chiene1678a12014-01-31 09:30:46 +00004297template <class _Yp, class _Dp>
Howard Hinnant73d21a42010-09-04 23:28:19 +00004298#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004299shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4300#else
4301shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4302#endif
Logan Chiene1678a12014-01-31 09:30:46 +00004303 typename enable_if
4304 <
4305 is_lvalue_reference<_Dp>::value &&
4306 !is_array<_Yp>::value &&
4307 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4308 __nat
4309 >::type)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004310 : __ptr_(__r.get())
4311{
Marshall Clow0ad232a2015-05-10 13:59:45 +00004312#if _LIBCPP_STD_VER > 11
4313 if (__ptr_ == nullptr)
4314 __cntrl_ = nullptr;
4315 else
4316#endif
4317 {
4318 typedef __shared_ptr_pointer<_Yp*,
4319 reference_wrapper<typename remove_reference<_Dp>::type>,
4320 allocator<_Yp> > _CntrlBlk;
4321 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4322 __enable_weak_this(__r.get());
4323 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004324 __r.release();
4325}
4326
4327#ifndef _LIBCPP_HAS_NO_VARIADICS
4328
4329template<class _Tp>
4330template<class ..._Args>
4331shared_ptr<_Tp>
4332shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4333{
4334 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4335 typedef allocator<_CntrlBlk> _A2;
4336 typedef __allocator_destructor<_A2> _D2;
4337 _A2 __a2;
4338 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00004339 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004340 shared_ptr<_Tp> __r;
4341 __r.__ptr_ = __hold2.get()->get();
4342 __r.__cntrl_ = __hold2.release();
4343 __r.__enable_weak_this(__r.__ptr_);
4344 return __r;
4345}
4346
4347template<class _Tp>
4348template<class _Alloc, class ..._Args>
4349shared_ptr<_Tp>
4350shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4351{
4352 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004353 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004354 typedef __allocator_destructor<_A2> _D2;
4355 _A2 __a2(__a);
4356 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004357 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4358 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004359 shared_ptr<_Tp> __r;
4360 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004361 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004362 __r.__enable_weak_this(__r.__ptr_);
4363 return __r;
4364}
4365
4366#else // _LIBCPP_HAS_NO_VARIADICS
4367
4368template<class _Tp>
4369shared_ptr<_Tp>
4370shared_ptr<_Tp>::make_shared()
4371{
4372 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4373 typedef allocator<_CntrlBlk> _Alloc2;
4374 typedef __allocator_destructor<_Alloc2> _D2;
4375 _Alloc2 __alloc2;
4376 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4377 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4378 shared_ptr<_Tp> __r;
4379 __r.__ptr_ = __hold2.get()->get();
4380 __r.__cntrl_ = __hold2.release();
4381 __r.__enable_weak_this(__r.__ptr_);
4382 return __r;
4383}
4384
4385template<class _Tp>
4386template<class _A0>
4387shared_ptr<_Tp>
4388shared_ptr<_Tp>::make_shared(_A0& __a0)
4389{
4390 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4391 typedef allocator<_CntrlBlk> _Alloc2;
4392 typedef __allocator_destructor<_Alloc2> _D2;
4393 _Alloc2 __alloc2;
4394 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4395 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4396 shared_ptr<_Tp> __r;
4397 __r.__ptr_ = __hold2.get()->get();
4398 __r.__cntrl_ = __hold2.release();
4399 __r.__enable_weak_this(__r.__ptr_);
4400 return __r;
4401}
4402
4403template<class _Tp>
4404template<class _A0, class _A1>
4405shared_ptr<_Tp>
4406shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4407{
4408 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4409 typedef allocator<_CntrlBlk> _Alloc2;
4410 typedef __allocator_destructor<_Alloc2> _D2;
4411 _Alloc2 __alloc2;
4412 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4413 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4414 shared_ptr<_Tp> __r;
4415 __r.__ptr_ = __hold2.get()->get();
4416 __r.__cntrl_ = __hold2.release();
4417 __r.__enable_weak_this(__r.__ptr_);
4418 return __r;
4419}
4420
4421template<class _Tp>
4422template<class _A0, class _A1, class _A2>
4423shared_ptr<_Tp>
4424shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4425{
4426 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4427 typedef allocator<_CntrlBlk> _Alloc2;
4428 typedef __allocator_destructor<_Alloc2> _D2;
4429 _Alloc2 __alloc2;
4430 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4431 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4432 shared_ptr<_Tp> __r;
4433 __r.__ptr_ = __hold2.get()->get();
4434 __r.__cntrl_ = __hold2.release();
4435 __r.__enable_weak_this(__r.__ptr_);
4436 return __r;
4437}
4438
4439template<class _Tp>
4440template<class _Alloc>
4441shared_ptr<_Tp>
4442shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4443{
4444 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004445 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004446 typedef __allocator_destructor<_Alloc2> _D2;
4447 _Alloc2 __alloc2(__a);
4448 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004449 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4450 _CntrlBlk(__a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004451 shared_ptr<_Tp> __r;
4452 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004453 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004454 __r.__enable_weak_this(__r.__ptr_);
4455 return __r;
4456}
4457
4458template<class _Tp>
4459template<class _Alloc, class _A0>
4460shared_ptr<_Tp>
4461shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4462{
4463 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004464 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004465 typedef __allocator_destructor<_Alloc2> _D2;
4466 _Alloc2 __alloc2(__a);
4467 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004468 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4469 _CntrlBlk(__a, __a0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004470 shared_ptr<_Tp> __r;
4471 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004472 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004473 __r.__enable_weak_this(__r.__ptr_);
4474 return __r;
4475}
4476
4477template<class _Tp>
4478template<class _Alloc, class _A0, class _A1>
4479shared_ptr<_Tp>
4480shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4481{
4482 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004483 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004484 typedef __allocator_destructor<_Alloc2> _D2;
4485 _Alloc2 __alloc2(__a);
4486 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004487 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4488 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004489 shared_ptr<_Tp> __r;
4490 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004491 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004492 __r.__enable_weak_this(__r.__ptr_);
4493 return __r;
4494}
4495
4496template<class _Tp>
4497template<class _Alloc, class _A0, class _A1, class _A2>
4498shared_ptr<_Tp>
4499shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4500{
4501 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004502 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004503 typedef __allocator_destructor<_Alloc2> _D2;
4504 _Alloc2 __alloc2(__a);
4505 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004506 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4507 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004508 shared_ptr<_Tp> __r;
4509 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier4e7d5362014-10-23 04:12:28 +00004510 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004511 __r.__enable_weak_this(__r.__ptr_);
4512 return __r;
4513}
4514
4515#endif // _LIBCPP_HAS_NO_VARIADICS
4516
4517template<class _Tp>
4518shared_ptr<_Tp>::~shared_ptr()
4519{
4520 if (__cntrl_)
4521 __cntrl_->__release_shared();
4522}
4523
4524template<class _Tp>
4525inline _LIBCPP_INLINE_VISIBILITY
4526shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004527shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004528{
4529 shared_ptr(__r).swap(*this);
4530 return *this;
4531}
4532
4533template<class _Tp>
4534template<class _Yp>
4535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004536typename enable_if
4537<
4538 is_convertible<_Yp*, _Tp*>::value,
4539 shared_ptr<_Tp>&
4540>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004541shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004542{
4543 shared_ptr(__r).swap(*this);
4544 return *this;
4545}
4546
Howard Hinnant73d21a42010-09-04 23:28:19 +00004547#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004548
4549template<class _Tp>
4550inline _LIBCPP_INLINE_VISIBILITY
4551shared_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00004552shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004553{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004554 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004555 return *this;
4556}
4557
4558template<class _Tp>
4559template<class _Yp>
4560inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004561typename enable_if
4562<
4563 is_convertible<_Yp*, _Tp*>::value,
4564 shared_ptr<_Tp>&
4565>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004566shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4567{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004568 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004569 return *this;
4570}
4571
4572template<class _Tp>
4573template<class _Yp>
4574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004575typename enable_if
4576<
4577 !is_array<_Yp>::value &&
4578 is_convertible<_Yp*, _Tp*>::value,
Howard Hinnant37c4acf2013-09-13 23:56:00 +00004579 shared_ptr<_Tp>
4580>::type&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004581shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4582{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004583 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004584 return *this;
4585}
4586
4587template<class _Tp>
4588template <class _Yp, class _Dp>
4589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004590typename enable_if
4591<
4592 !is_array<_Yp>::value &&
4593 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4594 shared_ptr<_Tp>&
4595>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004596shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4597{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004598 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004599 return *this;
4600}
4601
Howard Hinnant73d21a42010-09-04 23:28:19 +00004602#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004603
4604template<class _Tp>
4605template<class _Yp>
4606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004607typename enable_if
4608<
4609 !is_array<_Yp>::value &&
4610 is_convertible<_Yp*, _Tp*>::value,
4611 shared_ptr<_Tp>&
4612>::type
Howard Hinnant324bb032010-08-22 00:02:43 +00004613shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004614{
4615 shared_ptr(__r).swap(*this);
4616 return *this;
4617}
4618
4619template<class _Tp>
4620template <class _Yp, class _Dp>
4621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004622typename enable_if
4623<
4624 !is_array<_Yp>::value &&
4625 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4626 shared_ptr<_Tp>&
4627>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004628shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4629{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004630 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004631 return *this;
4632}
4633
Howard Hinnant73d21a42010-09-04 23:28:19 +00004634#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004635
4636template<class _Tp>
4637inline _LIBCPP_INLINE_VISIBILITY
4638void
Howard Hinnant1694d232011-05-28 14:41:13 +00004639shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004640{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004641 _VSTD::swap(__ptr_, __r.__ptr_);
4642 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004643}
4644
4645template<class _Tp>
4646inline _LIBCPP_INLINE_VISIBILITY
4647void
Howard Hinnant1694d232011-05-28 14:41:13 +00004648shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004649{
4650 shared_ptr().swap(*this);
4651}
4652
4653template<class _Tp>
4654template<class _Yp>
4655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004656typename enable_if
4657<
4658 is_convertible<_Yp*, _Tp*>::value,
4659 void
4660>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004661shared_ptr<_Tp>::reset(_Yp* __p)
4662{
4663 shared_ptr(__p).swap(*this);
4664}
4665
4666template<class _Tp>
4667template<class _Yp, class _Dp>
4668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004669typename enable_if
4670<
4671 is_convertible<_Yp*, _Tp*>::value,
4672 void
4673>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004674shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4675{
4676 shared_ptr(__p, __d).swap(*this);
4677}
4678
4679template<class _Tp>
4680template<class _Yp, class _Dp, class _Alloc>
4681inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004682typename enable_if
4683<
4684 is_convertible<_Yp*, _Tp*>::value,
4685 void
4686>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004687shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4688{
4689 shared_ptr(__p, __d, __a).swap(*this);
4690}
4691
4692#ifndef _LIBCPP_HAS_NO_VARIADICS
4693
Howard Hinnant324bb032010-08-22 00:02:43 +00004694template<class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004696typename enable_if
4697<
4698 !is_array<_Tp>::value,
4699 shared_ptr<_Tp>
4700>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004701make_shared(_Args&& ...__args)
4702{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004703 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004704}
4705
Howard Hinnant324bb032010-08-22 00:02:43 +00004706template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004708typename enable_if
4709<
4710 !is_array<_Tp>::value,
4711 shared_ptr<_Tp>
4712>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004713allocate_shared(const _Alloc& __a, _Args&& ...__args)
4714{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004715 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004716}
4717
4718#else // _LIBCPP_HAS_NO_VARIADICS
4719
4720template<class _Tp>
4721inline _LIBCPP_INLINE_VISIBILITY
4722shared_ptr<_Tp>
4723make_shared()
4724{
4725 return shared_ptr<_Tp>::make_shared();
4726}
4727
4728template<class _Tp, class _A0>
4729inline _LIBCPP_INLINE_VISIBILITY
4730shared_ptr<_Tp>
4731make_shared(_A0& __a0)
4732{
4733 return shared_ptr<_Tp>::make_shared(__a0);
4734}
4735
4736template<class _Tp, class _A0, class _A1>
4737inline _LIBCPP_INLINE_VISIBILITY
4738shared_ptr<_Tp>
4739make_shared(_A0& __a0, _A1& __a1)
4740{
4741 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4742}
4743
Howard Hinnant324bb032010-08-22 00:02:43 +00004744template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004745inline _LIBCPP_INLINE_VISIBILITY
4746shared_ptr<_Tp>
4747make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4748{
4749 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4750}
4751
4752template<class _Tp, class _Alloc>
4753inline _LIBCPP_INLINE_VISIBILITY
4754shared_ptr<_Tp>
4755allocate_shared(const _Alloc& __a)
4756{
4757 return shared_ptr<_Tp>::allocate_shared(__a);
4758}
4759
4760template<class _Tp, class _Alloc, class _A0>
4761inline _LIBCPP_INLINE_VISIBILITY
4762shared_ptr<_Tp>
4763allocate_shared(const _Alloc& __a, _A0& __a0)
4764{
4765 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4766}
4767
4768template<class _Tp, class _Alloc, class _A0, class _A1>
4769inline _LIBCPP_INLINE_VISIBILITY
4770shared_ptr<_Tp>
4771allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4772{
4773 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4774}
4775
4776template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4777inline _LIBCPP_INLINE_VISIBILITY
4778shared_ptr<_Tp>
4779allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4780{
4781 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4782}
4783
4784#endif // _LIBCPP_HAS_NO_VARIADICS
4785
4786template<class _Tp, class _Up>
4787inline _LIBCPP_INLINE_VISIBILITY
4788bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004789operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004790{
4791 return __x.get() == __y.get();
4792}
4793
4794template<class _Tp, class _Up>
4795inline _LIBCPP_INLINE_VISIBILITY
4796bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004797operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004798{
4799 return !(__x == __y);
4800}
4801
4802template<class _Tp, class _Up>
4803inline _LIBCPP_INLINE_VISIBILITY
4804bool
Howard Hinnant1694d232011-05-28 14:41:13 +00004805operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004806{
Eric Fiselier8492cd82015-02-05 23:01:40 +00004807 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4808 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant3fadda32012-02-21 21:02:58 +00004809}
4810
4811template<class _Tp, class _Up>
4812inline _LIBCPP_INLINE_VISIBILITY
4813bool
4814operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4815{
4816 return __y < __x;
4817}
4818
4819template<class _Tp, class _Up>
4820inline _LIBCPP_INLINE_VISIBILITY
4821bool
4822operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4823{
4824 return !(__y < __x);
4825}
4826
4827template<class _Tp, class _Up>
4828inline _LIBCPP_INLINE_VISIBILITY
4829bool
4830operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4831{
4832 return !(__x < __y);
4833}
4834
4835template<class _Tp>
4836inline _LIBCPP_INLINE_VISIBILITY
4837bool
4838operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4839{
4840 return !__x;
4841}
4842
4843template<class _Tp>
4844inline _LIBCPP_INLINE_VISIBILITY
4845bool
4846operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4847{
4848 return !__x;
4849}
4850
4851template<class _Tp>
4852inline _LIBCPP_INLINE_VISIBILITY
4853bool
4854operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4855{
4856 return static_cast<bool>(__x);
4857}
4858
4859template<class _Tp>
4860inline _LIBCPP_INLINE_VISIBILITY
4861bool
4862operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4863{
4864 return static_cast<bool>(__x);
4865}
4866
4867template<class _Tp>
4868inline _LIBCPP_INLINE_VISIBILITY
4869bool
4870operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4871{
4872 return less<_Tp*>()(__x.get(), nullptr);
4873}
4874
4875template<class _Tp>
4876inline _LIBCPP_INLINE_VISIBILITY
4877bool
4878operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4879{
4880 return less<_Tp*>()(nullptr, __x.get());
4881}
4882
4883template<class _Tp>
4884inline _LIBCPP_INLINE_VISIBILITY
4885bool
4886operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4887{
4888 return nullptr < __x;
4889}
4890
4891template<class _Tp>
4892inline _LIBCPP_INLINE_VISIBILITY
4893bool
4894operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4895{
4896 return __x < nullptr;
4897}
4898
4899template<class _Tp>
4900inline _LIBCPP_INLINE_VISIBILITY
4901bool
4902operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4903{
4904 return !(nullptr < __x);
4905}
4906
4907template<class _Tp>
4908inline _LIBCPP_INLINE_VISIBILITY
4909bool
4910operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4911{
4912 return !(__x < nullptr);
4913}
4914
4915template<class _Tp>
4916inline _LIBCPP_INLINE_VISIBILITY
4917bool
4918operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4919{
4920 return !(__x < nullptr);
4921}
4922
4923template<class _Tp>
4924inline _LIBCPP_INLINE_VISIBILITY
4925bool
4926operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4927{
4928 return !(nullptr < __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004929}
4930
4931template<class _Tp>
4932inline _LIBCPP_INLINE_VISIBILITY
4933void
Howard Hinnant1694d232011-05-28 14:41:13 +00004934swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004935{
4936 __x.swap(__y);
4937}
4938
4939template<class _Tp, class _Up>
4940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004941typename enable_if
4942<
4943 !is_array<_Tp>::value && !is_array<_Up>::value,
4944 shared_ptr<_Tp>
4945>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004946static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004947{
4948 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4949}
4950
4951template<class _Tp, class _Up>
4952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00004953typename enable_if
4954<
4955 !is_array<_Tp>::value && !is_array<_Up>::value,
4956 shared_ptr<_Tp>
4957>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004958dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004959{
4960 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4961 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4962}
4963
4964template<class _Tp, class _Up>
Howard Hinnant57199402012-01-02 17:56:02 +00004965typename enable_if
4966<
4967 is_array<_Tp>::value == is_array<_Up>::value,
4968 shared_ptr<_Tp>
4969>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00004970const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004971{
Howard Hinnant57199402012-01-02 17:56:02 +00004972 typedef typename remove_extent<_Tp>::type _RTp;
4973 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004974}
4975
Howard Hinnantd4444702010-08-11 17:04:31 +00004976#ifndef _LIBCPP_NO_RTTI
4977
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004978template<class _Dp, class _Tp>
4979inline _LIBCPP_INLINE_VISIBILITY
4980_Dp*
Howard Hinnant1694d232011-05-28 14:41:13 +00004981get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004982{
4983 return __p.template __get_deleter<_Dp>();
4984}
4985
Howard Hinnant324bb032010-08-22 00:02:43 +00004986#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00004987
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004988template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004989class _LIBCPP_TYPE_VIS_ONLY weak_ptr
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004990{
Howard Hinnant324bb032010-08-22 00:02:43 +00004991public:
4992 typedef _Tp element_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004993private:
4994 element_type* __ptr_;
4995 __shared_weak_count* __cntrl_;
4996
Howard Hinnant324bb032010-08-22 00:02:43 +00004997public:
Howard Hinnant46e94932012-07-07 20:56:04 +00004998 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004999 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant1694d232011-05-28 14:41:13 +00005000 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5001 _NOEXCEPT;
5002 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005003 template<class _Yp> weak_ptr(weak_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;
Howard Hinnant324bb032010-08-22 00:02:43 +00005006
Howard Hinnant57199402012-01-02 17:56:02 +00005007#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5008 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5009 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
5010 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5011 _NOEXCEPT;
5012#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant324bb032010-08-22 00:02:43 +00005013 ~weak_ptr();
5014
Howard Hinnant1694d232011-05-28 14:41:13 +00005015 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant57199402012-01-02 17:56:02 +00005016 template<class _Yp>
5017 typename enable_if
5018 <
5019 is_convertible<_Yp*, element_type*>::value,
5020 weak_ptr&
5021 >::type
5022 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5023
5024#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5025
5026 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5027 template<class _Yp>
5028 typename enable_if
5029 <
5030 is_convertible<_Yp*, element_type*>::value,
5031 weak_ptr&
5032 >::type
5033 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5034
5035#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5036
5037 template<class _Yp>
5038 typename enable_if
5039 <
5040 is_convertible<_Yp*, element_type*>::value,
5041 weak_ptr&
5042 >::type
5043 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005044
Howard Hinnant1694d232011-05-28 14:41:13 +00005045 void swap(weak_ptr& __r) _NOEXCEPT;
5046 void reset() _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00005047
Howard Hinnant82894812010-09-22 16:48:34 +00005048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005049 long use_count() const _NOEXCEPT
5050 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant82894812010-09-22 16:48:34 +00005051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005052 bool expired() const _NOEXCEPT
5053 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5054 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +00005055 template<class _Up>
5056 _LIBCPP_INLINE_VISIBILITY
5057 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005058 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant82894812010-09-22 16:48:34 +00005059 template<class _Up>
5060 _LIBCPP_INLINE_VISIBILITY
5061 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005062 {return __cntrl_ < __r.__cntrl_;}
5063
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005064 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5065 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005066};
5067
5068template<class _Tp>
5069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46e94932012-07-07 20:56:04 +00005070_LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005071weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005072 : __ptr_(0),
5073 __cntrl_(0)
5074{
5075}
5076
5077template<class _Tp>
5078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005079weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005080 : __ptr_(__r.__ptr_),
5081 __cntrl_(__r.__cntrl_)
5082{
5083 if (__cntrl_)
5084 __cntrl_->__add_weak();
5085}
5086
5087template<class _Tp>
5088template<class _Yp>
5089inline _LIBCPP_INLINE_VISIBILITY
5090weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005091 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005092 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005093 : __ptr_(__r.__ptr_),
5094 __cntrl_(__r.__cntrl_)
5095{
5096 if (__cntrl_)
5097 __cntrl_->__add_weak();
5098}
5099
5100template<class _Tp>
5101template<class _Yp>
5102inline _LIBCPP_INLINE_VISIBILITY
5103weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnante003ce42011-05-22 00:09:02 +00005104 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant1694d232011-05-28 14:41:13 +00005105 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005106 : __ptr_(__r.__ptr_),
5107 __cntrl_(__r.__cntrl_)
5108{
5109 if (__cntrl_)
5110 __cntrl_->__add_weak();
5111}
5112
Howard Hinnant57199402012-01-02 17:56:02 +00005113#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5114
5115template<class _Tp>
5116inline _LIBCPP_INLINE_VISIBILITY
5117weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5118 : __ptr_(__r.__ptr_),
5119 __cntrl_(__r.__cntrl_)
5120{
5121 __r.__ptr_ = 0;
5122 __r.__cntrl_ = 0;
5123}
5124
5125template<class _Tp>
5126template<class _Yp>
5127inline _LIBCPP_INLINE_VISIBILITY
5128weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5129 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5130 _NOEXCEPT
5131 : __ptr_(__r.__ptr_),
5132 __cntrl_(__r.__cntrl_)
5133{
5134 __r.__ptr_ = 0;
5135 __r.__cntrl_ = 0;
5136}
5137
5138#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5139
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005140template<class _Tp>
5141weak_ptr<_Tp>::~weak_ptr()
5142{
5143 if (__cntrl_)
5144 __cntrl_->__release_weak();
5145}
5146
5147template<class _Tp>
5148inline _LIBCPP_INLINE_VISIBILITY
5149weak_ptr<_Tp>&
Howard Hinnant1694d232011-05-28 14:41:13 +00005150weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005151{
5152 weak_ptr(__r).swap(*this);
5153 return *this;
5154}
5155
5156template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005157template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005158inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005159typename enable_if
5160<
5161 is_convertible<_Yp*, _Tp*>::value,
5162 weak_ptr<_Tp>&
5163>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005164weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005165{
5166 weak_ptr(__r).swap(*this);
5167 return *this;
5168}
5169
Howard Hinnant57199402012-01-02 17:56:02 +00005170#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5171
5172template<class _Tp>
5173inline _LIBCPP_INLINE_VISIBILITY
5174weak_ptr<_Tp>&
5175weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5176{
5177 weak_ptr(_VSTD::move(__r)).swap(*this);
5178 return *this;
5179}
5180
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005181template<class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +00005182template<class _Yp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57199402012-01-02 17:56:02 +00005184typename enable_if
5185<
5186 is_convertible<_Yp*, _Tp*>::value,
5187 weak_ptr<_Tp>&
5188>::type
5189weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5190{
5191 weak_ptr(_VSTD::move(__r)).swap(*this);
5192 return *this;
5193}
5194
5195#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5196
5197template<class _Tp>
5198template<class _Yp>
5199inline _LIBCPP_INLINE_VISIBILITY
5200typename enable_if
5201<
5202 is_convertible<_Yp*, _Tp*>::value,
5203 weak_ptr<_Tp>&
5204>::type
Howard Hinnant1694d232011-05-28 14:41:13 +00005205weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005206{
5207 weak_ptr(__r).swap(*this);
5208 return *this;
5209}
5210
5211template<class _Tp>
5212inline _LIBCPP_INLINE_VISIBILITY
5213void
Howard Hinnant1694d232011-05-28 14:41:13 +00005214weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005215{
Howard Hinnant0949eed2011-06-30 21:18:19 +00005216 _VSTD::swap(__ptr_, __r.__ptr_);
5217 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005218}
5219
5220template<class _Tp>
5221inline _LIBCPP_INLINE_VISIBILITY
5222void
Howard Hinnant1694d232011-05-28 14:41:13 +00005223swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005224{
5225 __x.swap(__y);
5226}
5227
5228template<class _Tp>
5229inline _LIBCPP_INLINE_VISIBILITY
5230void
Howard Hinnant1694d232011-05-28 14:41:13 +00005231weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005232{
5233 weak_ptr().swap(*this);
5234}
5235
5236template<class _Tp>
5237template<class _Yp>
5238shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5239 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5240 : __ptr_(__r.__ptr_),
5241 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5242{
5243 if (__cntrl_ == 0)
5244#ifndef _LIBCPP_NO_EXCEPTIONS
5245 throw bad_weak_ptr();
5246#else
5247 assert(!"bad_weak_ptr");
5248#endif
5249}
5250
5251template<class _Tp>
5252shared_ptr<_Tp>
Howard Hinnant1694d232011-05-28 14:41:13 +00005253weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005254{
5255 shared_ptr<_Tp> __r;
5256 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5257 if (__r.__cntrl_)
5258 __r.__ptr_ = __ptr_;
5259 return __r;
5260}
5261
Howard Hinnant324bb032010-08-22 00:02:43 +00005262template <class _Tp> struct owner_less;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005263
5264template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005265struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005266 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant324bb032010-08-22 00:02:43 +00005267{
5268 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005270 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5271 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005273 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5274 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005276 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5277 {return __x.owner_before(__y);}
Howard Hinnant324bb032010-08-22 00:02:43 +00005278};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005279
5280template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005281struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005282 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5283{
Howard Hinnant324bb032010-08-22 00:02:43 +00005284 typedef bool result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005286 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5287 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005289 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5290 {return __x.owner_before(__y);}
Howard Hinnant82894812010-09-22 16:48:34 +00005291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005292 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5293 {return __x.owner_before(__y);}
5294};
5295
5296template<class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005297class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005298{
5299 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant324bb032010-08-22 00:02:43 +00005300protected:
Howard Hinnant46e94932012-07-07 20:56:04 +00005301 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant1694d232011-05-28 14:41:13 +00005302 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005304 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant82894812010-09-22 16:48:34 +00005305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005306 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5307 {return *this;}
Howard Hinnant82894812010-09-22 16:48:34 +00005308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005309 ~enable_shared_from_this() {}
Howard Hinnant324bb032010-08-22 00:02:43 +00005310public:
Howard Hinnant82894812010-09-22 16:48:34 +00005311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005312 shared_ptr<_Tp> shared_from_this()
5313 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant82894812010-09-22 16:48:34 +00005314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005315 shared_ptr<_Tp const> shared_from_this() const
5316 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005317
5318 template <class _Up> friend class shared_ptr;
5319};
5320
Howard Hinnant21aefc32010-06-03 16:42:57 +00005321template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005322struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
Howard Hinnant21aefc32010-06-03 16:42:57 +00005323{
5324 typedef shared_ptr<_Tp> argument_type;
5325 typedef size_t result_type;
Howard Hinnant82894812010-09-22 16:48:34 +00005326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1694d232011-05-28 14:41:13 +00005327 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant21aefc32010-06-03 16:42:57 +00005328 {
5329 return hash<_Tp*>()(__ptr.get());
5330 }
5331};
5332
Howard Hinnant99968442011-11-29 18:15:50 +00005333template<class _CharT, class _Traits, class _Yp>
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005334inline _LIBCPP_INLINE_VISIBILITY
5335basic_ostream<_CharT, _Traits>&
Howard Hinnant99968442011-11-29 18:15:50 +00005336operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnant464aa5c2011-07-18 15:51:59 +00005337
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005338#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005339
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005340class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005341{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005342 void* __lx;
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005343public:
5344 void lock() _NOEXCEPT;
5345 void unlock() _NOEXCEPT;
5346
5347private:
5348 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5349 __sp_mut(const __sp_mut&);
5350 __sp_mut& operator=(const __sp_mut&);
5351
Howard Hinnant83eade62013-03-06 23:30:19 +00005352 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005353};
5354
Howard Hinnant83eade62013-03-06 23:30:19 +00005355_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005356
5357template <class _Tp>
5358inline _LIBCPP_INLINE_VISIBILITY
5359bool
5360atomic_is_lock_free(const shared_ptr<_Tp>*)
5361{
5362 return false;
5363}
5364
5365template <class _Tp>
5366shared_ptr<_Tp>
5367atomic_load(const shared_ptr<_Tp>* __p)
5368{
5369 __sp_mut& __m = __get_sp_mut(__p);
5370 __m.lock();
5371 shared_ptr<_Tp> __q = *__p;
5372 __m.unlock();
5373 return __q;
5374}
5375
5376template <class _Tp>
5377inline _LIBCPP_INLINE_VISIBILITY
5378shared_ptr<_Tp>
5379atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5380{
5381 return atomic_load(__p);
5382}
5383
5384template <class _Tp>
5385void
5386atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5387{
5388 __sp_mut& __m = __get_sp_mut(__p);
5389 __m.lock();
5390 __p->swap(__r);
5391 __m.unlock();
5392}
5393
5394template <class _Tp>
5395inline _LIBCPP_INLINE_VISIBILITY
5396void
5397atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5398{
5399 atomic_store(__p, __r);
5400}
5401
5402template <class _Tp>
5403shared_ptr<_Tp>
5404atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5405{
5406 __sp_mut& __m = __get_sp_mut(__p);
5407 __m.lock();
5408 __p->swap(__r);
5409 __m.unlock();
5410 return __r;
5411}
5412
5413template <class _Tp>
5414inline _LIBCPP_INLINE_VISIBILITY
5415shared_ptr<_Tp>
5416atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5417{
5418 return atomic_exchange(__p, __r);
5419}
5420
5421template <class _Tp>
5422bool
5423atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5424{
5425 __sp_mut& __m = __get_sp_mut(__p);
5426 __m.lock();
5427 if (__p->__owner_equivalent(*__v))
5428 {
5429 *__p = __w;
5430 __m.unlock();
5431 return true;
5432 }
5433 *__v = *__p;
5434 __m.unlock();
5435 return false;
5436}
5437
5438template <class _Tp>
5439inline _LIBCPP_INLINE_VISIBILITY
5440bool
5441atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5442{
5443 return atomic_compare_exchange_strong(__p, __v, __w);
5444}
5445
5446template <class _Tp>
5447inline _LIBCPP_INLINE_VISIBILITY
5448bool
5449atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5450 shared_ptr<_Tp> __w, memory_order, memory_order)
5451{
5452 return atomic_compare_exchange_strong(__p, __v, __w);
5453}
5454
5455template <class _Tp>
5456inline _LIBCPP_INLINE_VISIBILITY
5457bool
5458atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5459 shared_ptr<_Tp> __w, memory_order, memory_order)
5460{
5461 return atomic_compare_exchange_weak(__p, __v, __w);
5462}
5463
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00005464#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant5fec82d2012-07-30 01:40:57 +00005465
Howard Hinnant324bb032010-08-22 00:02:43 +00005466//enum class
Howard Hinnant83eade62013-03-06 23:30:19 +00005467struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005468{
Howard Hinnant9c0df142012-10-30 19:06:59 +00005469 enum __lx
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005470 {
5471 relaxed,
5472 preferred,
5473 strict
5474 };
5475
Howard Hinnant9c0df142012-10-30 19:06:59 +00005476 __lx __v_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005477
Howard Hinnant82894812010-09-22 16:48:34 +00005478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9c0df142012-10-30 19:06:59 +00005479 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant82894812010-09-22 16:48:34 +00005480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005481 operator int() const {return __v_;}
5482};
5483
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005484_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5485_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5486_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5487_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5488_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005489
5490template <class _Tp>
5491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant324bb032010-08-22 00:02:43 +00005492_Tp*
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005493undeclare_reachable(_Tp* __p)
5494{
5495 return static_cast<_Tp*>(__undeclare_reachable(__p));
5496}
5497
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005498_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005499
5500_LIBCPP_END_NAMESPACE_STD
5501
5502#endif // _LIBCPP_MEMORY