blob: 93e8f67379bb0a7284ff709f5420ff34cd2872e0 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +000031
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U> using rebind = <details>;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000033
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 static pointer pointer_to(<details>);
35};
36
Howard Hinnant719bda32011-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 Hinnantc51e1022010-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 Hinnant8e4e6002010-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 Hinnantc51e1022010-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 Hinnant719bda32011-05-28 14:41:13 +000085 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantc51e1022010-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 Clow4f834b52013-08-27 20:22:15 +000093 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnantc51e1022010-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 Hinnant719bda32011-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 Hinnantc51e1022010-05-11 19:42:16 +0000130 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant719bda32011-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 Hinnantc51e1022010-05-11 19:42:16 +0000137};
138
139template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000140bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000141
142template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000143bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-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 Hinnant719bda32011-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 Hinnantc51e1022010-05-11 19:42:16 +0000165
166template <class InputIterator, class ForwardIterator>
167ForwardIterator
168uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
169
Howard Hinnant719bda32011-05-28 14:41:13 +0000170template <class InputIterator, class Size, class ForwardIterator>
171ForwardIterator
172uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
173
Howard Hinnantc51e1022010-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 Hinnant3c811092010-11-18 16:13:03 +0000178ForwardIterator
179uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantc51e1022010-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 Hinnantd26c01d2010-08-19 18:39:17 +0000208template <class T>
209struct default_delete
210{
Howard Hinnant719bda32011-05-28 14:41:13 +0000211 constexpr default_delete() noexcept = default;
212 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000213
Howard Hinnant719bda32011-05-28 14:41:13 +0000214 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000215};
216
217template <class T>
218struct default_delete<T[]>
219{
Howard Hinnant719bda32011-05-28 14:41:13 +0000220 constexpr default_delete() noexcept = default;
221 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000222 template <class U> void operator()(U*) const = delete;
223};
224
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000240 template <class U, class E>
Howard Hinnant719bda32011-05-28 14:41:13 +0000241 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000242 template <class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000243 unique_ptr(auto_ptr<U>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000244
245 // destructor
246 ~unique_ptr();
247
248 // assignment
Howard Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000252
253 // observers
254 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000260
261 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000262 pointer release() noexcept;
263 void reset(pointer p = pointer()) noexcept;
264 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000282
283 // destructor
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000284 ~unique_ptr();
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000285
286 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000287 unique_ptr& operator=(unique_ptr&& u) noexcept;
288 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000289
290 // observers
291 T& operator[](size_t i) const;
Howard Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000296
297 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000298 pointer release() noexcept;
299 void reset(pointer p = pointer()) noexcept;
300 void reset(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000301 template <class U> void reset(U) = delete;
Howard Hinnant719bda32011-05-28 14:41:13 +0000302 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000303};
304
305template <class T, class D>
Howard Hinnant719bda32011-05-28 14:41:13 +0000306 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000347class bad_weak_ptr
348 : public std::exception
349{
Howard Hinnant719bda32011-05-28 14:41:13 +0000350 bad_weak_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000351};
352
Marshall Clow9e8f4a92013-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 Hinnantd26c01d2010-08-19 18:39:17 +0000357template<class T>
358class shared_ptr
359{
360public:
361 typedef T element_type;
362
363 // constructors:
Howard Hinnant719bda32011-05-28 14:41:13 +0000364 constexpr shared_ptr() noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-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 Hinnant719bda32011-05-28 14:41:13 +0000392 void swap(shared_ptr& r) noexcept;
393 void reset() noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-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 Hinnant719bda32011-05-28 14:41:13 +0000411 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000412template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000413 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000414template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000415 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000416template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000417 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000418template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000419 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000420template<class T, class U>
Howard Hinnant719bda32011-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 Hinnantd26c01d2010-08-19 18:39:17 +0000447
448// shared_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000449template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000450
451// shared_ptr casts:
452template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000453 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000454template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000455 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000456template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000457 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-05-28 14:41:13 +0000464template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Clowe9b0a5c2014-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 Hinnantd26c01d2010-08-19 18:39:17 +0000484
485 // destructor
486 ~weak_ptr();
487
488 // assignment
Howard Hinnant719bda32011-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 Clowe9b0a5c2014-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 Hinnantd26c01d2010-08-19 18:39:17 +0000494
495 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000496 void swap(weak_ptr& r) noexcept;
497 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000498
499 // observers
Howard Hinnant719bda32011-05-28 14:41:13 +0000500 long use_count() const noexcept;
501 bool expired() const noexcept;
502 shared_ptr<T> lock() const noexcept;
Marshall Clow495e4a62013-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 Hinnantd26c01d2010-08-19 18:39:17 +0000505};
506
507// weak_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000508template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-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 Hinnant719bda32011-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 Hinnantd26c01d2010-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 Hinnant719bda32011-05-28 14:41:13 +0000588pointer_safety get_pointer_safety() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000589
Howard Hinnantc51e1022010-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 Hinnantdc095972011-07-18 15:51:59 +0000606#include <iosfwd>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000607#include <tuple>
Howard Hinnantd2cab2f2012-02-15 00:41:34 +0000608#include <cstring>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609#if defined(_LIBCPP_NO_EXCEPTIONS)
610 #include <cassert>
611#endif
612
Jonathan Roelofs39cb6bf2014-09-05 19:45:05 +0000613#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant9fa30202012-07-30 01:40:57 +0000614# include <atomic>
615#endif
616
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000617#include <__undef_min_max>
Saleem Abdulrasooldcf27a62015-02-13 22:15:32 +0000618#include <__undef___deallocate>
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000619
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000620#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000622#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623
624_LIBCPP_BEGIN_NAMESPACE_STD
625
Howard Hinnant8bea6da2013-08-08 18:38:55 +0000626// addressof moved to <__functional_base>
Douglas Gregor13034442011-06-22 22:17:44 +0000627
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628template <class _Tp> class allocator;
629
630template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000631class _LIBCPP_TYPE_VIS_ONLY allocator<void>
Howard Hinnantc51e1022010-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 Hinnant9f771052012-01-19 23:15:22 +0000641template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000642class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
Howard Hinnant9f771052012-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 Hinnantc51e1022010-05-11 19:42:16 +0000652// pointer_traits
653
654template <class _Tp>
655struct __has_element_type
656{
657private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000658 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000688#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000740#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741
742template <class _Tp>
743struct __has_difference_type
744{
745private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000746 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +0000769 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000804#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +0000874#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
876template <class _Ptr>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000877struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
Howard Hinnantc51e1022010-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 Hinnantf09283d2011-05-11 20:21:19 +0000884 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885#else
886 template <class _Up> struct rebind
887 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000888#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889
890private:
891 struct __nat {};
892public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnanta37d3cf2013-08-12 18:38:34 +0000900struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant719bda32011-05-28 14:41:13 +0000917 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000918 {return _VSTD::addressof(__r);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919};
920
921// allocator_traits
922
923namespace __has_pointer_type_imp
924{
Howard Hinnant6e260172013-09-21 01:45:05 +0000925 template <class _Up> static __two __test(...);
926 template <class _Up> static char __test(typename _Up::pointer* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927}
928
929template <class _Tp>
930struct __has_pointer_type
Howard Hinnant6e260172013-09-21 01:45:05 +0000931 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
Howard Hinnantc51e1022010-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 Hinnant8e4e6002010-11-18 01:40:00 +0000950} // __pointer_type_imp
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +0000962 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +0000989 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +00001016 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnantc834c512011-11-29 18:15:50 +00001039template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001041_Tp*
1042__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnantc51e1022010-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 Hinnant719bda32011-05-28 14:41:13 +00001050__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001052 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053}
1054
1055template <class _Tp>
1056struct __has_size_type
1057{
1058private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001059 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant8e4e6002010-11-18 01:40:00 +00001066template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067struct __size_type
1068{
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001069 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070};
1071
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001072template <class _Alloc, class _DiffType>
1073struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +00001082 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +00001105 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +00001128 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant49e145e2012-10-30 19:06:59 +00001151 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001184#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-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 Hinnantc51e1022010-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 Hinnantc51e1022010-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 Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001238#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001263#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264
1265template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1266struct __has_allocate_hint
1267 : true_type
1268{
1269};
1270
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001271#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272
Howard Hinnant986832c2011-07-29 21:35:53 +00001273#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274
1275template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001276decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1277 _VSTD::declval<_Args>()...),
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001354#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-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 Hinnantd2cab2f2012-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 Hinnant3b6579a2010-08-22 00:02:43 +00001372#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001392#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393
Howard Hinnant8e4e6002010-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 Hinnantc51e1022010-05-11 19:42:16 +00001406template <class _Alloc>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001407struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
Howard Hinnantc51e1022010-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 Hinnant8e4e6002010-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 Hinnantc51e1022010-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 Hinnantf09283d2011-05-11 20:21:19 +00001429 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001431#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001436#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437
Howard Hinnant756c69b2010-09-22 16:48:34 +00001438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439 static pointer allocate(allocator_type& __a, size_type __n)
1440 {return __a.allocate(__n);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +00001446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001447 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448 {__a.deallocate(__p, __n);}
1449
1450#ifndef _LIBCPP_HAS_NO_VARIADICS
1451 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow3996b8b2014-11-11 19:22:33 +00001454 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001455 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001456#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +00001464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +00001470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +00001477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant3b6579a2010-08-22 00:02:43 +00001483#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484
1485 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnant756c69b2010-09-22 16:48:34 +00001490 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4f834b52013-08-27 20:22:15 +00001491 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1493
Howard Hinnant756c69b2010-09-22 16:48:34 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-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 Hinnantd2cab2f2012-02-15 00:41:34 +00001501 template <class _Ptr>
1502 _LIBCPP_INLINE_VISIBILITY
1503 static
1504 void
1505 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1506 {
1507 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1508 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1509 }
1510
1511 template <class _Tp>
1512 _LIBCPP_INLINE_VISIBILITY
1513 static
1514 typename enable_if
1515 <
1516 (is_same<allocator_type, allocator<_Tp> >::value
1517 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1518 is_trivially_move_constructible<_Tp>::value,
1519 void
1520 >::type
1521 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1522 {
1523 ptrdiff_t _Np = __end1 - __begin1;
1524 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1525 __begin2 += _Np;
1526 }
1527
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001528 template <class _Iter, class _Ptr>
1529 _LIBCPP_INLINE_VISIBILITY
1530 static
1531 void
1532 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1533 {
1534 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1535 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1536 }
1537
1538 template <class _Tp>
1539 _LIBCPP_INLINE_VISIBILITY
1540 static
1541 typename enable_if
1542 <
1543 (is_same<allocator_type, allocator<_Tp> >::value
1544 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1545 is_trivially_move_constructible<_Tp>::value,
1546 void
1547 >::type
1548 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1549 {
1550 typedef typename remove_const<_Tp>::type _Vp;
1551 ptrdiff_t _Np = __end1 - __begin1;
1552 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1553 __begin2 += _Np;
1554 }
1555
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001556 template <class _Ptr>
1557 _LIBCPP_INLINE_VISIBILITY
1558 static
1559 void
1560 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1561 {
1562 while (__end1 != __begin1)
Howard Hinnant5adee4c2013-01-11 20:36:59 +00001563 {
1564 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1565 --__end2;
1566 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001567 }
1568
1569 template <class _Tp>
1570 _LIBCPP_INLINE_VISIBILITY
1571 static
1572 typename enable_if
1573 <
1574 (is_same<allocator_type, allocator<_Tp> >::value
1575 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1576 is_trivially_move_constructible<_Tp>::value,
1577 void
1578 >::type
1579 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1580 {
1581 ptrdiff_t _Np = __end1 - __begin1;
1582 __end2 -= _Np;
1583 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1584 }
1585
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586private:
1587
Howard Hinnant756c69b2010-09-22 16:48:34 +00001588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589 static pointer allocate(allocator_type& __a, size_type __n,
1590 const_void_pointer __hint, true_type)
1591 {return __a.allocate(__n, __hint);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnant28b24882011-12-01 20:21:04 +00001594 const_void_pointer, false_type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 {return __a.allocate(__n);}
1596
1597#ifndef _LIBCPP_HAS_NO_VARIADICS
1598 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001601 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1605 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001606 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001608#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609
1610 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1613 {__a.destroy(__p);}
1614 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001616 static void __destroy(false_type, allocator_type&, _Tp* __p)
1617 {
1618 __p->~_Tp();
1619 }
1620
Howard Hinnant756c69b2010-09-22 16:48:34 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001622 static size_type __max_size(true_type, const allocator_type& __a)
1623 {return __a.max_size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625 static size_type __max_size(false_type, const allocator_type&)
1626 {return numeric_limits<size_type>::max();}
1627
Howard Hinnant756c69b2010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629 static allocator_type
1630 select_on_container_copy_construction(true_type, const allocator_type& __a)
1631 {return __a.select_on_container_copy_construction();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633 static allocator_type
1634 select_on_container_copy_construction(false_type, const allocator_type& __a)
1635 {return __a;}
1636};
1637
Marshall Clow940e01c2015-04-07 05:21:38 +00001638template <class _Traits, class _Tp>
1639struct __rebind_alloc_helper
1640{
1641#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1642 typedef typename _Traits::template rebind_alloc<_Tp> type;
1643#else
1644 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1645#endif
1646};
1647
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648// allocator
1649
1650template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001651class _LIBCPP_TYPE_VIS_ONLY allocator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652{
1653public:
1654 typedef size_t size_type;
1655 typedef ptrdiff_t difference_type;
1656 typedef _Tp* pointer;
1657 typedef const _Tp* const_pointer;
1658 typedef _Tp& reference;
1659 typedef const _Tp& const_reference;
1660 typedef _Tp value_type;
1661
Howard Hinnant4931e092011-06-02 21:38:57 +00001662 typedef true_type propagate_on_container_move_assignment;
1663
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1665
Howard Hinnant719bda32011-05-28 14:41:13 +00001666 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1667 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1668 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001669 {return _VSTD::addressof(__x);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001670 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001671 {return _VSTD::addressof(__x);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith1f1c1472014-06-04 19:54:15 +00001673 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant719bda32011-05-28 14:41:13 +00001674 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith1f1c1472014-06-04 19:54:15 +00001675 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001676 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1677 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001678#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679 template <class _Up, class... _Args>
1680 _LIBCPP_INLINE_VISIBILITY
1681 void
1682 construct(_Up* __p, _Args&&... __args)
1683 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001684 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001686#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 _LIBCPP_INLINE_VISIBILITY
1688 void
1689 construct(pointer __p)
1690 {
1691 ::new((void*)__p) _Tp();
1692 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001693# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001694
Howard Hinnantc51e1022010-05-11 19:42:16 +00001695 template <class _A0>
1696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001697 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698 construct(pointer __p, _A0& __a0)
1699 {
1700 ::new((void*)__p) _Tp(__a0);
1701 }
1702 template <class _A0>
1703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001704 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705 construct(pointer __p, const _A0& __a0)
1706 {
1707 ::new((void*)__p) _Tp(__a0);
1708 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001709# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710 template <class _A0, class _A1>
1711 _LIBCPP_INLINE_VISIBILITY
1712 void
1713 construct(pointer __p, _A0& __a0, _A1& __a1)
1714 {
1715 ::new((void*)__p) _Tp(__a0, __a1);
1716 }
1717 template <class _A0, class _A1>
1718 _LIBCPP_INLINE_VISIBILITY
1719 void
1720 construct(pointer __p, const _A0& __a0, _A1& __a1)
1721 {
1722 ::new((void*)__p) _Tp(__a0, __a1);
1723 }
1724 template <class _A0, class _A1>
1725 _LIBCPP_INLINE_VISIBILITY
1726 void
1727 construct(pointer __p, _A0& __a0, const _A1& __a1)
1728 {
1729 ::new((void*)__p) _Tp(__a0, __a1);
1730 }
1731 template <class _A0, class _A1>
1732 _LIBCPP_INLINE_VISIBILITY
1733 void
1734 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1735 {
1736 ::new((void*)__p) _Tp(__a0, __a1);
1737 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001738#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1740};
1741
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001742template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001743class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001744{
1745public:
1746 typedef size_t size_type;
1747 typedef ptrdiff_t difference_type;
1748 typedef const _Tp* pointer;
1749 typedef const _Tp* const_pointer;
1750 typedef const _Tp& reference;
1751 typedef const _Tp& const_reference;
Howard Hinnant9bc95e22013-06-07 01:56:37 +00001752 typedef const _Tp value_type;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001753
1754 typedef true_type propagate_on_container_move_assignment;
1755
1756 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1757
1758 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1759 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1760 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1761 {return _VSTD::addressof(__x);}
1762 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Richard Smith1f1c1472014-06-04 19:54:15 +00001763 {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001764 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith1f1c1472014-06-04 19:54:15 +00001765 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001766 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1767 {return size_type(~0) / sizeof(_Tp);}
1768#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1769 template <class _Up, class... _Args>
1770 _LIBCPP_INLINE_VISIBILITY
1771 void
1772 construct(_Up* __p, _Args&&... __args)
1773 {
1774 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1775 }
1776#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1777 _LIBCPP_INLINE_VISIBILITY
1778 void
1779 construct(pointer __p)
1780 {
1781 ::new((void*)__p) _Tp();
1782 }
1783# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001784
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001785 template <class _A0>
1786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001787 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001788 construct(pointer __p, _A0& __a0)
1789 {
1790 ::new((void*)__p) _Tp(__a0);
1791 }
1792 template <class _A0>
1793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001794 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001795 construct(pointer __p, const _A0& __a0)
1796 {
1797 ::new((void*)__p) _Tp(__a0);
1798 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001799# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1800 template <class _A0, class _A1>
1801 _LIBCPP_INLINE_VISIBILITY
1802 void
1803 construct(pointer __p, _A0& __a0, _A1& __a1)
1804 {
1805 ::new((void*)__p) _Tp(__a0, __a1);
1806 }
1807 template <class _A0, class _A1>
1808 _LIBCPP_INLINE_VISIBILITY
1809 void
1810 construct(pointer __p, const _A0& __a0, _A1& __a1)
1811 {
1812 ::new((void*)__p) _Tp(__a0, __a1);
1813 }
1814 template <class _A0, class _A1>
1815 _LIBCPP_INLINE_VISIBILITY
1816 void
1817 construct(pointer __p, _A0& __a0, const _A1& __a1)
1818 {
1819 ::new((void*)__p) _Tp(__a0, __a1);
1820 }
1821 template <class _A0, class _A1>
1822 _LIBCPP_INLINE_VISIBILITY
1823 void
1824 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1825 {
1826 ::new((void*)__p) _Tp(__a0, __a1);
1827 }
1828#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1829 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1830};
1831
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832template <class _Tp, class _Up>
1833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001834bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001835
1836template <class _Tp, class _Up>
1837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001838bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839
1840template <class _OutputIterator, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001841class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842 : public iterator<output_iterator_tag,
1843 _Tp, // purposefully not C++03
1844 ptrdiff_t, // purposefully not C++03
1845 _Tp*, // purposefully not C++03
1846 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1847{
1848private:
1849 _OutputIterator __x_;
1850public:
1851 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1852 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1853 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1854 {::new(&*__x_) _Tp(__element); return *this;}
1855 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1856 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1857 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1858};
1859
1860template <class _Tp>
1861pair<_Tp*, ptrdiff_t>
Howard Hinnant719bda32011-05-28 14:41:13 +00001862get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863{
1864 pair<_Tp*, ptrdiff_t> __r(0, 0);
1865 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1866 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1867 / sizeof(_Tp);
1868 if (__n > __m)
1869 __n = __m;
1870 while (__n > 0)
1871 {
1872 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1873 if (__r.first)
1874 {
1875 __r.second = __n;
1876 break;
1877 }
1878 __n /= 2;
1879 }
1880 return __r;
1881}
1882
1883template <class _Tp>
1884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001885void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886
1887template <class _Tp>
1888struct auto_ptr_ref
1889{
1890 _Tp* __ptr_;
1891};
1892
1893template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001894class _LIBCPP_TYPE_VIS_ONLY auto_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895{
1896private:
1897 _Tp* __ptr_;
1898public:
1899 typedef _Tp element_type;
1900
1901 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1902 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1903 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1904 : __ptr_(__p.release()) {}
1905 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1906 {reset(__p.release()); return *this;}
1907 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1908 {reset(__p.release()); return *this;}
1909 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1910 {reset(__p.__ptr_); return *this;}
1911 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
1912
1913 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
1914 {return *__ptr_;}
1915 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
1916 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
1917 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
1918 {
1919 _Tp* __t = __ptr_;
1920 __ptr_ = 0;
1921 return __t;
1922 }
1923 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
1924 {
1925 if (__ptr_ != __p)
1926 delete __ptr_;
1927 __ptr_ = __p;
1928 }
1929
1930 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
1931 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
1932 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
1933 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
1934 {return auto_ptr<_Up>(release());}
1935};
1936
1937template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001938class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939{
1940public:
1941 typedef void element_type;
1942};
1943
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
1945 typename remove_cv<_T2>::type>::value,
Howard Hinnantd0aabf82011-12-11 20:31:33 +00001946 bool = is_empty<_T1>::value
1947#if __has_feature(is_final)
1948 && !__is_final(_T1)
1949#endif
1950 ,
1951 bool = is_empty<_T2>::value
1952#if __has_feature(is_final)
1953 && !__is_final(_T2)
1954#endif
1955 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001956struct __libcpp_compressed_pair_switch;
1957
1958template <class _T1, class _T2, bool IsSame>
1959struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
1960
1961template <class _T1, class _T2, bool IsSame>
1962struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
1963
1964template <class _T1, class _T2, bool IsSame>
1965struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
1966
1967template <class _T1, class _T2>
1968struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
1969
1970template <class _T1, class _T2>
1971struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
1972
1973template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
1974class __libcpp_compressed_pair_imp;
1975
1976template <class _T1, class _T2>
1977class __libcpp_compressed_pair_imp<_T1, _T2, 0>
1978{
1979private:
1980 _T1 __first_;
1981 _T2 __second_;
1982public:
1983 typedef _T1 _T1_param;
1984 typedef _T2 _T2_param;
1985
1986 typedef typename remove_reference<_T1>::type& _T1_reference;
1987 typedef typename remove_reference<_T2>::type& _T2_reference;
1988
1989 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
1990 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
1991
1992 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001993 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001994 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001995 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001996 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001998 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001999
Howard Hinnant59f73012013-11-13 00:39:22 +00002000#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002001
2002 _LIBCPP_INLINE_VISIBILITY
2003 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2004 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2005 is_nothrow_copy_constructible<_T2>::value)
2006 : __first_(__p.first()),
2007 __second_(__p.second()) {}
2008
2009 _LIBCPP_INLINE_VISIBILITY
2010 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2011 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2012 is_nothrow_copy_assignable<_T2>::value)
2013 {
2014 __first_ = __p.first();
2015 __second_ = __p.second();
2016 return *this;
2017 }
2018
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002019 _LIBCPP_INLINE_VISIBILITY
2020 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002021 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2022 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002023 : __first_(_VSTD::forward<_T1>(__p.first())),
2024 __second_(_VSTD::forward<_T2>(__p.second())) {}
2025
2026 _LIBCPP_INLINE_VISIBILITY
2027 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2028 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2029 is_nothrow_move_assignable<_T2>::value)
2030 {
2031 __first_ = _VSTD::forward<_T1>(__p.first());
2032 __second_ = _VSTD::forward<_T2>(__p.second());
2033 return *this;
2034 }
2035
Howard Hinnant59f73012013-11-13 00:39:22 +00002036#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002037
Howard Hinnant83b1c052011-12-19 17:58:44 +00002038#ifndef _LIBCPP_HAS_NO_VARIADICS
2039
2040 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2041 _LIBCPP_INLINE_VISIBILITY
2042 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2043 tuple<_Args1...> __first_args,
2044 tuple<_Args2...> __second_args,
2045 __tuple_indices<_I1...>,
2046 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002047 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2048 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002049 {}
2050
2051#endif // _LIBCPP_HAS_NO_VARIADICS
2052
Howard Hinnant719bda32011-05-28 14:41:13 +00002053 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2054 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002055
Howard Hinnant719bda32011-05-28 14:41:13 +00002056 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2057 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002058
2059 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002060 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002061 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002063 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002064 swap(__first_, __x.__first_);
2065 swap(__second_, __x.__second_);
2066 }
2067};
2068
2069template <class _T1, class _T2>
2070class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2071 : private _T1
2072{
2073private:
2074 _T2 __second_;
2075public:
2076 typedef _T1 _T1_param;
2077 typedef _T2 _T2_param;
2078
2079 typedef _T1& _T1_reference;
2080 typedef typename remove_reference<_T2>::type& _T2_reference;
2081
2082 typedef const _T1& _T1_const_reference;
2083 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2084
2085 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002086 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002087 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002088 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002089 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002090 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002091 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092
Howard Hinnant59f73012013-11-13 00:39:22 +00002093#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002094
2095 _LIBCPP_INLINE_VISIBILITY
2096 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2097 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2098 is_nothrow_copy_constructible<_T2>::value)
2099 : _T1(__p.first()), __second_(__p.second()) {}
2100
2101 _LIBCPP_INLINE_VISIBILITY
2102 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2103 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2104 is_nothrow_copy_assignable<_T2>::value)
2105 {
2106 _T1::operator=(__p.first());
2107 __second_ = __p.second();
2108 return *this;
2109 }
2110
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002111 _LIBCPP_INLINE_VISIBILITY
2112 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002113 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2114 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002115 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002116
2117 _LIBCPP_INLINE_VISIBILITY
2118 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2119 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2120 is_nothrow_move_assignable<_T2>::value)
2121 {
2122 _T1::operator=(_VSTD::move(__p.first()));
2123 __second_ = _VSTD::forward<_T2>(__p.second());
2124 return *this;
2125 }
2126
Howard Hinnant59f73012013-11-13 00:39:22 +00002127#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002128
Howard Hinnant83b1c052011-12-19 17:58:44 +00002129#ifndef _LIBCPP_HAS_NO_VARIADICS
2130
2131 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2132 _LIBCPP_INLINE_VISIBILITY
2133 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2134 tuple<_Args1...> __first_args,
2135 tuple<_Args2...> __second_args,
2136 __tuple_indices<_I1...>,
2137 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002138 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2139 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002140 {}
2141
2142#endif // _LIBCPP_HAS_NO_VARIADICS
2143
Howard Hinnant719bda32011-05-28 14:41:13 +00002144 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2145 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002146
Howard Hinnant719bda32011-05-28 14:41:13 +00002147 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2148 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002149
2150 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002151 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002152 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002154 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 swap(__second_, __x.__second_);
2156 }
2157};
2158
2159template <class _T1, class _T2>
2160class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2161 : private _T2
2162{
2163private:
2164 _T1 __first_;
2165public:
2166 typedef _T1 _T1_param;
2167 typedef _T2 _T2_param;
2168
2169 typedef typename remove_reference<_T1>::type& _T1_reference;
2170 typedef _T2& _T2_reference;
2171
2172 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2173 typedef const _T2& _T2_const_reference;
2174
2175 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2176 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002177 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002178 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002179 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant719bda32011-05-28 14:41:13 +00002181 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2182 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002183 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184
Howard Hinnant59f73012013-11-13 00:39:22 +00002185#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002186
2187 _LIBCPP_INLINE_VISIBILITY
2188 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2189 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2190 is_nothrow_copy_constructible<_T2>::value)
2191 : _T2(__p.second()), __first_(__p.first()) {}
2192
2193 _LIBCPP_INLINE_VISIBILITY
2194 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2195 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2196 is_nothrow_copy_assignable<_T2>::value)
2197 {
2198 _T2::operator=(__p.second());
2199 __first_ = __p.first();
2200 return *this;
2201 }
2202
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002204 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002205 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2206 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002207 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002208
2209 _LIBCPP_INLINE_VISIBILITY
2210 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2211 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2212 is_nothrow_move_assignable<_T2>::value)
2213 {
2214 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2215 __first_ = _VSTD::move(__p.first());
2216 return *this;
2217 }
2218
Howard Hinnant59f73012013-11-13 00:39:22 +00002219#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002220
Howard Hinnant83b1c052011-12-19 17:58:44 +00002221#ifndef _LIBCPP_HAS_NO_VARIADICS
2222
2223 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2224 _LIBCPP_INLINE_VISIBILITY
2225 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2226 tuple<_Args1...> __first_args,
2227 tuple<_Args2...> __second_args,
2228 __tuple_indices<_I1...>,
2229 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002230 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2231 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002232
2233 {}
2234
2235#endif // _LIBCPP_HAS_NO_VARIADICS
2236
Howard Hinnant719bda32011-05-28 14:41:13 +00002237 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2238 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002239
Howard Hinnant719bda32011-05-28 14:41:13 +00002240 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2241 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002242
2243 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002244 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002245 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002246 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002247 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002248 swap(__first_, __x.__first_);
2249 }
2250};
2251
2252template <class _T1, class _T2>
2253class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2254 : private _T1,
2255 private _T2
2256{
2257public:
2258 typedef _T1 _T1_param;
2259 typedef _T2 _T2_param;
2260
2261 typedef _T1& _T1_reference;
2262 typedef _T2& _T2_reference;
2263
2264 typedef const _T1& _T1_const_reference;
2265 typedef const _T2& _T2_const_reference;
2266
2267 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2268 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002269 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002270 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002271 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002272 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002273 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274
Howard Hinnant59f73012013-11-13 00:39:22 +00002275#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002276
2277 _LIBCPP_INLINE_VISIBILITY
2278 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2279 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2280 is_nothrow_copy_constructible<_T2>::value)
2281 : _T1(__p.first()), _T2(__p.second()) {}
2282
2283 _LIBCPP_INLINE_VISIBILITY
2284 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2285 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2286 is_nothrow_copy_assignable<_T2>::value)
2287 {
2288 _T1::operator=(__p.first());
2289 _T2::operator=(__p.second());
2290 return *this;
2291 }
2292
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002293 _LIBCPP_INLINE_VISIBILITY
2294 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002295 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2296 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002297 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002298
2299 _LIBCPP_INLINE_VISIBILITY
2300 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2301 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2302 is_nothrow_move_assignable<_T2>::value)
2303 {
2304 _T1::operator=(_VSTD::move(__p.first()));
2305 _T2::operator=(_VSTD::move(__p.second()));
2306 return *this;
2307 }
2308
Howard Hinnant59f73012013-11-13 00:39:22 +00002309#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002310
Howard Hinnant83b1c052011-12-19 17:58:44 +00002311#ifndef _LIBCPP_HAS_NO_VARIADICS
2312
2313 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2314 _LIBCPP_INLINE_VISIBILITY
2315 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2316 tuple<_Args1...> __first_args,
2317 tuple<_Args2...> __second_args,
2318 __tuple_indices<_I1...>,
2319 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002320 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2321 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002322 {}
2323
2324#endif // _LIBCPP_HAS_NO_VARIADICS
2325
Howard Hinnant719bda32011-05-28 14:41:13 +00002326 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2327 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002328
Howard Hinnant719bda32011-05-28 14:41:13 +00002329 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2330 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002331
Howard Hinnant28b24882011-12-01 20:21:04 +00002332 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant719bda32011-05-28 14:41:13 +00002333 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002334 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002335 {
2336 }
2337};
2338
2339template <class _T1, class _T2>
2340class __compressed_pair
2341 : private __libcpp_compressed_pair_imp<_T1, _T2>
2342{
2343 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2344public:
2345 typedef typename base::_T1_param _T1_param;
2346 typedef typename base::_T2_param _T2_param;
2347
2348 typedef typename base::_T1_reference _T1_reference;
2349 typedef typename base::_T2_reference _T2_reference;
2350
2351 typedef typename base::_T1_const_reference _T1_const_reference;
2352 typedef typename base::_T2_const_reference _T2_const_reference;
2353
2354 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002355 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002356 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002357 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002358 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002359 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002360 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002361
Howard Hinnant59f73012013-11-13 00:39:22 +00002362#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002363
2364 _LIBCPP_INLINE_VISIBILITY
2365 __compressed_pair(const __compressed_pair& __p)
2366 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2367 is_nothrow_copy_constructible<_T2>::value)
2368 : base(__p) {}
2369
2370 _LIBCPP_INLINE_VISIBILITY
2371 __compressed_pair& operator=(const __compressed_pair& __p)
2372 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2373 is_nothrow_copy_assignable<_T2>::value)
2374 {
2375 base::operator=(__p);
2376 return *this;
2377 }
2378
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002380 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002381 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2382 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002383 : base(_VSTD::move(__p)) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002384
2385 _LIBCPP_INLINE_VISIBILITY
2386 __compressed_pair& operator=(__compressed_pair&& __p)
2387 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2388 is_nothrow_move_assignable<_T2>::value)
2389 {
2390 base::operator=(_VSTD::move(__p));
2391 return *this;
2392 }
Howard Hinnant83b1c052011-12-19 17:58:44 +00002393
Howard Hinnant59f73012013-11-13 00:39:22 +00002394#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002395
Howard Hinnant83b1c052011-12-19 17:58:44 +00002396#ifndef _LIBCPP_HAS_NO_VARIADICS
2397
2398 template <class... _Args1, class... _Args2>
2399 _LIBCPP_INLINE_VISIBILITY
2400 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2401 tuple<_Args2...> __second_args)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002402 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant83b1c052011-12-19 17:58:44 +00002403 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2404 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2405 {}
2406
2407#endif // _LIBCPP_HAS_NO_VARIADICS
2408
Howard Hinnant719bda32011-05-28 14:41:13 +00002409 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2410 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002411
Howard Hinnant719bda32011-05-28 14:41:13 +00002412 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2413 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002414
Howard Hinnant719bda32011-05-28 14:41:13 +00002415 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2416 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002417 __is_nothrow_swappable<_T2>::value)
Howard Hinnant719bda32011-05-28 14:41:13 +00002418 {base::swap(__x);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002419};
2420
2421template <class _T1, class _T2>
2422inline _LIBCPP_INLINE_VISIBILITY
2423void
2424swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant719bda32011-05-28 14:41:13 +00002425 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002426 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002427 {__x.swap(__y);}
2428
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002429// __same_or_less_cv_qualified
2430
2431template <class _Ptr1, class _Ptr2,
2432 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2433 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2434 >::value
2435 >
2436struct __same_or_less_cv_qualified_imp
2437 : is_convertible<_Ptr1, _Ptr2> {};
2438
2439template <class _Ptr1, class _Ptr2>
2440struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2441 : false_type {};
2442
Marshall Clowdf296162014-04-26 05:19:48 +00002443template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2444 is_same<_Ptr1, _Ptr2>::value ||
2445 __has_element_type<_Ptr1>::value>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002446struct __same_or_less_cv_qualified
2447 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2448
2449template <class _Ptr1, class _Ptr2>
Marshall Clowdf296162014-04-26 05:19:48 +00002450struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002451 : false_type {};
2452
2453// default_delete
2454
Howard Hinnantc51e1022010-05-11 19:42:16 +00002455template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002456struct _LIBCPP_TYPE_VIS_ONLY default_delete
Howard Hinnantc51e1022010-05-11 19:42:16 +00002457{
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002458#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2459 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2460#else
2461 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2462#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002463 template <class _Up>
2464 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant719bda32011-05-28 14:41:13 +00002465 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2466 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002467 {
2468 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant14015fd2013-04-24 19:44:26 +00002469 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002470 delete __ptr;
2471 }
2472};
2473
2474template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002475struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002476{
Howard Hinnant4500ca52011-12-18 21:19:44 +00002477public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002478#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2479 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2480#else
2481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2482#endif
Howard Hinnant4500ca52011-12-18 21:19:44 +00002483 template <class _Up>
2484 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002485 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant4500ca52011-12-18 21:19:44 +00002486 template <class _Up>
2487 _LIBCPP_INLINE_VISIBILITY
2488 void operator() (_Up* __ptr,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002489 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002490 {
2491 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant14015fd2013-04-24 19:44:26 +00002492 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002493 delete [] __ptr;
2494 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002495};
2496
2497template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002498class _LIBCPP_TYPE_VIS_ONLY unique_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00002499{
2500public:
2501 typedef _Tp element_type;
2502 typedef _Dp deleter_type;
2503 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2504private:
2505 __compressed_pair<pointer, deleter_type> __ptr_;
2506
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002507#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002508 unique_ptr(unique_ptr&);
2509 template <class _Up, class _Ep>
2510 unique_ptr(unique_ptr<_Up, _Ep>&);
2511 unique_ptr& operator=(unique_ptr&);
2512 template <class _Up, class _Ep>
2513 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant74279a52010-09-04 23:28:19 +00002514#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002515
2516 struct __nat {int __for_bool_;};
2517
2518 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2519 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2520public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002521 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002522 : __ptr_(pointer())
2523 {
2524 static_assert(!is_pointer<deleter_type>::value,
2525 "unique_ptr constructed with null function pointer deleter");
2526 }
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002527 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-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 Hinnant719bda32011-05-28 14:41:13 +00002533 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002534 : __ptr_(_VSTD::move(__p))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002535 {
2536 static_assert(!is_pointer<deleter_type>::value,
2537 "unique_ptr constructed with null function pointer deleter");
2538 }
2539
Howard Hinnant74279a52010-09-04 23:28:19 +00002540#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002541 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2542 is_reference<deleter_type>::value,
2543 deleter_type,
2544 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002545 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002546 : __ptr_(__p, __d) {}
2547
2548 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002549 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002550 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002551 {
2552 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2553 }
Howard Hinnant719bda32011-05-28 14:41:13 +00002554 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002555 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002556 template <class _Up, class _Ep>
2557 _LIBCPP_INLINE_VISIBILITY
2558 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2559 typename enable_if
2560 <
2561 !is_array<_Up>::value &&
2562 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2563 is_convertible<_Ep, deleter_type>::value &&
2564 (
2565 !is_reference<deleter_type>::value ||
2566 is_same<deleter_type, _Ep>::value
2567 ),
2568 __nat
Howard Hinnant719bda32011-05-28 14:41:13 +00002569 >::type = __nat()) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002570 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002571
2572 template <class _Up>
2573 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2574 typename enable_if<
2575 is_convertible<_Up*, _Tp*>::value &&
2576 is_same<_Dp, default_delete<_Tp> >::value,
2577 __nat
Howard Hinnant719bda32011-05-28 14:41:13 +00002578 >::type = __nat()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579 : __ptr_(__p.release())
2580 {
2581 }
2582
Howard Hinnant719bda32011-05-28 14:41:13 +00002583 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002584 {
2585 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002586 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002587 return *this;
2588 }
2589
2590 template <class _Up, class _Ep>
2591 _LIBCPP_INLINE_VISIBILITY
2592 typename enable_if
2593 <
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002594 !is_array<_Up>::value &&
2595 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2596 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597 unique_ptr&
2598 >::type
Howard Hinnant719bda32011-05-28 14:41:13 +00002599 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002600 {
2601 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002602 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603 return *this;
2604 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002605#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002606
2607 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2608 {
2609 return __rv<unique_ptr>(*this);
2610 }
2611
2612 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002613 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002614
2615 template <class _Up, class _Ep>
2616 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr<_Up, _Ep> __u)
2617 {
2618 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002619 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002620 return *this;
2621 }
2622
2623 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002624 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002625
2626 template <class _Up>
2627 _LIBCPP_INLINE_VISIBILITY
2628 typename enable_if<
2629 is_convertible<_Up*, _Tp*>::value &&
2630 is_same<_Dp, default_delete<_Tp> >::value,
2631 unique_ptr&
2632 >::type
2633 operator=(auto_ptr<_Up> __p)
2634 {reset(__p.release()); return *this;}
2635
Howard Hinnant74279a52010-09-04 23:28:19 +00002636#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002637 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2638
Howard Hinnant719bda32011-05-28 14:41:13 +00002639 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002640 {
2641 reset();
2642 return *this;
2643 }
2644
2645 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2646 {return *__ptr_.first();}
Howard Hinnant719bda32011-05-28 14:41:13 +00002647 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2648 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2649 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2650 {return __ptr_.second();}
2651 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2652 {return __ptr_.second();}
Howard Hinnant86a291f2012-02-21 21:46:43 +00002653 _LIBCPP_INLINE_VISIBILITY
2654 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2655 {return __ptr_.first() != nullptr;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002656
Howard Hinnant719bda32011-05-28 14:41:13 +00002657 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002658 {
2659 pointer __t = __ptr_.first();
2660 __ptr_.first() = pointer();
2661 return __t;
2662 }
2663
Howard Hinnant719bda32011-05-28 14:41:13 +00002664 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002665 {
2666 pointer __tmp = __ptr_.first();
2667 __ptr_.first() = __p;
2668 if (__tmp)
2669 __ptr_.second()(__tmp);
2670 }
2671
Howard Hinnant719bda32011-05-28 14:41:13 +00002672 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2673 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674};
2675
2676template <class _Tp, class _Dp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002677class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002678{
2679public:
2680 typedef _Tp element_type;
2681 typedef _Dp deleter_type;
2682 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2683private:
2684 __compressed_pair<pointer, deleter_type> __ptr_;
2685
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002686#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002687 unique_ptr(unique_ptr&);
2688 template <class _Up>
2689 unique_ptr(unique_ptr<_Up>&);
2690 unique_ptr& operator=(unique_ptr&);
2691 template <class _Up>
2692 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant74279a52010-09-04 23:28:19 +00002693#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002694
2695 struct __nat {int __for_bool_;};
2696
2697 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2698 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2699public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002701 : __ptr_(pointer())
2702 {
2703 static_assert(!is_pointer<deleter_type>::value,
2704 "unique_ptr constructed with null function pointer deleter");
2705 }
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002706 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-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 Hinnant74279a52010-09-04 23:28:19 +00002712#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00002713 template <class _Pp>
2714 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2715 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002716 : __ptr_(__p)
2717 {
2718 static_assert(!is_pointer<deleter_type>::value,
2719 "unique_ptr constructed with null function pointer deleter");
2720 }
2721
Logan Chiend435f8b2014-01-31 09:30:46 +00002722 template <class _Pp>
Howard Hinnantc834c512011-11-29 18:15:50 +00002723 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantc51e1022010-05-11 19:42:16 +00002724 is_reference<deleter_type>::value,
2725 deleter_type,
Logan Chiend435f8b2014-01-31 09:30:46 +00002726 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2727 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00002728 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729 : __ptr_(__p, __d) {}
2730
2731 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2732 is_reference<deleter_type>::value,
2733 deleter_type,
2734 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002735 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736 : __ptr_(pointer(), __d) {}
2737
Logan Chiend435f8b2014-01-31 09:30:46 +00002738 template <class _Pp>
2739 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2740 typename remove_reference<deleter_type>::type&& __d,
2741 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00002742 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002743 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002744 {
2745 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2746 }
2747
2748 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002749 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002750 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002751 {
2752 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2753 }
2754
Howard Hinnant719bda32011-05-28 14:41:13 +00002755 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002756 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002757
Howard Hinnant719bda32011-05-28 14:41:13 +00002758 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002759 {
2760 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002761 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002762 return *this;
2763 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002764
2765 template <class _Up, class _Ep>
2766 _LIBCPP_INLINE_VISIBILITY
2767 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2768 typename enable_if
2769 <
2770 is_array<_Up>::value &&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002771 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant4500ca52011-12-18 21:19:44 +00002772 && is_convertible<_Ep, deleter_type>::value &&
2773 (
2774 !is_reference<deleter_type>::value ||
2775 is_same<deleter_type, _Ep>::value
2776 ),
2777 __nat
2778 >::type = __nat()
2779 ) _NOEXCEPT
2780 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2781
2782
2783 template <class _Up, class _Ep>
2784 _LIBCPP_INLINE_VISIBILITY
2785 typename enable_if
2786 <
2787 is_array<_Up>::value &&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002788 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2789 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant4500ca52011-12-18 21:19:44 +00002790 unique_ptr&
2791 >::type
2792 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2793 {
2794 reset(__u.release());
2795 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2796 return *this;
2797 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002798#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002799
2800 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2801 : __ptr_(__p)
2802 {
2803 static_assert(!is_pointer<deleter_type>::value,
2804 "unique_ptr constructed with null function pointer deleter");
2805 }
2806
2807 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002808 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002809
2810 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002811 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002812
2813 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2814 {
2815 return __rv<unique_ptr>(*this);
2816 }
2817
2818 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002819 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002820
2821 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2822 {
2823 reset(__u->release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002824 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002825 return *this;
2826 }
2827
Howard Hinnant74279a52010-09-04 23:28:19 +00002828#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002829 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2830
Howard Hinnant719bda32011-05-28 14:41:13 +00002831 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002832 {
2833 reset();
2834 return *this;
2835 }
2836
2837 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2838 {return __ptr_.first()[__i];}
Howard Hinnant719bda32011-05-28 14:41:13 +00002839 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2840 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2841 {return __ptr_.second();}
2842 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2843 {return __ptr_.second();}
Howard Hinnant86a291f2012-02-21 21:46:43 +00002844 _LIBCPP_INLINE_VISIBILITY
2845 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2846 {return __ptr_.first() != nullptr;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002847
Howard Hinnant719bda32011-05-28 14:41:13 +00002848 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002849 {
2850 pointer __t = __ptr_.first();
2851 __ptr_.first() = pointer();
2852 return __t;
2853 }
2854
Howard Hinnant74279a52010-09-04 23:28:19 +00002855#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00002856 template <class _Pp>
2857 _LIBCPP_INLINE_VISIBILITY
2858 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2859 reset(_Pp __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002860 {
2861 pointer __tmp = __ptr_.first();
2862 __ptr_.first() = __p;
2863 if (__tmp)
2864 __ptr_.second()(__tmp);
2865 }
Howard Hinnant719bda32011-05-28 14:41:13 +00002866 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867 {
2868 pointer __tmp = __ptr_.first();
2869 __ptr_.first() = nullptr;
2870 if (__tmp)
2871 __ptr_.second()(__tmp);
2872 }
Howard Hinnant719bda32011-05-28 14:41:13 +00002873 _LIBCPP_INLINE_VISIBILITY void reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002874 {
2875 pointer __tmp = __ptr_.first();
2876 __ptr_.first() = nullptr;
2877 if (__tmp)
2878 __ptr_.second()(__tmp);
2879 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002880#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002881 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer())
2882 {
2883 pointer __tmp = __ptr_.first();
2884 __ptr_.first() = __p;
2885 if (__tmp)
2886 __ptr_.second()(__tmp);
2887 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002888#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002889
2890 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2891private:
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002892
Howard Hinnant74279a52010-09-04 23:28:19 +00002893#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894 template <class _Up>
2895 explicit unique_ptr(_Up);
2896 template <class _Up>
2897 unique_ptr(_Up __u,
2898 typename conditional<
2899 is_reference<deleter_type>::value,
2900 deleter_type,
2901 typename add_lvalue_reference<const deleter_type>::type>::type,
2902 typename enable_if
2903 <
2904 is_convertible<_Up, pointer>::value,
2905 __nat
2906 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00002907#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002908};
2909
2910template <class _Tp, class _Dp>
2911inline _LIBCPP_INLINE_VISIBILITY
2912void
Howard Hinnant719bda32011-05-28 14:41:13 +00002913swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002914
2915template <class _T1, class _D1, class _T2, class _D2>
2916inline _LIBCPP_INLINE_VISIBILITY
2917bool
2918operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2919
2920template <class _T1, class _D1, class _T2, class _D2>
2921inline _LIBCPP_INLINE_VISIBILITY
2922bool
2923operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2924
2925template <class _T1, class _D1, class _T2, class _D2>
2926inline _LIBCPP_INLINE_VISIBILITY
2927bool
Howard Hinnantb17caf92012-02-21 21:02:58 +00002928operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2929{
2930 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2931 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselierf8898c82015-02-05 23:01:40 +00002932 typedef typename common_type<_P1, _P2>::type _Vp;
2933 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00002934}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002935
2936template <class _T1, class _D1, class _T2, class _D2>
2937inline _LIBCPP_INLINE_VISIBILITY
2938bool
2939operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2940
2941template <class _T1, class _D1, class _T2, class _D2>
2942inline _LIBCPP_INLINE_VISIBILITY
2943bool
2944operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2945
2946template <class _T1, class _D1, class _T2, class _D2>
2947inline _LIBCPP_INLINE_VISIBILITY
2948bool
2949operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2950
Howard Hinnantb17caf92012-02-21 21:02:58 +00002951template <class _T1, class _D1>
2952inline _LIBCPP_INLINE_VISIBILITY
2953bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002954operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002955{
2956 return !__x;
2957}
2958
2959template <class _T1, class _D1>
2960inline _LIBCPP_INLINE_VISIBILITY
2961bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002962operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002963{
2964 return !__x;
2965}
2966
2967template <class _T1, class _D1>
2968inline _LIBCPP_INLINE_VISIBILITY
2969bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002970operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002971{
2972 return static_cast<bool>(__x);
2973}
2974
2975template <class _T1, class _D1>
2976inline _LIBCPP_INLINE_VISIBILITY
2977bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002978operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002979{
2980 return static_cast<bool>(__x);
2981}
2982
2983template <class _T1, class _D1>
2984inline _LIBCPP_INLINE_VISIBILITY
2985bool
2986operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2987{
2988 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2989 return less<_P1>()(__x.get(), nullptr);
2990}
2991
2992template <class _T1, class _D1>
2993inline _LIBCPP_INLINE_VISIBILITY
2994bool
2995operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2996{
2997 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2998 return less<_P1>()(nullptr, __x.get());
2999}
3000
3001template <class _T1, class _D1>
3002inline _LIBCPP_INLINE_VISIBILITY
3003bool
3004operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3005{
3006 return nullptr < __x;
3007}
3008
3009template <class _T1, class _D1>
3010inline _LIBCPP_INLINE_VISIBILITY
3011bool
3012operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3013{
3014 return __x < nullptr;
3015}
3016
3017template <class _T1, class _D1>
3018inline _LIBCPP_INLINE_VISIBILITY
3019bool
3020operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3021{
3022 return !(nullptr < __x);
3023}
3024
3025template <class _T1, class _D1>
3026inline _LIBCPP_INLINE_VISIBILITY
3027bool
3028operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3029{
3030 return !(__x < nullptr);
3031}
3032
3033template <class _T1, class _D1>
3034inline _LIBCPP_INLINE_VISIBILITY
3035bool
3036operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3037{
3038 return !(__x < nullptr);
3039}
3040
3041template <class _T1, class _D1>
3042inline _LIBCPP_INLINE_VISIBILITY
3043bool
3044operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3045{
3046 return !(nullptr < __x);
3047}
3048
Howard Hinnant9e028f12012-05-01 15:37:54 +00003049#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3050
3051template <class _Tp, class _Dp>
3052inline _LIBCPP_INLINE_VISIBILITY
3053unique_ptr<_Tp, _Dp>
3054move(unique_ptr<_Tp, _Dp>& __t)
3055{
3056 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3057}
3058
3059#endif
3060
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003061#if _LIBCPP_STD_VER > 11
3062
3063template<class _Tp>
3064struct __unique_if
3065{
3066 typedef unique_ptr<_Tp> __unique_single;
3067};
3068
3069template<class _Tp>
3070struct __unique_if<_Tp[]>
3071{
3072 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3073};
3074
3075template<class _Tp, size_t _Np>
3076struct __unique_if<_Tp[_Np]>
3077{
3078 typedef void __unique_array_known_bound;
3079};
3080
3081template<class _Tp, class... _Args>
Marshall Clow724e3df2013-07-02 20:06:09 +00003082inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003083typename __unique_if<_Tp>::__unique_single
3084make_unique(_Args&&... __args)
3085{
3086 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3087}
3088
3089template<class _Tp>
Marshall Clow724e3df2013-07-02 20:06:09 +00003090inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003091typename __unique_if<_Tp>::__unique_array_unknown_bound
3092make_unique(size_t __n)
3093{
3094 typedef typename remove_extent<_Tp>::type _Up;
3095 return unique_ptr<_Tp>(new _Up[__n]());
3096}
3097
3098template<class _Tp, class... _Args>
3099 typename __unique_if<_Tp>::__unique_array_known_bound
3100 make_unique(_Args&&...) = delete;
3101
3102#endif // _LIBCPP_STD_VER > 11
3103
Howard Hinnant944510a2011-06-14 19:58:17 +00003104template <class _Tp> struct hash;
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003105
Howard Hinnant6a855442013-07-03 17:39:28 +00003106template <class _Size>
3107inline _LIBCPP_INLINE_VISIBILITY
3108_Size
3109__loadword(const void* __p)
3110{
3111 _Size __r;
3112 std::memcpy(&__r, __p, sizeof(__r));
3113 return __r;
3114}
3115
Howard Hinnantf1973402011-12-10 20:28:56 +00003116// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3117// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3118// multiplication, which can be very slow on 32-bit systems.
Howard Hinnantad71c232011-12-05 00:08:45 +00003119template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantf1973402011-12-10 20:28:56 +00003120struct __murmur2_or_cityhash;
Howard Hinnantad71c232011-12-05 00:08:45 +00003121
3122template <class _Size>
Howard Hinnantf1973402011-12-10 20:28:56 +00003123struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnantad71c232011-12-05 00:08:45 +00003124{
3125 _Size operator()(const void* __key, _Size __len);
3126};
3127
Howard Hinnantf1973402011-12-10 20:28:56 +00003128// murmur2
Howard Hinnantad71c232011-12-05 00:08:45 +00003129template <class _Size>
3130_Size
Howard Hinnantf1973402011-12-10 20:28:56 +00003131__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
Howard Hinnantad71c232011-12-05 00:08:45 +00003132{
3133 const _Size __m = 0x5bd1e995;
3134 const _Size __r = 24;
3135 _Size __h = __len;
3136 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3137 for (; __len >= 4; __data += 4, __len -= 4)
3138 {
Howard Hinnant6a855442013-07-03 17:39:28 +00003139 _Size __k = __loadword<_Size>(__data);
Howard Hinnantad71c232011-12-05 00:08:45 +00003140 __k *= __m;
3141 __k ^= __k >> __r;
3142 __k *= __m;
3143 __h *= __m;
3144 __h ^= __k;
3145 }
3146 switch (__len)
3147 {
3148 case 3:
3149 __h ^= __data[2] << 16;
3150 case 2:
3151 __h ^= __data[1] << 8;
3152 case 1:
3153 __h ^= __data[0];
3154 __h *= __m;
3155 }
3156 __h ^= __h >> 13;
3157 __h *= __m;
3158 __h ^= __h >> 15;
3159 return __h;
3160}
3161
3162template <class _Size>
Howard Hinnantf1973402011-12-10 20:28:56 +00003163struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnantad71c232011-12-05 00:08:45 +00003164{
3165 _Size operator()(const void* __key, _Size __len);
Howard Hinnantf1973402011-12-10 20:28:56 +00003166
3167 private:
3168 // Some primes between 2^63 and 2^64.
3169 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3170 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3171 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3172 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3173
3174 static _Size __rotate(_Size __val, int __shift) {
3175 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3176 }
3177
3178 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3179 return (__val >> __shift) | (__val << (64 - __shift));
3180 }
3181
3182 static _Size __shift_mix(_Size __val) {
3183 return __val ^ (__val >> 47);
3184 }
3185
3186 static _Size __hash_len_16(_Size __u, _Size __v) {
3187 const _Size __mul = 0x9ddfea08eb382d69ULL;
3188 _Size __a = (__u ^ __v) * __mul;
3189 __a ^= (__a >> 47);
3190 _Size __b = (__v ^ __a) * __mul;
3191 __b ^= (__b >> 47);
3192 __b *= __mul;
3193 return __b;
3194 }
3195
3196 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3197 if (__len > 8) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003198 const _Size __a = __loadword<_Size>(__s);
3199 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003200 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3201 }
3202 if (__len >= 4) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003203 const uint32_t __a = __loadword<uint32_t>(__s);
3204 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnantf1973402011-12-10 20:28:56 +00003205 return __hash_len_16(__len + (__a << 3), __b);
3206 }
3207 if (__len > 0) {
3208 const unsigned char __a = __s[0];
3209 const unsigned char __b = __s[__len >> 1];
3210 const unsigned char __c = __s[__len - 1];
3211 const uint32_t __y = static_cast<uint32_t>(__a) +
3212 (static_cast<uint32_t>(__b) << 8);
3213 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3214 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3215 }
3216 return __k2;
3217 }
3218
3219 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003220 const _Size __a = __loadword<_Size>(__s) * __k1;
3221 const _Size __b = __loadword<_Size>(__s + 8);
3222 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3223 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnantf1973402011-12-10 20:28:56 +00003224 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3225 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3226 }
3227
3228 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3229 // Callers do best to use "random-looking" values for a and b.
3230 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3231 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3232 __a += __w;
3233 __b = __rotate(__b + __a + __z, 21);
3234 const _Size __c = __a;
3235 __a += __x;
3236 __a += __y;
3237 __b += __rotate(__a, 44);
3238 return pair<_Size, _Size>(__a + __z, __b + __c);
3239 }
3240
3241 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3242 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3243 const char* __s, _Size __a, _Size __b) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003244 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3245 __loadword<_Size>(__s + 8),
3246 __loadword<_Size>(__s + 16),
3247 __loadword<_Size>(__s + 24),
Howard Hinnantf1973402011-12-10 20:28:56 +00003248 __a,
3249 __b);
3250 }
3251
3252 // Return an 8-byte hash for 33 to 64 bytes.
3253 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003254 _Size __z = __loadword<_Size>(__s + 24);
3255 _Size __a = __loadword<_Size>(__s) +
3256 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnantf1973402011-12-10 20:28:56 +00003257 _Size __b = __rotate(__a + __z, 52);
3258 _Size __c = __rotate(__a, 37);
Howard Hinnant6a855442013-07-03 17:39:28 +00003259 __a += __loadword<_Size>(__s + 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003260 __c += __rotate(__a, 7);
Howard Hinnant6a855442013-07-03 17:39:28 +00003261 __a += __loadword<_Size>(__s + 16);
Howard Hinnantf1973402011-12-10 20:28:56 +00003262 _Size __vf = __a + __z;
3263 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant6a855442013-07-03 17:39:28 +00003264 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3265 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003266 __b = __rotate(__a + __z, 52);
3267 __c = __rotate(__a, 37);
Howard Hinnant6a855442013-07-03 17:39:28 +00003268 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnantf1973402011-12-10 20:28:56 +00003269 __c += __rotate(__a, 7);
Howard Hinnant6a855442013-07-03 17:39:28 +00003270 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnantf1973402011-12-10 20:28:56 +00003271 _Size __wf = __a + __z;
3272 _Size __ws = __b + __rotate(__a, 31) + __c;
3273 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3274 return __shift_mix(__r * __k0 + __vs) * __k2;
3275 }
Howard Hinnantad71c232011-12-05 00:08:45 +00003276};
3277
Howard Hinnantf1973402011-12-10 20:28:56 +00003278// cityhash64
Howard Hinnantad71c232011-12-05 00:08:45 +00003279template <class _Size>
3280_Size
Howard Hinnantf1973402011-12-10 20:28:56 +00003281__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
Howard Hinnantad71c232011-12-05 00:08:45 +00003282{
Howard Hinnantf1973402011-12-10 20:28:56 +00003283 const char* __s = static_cast<const char*>(__key);
3284 if (__len <= 32) {
3285 if (__len <= 16) {
3286 return __hash_len_0_to_16(__s, __len);
3287 } else {
3288 return __hash_len_17_to_32(__s, __len);
Howard Hinnantad71c232011-12-05 00:08:45 +00003289 }
Howard Hinnantf1973402011-12-10 20:28:56 +00003290 } else if (__len <= 64) {
3291 return __hash_len_33_to_64(__s, __len);
3292 }
3293
3294 // For strings over 64 bytes we hash the end first, and then as we
3295 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant6a855442013-07-03 17:39:28 +00003296 _Size __x = __loadword<_Size>(__s + __len - 40);
3297 _Size __y = __loadword<_Size>(__s + __len - 16) +
3298 __loadword<_Size>(__s + __len - 56);
3299 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3300 __loadword<_Size>(__s + __len - 24));
Howard Hinnantf1973402011-12-10 20:28:56 +00003301 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3302 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant6a855442013-07-03 17:39:28 +00003303 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnantf1973402011-12-10 20:28:56 +00003304
3305 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3306 __len = (__len - 1) & ~static_cast<_Size>(63);
3307 do {
Howard Hinnant6a855442013-07-03 17:39:28 +00003308 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3309 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnantf1973402011-12-10 20:28:56 +00003310 __x ^= __w.second;
Howard Hinnant6a855442013-07-03 17:39:28 +00003311 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnantf1973402011-12-10 20:28:56 +00003312 __z = __rotate(__z + __w.first, 33) * __k1;
3313 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3314 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant6a855442013-07-03 17:39:28 +00003315 __y + __loadword<_Size>(__s + 16));
Howard Hinnantf1973402011-12-10 20:28:56 +00003316 std::swap(__z, __x);
3317 __s += 64;
3318 __len -= 64;
3319 } while (__len != 0);
3320 return __hash_len_16(
3321 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3322 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnantad71c232011-12-05 00:08:45 +00003323}
3324
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003325template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3326struct __scalar_hash;
3327
3328template <class _Tp>
3329struct __scalar_hash<_Tp, 0>
3330 : public unary_function<_Tp, size_t>
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003331{
Howard Hinnant756c69b2010-09-22 16:48:34 +00003332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003333 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003334 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003335 union
3336 {
3337 _Tp __t;
3338 size_t __a;
3339 } __u;
3340 __u.__a = 0;
3341 __u.__t = __v;
3342 return __u.__a;
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003343 }
3344};
3345
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003346template <class _Tp>
3347struct __scalar_hash<_Tp, 1>
3348 : public unary_function<_Tp, size_t>
3349{
3350 _LIBCPP_INLINE_VISIBILITY
3351 size_t operator()(_Tp __v) const _NOEXCEPT
3352 {
3353 union
3354 {
3355 _Tp __t;
3356 size_t __a;
3357 } __u;
3358 __u.__t = __v;
3359 return __u.__a;
3360 }
3361};
3362
3363template <class _Tp>
3364struct __scalar_hash<_Tp, 2>
3365 : public unary_function<_Tp, size_t>
3366{
3367 _LIBCPP_INLINE_VISIBILITY
3368 size_t operator()(_Tp __v) const _NOEXCEPT
3369 {
3370 union
3371 {
3372 _Tp __t;
3373 struct
3374 {
3375 size_t __a;
3376 size_t __b;
3377 };
3378 } __u;
3379 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003380 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003381 }
3382};
3383
3384template <class _Tp>
3385struct __scalar_hash<_Tp, 3>
3386 : public unary_function<_Tp, size_t>
3387{
3388 _LIBCPP_INLINE_VISIBILITY
3389 size_t operator()(_Tp __v) const _NOEXCEPT
3390 {
3391 union
3392 {
3393 _Tp __t;
3394 struct
3395 {
3396 size_t __a;
3397 size_t __b;
3398 size_t __c;
3399 };
3400 } __u;
3401 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003402 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003403 }
3404};
3405
3406template <class _Tp>
3407struct __scalar_hash<_Tp, 4>
3408 : public unary_function<_Tp, size_t>
3409{
3410 _LIBCPP_INLINE_VISIBILITY
3411 size_t operator()(_Tp __v) const _NOEXCEPT
3412 {
3413 union
3414 {
3415 _Tp __t;
3416 struct
3417 {
3418 size_t __a;
3419 size_t __b;
3420 size_t __c;
3421 size_t __d;
3422 };
3423 } __u;
3424 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003425 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003426 }
3427};
3428
3429template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003430struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
Howard Hinnant9fa30202012-07-30 01:40:57 +00003431 : public unary_function<_Tp*, size_t>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003432{
Howard Hinnant9fa30202012-07-30 01:40:57 +00003433 _LIBCPP_INLINE_VISIBILITY
3434 size_t operator()(_Tp* __v) const _NOEXCEPT
3435 {
3436 union
3437 {
3438 _Tp* __t;
3439 size_t __a;
3440 } __u;
3441 __u.__t = __v;
3442 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3443 }
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003444};
3445
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003446template <class _Tp, class _Dp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003447struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003448{
3449 typedef unique_ptr<_Tp, _Dp> argument_type;
3450 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003452 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003453 {
3454 typedef typename argument_type::pointer pointer;
3455 return hash<pointer>()(__ptr.get());
3456 }
3457};
3458
Howard Hinnantc51e1022010-05-11 19:42:16 +00003459struct __destruct_n
3460{
3461private:
3462 size_t size;
3463
3464 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003465 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003466 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3467
3468 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003469 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003470 {}
3471
Howard Hinnant719bda32011-05-28 14:41:13 +00003472 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003473 {++size;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003474 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003475 {}
3476
Howard Hinnant719bda32011-05-28 14:41:13 +00003477 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003478 {size = __s;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003479 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003480 {}
3481public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003482 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3483 : size(__s) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003484
3485 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003486 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003487 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003488
3489 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003490 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003491 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003492
3493 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003494 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003495 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003496};
3497
3498template <class _Alloc>
3499class __allocator_destructor
3500{
3501 typedef allocator_traits<_Alloc> __alloc_traits;
3502public:
3503 typedef typename __alloc_traits::pointer pointer;
3504 typedef typename __alloc_traits::size_type size_type;
3505private:
3506 _Alloc& __alloc_;
3507 size_type __s_;
3508public:
3509 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant719bda32011-05-28 14:41:13 +00003510 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003511 : __alloc_(__a), __s_(__s) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003513 void operator()(pointer __p) _NOEXCEPT
3514 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003515};
3516
3517template <class _InputIterator, class _ForwardIterator>
3518_ForwardIterator
3519uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3520{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003521 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003522#ifndef _LIBCPP_NO_EXCEPTIONS
3523 _ForwardIterator __s = __r;
3524 try
3525 {
3526#endif
3527 for (; __f != __l; ++__f, ++__r)
3528 ::new(&*__r) value_type(*__f);
3529#ifndef _LIBCPP_NO_EXCEPTIONS
3530 }
3531 catch (...)
3532 {
3533 for (; __s != __r; ++__s)
3534 __s->~value_type();
3535 throw;
3536 }
3537#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003538 return __r;
3539}
3540
3541template <class _InputIterator, class _Size, class _ForwardIterator>
3542_ForwardIterator
3543uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3544{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003545 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003546#ifndef _LIBCPP_NO_EXCEPTIONS
3547 _ForwardIterator __s = __r;
3548 try
3549 {
3550#endif
3551 for (; __n > 0; ++__f, ++__r, --__n)
3552 ::new(&*__r) value_type(*__f);
3553#ifndef _LIBCPP_NO_EXCEPTIONS
3554 }
3555 catch (...)
3556 {
3557 for (; __s != __r; ++__s)
3558 __s->~value_type();
3559 throw;
3560 }
3561#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003562 return __r;
3563}
3564
3565template <class _ForwardIterator, class _Tp>
3566void
3567uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3568{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003569 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003570#ifndef _LIBCPP_NO_EXCEPTIONS
3571 _ForwardIterator __s = __f;
3572 try
3573 {
3574#endif
3575 for (; __f != __l; ++__f)
3576 ::new(&*__f) value_type(__x);
3577#ifndef _LIBCPP_NO_EXCEPTIONS
3578 }
3579 catch (...)
3580 {
3581 for (; __s != __f; ++__s)
3582 __s->~value_type();
3583 throw;
3584 }
3585#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003586}
3587
3588template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant3c811092010-11-18 16:13:03 +00003589_ForwardIterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00003590uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3591{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003592 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003593#ifndef _LIBCPP_NO_EXCEPTIONS
3594 _ForwardIterator __s = __f;
3595 try
3596 {
3597#endif
3598 for (; __n > 0; ++__f, --__n)
3599 ::new(&*__f) value_type(__x);
3600#ifndef _LIBCPP_NO_EXCEPTIONS
3601 }
3602 catch (...)
3603 {
3604 for (; __s != __f; ++__s)
3605 __s->~value_type();
3606 throw;
3607 }
3608#endif
Howard Hinnant3c811092010-11-18 16:13:03 +00003609 return __f;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003610}
3611
Howard Hinnant756c69b2010-09-22 16:48:34 +00003612class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003613 : public std::exception
3614{
3615public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003616 virtual ~bad_weak_ptr() _NOEXCEPT;
3617 virtual const char* what() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003618};
3619
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003620template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003621
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003622class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003623{
3624 __shared_count(const __shared_count&);
3625 __shared_count& operator=(const __shared_count&);
3626
3627protected:
3628 long __shared_owners_;
3629 virtual ~__shared_count();
3630private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003631 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003632
3633public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003635 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003636 : __shared_owners_(__refs) {}
3637
Howard Hinnant719bda32011-05-28 14:41:13 +00003638 void __add_shared() _NOEXCEPT;
3639 bool __release_shared() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003641 long use_count() const _NOEXCEPT {return __shared_owners_ + 1;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003642};
3643
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003644class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003645 : private __shared_count
3646{
3647 long __shared_weak_owners_;
3648
3649public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003651 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003652 : __shared_count(__refs),
3653 __shared_weak_owners_(__refs) {}
3654protected:
3655 virtual ~__shared_weak_count();
3656
3657public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003658 void __add_shared() _NOEXCEPT;
3659 void __add_weak() _NOEXCEPT;
3660 void __release_shared() _NOEXCEPT;
3661 void __release_weak() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003663 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3664 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003665
Howard Hinnant807d6332013-02-25 15:50:36 +00003666 // Define the function out only if we build static libc++ without RTTI.
3667 // Otherwise we may break clients who need to compile their projects with
3668 // -fno-rtti and yet link against a libc++.dylib compiled
3669 // without -fno-rtti.
3670#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant719bda32011-05-28 14:41:13 +00003671 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant807d6332013-02-25 15:50:36 +00003672#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003673private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003674 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003675};
3676
3677template <class _Tp, class _Dp, class _Alloc>
3678class __shared_ptr_pointer
3679 : public __shared_weak_count
3680{
3681 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3682public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003684 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003685 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003686
Howard Hinnant72f73582010-08-11 17:04:31 +00003687#ifndef _LIBCPP_NO_RTTI
Howard Hinnant719bda32011-05-28 14:41:13 +00003688 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant72f73582010-08-11 17:04:31 +00003689#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003690
3691private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003692 virtual void __on_zero_shared() _NOEXCEPT;
3693 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003694};
3695
Howard Hinnant72f73582010-08-11 17:04:31 +00003696#ifndef _LIBCPP_NO_RTTI
3697
Howard Hinnantc51e1022010-05-11 19:42:16 +00003698template <class _Tp, class _Dp, class _Alloc>
3699const void*
Howard Hinnant719bda32011-05-28 14:41:13 +00003700__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003701{
Marshall Clowa8dfc942014-11-17 19:05:50 +00003702 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003703}
3704
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003705#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00003706
Howard Hinnantc51e1022010-05-11 19:42:16 +00003707template <class _Tp, class _Dp, class _Alloc>
3708void
Howard Hinnant719bda32011-05-28 14:41:13 +00003709__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003710{
3711 __data_.first().second()(__data_.first().first());
3712 __data_.first().second().~_Dp();
3713}
3714
3715template <class _Tp, class _Dp, class _Alloc>
3716void
Howard Hinnant719bda32011-05-28 14:41:13 +00003717__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003718{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003719 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3720 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003721 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3722
Eric Fiselierf8898c82015-02-05 23:01:40 +00003723 _Al __a(__data_.second());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003724 __data_.second().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003725 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003726}
3727
3728template <class _Tp, class _Alloc>
3729class __shared_ptr_emplace
3730 : public __shared_weak_count
3731{
3732 __compressed_pair<_Alloc, _Tp> __data_;
3733public:
3734#ifndef _LIBCPP_HAS_NO_VARIADICS
3735
Howard Hinnant756c69b2010-09-22 16:48:34 +00003736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003737 __shared_ptr_emplace(_Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003738 : __data_(_VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003739
3740 template <class ..._Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003742 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant83b1c052011-12-19 17:58:44 +00003743 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3744 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003745
3746#else // _LIBCPP_HAS_NO_VARIADICS
3747
Howard Hinnant756c69b2010-09-22 16:48:34 +00003748 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003749 __shared_ptr_emplace(_Alloc __a)
3750 : __data_(__a) {}
3751
3752 template <class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003754 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3755 : __data_(__a, _Tp(__a0)) {}
3756
3757 template <class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003759 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3760 : __data_(__a, _Tp(__a0, __a1)) {}
3761
3762 template <class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003764 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3765 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3766
3767#endif // _LIBCPP_HAS_NO_VARIADICS
3768
3769private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003770 virtual void __on_zero_shared() _NOEXCEPT;
3771 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003772public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003774 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003775};
3776
3777template <class _Tp, class _Alloc>
3778void
Howard Hinnant719bda32011-05-28 14:41:13 +00003779__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003780{
3781 __data_.second().~_Tp();
3782}
3783
3784template <class _Tp, class _Alloc>
3785void
Howard Hinnant719bda32011-05-28 14:41:13 +00003786__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003787{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003788 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3789 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003790 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselierf8898c82015-02-05 23:01:40 +00003791 _Al __a(__data_.first());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003792 __data_.first().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003793 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003794}
3795
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003796template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003797
3798template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003799class _LIBCPP_TYPE_VIS_ONLY shared_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003800{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003801public:
3802 typedef _Tp element_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003803private:
3804 element_type* __ptr_;
3805 __shared_weak_count* __cntrl_;
3806
3807 struct __nat {int __for_bool_;};
3808public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003809 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3810 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiend435f8b2014-01-31 09:30:46 +00003811 template<class _Yp>
3812 explicit shared_ptr(_Yp* __p,
3813 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3814 template<class _Yp, class _Dp>
3815 shared_ptr(_Yp* __p, _Dp __d,
3816 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3817 template<class _Yp, class _Dp, class _Alloc>
3818 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3819 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003820 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3821 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Howard Hinnant719bda32011-05-28 14:41:13 +00003822 template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3823 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003824 template<class _Yp>
3825 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00003826 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3827 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003828#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant719bda32011-05-28 14:41:13 +00003829 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003830 template<class _Yp> shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00003831 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
3832 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003833#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003834 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003835 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003836#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003837 template<class _Yp>
3838 shared_ptr(auto_ptr<_Yp>&& __r,
3839 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003840#else
Logan Chiend435f8b2014-01-31 09:30:46 +00003841 template<class _Yp>
3842 shared_ptr(auto_ptr<_Yp> __r,
3843 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003844#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00003845#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003846 template <class _Yp, class _Dp>
3847 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3848 typename enable_if
3849 <
3850 !is_lvalue_reference<_Dp>::value &&
3851 !is_array<_Yp>::value &&
3852 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3853 __nat
3854 >::type = __nat());
3855 template <class _Yp, class _Dp>
3856 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3857 typename enable_if
3858 <
3859 is_lvalue_reference<_Dp>::value &&
3860 !is_array<_Yp>::value &&
3861 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3862 __nat
3863 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003864#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003865 template <class _Yp, class _Dp>
3866 shared_ptr(unique_ptr<_Yp, _Dp>,
3867 typename enable_if
3868 <
3869 !is_lvalue_reference<_Dp>::value &&
3870 !is_array<_Yp>::value &&
3871 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3872 __nat
3873 >::type = __nat());
3874 template <class _Yp, class _Dp>
3875 shared_ptr(unique_ptr<_Yp, _Dp>,
3876 typename enable_if
3877 <
3878 is_lvalue_reference<_Dp>::value &&
3879 !is_array<_Yp>::value &&
3880 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3881 __nat
3882 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003883#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003884
3885 ~shared_ptr();
3886
Howard Hinnant719bda32011-05-28 14:41:13 +00003887 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003888 template<class _Yp>
3889 typename enable_if
3890 <
3891 is_convertible<_Yp*, element_type*>::value,
3892 shared_ptr&
3893 >::type
3894 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003895#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant719bda32011-05-28 14:41:13 +00003896 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003897 template<class _Yp>
3898 typename enable_if
3899 <
3900 is_convertible<_Yp*, element_type*>::value,
3901 shared_ptr<_Tp>&
3902 >::type
3903 operator=(shared_ptr<_Yp>&& __r);
3904 template<class _Yp>
3905 typename enable_if
3906 <
3907 !is_array<_Yp>::value &&
3908 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00003909 shared_ptr
3910 >::type&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003911 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00003912#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003913 template<class _Yp>
3914 typename enable_if
3915 <
3916 !is_array<_Yp>::value &&
3917 is_convertible<_Yp*, element_type*>::value,
3918 shared_ptr&
3919 >::type
3920 operator=(auto_ptr<_Yp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003921#endif
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003922 template <class _Yp, class _Dp>
3923 typename enable_if
3924 <
3925 !is_array<_Yp>::value &&
3926 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3927 shared_ptr&
3928 >::type
Howard Hinnant74279a52010-09-04 23:28:19 +00003929#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003930 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00003931#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003932 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003933#endif
3934
Howard Hinnant719bda32011-05-28 14:41:13 +00003935 void swap(shared_ptr& __r) _NOEXCEPT;
3936 void reset() _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003937 template<class _Yp>
3938 typename enable_if
3939 <
3940 is_convertible<_Yp*, element_type*>::value,
3941 void
3942 >::type
3943 reset(_Yp* __p);
3944 template<class _Yp, class _Dp>
3945 typename enable_if
3946 <
3947 is_convertible<_Yp*, element_type*>::value,
3948 void
3949 >::type
3950 reset(_Yp* __p, _Dp __d);
3951 template<class _Yp, class _Dp, class _Alloc>
3952 typename enable_if
3953 <
3954 is_convertible<_Yp*, element_type*>::value,
3955 void
3956 >::type
3957 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003958
Howard Hinnant756c69b2010-09-22 16:48:34 +00003959 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003960 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003962 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3963 {return *__ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003965 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003967 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003969 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003970 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00003971 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003972 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003974 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003975 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003976 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003978 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003979 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant9fa30202012-07-30 01:40:57 +00003980 _LIBCPP_INLINE_VISIBILITY
3981 bool
3982 __owner_equivalent(const shared_ptr& __p) const
3983 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003984
Howard Hinnant72f73582010-08-11 17:04:31 +00003985#ifndef _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003986 template <class _Dp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003988 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003989 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003990#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003991
3992#ifndef _LIBCPP_HAS_NO_VARIADICS
3993
3994 template<class ..._Args>
3995 static
3996 shared_ptr<_Tp>
3997 make_shared(_Args&& ...__args);
3998
3999 template<class _Alloc, class ..._Args>
4000 static
4001 shared_ptr<_Tp>
4002 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4003
4004#else // _LIBCPP_HAS_NO_VARIADICS
4005
4006 static shared_ptr<_Tp> make_shared();
4007
4008 template<class _A0>
4009 static shared_ptr<_Tp> make_shared(_A0&);
4010
4011 template<class _A0, class _A1>
4012 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4013
4014 template<class _A0, class _A1, class _A2>
4015 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4016
4017 template<class _Alloc>
4018 static shared_ptr<_Tp>
4019 allocate_shared(const _Alloc& __a);
4020
4021 template<class _Alloc, class _A0>
4022 static shared_ptr<_Tp>
4023 allocate_shared(const _Alloc& __a, _A0& __a0);
4024
4025 template<class _Alloc, class _A0, class _A1>
4026 static shared_ptr<_Tp>
4027 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4028
4029 template<class _Alloc, class _A0, class _A1, class _A2>
4030 static shared_ptr<_Tp>
4031 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4032
4033#endif // _LIBCPP_HAS_NO_VARIADICS
4034
4035private:
4036
4037 template <class _Yp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004039 void
Howard Hinnant719bda32011-05-28 14:41:13 +00004040 __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004041 {
4042 if (__e)
4043 __e->__weak_this_ = *this;
4044 }
4045
Howard Hinnant756c69b2010-09-22 16:48:34 +00004046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004047 void __enable_weak_this(const void*) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00004048
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004049 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4050 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004051};
4052
4053template<class _Tp>
4054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004055_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004056shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004057 : __ptr_(0),
4058 __cntrl_(0)
4059{
4060}
4061
4062template<class _Tp>
4063inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004064_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004065shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004066 : __ptr_(0),
4067 __cntrl_(0)
4068{
4069}
4070
4071template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004072template<class _Yp>
4073shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4074 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004075 : __ptr_(__p)
4076{
4077 unique_ptr<_Yp> __hold(__p);
4078 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4079 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4080 __hold.release();
4081 __enable_weak_this(__p);
4082}
4083
4084template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004085template<class _Yp, class _Dp>
4086shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4087 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004088 : __ptr_(__p)
4089{
4090#ifndef _LIBCPP_NO_EXCEPTIONS
4091 try
4092 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004093#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004094 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4095 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
4096 __enable_weak_this(__p);
4097#ifndef _LIBCPP_NO_EXCEPTIONS
4098 }
4099 catch (...)
4100 {
4101 __d(__p);
4102 throw;
4103 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004104#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004105}
4106
4107template<class _Tp>
4108template<class _Dp>
4109shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4110 : __ptr_(0)
4111{
4112#ifndef _LIBCPP_NO_EXCEPTIONS
4113 try
4114 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004115#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004116 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4117 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4118#ifndef _LIBCPP_NO_EXCEPTIONS
4119 }
4120 catch (...)
4121 {
4122 __d(__p);
4123 throw;
4124 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004125#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004126}
4127
4128template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004129template<class _Yp, class _Dp, class _Alloc>
4130shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4131 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004132 : __ptr_(__p)
4133{
4134#ifndef _LIBCPP_NO_EXCEPTIONS
4135 try
4136 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004137#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004138 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004139 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004140 typedef __allocator_destructor<_A2> _D2;
4141 _A2 __a2(__a);
4142 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004143 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4144 _CntrlBlk(__p, __d, __a);
4145 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004146 __enable_weak_this(__p);
4147#ifndef _LIBCPP_NO_EXCEPTIONS
4148 }
4149 catch (...)
4150 {
4151 __d(__p);
4152 throw;
4153 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004154#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004155}
4156
4157template<class _Tp>
4158template<class _Dp, class _Alloc>
4159shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4160 : __ptr_(0)
4161{
4162#ifndef _LIBCPP_NO_EXCEPTIONS
4163 try
4164 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004165#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004166 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004167 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004168 typedef __allocator_destructor<_A2> _D2;
4169 _A2 __a2(__a);
4170 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004171 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4172 _CntrlBlk(__p, __d, __a);
4173 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004174#ifndef _LIBCPP_NO_EXCEPTIONS
4175 }
4176 catch (...)
4177 {
4178 __d(__p);
4179 throw;
4180 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004181#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004182}
4183
4184template<class _Tp>
4185template<class _Yp>
4186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004187shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004188 : __ptr_(__p),
4189 __cntrl_(__r.__cntrl_)
4190{
4191 if (__cntrl_)
4192 __cntrl_->__add_shared();
4193}
4194
4195template<class _Tp>
4196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004197shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004198 : __ptr_(__r.__ptr_),
4199 __cntrl_(__r.__cntrl_)
4200{
4201 if (__cntrl_)
4202 __cntrl_->__add_shared();
4203}
4204
4205template<class _Tp>
4206template<class _Yp>
4207inline _LIBCPP_INLINE_VISIBILITY
4208shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4209 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004210 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004211 : __ptr_(__r.__ptr_),
4212 __cntrl_(__r.__cntrl_)
4213{
4214 if (__cntrl_)
4215 __cntrl_->__add_shared();
4216}
4217
Howard Hinnant74279a52010-09-04 23:28:19 +00004218#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004219
4220template<class _Tp>
4221inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004222shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004223 : __ptr_(__r.__ptr_),
4224 __cntrl_(__r.__cntrl_)
4225{
4226 __r.__ptr_ = 0;
4227 __r.__cntrl_ = 0;
4228}
4229
4230template<class _Tp>
4231template<class _Yp>
4232inline _LIBCPP_INLINE_VISIBILITY
4233shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4234 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004235 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004236 : __ptr_(__r.__ptr_),
4237 __cntrl_(__r.__cntrl_)
4238{
4239 __r.__ptr_ = 0;
4240 __r.__cntrl_ = 0;
4241}
4242
Howard Hinnant74279a52010-09-04 23:28:19 +00004243#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004244
4245template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004246template<class _Yp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004247#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004248shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249#else
Logan Chiend435f8b2014-01-31 09:30:46 +00004250shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004251#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004252 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004253 : __ptr_(__r.get())
4254{
4255 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4256 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4257 __enable_weak_this(__r.get());
4258 __r.release();
4259}
4260
4261template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004262template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004263#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004264shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4265#else
4266shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4267#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004268 typename enable_if
4269 <
4270 !is_lvalue_reference<_Dp>::value &&
4271 !is_array<_Yp>::value &&
4272 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4273 __nat
4274 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004275 : __ptr_(__r.get())
4276{
4277 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4278 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
4279 __enable_weak_this(__r.get());
4280 __r.release();
4281}
4282
4283template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004284template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004285#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004286shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4287#else
4288shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4289#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004290 typename enable_if
4291 <
4292 is_lvalue_reference<_Dp>::value &&
4293 !is_array<_Yp>::value &&
4294 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4295 __nat
4296 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004297 : __ptr_(__r.get())
4298{
4299 typedef __shared_ptr_pointer<_Yp*,
4300 reference_wrapper<typename remove_reference<_Dp>::type>,
4301 allocator<_Yp> > _CntrlBlk;
4302 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
4303 __enable_weak_this(__r.get());
4304 __r.release();
4305}
4306
4307#ifndef _LIBCPP_HAS_NO_VARIADICS
4308
4309template<class _Tp>
4310template<class ..._Args>
4311shared_ptr<_Tp>
4312shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4313{
4314 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4315 typedef allocator<_CntrlBlk> _A2;
4316 typedef __allocator_destructor<_A2> _D2;
4317 _A2 __a2;
4318 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004319 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004320 shared_ptr<_Tp> __r;
4321 __r.__ptr_ = __hold2.get()->get();
4322 __r.__cntrl_ = __hold2.release();
4323 __r.__enable_weak_this(__r.__ptr_);
4324 return __r;
4325}
4326
4327template<class _Tp>
4328template<class _Alloc, class ..._Args>
4329shared_ptr<_Tp>
4330shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4331{
4332 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004333 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004334 typedef __allocator_destructor<_A2> _D2;
4335 _A2 __a2(__a);
4336 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004337 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4338 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004339 shared_ptr<_Tp> __r;
4340 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004341 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004342 __r.__enable_weak_this(__r.__ptr_);
4343 return __r;
4344}
4345
4346#else // _LIBCPP_HAS_NO_VARIADICS
4347
4348template<class _Tp>
4349shared_ptr<_Tp>
4350shared_ptr<_Tp>::make_shared()
4351{
4352 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4353 typedef allocator<_CntrlBlk> _Alloc2;
4354 typedef __allocator_destructor<_Alloc2> _D2;
4355 _Alloc2 __alloc2;
4356 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4357 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4358 shared_ptr<_Tp> __r;
4359 __r.__ptr_ = __hold2.get()->get();
4360 __r.__cntrl_ = __hold2.release();
4361 __r.__enable_weak_this(__r.__ptr_);
4362 return __r;
4363}
4364
4365template<class _Tp>
4366template<class _A0>
4367shared_ptr<_Tp>
4368shared_ptr<_Tp>::make_shared(_A0& __a0)
4369{
4370 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4371 typedef allocator<_CntrlBlk> _Alloc2;
4372 typedef __allocator_destructor<_Alloc2> _D2;
4373 _Alloc2 __alloc2;
4374 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4375 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4376 shared_ptr<_Tp> __r;
4377 __r.__ptr_ = __hold2.get()->get();
4378 __r.__cntrl_ = __hold2.release();
4379 __r.__enable_weak_this(__r.__ptr_);
4380 return __r;
4381}
4382
4383template<class _Tp>
4384template<class _A0, class _A1>
4385shared_ptr<_Tp>
4386shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4387{
4388 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4389 typedef allocator<_CntrlBlk> _Alloc2;
4390 typedef __allocator_destructor<_Alloc2> _D2;
4391 _Alloc2 __alloc2;
4392 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4393 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4394 shared_ptr<_Tp> __r;
4395 __r.__ptr_ = __hold2.get()->get();
4396 __r.__cntrl_ = __hold2.release();
4397 __r.__enable_weak_this(__r.__ptr_);
4398 return __r;
4399}
4400
4401template<class _Tp>
4402template<class _A0, class _A1, class _A2>
4403shared_ptr<_Tp>
4404shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4405{
4406 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4407 typedef allocator<_CntrlBlk> _Alloc2;
4408 typedef __allocator_destructor<_Alloc2> _D2;
4409 _Alloc2 __alloc2;
4410 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4411 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4412 shared_ptr<_Tp> __r;
4413 __r.__ptr_ = __hold2.get()->get();
4414 __r.__cntrl_ = __hold2.release();
4415 __r.__enable_weak_this(__r.__ptr_);
4416 return __r;
4417}
4418
4419template<class _Tp>
4420template<class _Alloc>
4421shared_ptr<_Tp>
4422shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4423{
4424 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004425 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004426 typedef __allocator_destructor<_Alloc2> _D2;
4427 _Alloc2 __alloc2(__a);
4428 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004429 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4430 _CntrlBlk(__a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004431 shared_ptr<_Tp> __r;
4432 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004433 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004434 __r.__enable_weak_this(__r.__ptr_);
4435 return __r;
4436}
4437
4438template<class _Tp>
4439template<class _Alloc, class _A0>
4440shared_ptr<_Tp>
4441shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4442{
4443 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004444 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004445 typedef __allocator_destructor<_Alloc2> _D2;
4446 _Alloc2 __alloc2(__a);
4447 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004448 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4449 _CntrlBlk(__a, __a0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004450 shared_ptr<_Tp> __r;
4451 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004452 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004453 __r.__enable_weak_this(__r.__ptr_);
4454 return __r;
4455}
4456
4457template<class _Tp>
4458template<class _Alloc, class _A0, class _A1>
4459shared_ptr<_Tp>
4460shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4461{
4462 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004463 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004464 typedef __allocator_destructor<_Alloc2> _D2;
4465 _Alloc2 __alloc2(__a);
4466 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004467 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4468 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004469 shared_ptr<_Tp> __r;
4470 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004471 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004472 __r.__enable_weak_this(__r.__ptr_);
4473 return __r;
4474}
4475
4476template<class _Tp>
4477template<class _Alloc, class _A0, class _A1, class _A2>
4478shared_ptr<_Tp>
4479shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4480{
4481 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004482 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004483 typedef __allocator_destructor<_Alloc2> _D2;
4484 _Alloc2 __alloc2(__a);
4485 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004486 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4487 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004488 shared_ptr<_Tp> __r;
4489 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004490 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004491 __r.__enable_weak_this(__r.__ptr_);
4492 return __r;
4493}
4494
4495#endif // _LIBCPP_HAS_NO_VARIADICS
4496
4497template<class _Tp>
4498shared_ptr<_Tp>::~shared_ptr()
4499{
4500 if (__cntrl_)
4501 __cntrl_->__release_shared();
4502}
4503
4504template<class _Tp>
4505inline _LIBCPP_INLINE_VISIBILITY
4506shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004507shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004508{
4509 shared_ptr(__r).swap(*this);
4510 return *this;
4511}
4512
4513template<class _Tp>
4514template<class _Yp>
4515inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004516typename enable_if
4517<
4518 is_convertible<_Yp*, _Tp*>::value,
4519 shared_ptr<_Tp>&
4520>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004521shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004522{
4523 shared_ptr(__r).swap(*this);
4524 return *this;
4525}
4526
Howard Hinnant74279a52010-09-04 23:28:19 +00004527#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004528
4529template<class _Tp>
4530inline _LIBCPP_INLINE_VISIBILITY
4531shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004532shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004533{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004534 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004535 return *this;
4536}
4537
4538template<class _Tp>
4539template<class _Yp>
4540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004541typename enable_if
4542<
4543 is_convertible<_Yp*, _Tp*>::value,
4544 shared_ptr<_Tp>&
4545>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004546shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4547{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004548 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004549 return *this;
4550}
4551
4552template<class _Tp>
4553template<class _Yp>
4554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004555typename enable_if
4556<
4557 !is_array<_Yp>::value &&
4558 is_convertible<_Yp*, _Tp*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00004559 shared_ptr<_Tp>
4560>::type&
Howard Hinnantc51e1022010-05-11 19:42:16 +00004561shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4562{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004563 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004564 return *this;
4565}
4566
4567template<class _Tp>
4568template <class _Yp, class _Dp>
4569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004570typename enable_if
4571<
4572 !is_array<_Yp>::value &&
4573 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4574 shared_ptr<_Tp>&
4575>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004576shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4577{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004578 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004579 return *this;
4580}
4581
Howard Hinnant74279a52010-09-04 23:28:19 +00004582#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004583
4584template<class _Tp>
4585template<class _Yp>
4586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004587typename enable_if
4588<
4589 !is_array<_Yp>::value &&
4590 is_convertible<_Yp*, _Tp*>::value,
4591 shared_ptr<_Tp>&
4592>::type
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004593shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004594{
4595 shared_ptr(__r).swap(*this);
4596 return *this;
4597}
4598
4599template<class _Tp>
4600template <class _Yp, class _Dp>
4601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004602typename enable_if
4603<
4604 !is_array<_Yp>::value &&
4605 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4606 shared_ptr<_Tp>&
4607>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004608shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4609{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004610 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004611 return *this;
4612}
4613
Howard Hinnant74279a52010-09-04 23:28:19 +00004614#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004615
4616template<class _Tp>
4617inline _LIBCPP_INLINE_VISIBILITY
4618void
Howard Hinnant719bda32011-05-28 14:41:13 +00004619shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004620{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004621 _VSTD::swap(__ptr_, __r.__ptr_);
4622 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004623}
4624
4625template<class _Tp>
4626inline _LIBCPP_INLINE_VISIBILITY
4627void
Howard Hinnant719bda32011-05-28 14:41:13 +00004628shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004629{
4630 shared_ptr().swap(*this);
4631}
4632
4633template<class _Tp>
4634template<class _Yp>
4635inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004636typename enable_if
4637<
4638 is_convertible<_Yp*, _Tp*>::value,
4639 void
4640>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004641shared_ptr<_Tp>::reset(_Yp* __p)
4642{
4643 shared_ptr(__p).swap(*this);
4644}
4645
4646template<class _Tp>
4647template<class _Yp, class _Dp>
4648inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004649typename enable_if
4650<
4651 is_convertible<_Yp*, _Tp*>::value,
4652 void
4653>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004654shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4655{
4656 shared_ptr(__p, __d).swap(*this);
4657}
4658
4659template<class _Tp>
4660template<class _Yp, class _Dp, class _Alloc>
4661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004662typename enable_if
4663<
4664 is_convertible<_Yp*, _Tp*>::value,
4665 void
4666>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004667shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4668{
4669 shared_ptr(__p, __d, __a).swap(*this);
4670}
4671
4672#ifndef _LIBCPP_HAS_NO_VARIADICS
4673
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004674template<class _Tp, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004676typename enable_if
4677<
4678 !is_array<_Tp>::value,
4679 shared_ptr<_Tp>
4680>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004681make_shared(_Args&& ...__args)
4682{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004683 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004684}
4685
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004686template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004688typename enable_if
4689<
4690 !is_array<_Tp>::value,
4691 shared_ptr<_Tp>
4692>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004693allocate_shared(const _Alloc& __a, _Args&& ...__args)
4694{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004695 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004696}
4697
4698#else // _LIBCPP_HAS_NO_VARIADICS
4699
4700template<class _Tp>
4701inline _LIBCPP_INLINE_VISIBILITY
4702shared_ptr<_Tp>
4703make_shared()
4704{
4705 return shared_ptr<_Tp>::make_shared();
4706}
4707
4708template<class _Tp, class _A0>
4709inline _LIBCPP_INLINE_VISIBILITY
4710shared_ptr<_Tp>
4711make_shared(_A0& __a0)
4712{
4713 return shared_ptr<_Tp>::make_shared(__a0);
4714}
4715
4716template<class _Tp, class _A0, class _A1>
4717inline _LIBCPP_INLINE_VISIBILITY
4718shared_ptr<_Tp>
4719make_shared(_A0& __a0, _A1& __a1)
4720{
4721 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4722}
4723
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004724template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004725inline _LIBCPP_INLINE_VISIBILITY
4726shared_ptr<_Tp>
4727make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4728{
4729 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4730}
4731
4732template<class _Tp, class _Alloc>
4733inline _LIBCPP_INLINE_VISIBILITY
4734shared_ptr<_Tp>
4735allocate_shared(const _Alloc& __a)
4736{
4737 return shared_ptr<_Tp>::allocate_shared(__a);
4738}
4739
4740template<class _Tp, class _Alloc, class _A0>
4741inline _LIBCPP_INLINE_VISIBILITY
4742shared_ptr<_Tp>
4743allocate_shared(const _Alloc& __a, _A0& __a0)
4744{
4745 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4746}
4747
4748template<class _Tp, class _Alloc, class _A0, class _A1>
4749inline _LIBCPP_INLINE_VISIBILITY
4750shared_ptr<_Tp>
4751allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4752{
4753 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4754}
4755
4756template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4757inline _LIBCPP_INLINE_VISIBILITY
4758shared_ptr<_Tp>
4759allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4760{
4761 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4762}
4763
4764#endif // _LIBCPP_HAS_NO_VARIADICS
4765
4766template<class _Tp, class _Up>
4767inline _LIBCPP_INLINE_VISIBILITY
4768bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004769operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004770{
4771 return __x.get() == __y.get();
4772}
4773
4774template<class _Tp, class _Up>
4775inline _LIBCPP_INLINE_VISIBILITY
4776bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004777operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004778{
4779 return !(__x == __y);
4780}
4781
4782template<class _Tp, class _Up>
4783inline _LIBCPP_INLINE_VISIBILITY
4784bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004785operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004786{
Eric Fiselierf8898c82015-02-05 23:01:40 +00004787 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4788 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00004789}
4790
4791template<class _Tp, class _Up>
4792inline _LIBCPP_INLINE_VISIBILITY
4793bool
4794operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4795{
4796 return __y < __x;
4797}
4798
4799template<class _Tp, class _Up>
4800inline _LIBCPP_INLINE_VISIBILITY
4801bool
4802operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4803{
4804 return !(__y < __x);
4805}
4806
4807template<class _Tp, class _Up>
4808inline _LIBCPP_INLINE_VISIBILITY
4809bool
4810operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4811{
4812 return !(__x < __y);
4813}
4814
4815template<class _Tp>
4816inline _LIBCPP_INLINE_VISIBILITY
4817bool
4818operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4819{
4820 return !__x;
4821}
4822
4823template<class _Tp>
4824inline _LIBCPP_INLINE_VISIBILITY
4825bool
4826operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4827{
4828 return !__x;
4829}
4830
4831template<class _Tp>
4832inline _LIBCPP_INLINE_VISIBILITY
4833bool
4834operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4835{
4836 return static_cast<bool>(__x);
4837}
4838
4839template<class _Tp>
4840inline _LIBCPP_INLINE_VISIBILITY
4841bool
4842operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4843{
4844 return static_cast<bool>(__x);
4845}
4846
4847template<class _Tp>
4848inline _LIBCPP_INLINE_VISIBILITY
4849bool
4850operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4851{
4852 return less<_Tp*>()(__x.get(), nullptr);
4853}
4854
4855template<class _Tp>
4856inline _LIBCPP_INLINE_VISIBILITY
4857bool
4858operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4859{
4860 return less<_Tp*>()(nullptr, __x.get());
4861}
4862
4863template<class _Tp>
4864inline _LIBCPP_INLINE_VISIBILITY
4865bool
4866operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4867{
4868 return nullptr < __x;
4869}
4870
4871template<class _Tp>
4872inline _LIBCPP_INLINE_VISIBILITY
4873bool
4874operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4875{
4876 return __x < nullptr;
4877}
4878
4879template<class _Tp>
4880inline _LIBCPP_INLINE_VISIBILITY
4881bool
4882operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4883{
4884 return !(nullptr < __x);
4885}
4886
4887template<class _Tp>
4888inline _LIBCPP_INLINE_VISIBILITY
4889bool
4890operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4891{
4892 return !(__x < nullptr);
4893}
4894
4895template<class _Tp>
4896inline _LIBCPP_INLINE_VISIBILITY
4897bool
4898operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4899{
4900 return !(__x < nullptr);
4901}
4902
4903template<class _Tp>
4904inline _LIBCPP_INLINE_VISIBILITY
4905bool
4906operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4907{
4908 return !(nullptr < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004909}
4910
4911template<class _Tp>
4912inline _LIBCPP_INLINE_VISIBILITY
4913void
Howard Hinnant719bda32011-05-28 14:41:13 +00004914swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004915{
4916 __x.swap(__y);
4917}
4918
4919template<class _Tp, class _Up>
4920inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004921typename enable_if
4922<
4923 !is_array<_Tp>::value && !is_array<_Up>::value,
4924 shared_ptr<_Tp>
4925>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004926static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004927{
4928 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4929}
4930
4931template<class _Tp, class _Up>
4932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004933typename enable_if
4934<
4935 !is_array<_Tp>::value && !is_array<_Up>::value,
4936 shared_ptr<_Tp>
4937>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004938dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004939{
4940 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4941 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4942}
4943
4944template<class _Tp, class _Up>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004945typename enable_if
4946<
4947 is_array<_Tp>::value == is_array<_Up>::value,
4948 shared_ptr<_Tp>
4949>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004950const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004951{
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004952 typedef typename remove_extent<_Tp>::type _RTp;
4953 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004954}
4955
Howard Hinnant72f73582010-08-11 17:04:31 +00004956#ifndef _LIBCPP_NO_RTTI
4957
Howard Hinnantc51e1022010-05-11 19:42:16 +00004958template<class _Dp, class _Tp>
4959inline _LIBCPP_INLINE_VISIBILITY
4960_Dp*
Howard Hinnant719bda32011-05-28 14:41:13 +00004961get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004962{
4963 return __p.template __get_deleter<_Dp>();
4964}
4965
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004966#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00004967
Howard Hinnantc51e1022010-05-11 19:42:16 +00004968template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004969class _LIBCPP_TYPE_VIS_ONLY weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00004970{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004971public:
4972 typedef _Tp element_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004973private:
4974 element_type* __ptr_;
4975 __shared_weak_count* __cntrl_;
4976
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004977public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004978 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004979 template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004980 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4981 _NOEXCEPT;
4982 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004983 template<class _Yp> weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004984 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4985 _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004986
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004987#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4988 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4989 template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
4990 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4991 _NOEXCEPT;
4992#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004993 ~weak_ptr();
4994
Howard Hinnant719bda32011-05-28 14:41:13 +00004995 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004996 template<class _Yp>
4997 typename enable_if
4998 <
4999 is_convertible<_Yp*, element_type*>::value,
5000 weak_ptr&
5001 >::type
5002 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5003
5004#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5005
5006 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5007 template<class _Yp>
5008 typename enable_if
5009 <
5010 is_convertible<_Yp*, element_type*>::value,
5011 weak_ptr&
5012 >::type
5013 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5014
5015#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5016
5017 template<class _Yp>
5018 typename enable_if
5019 <
5020 is_convertible<_Yp*, element_type*>::value,
5021 weak_ptr&
5022 >::type
5023 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005024
Howard Hinnant719bda32011-05-28 14:41:13 +00005025 void swap(weak_ptr& __r) _NOEXCEPT;
5026 void reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005027
Howard Hinnant756c69b2010-09-22 16:48:34 +00005028 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005029 long use_count() const _NOEXCEPT
5030 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005032 bool expired() const _NOEXCEPT
5033 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5034 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005035 template<class _Up>
5036 _LIBCPP_INLINE_VISIBILITY
5037 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00005038 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005039 template<class _Up>
5040 _LIBCPP_INLINE_VISIBILITY
5041 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00005042 {return __cntrl_ < __r.__cntrl_;}
5043
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005044 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5045 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005046};
5047
5048template<class _Tp>
5049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005050_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005051weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005052 : __ptr_(0),
5053 __cntrl_(0)
5054{
5055}
5056
5057template<class _Tp>
5058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005059weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005060 : __ptr_(__r.__ptr_),
5061 __cntrl_(__r.__cntrl_)
5062{
5063 if (__cntrl_)
5064 __cntrl_->__add_weak();
5065}
5066
5067template<class _Tp>
5068template<class _Yp>
5069inline _LIBCPP_INLINE_VISIBILITY
5070weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005071 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005072 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005073 : __ptr_(__r.__ptr_),
5074 __cntrl_(__r.__cntrl_)
5075{
5076 if (__cntrl_)
5077 __cntrl_->__add_weak();
5078}
5079
5080template<class _Tp>
5081template<class _Yp>
5082inline _LIBCPP_INLINE_VISIBILITY
5083weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005084 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005085 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005086 : __ptr_(__r.__ptr_),
5087 __cntrl_(__r.__cntrl_)
5088{
5089 if (__cntrl_)
5090 __cntrl_->__add_weak();
5091}
5092
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005093#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5094
5095template<class _Tp>
5096inline _LIBCPP_INLINE_VISIBILITY
5097weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5098 : __ptr_(__r.__ptr_),
5099 __cntrl_(__r.__cntrl_)
5100{
5101 __r.__ptr_ = 0;
5102 __r.__cntrl_ = 0;
5103}
5104
5105template<class _Tp>
5106template<class _Yp>
5107inline _LIBCPP_INLINE_VISIBILITY
5108weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5109 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5110 _NOEXCEPT
5111 : __ptr_(__r.__ptr_),
5112 __cntrl_(__r.__cntrl_)
5113{
5114 __r.__ptr_ = 0;
5115 __r.__cntrl_ = 0;
5116}
5117
5118#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5119
Howard Hinnantc51e1022010-05-11 19:42:16 +00005120template<class _Tp>
5121weak_ptr<_Tp>::~weak_ptr()
5122{
5123 if (__cntrl_)
5124 __cntrl_->__release_weak();
5125}
5126
5127template<class _Tp>
5128inline _LIBCPP_INLINE_VISIBILITY
5129weak_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00005130weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005131{
5132 weak_ptr(__r).swap(*this);
5133 return *this;
5134}
5135
5136template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005137template<class _Yp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00005138inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005139typename enable_if
5140<
5141 is_convertible<_Yp*, _Tp*>::value,
5142 weak_ptr<_Tp>&
5143>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005144weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005145{
5146 weak_ptr(__r).swap(*this);
5147 return *this;
5148}
5149
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005150#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5151
5152template<class _Tp>
5153inline _LIBCPP_INLINE_VISIBILITY
5154weak_ptr<_Tp>&
5155weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5156{
5157 weak_ptr(_VSTD::move(__r)).swap(*this);
5158 return *this;
5159}
5160
Howard Hinnantc51e1022010-05-11 19:42:16 +00005161template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005162template<class _Yp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00005163inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005164typename enable_if
5165<
5166 is_convertible<_Yp*, _Tp*>::value,
5167 weak_ptr<_Tp>&
5168>::type
5169weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5170{
5171 weak_ptr(_VSTD::move(__r)).swap(*this);
5172 return *this;
5173}
5174
5175#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5176
5177template<class _Tp>
5178template<class _Yp>
5179inline _LIBCPP_INLINE_VISIBILITY
5180typename enable_if
5181<
5182 is_convertible<_Yp*, _Tp*>::value,
5183 weak_ptr<_Tp>&
5184>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005185weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005186{
5187 weak_ptr(__r).swap(*this);
5188 return *this;
5189}
5190
5191template<class _Tp>
5192inline _LIBCPP_INLINE_VISIBILITY
5193void
Howard Hinnant719bda32011-05-28 14:41:13 +00005194weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005195{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00005196 _VSTD::swap(__ptr_, __r.__ptr_);
5197 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005198}
5199
5200template<class _Tp>
5201inline _LIBCPP_INLINE_VISIBILITY
5202void
Howard Hinnant719bda32011-05-28 14:41:13 +00005203swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005204{
5205 __x.swap(__y);
5206}
5207
5208template<class _Tp>
5209inline _LIBCPP_INLINE_VISIBILITY
5210void
Howard Hinnant719bda32011-05-28 14:41:13 +00005211weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005212{
5213 weak_ptr().swap(*this);
5214}
5215
5216template<class _Tp>
5217template<class _Yp>
5218shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5219 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5220 : __ptr_(__r.__ptr_),
5221 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5222{
5223 if (__cntrl_ == 0)
5224#ifndef _LIBCPP_NO_EXCEPTIONS
5225 throw bad_weak_ptr();
5226#else
5227 assert(!"bad_weak_ptr");
5228#endif
5229}
5230
5231template<class _Tp>
5232shared_ptr<_Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00005233weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005234{
5235 shared_ptr<_Tp> __r;
5236 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5237 if (__r.__cntrl_)
5238 __r.__ptr_ = __ptr_;
5239 return __r;
5240}
5241
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005242template <class _Tp> struct owner_less;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005243
5244template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005245struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005246 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005247{
5248 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005250 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5251 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005253 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5254 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005256 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5257 {return __x.owner_before(__y);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005258};
Howard Hinnantc51e1022010-05-11 19:42:16 +00005259
5260template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005261struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005262 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5263{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005264 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005266 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5267 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005269 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5270 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005271 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005272 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5273 {return __x.owner_before(__y);}
5274};
5275
5276template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005277class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
Howard Hinnantc51e1022010-05-11 19:42:16 +00005278{
5279 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005280protected:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005281 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005282 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005284 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005286 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5287 {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005289 ~enable_shared_from_this() {}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005290public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00005291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005292 shared_ptr<_Tp> shared_from_this()
5293 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005295 shared_ptr<_Tp const> shared_from_this() const
5296 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00005297
5298 template <class _Up> friend class shared_ptr;
5299};
5300
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005301template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005302struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005303{
5304 typedef shared_ptr<_Tp> argument_type;
5305 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005307 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005308 {
5309 return hash<_Tp*>()(__ptr.get());
5310 }
5311};
5312
Howard Hinnantc834c512011-11-29 18:15:50 +00005313template<class _CharT, class _Traits, class _Yp>
Howard Hinnantdc095972011-07-18 15:51:59 +00005314inline _LIBCPP_INLINE_VISIBILITY
5315basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00005316operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnantdc095972011-07-18 15:51:59 +00005317
Jonathan Roelofs39cb6bf2014-09-05 19:45:05 +00005318#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005319
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005320class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant9fa30202012-07-30 01:40:57 +00005321{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005322 void* __lx;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005323public:
5324 void lock() _NOEXCEPT;
5325 void unlock() _NOEXCEPT;
5326
5327private:
5328 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5329 __sp_mut(const __sp_mut&);
5330 __sp_mut& operator=(const __sp_mut&);
5331
Howard Hinnant8331b762013-03-06 23:30:19 +00005332 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005333};
5334
Howard Hinnant8331b762013-03-06 23:30:19 +00005335_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005336
5337template <class _Tp>
5338inline _LIBCPP_INLINE_VISIBILITY
5339bool
5340atomic_is_lock_free(const shared_ptr<_Tp>*)
5341{
5342 return false;
5343}
5344
5345template <class _Tp>
5346shared_ptr<_Tp>
5347atomic_load(const shared_ptr<_Tp>* __p)
5348{
5349 __sp_mut& __m = __get_sp_mut(__p);
5350 __m.lock();
5351 shared_ptr<_Tp> __q = *__p;
5352 __m.unlock();
5353 return __q;
5354}
5355
5356template <class _Tp>
5357inline _LIBCPP_INLINE_VISIBILITY
5358shared_ptr<_Tp>
5359atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5360{
5361 return atomic_load(__p);
5362}
5363
5364template <class _Tp>
5365void
5366atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5367{
5368 __sp_mut& __m = __get_sp_mut(__p);
5369 __m.lock();
5370 __p->swap(__r);
5371 __m.unlock();
5372}
5373
5374template <class _Tp>
5375inline _LIBCPP_INLINE_VISIBILITY
5376void
5377atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5378{
5379 atomic_store(__p, __r);
5380}
5381
5382template <class _Tp>
5383shared_ptr<_Tp>
5384atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5385{
5386 __sp_mut& __m = __get_sp_mut(__p);
5387 __m.lock();
5388 __p->swap(__r);
5389 __m.unlock();
5390 return __r;
5391}
5392
5393template <class _Tp>
5394inline _LIBCPP_INLINE_VISIBILITY
5395shared_ptr<_Tp>
5396atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5397{
5398 return atomic_exchange(__p, __r);
5399}
5400
5401template <class _Tp>
5402bool
5403atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5404{
5405 __sp_mut& __m = __get_sp_mut(__p);
5406 __m.lock();
5407 if (__p->__owner_equivalent(*__v))
5408 {
5409 *__p = __w;
5410 __m.unlock();
5411 return true;
5412 }
5413 *__v = *__p;
5414 __m.unlock();
5415 return false;
5416}
5417
5418template <class _Tp>
5419inline _LIBCPP_INLINE_VISIBILITY
5420bool
5421atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5422{
5423 return atomic_compare_exchange_strong(__p, __v, __w);
5424}
5425
5426template <class _Tp>
5427inline _LIBCPP_INLINE_VISIBILITY
5428bool
5429atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5430 shared_ptr<_Tp> __w, memory_order, memory_order)
5431{
5432 return atomic_compare_exchange_strong(__p, __v, __w);
5433}
5434
5435template <class _Tp>
5436inline _LIBCPP_INLINE_VISIBILITY
5437bool
5438atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5439 shared_ptr<_Tp> __w, memory_order, memory_order)
5440{
5441 return atomic_compare_exchange_weak(__p, __v, __w);
5442}
5443
Jonathan Roelofs39cb6bf2014-09-05 19:45:05 +00005444#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005445
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005446//enum class
Howard Hinnant8331b762013-03-06 23:30:19 +00005447struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantc51e1022010-05-11 19:42:16 +00005448{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005449 enum __lx
Howard Hinnantc51e1022010-05-11 19:42:16 +00005450 {
5451 relaxed,
5452 preferred,
5453 strict
5454 };
5455
Howard Hinnant49e145e2012-10-30 19:06:59 +00005456 __lx __v_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005457
Howard Hinnant756c69b2010-09-22 16:48:34 +00005458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e145e2012-10-30 19:06:59 +00005459 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005461 operator int() const {return __v_;}
5462};
5463
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005464_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5465_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5466_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5467_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5468_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005469
5470template <class _Tp>
5471inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005472_Tp*
Howard Hinnantc51e1022010-05-11 19:42:16 +00005473undeclare_reachable(_Tp* __p)
5474{
5475 return static_cast<_Tp*>(__undeclare_reachable(__p));
5476}
5477
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005478_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005479
5480_LIBCPP_END_NAMESPACE_STD
5481
5482#endif // _LIBCPP_MEMORY