blob: 31f58b7c0a4b77e46f1357c3870355d844967688 [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;
Marshall Clow0b587562015-06-02 16:34:03 +000078 typedef Alloc::is_always_equal
79 | is_empty is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +000080
81 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
82 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
83
84 static pointer allocate(allocator_type& a, size_type n);
85 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
86
Howard Hinnant719bda32011-05-28 14:41:13 +000087 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
89 template <class T, class... Args>
90 static void construct(allocator_type& a, T* p, Args&&... args);
91
92 template <class T>
93 static void destroy(allocator_type& a, T* p);
94
Marshall Clow4f834b52013-08-27 20:22:15 +000095 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000096
97 static allocator_type
98 select_on_container_copy_construction(const allocator_type& a);
99};
100
101template <>
102class allocator<void>
103{
104public:
105 typedef void* pointer;
106 typedef const void* const_pointer;
107 typedef void value_type;
108
109 template <class _Up> struct rebind {typedef allocator<_Up> other;};
110};
111
112template <class T>
113class allocator
114{
115public:
116 typedef size_t size_type;
117 typedef ptrdiff_t difference_type;
118 typedef T* pointer;
119 typedef const T* const_pointer;
120 typedef typename add_lvalue_reference<T>::type reference;
121 typedef typename add_lvalue_reference<const T>::type const_reference;
122 typedef T value_type;
123
124 template <class U> struct rebind {typedef allocator<U> other;};
125
Howard Hinnant719bda32011-05-28 14:41:13 +0000126 allocator() noexcept;
127 allocator(const allocator&) noexcept;
128 template <class U> allocator(const allocator<U>&) noexcept;
129 ~allocator();
130 pointer address(reference x) const noexcept;
131 const_pointer address(const_reference x) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant719bda32011-05-28 14:41:13 +0000133 void deallocate(pointer p, size_type n) noexcept;
134 size_type max_size() const noexcept;
135 template<class U, class... Args>
136 void construct(U* p, Args&&... args);
137 template <class U>
138 void destroy(U* p);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139};
140
141template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000142bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143
144template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000145bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000146
147template <class OutputIterator, class T>
148class raw_storage_iterator
149 : public iterator<output_iterator_tag,
150 T, // purposefully not C++03
151 ptrdiff_t, // purposefully not C++03
152 T*, // purposefully not C++03
153 raw_storage_iterator&> // purposefully not C++03
154{
155public:
156 explicit raw_storage_iterator(OutputIterator x);
157 raw_storage_iterator& operator*();
158 raw_storage_iterator& operator=(const T& element);
159 raw_storage_iterator& operator++();
160 raw_storage_iterator operator++(int);
161};
162
Howard Hinnant719bda32011-05-28 14:41:13 +0000163template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
164template <class T> void return_temporary_buffer(T* p) noexcept;
165
166template <class T> T* addressof(T& r) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167
168template <class InputIterator, class ForwardIterator>
169ForwardIterator
170uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
171
Howard Hinnant719bda32011-05-28 14:41:13 +0000172template <class InputIterator, class Size, class ForwardIterator>
173ForwardIterator
174uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
175
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176template <class ForwardIterator, class T>
177void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
178
179template <class ForwardIterator, class Size, class T>
Howard Hinnant3c811092010-11-18 16:13:03 +0000180ForwardIterator
181uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
Eric Fiselier383f6cf2016-07-24 03:51:39 +0000183template <class T>
184void destroy_at(T* location);
185
186template <class ForwardIterator>
187 void destroy(ForwardIterator first, ForwardIterator last);
188
189template <class ForwardIterator, class Size>
190 ForwardIterator destroy_n(ForwardIterator first, Size n);
191
192template <class InputIterator, class ForwardIterator>
193 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
194
195template <class InputIterator, class Size, class ForwardIterator>
196 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
197
198template <class ForwardIterator>
199 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
200
201template <class ForwardIterator, class Size>
202 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
203
204template <class ForwardIterator>
205 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
206
207template <class ForwardIterator, class Size>
208 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
209
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210template <class Y> struct auto_ptr_ref {};
211
212template<class X>
213class auto_ptr
214{
215public:
216 typedef X element_type;
217
218 explicit auto_ptr(X* p =0) throw();
219 auto_ptr(auto_ptr&) throw();
220 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
221 auto_ptr& operator=(auto_ptr&) throw();
222 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
223 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
224 ~auto_ptr() throw();
225
226 typename add_lvalue_reference<X>::type operator*() const throw();
227 X* operator->() const throw();
228 X* get() const throw();
229 X* release() throw();
230 void reset(X* p =0) throw();
231
232 auto_ptr(auto_ptr_ref<X>) throw();
233 template<class Y> operator auto_ptr_ref<Y>() throw();
234 template<class Y> operator auto_ptr<Y>() throw();
235};
236
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000237template <class T>
238struct default_delete
239{
Howard Hinnant719bda32011-05-28 14:41:13 +0000240 constexpr default_delete() noexcept = default;
241 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000242
Howard Hinnant719bda32011-05-28 14:41:13 +0000243 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000244};
245
246template <class T>
247struct default_delete<T[]>
248{
Howard Hinnant719bda32011-05-28 14:41:13 +0000249 constexpr default_delete() noexcept = default;
250 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000251 template <class U> void operator()(U*) const = delete;
252};
253
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000254template <class T, class D = default_delete<T>>
255class unique_ptr
256{
257public:
258 typedef see below pointer;
259 typedef T element_type;
260 typedef D deleter_type;
261
262 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000263 constexpr unique_ptr() noexcept;
264 explicit unique_ptr(pointer p) noexcept;
265 unique_ptr(pointer p, see below d1) noexcept;
266 unique_ptr(pointer p, see below d2) noexcept;
267 unique_ptr(unique_ptr&& u) noexcept;
268 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000269 template <class U, class E>
Howard Hinnant719bda32011-05-28 14:41:13 +0000270 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000271 template <class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000272 unique_ptr(auto_ptr<U>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000273
274 // destructor
275 ~unique_ptr();
276
277 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000278 unique_ptr& operator=(unique_ptr&& u) noexcept;
279 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
280 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000281
282 // observers
283 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000284 pointer operator->() const noexcept;
285 pointer get() const noexcept;
286 deleter_type& get_deleter() noexcept;
287 const deleter_type& get_deleter() const noexcept;
288 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000289
290 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000291 pointer release() noexcept;
292 void reset(pointer p = pointer()) noexcept;
293 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000294};
295
296template <class T, class D>
297class unique_ptr<T[], D>
298{
299public:
300 typedef implementation-defined pointer;
301 typedef T element_type;
302 typedef D deleter_type;
303
304 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000305 constexpr unique_ptr() noexcept;
306 explicit unique_ptr(pointer p) noexcept;
307 unique_ptr(pointer p, see below d) noexcept;
308 unique_ptr(pointer p, see below d) noexcept;
309 unique_ptr(unique_ptr&& u) noexcept;
310 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000311
312 // destructor
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000313 ~unique_ptr();
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000314
315 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000316 unique_ptr& operator=(unique_ptr&& u) noexcept;
317 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000318
319 // observers
320 T& operator[](size_t i) const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000321 pointer get() const noexcept;
322 deleter_type& get_deleter() noexcept;
323 const deleter_type& get_deleter() const noexcept;
324 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000325
326 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000327 pointer release() noexcept;
328 void reset(pointer p = pointer()) noexcept;
329 void reset(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000330 template <class U> void reset(U) = delete;
Howard Hinnant719bda32011-05-28 14:41:13 +0000331 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000332};
333
334template <class T, class D>
Howard Hinnant719bda32011-05-28 14:41:13 +0000335 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000336
337template <class T1, class D1, class T2, class D2>
338 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
339template <class T1, class D1, class T2, class D2>
340 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
341template <class T1, class D1, class T2, class D2>
342 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
343template <class T1, class D1, class T2, class D2>
344 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
345template <class T1, class D1, class T2, class D2>
346 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
347template <class T1, class D1, class T2, class D2>
348 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
349
Howard Hinnant719bda32011-05-28 14:41:13 +0000350template <class T, class D>
351 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
352template <class T, class D>
353 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
354template <class T, class D>
355 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
356template <class T, class D>
357 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
358
359template <class T, class D>
360 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
361template <class T, class D>
362 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
363template <class T, class D>
364 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
365template <class T, class D>
366 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
367template <class T, class D>
368 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
369template <class T, class D>
370 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
371template <class T, class D>
372 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
373template <class T, class D>
374 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
375
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000376class bad_weak_ptr
377 : public std::exception
378{
Howard Hinnant719bda32011-05-28 14:41:13 +0000379 bad_weak_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000380};
381
Marshall Clow9e8f4a92013-07-01 18:16:03 +0000382template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
383template<class T> unique_ptr<T> make_unique(size_t n); // C++14
384template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
385
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000386template<class T>
387class shared_ptr
388{
389public:
390 typedef T element_type;
Eric Fiselierae5b6672016-06-27 01:02:43 +0000391 typedef weak_ptr<T> weak_type; // C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000392
393 // constructors:
Howard Hinnant719bda32011-05-28 14:41:13 +0000394 constexpr shared_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000395 template<class Y> explicit shared_ptr(Y* p);
396 template<class Y, class D> shared_ptr(Y* p, D d);
397 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
398 template <class D> shared_ptr(nullptr_t p, D d);
399 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant719bda32011-05-28 14:41:13 +0000400 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
401 shared_ptr(const shared_ptr& r) noexcept;
402 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
403 shared_ptr(shared_ptr&& r) noexcept;
404 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000405 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
406 template<class Y> shared_ptr(auto_ptr<Y>&& r);
407 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
408 shared_ptr(nullptr_t) : shared_ptr() { }
409
410 // destructor:
411 ~shared_ptr();
412
413 // assignment:
Howard Hinnant719bda32011-05-28 14:41:13 +0000414 shared_ptr& operator=(const shared_ptr& r) noexcept;
415 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
416 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000417 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
418 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
419 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
420
421 // modifiers:
Howard Hinnant719bda32011-05-28 14:41:13 +0000422 void swap(shared_ptr& r) noexcept;
423 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000424 template<class Y> void reset(Y* p);
425 template<class Y, class D> void reset(Y* p, D d);
426 template<class Y, class D, class A> void reset(Y* p, D d, A a);
427
Howard Hinnant719bda32011-05-28 14:41:13 +0000428 // observers:
429 T* get() const noexcept;
430 T& operator*() const noexcept;
431 T* operator->() const noexcept;
432 long use_count() const noexcept;
433 bool unique() const noexcept;
434 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000435 template<class U> bool owner_before(shared_ptr<U> const& b) const;
436 template<class U> bool owner_before(weak_ptr<U> const& b) const;
437};
438
439// shared_ptr comparisons:
440template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000441 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000442template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000443 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000444template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000445 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000446template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000447 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000448template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000449 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000450template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000451 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
452
453template <class T>
454 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
455template <class T>
456 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
457template <class T>
458 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
459template <class T>
460 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
461template <class T>
462 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
463template <class T>
464bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
465template <class T>
466 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
467template <class T>
468 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
469template <class T>
470 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
471template <class T>
472 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
473template <class T>
474 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
475template <class T>
476 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000477
478// shared_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000479template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000480
481// shared_ptr casts:
482template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000483 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000484template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000485 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000486template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000487 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000488
489// shared_ptr I/O:
490template<class E, class T, class Y>
491 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
492
493// shared_ptr get_deleter:
Howard Hinnant719bda32011-05-28 14:41:13 +0000494template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000495
496template<class T, class... Args>
497 shared_ptr<T> make_shared(Args&&... args);
498template<class T, class A, class... Args>
499 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
500
501template<class T>
502class weak_ptr
503{
504public:
505 typedef T element_type;
506
507 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000508 constexpr weak_ptr() noexcept;
509 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
510 weak_ptr(weak_ptr const& r) noexcept;
511 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000512 weak_ptr(weak_ptr&& r) noexcept; // C++14
513 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000514
515 // destructor
516 ~weak_ptr();
517
518 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000519 weak_ptr& operator=(weak_ptr const& r) noexcept;
520 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
521 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000522 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
523 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000524
525 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000526 void swap(weak_ptr& r) noexcept;
527 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000528
529 // observers
Howard Hinnant719bda32011-05-28 14:41:13 +0000530 long use_count() const noexcept;
531 bool expired() const noexcept;
532 shared_ptr<T> lock() const noexcept;
Marshall Clow495e4a62013-09-03 14:37:50 +0000533 template<class U> bool owner_before(shared_ptr<U> const& b) const;
534 template<class U> bool owner_before(weak_ptr<U> const& b) const;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000535};
536
537// weak_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000538template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000539
540// class owner_less:
541template<class T> struct owner_less;
542
543template<class T>
544struct owner_less<shared_ptr<T>>
545 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
546{
547 typedef bool result_type;
548 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
549 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
550 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
551};
552
553template<class T>
554struct owner_less<weak_ptr<T>>
555 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
556{
557 typedef bool result_type;
558 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
559 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
560 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
561};
562
563template<class T>
564class enable_shared_from_this
565{
566protected:
Howard Hinnant719bda32011-05-28 14:41:13 +0000567 constexpr enable_shared_from_this() noexcept;
568 enable_shared_from_this(enable_shared_from_this const&) noexcept;
569 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000570 ~enable_shared_from_this();
571public:
572 shared_ptr<T> shared_from_this();
573 shared_ptr<T const> shared_from_this() const;
574};
575
576template<class T>
577 bool atomic_is_lock_free(const shared_ptr<T>* p);
578template<class T>
579 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
580template<class T>
581 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
582template<class T>
583 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
584template<class T>
585 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
586template<class T>
587 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
588template<class T>
589 shared_ptr<T>
590 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
591template<class T>
592 bool
593 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
594template<class T>
595 bool
596 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
597template<class T>
598 bool
599 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
600 shared_ptr<T> w, memory_order success,
601 memory_order failure);
602template<class T>
603 bool
604 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
605 shared_ptr<T> w, memory_order success,
606 memory_order failure);
607// Hash support
608template <class T> struct hash;
609template <class T, class D> struct hash<unique_ptr<T, D> >;
610template <class T> struct hash<shared_ptr<T> >;
611
612// Pointer safety
613enum class pointer_safety { relaxed, preferred, strict };
614void declare_reachable(void *p);
615template <class T> T *undeclare_reachable(T *p);
616void declare_no_pointers(char *p, size_t n);
617void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant719bda32011-05-28 14:41:13 +0000618pointer_safety get_pointer_safety() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000619
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
621
622} // std
623
624*/
625
626#include <__config>
627#include <type_traits>
628#include <typeinfo>
629#include <cstddef>
630#include <cstdint>
631#include <new>
632#include <utility>
633#include <limits>
634#include <iterator>
635#include <__functional_base>
Howard Hinnantdc095972011-07-18 15:51:59 +0000636#include <iosfwd>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000637#include <tuple>
Eric Fiselier2db2bd52016-05-07 03:12:24 +0000638#include <stdexcept>
Howard Hinnantd2cab2f2012-02-15 00:41:34 +0000639#include <cstring>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000641#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +0000642# include <atomic>
643#endif
644
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000645#include <__undef_min_max>
Saleem Abdulrasooldcf27a62015-02-13 22:15:32 +0000646#include <__undef___deallocate>
Howard Hinnantc5a5fbd2011-11-29 16:45:27 +0000647
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000648#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000650#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651
652_LIBCPP_BEGIN_NAMESPACE_STD
653
Eric Fiselier89659d12015-07-07 00:27:16 +0000654template <class _ValueType>
655inline _LIBCPP_ALWAYS_INLINE
656_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
657#if !defined(_LIBCPP_HAS_NO_THREADS) && \
658 defined(__ATOMIC_RELAXED) && \
659 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
660 return __atomic_load_n(__value, __ATOMIC_RELAXED);
661#else
662 return *__value;
663#endif
664}
665
Howard Hinnant8bea6da2013-08-08 18:38:55 +0000666// addressof moved to <__functional_base>
Douglas Gregor13034442011-06-22 22:17:44 +0000667
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668template <class _Tp> class allocator;
669
670template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000671class _LIBCPP_TYPE_VIS_ONLY allocator<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672{
673public:
674 typedef void* pointer;
675 typedef const void* const_pointer;
676 typedef void value_type;
677
678 template <class _Up> struct rebind {typedef allocator<_Up> other;};
679};
680
Howard Hinnant9f771052012-01-19 23:15:22 +0000681template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000682class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
Howard Hinnant9f771052012-01-19 23:15:22 +0000683{
684public:
685 typedef const void* pointer;
686 typedef const void* const_pointer;
687 typedef const void value_type;
688
689 template <class _Up> struct rebind {typedef allocator<_Up> other;};
690};
691
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692// pointer_traits
693
694template <class _Tp>
695struct __has_element_type
696{
697private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000698 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699 template <class _Up> static __two __test(...);
700 template <class _Up> static char __test(typename _Up::element_type* = 0);
701public:
702 static const bool value = sizeof(__test<_Tp>(0)) == 1;
703};
704
705template <class _Ptr, bool = __has_element_type<_Ptr>::value>
706struct __pointer_traits_element_type;
707
708template <class _Ptr>
709struct __pointer_traits_element_type<_Ptr, true>
710{
711 typedef typename _Ptr::element_type type;
712};
713
714#ifndef _LIBCPP_HAS_NO_VARIADICS
715
716template <template <class, class...> class _Sp, class _Tp, class ..._Args>
717struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
718{
719 typedef typename _Sp<_Tp, _Args...>::element_type type;
720};
721
722template <template <class, class...> class _Sp, class _Tp, class ..._Args>
723struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
724{
725 typedef _Tp type;
726};
727
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000728#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729
730template <template <class> class _Sp, class _Tp>
731struct __pointer_traits_element_type<_Sp<_Tp>, true>
732{
733 typedef typename _Sp<_Tp>::element_type type;
734};
735
736template <template <class> class _Sp, class _Tp>
737struct __pointer_traits_element_type<_Sp<_Tp>, false>
738{
739 typedef _Tp type;
740};
741
742template <template <class, class> class _Sp, class _Tp, class _A0>
743struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
744{
745 typedef typename _Sp<_Tp, _A0>::element_type type;
746};
747
748template <template <class, class> class _Sp, class _Tp, class _A0>
749struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
750{
751 typedef _Tp type;
752};
753
754template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
755struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
756{
757 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
758};
759
760template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
761struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
762{
763 typedef _Tp type;
764};
765
766template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
767 class _A1, class _A2>
768struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
769{
770 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
771};
772
773template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
774 class _A1, class _A2>
775struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
776{
777 typedef _Tp type;
778};
779
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000780#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781
782template <class _Tp>
783struct __has_difference_type
784{
785private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000786 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 template <class _Up> static __two __test(...);
788 template <class _Up> static char __test(typename _Up::difference_type* = 0);
789public:
790 static const bool value = sizeof(__test<_Tp>(0)) == 1;
791};
792
793template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
794struct __pointer_traits_difference_type
795{
796 typedef ptrdiff_t type;
797};
798
799template <class _Ptr>
800struct __pointer_traits_difference_type<_Ptr, true>
801{
802 typedef typename _Ptr::difference_type type;
803};
804
805template <class _Tp, class _Up>
806struct __has_rebind
807{
808private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000809 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810 template <class _Xp> static __two __test(...);
811 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
812public:
813 static const bool value = sizeof(__test<_Tp>(0)) == 1;
814};
815
816template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
817struct __pointer_traits_rebind
818{
819#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
820 typedef typename _Tp::template rebind<_Up> type;
821#else
822 typedef typename _Tp::template rebind<_Up>::other type;
823#endif
824};
825
826#ifndef _LIBCPP_HAS_NO_VARIADICS
827
828template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
829struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
830{
831#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
832 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
833#else
834 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
835#endif
836};
837
838template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
839struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
840{
841 typedef _Sp<_Up, _Args...> type;
842};
843
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000844#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845
846template <template <class> class _Sp, class _Tp, class _Up>
847struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
848{
849#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
850 typedef typename _Sp<_Tp>::template rebind<_Up> type;
851#else
852 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
853#endif
854};
855
856template <template <class> class _Sp, class _Tp, class _Up>
857struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
858{
859 typedef _Sp<_Up> type;
860};
861
862template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
863struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
864{
865#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
866 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
867#else
868 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
869#endif
870};
871
872template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
873struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
874{
875 typedef _Sp<_Up, _A0> type;
876};
877
878template <template <class, class, class> class _Sp, class _Tp, class _A0,
879 class _A1, class _Up>
880struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
881{
882#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
883 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
884#else
885 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
886#endif
887};
888
889template <template <class, class, class> class _Sp, class _Tp, class _A0,
890 class _A1, class _Up>
891struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
892{
893 typedef _Sp<_Up, _A0, _A1> type;
894};
895
896template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
897 class _A1, class _A2, class _Up>
898struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
899{
900#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
901 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
902#else
903 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
904#endif
905};
906
907template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
908 class _A1, class _A2, class _Up>
909struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
910{
911 typedef _Sp<_Up, _A0, _A1, _A2> type;
912};
913
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000914#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915
916template <class _Ptr>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000917struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918{
919 typedef _Ptr pointer;
920 typedef typename __pointer_traits_element_type<pointer>::type element_type;
921 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
922
923#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantf09283d2011-05-11 20:21:19 +0000924 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925#else
926 template <class _Up> struct rebind
927 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000928#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929
930private:
931 struct __nat {};
932public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934 static pointer pointer_to(typename conditional<is_void<element_type>::value,
935 __nat, element_type>::type& __r)
936 {return pointer::pointer_to(__r);}
937};
938
939template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000940struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941{
942 typedef _Tp* pointer;
943 typedef _Tp element_type;
944 typedef ptrdiff_t difference_type;
945
946#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
947 template <class _Up> using rebind = _Up*;
948#else
949 template <class _Up> struct rebind {typedef _Up* other;};
950#endif
951
952private:
953 struct __nat {};
954public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant719bda32011-05-28 14:41:13 +0000957 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000958 {return _VSTD::addressof(__r);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959};
960
Eric Fiselierae3ab842015-08-23 02:56:05 +0000961template <class _From, class _To>
962struct __rebind_pointer {
963#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
964 typedef typename pointer_traits<_From>::template rebind<_To> type;
965#else
966 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
967#endif
968};
969
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970// allocator_traits
971
972namespace __has_pointer_type_imp
973{
Howard Hinnant6e260172013-09-21 01:45:05 +0000974 template <class _Up> static __two __test(...);
975 template <class _Up> static char __test(typename _Up::pointer* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976}
977
978template <class _Tp>
979struct __has_pointer_type
Howard Hinnant6e260172013-09-21 01:45:05 +0000980 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981{
982};
983
984namespace __pointer_type_imp
985{
986
987template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
988struct __pointer_type
989{
990 typedef typename _Dp::pointer type;
991};
992
993template <class _Tp, class _Dp>
994struct __pointer_type<_Tp, _Dp, false>
995{
996 typedef _Tp* type;
997};
998
Howard Hinnant8e4e6002010-11-18 01:40:00 +0000999} // __pointer_type_imp
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000
1001template <class _Tp, class _Dp>
1002struct __pointer_type
1003{
1004 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1005};
1006
1007template <class _Tp>
1008struct __has_const_pointer
1009{
1010private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001011 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012 template <class _Up> static __two __test(...);
1013 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1014public:
1015 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1016};
1017
1018template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1019struct __const_pointer
1020{
1021 typedef typename _Alloc::const_pointer type;
1022};
1023
1024template <class _Tp, class _Ptr, class _Alloc>
1025struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1026{
1027#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1028 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1029#else
1030 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1031#endif
1032};
1033
1034template <class _Tp>
1035struct __has_void_pointer
1036{
1037private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001038 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 template <class _Up> static __two __test(...);
1040 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1041public:
1042 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1043};
1044
1045template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1046struct __void_pointer
1047{
1048 typedef typename _Alloc::void_pointer type;
1049};
1050
1051template <class _Ptr, class _Alloc>
1052struct __void_pointer<_Ptr, _Alloc, false>
1053{
1054#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1055 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1056#else
1057 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1058#endif
1059};
1060
1061template <class _Tp>
1062struct __has_const_void_pointer
1063{
1064private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001065 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 template <class _Up> static __two __test(...);
1067 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1068public:
1069 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1070};
1071
1072template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1073struct __const_void_pointer
1074{
1075 typedef typename _Alloc::const_void_pointer type;
1076};
1077
1078template <class _Ptr, class _Alloc>
1079struct __const_void_pointer<_Ptr, _Alloc, false>
1080{
1081#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1082 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1083#else
1084 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1085#endif
1086};
1087
Howard Hinnantc834c512011-11-29 18:15:50 +00001088template <class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001090_Tp*
1091__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092{
1093 return __p;
1094}
1095
1096template <class _Pointer>
1097inline _LIBCPP_INLINE_VISIBILITY
1098typename pointer_traits<_Pointer>::element_type*
Howard Hinnant719bda32011-05-28 14:41:13 +00001099__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001101 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102}
1103
1104template <class _Tp>
1105struct __has_size_type
1106{
1107private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001108 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 template <class _Up> static __two __test(...);
1110 template <class _Up> static char __test(typename _Up::size_type* = 0);
1111public:
1112 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1113};
1114
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001115template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116struct __size_type
1117{
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001118 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119};
1120
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001121template <class _Alloc, class _DiffType>
1122struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123{
1124 typedef typename _Alloc::size_type type;
1125};
1126
1127template <class _Tp>
1128struct __has_propagate_on_container_copy_assignment
1129{
1130private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001131 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 template <class _Up> static __two __test(...);
1133 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1134public:
1135 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1136};
1137
1138template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1139struct __propagate_on_container_copy_assignment
1140{
1141 typedef false_type type;
1142};
1143
1144template <class _Alloc>
1145struct __propagate_on_container_copy_assignment<_Alloc, true>
1146{
1147 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1148};
1149
1150template <class _Tp>
1151struct __has_propagate_on_container_move_assignment
1152{
1153private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001154 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155 template <class _Up> static __two __test(...);
1156 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1157public:
1158 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1159};
1160
1161template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1162struct __propagate_on_container_move_assignment
1163{
1164 typedef false_type type;
1165};
1166
1167template <class _Alloc>
1168struct __propagate_on_container_move_assignment<_Alloc, true>
1169{
1170 typedef typename _Alloc::propagate_on_container_move_assignment type;
1171};
1172
1173template <class _Tp>
1174struct __has_propagate_on_container_swap
1175{
1176private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001177 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 template <class _Up> static __two __test(...);
1179 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1180public:
1181 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1182};
1183
1184template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1185struct __propagate_on_container_swap
1186{
1187 typedef false_type type;
1188};
1189
1190template <class _Alloc>
1191struct __propagate_on_container_swap<_Alloc, true>
1192{
1193 typedef typename _Alloc::propagate_on_container_swap type;
1194};
1195
Marshall Clow0b587562015-06-02 16:34:03 +00001196template <class _Tp>
1197struct __has_is_always_equal
1198{
1199private:
1200 struct __two {char __lx; char __lxx;};
1201 template <class _Up> static __two __test(...);
1202 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1203public:
1204 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1205};
1206
1207template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1208struct __is_always_equal
1209{
1210 typedef typename _VSTD::is_empty<_Alloc>::type type;
1211};
1212
1213template <class _Alloc>
1214struct __is_always_equal<_Alloc, true>
1215{
1216 typedef typename _Alloc::is_always_equal type;
1217};
1218
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1220struct __has_rebind_other
1221{
1222private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001223 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 template <class _Xp> static __two __test(...);
1225 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1226public:
1227 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1228};
1229
1230template <class _Tp, class _Up>
1231struct __has_rebind_other<_Tp, _Up, false>
1232{
1233 static const bool value = false;
1234};
1235
1236template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1237struct __allocator_traits_rebind
1238{
1239 typedef typename _Tp::template rebind<_Up>::other type;
1240};
1241
1242#ifndef _LIBCPP_HAS_NO_VARIADICS
1243
1244template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1245struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1246{
1247 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1248};
1249
1250template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1251struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1252{
1253 typedef _Alloc<_Up, _Args...> type;
1254};
1255
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001256#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257
1258template <template <class> class _Alloc, class _Tp, class _Up>
1259struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1260{
1261 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1262};
1263
1264template <template <class> class _Alloc, class _Tp, class _Up>
1265struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1266{
1267 typedef _Alloc<_Up> type;
1268};
1269
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1271struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1272{
1273 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1274};
1275
1276template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1277struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1278{
1279 typedef _Alloc<_Up, _A0> type;
1280};
1281
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1283 class _A1, class _Up>
1284struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1285{
1286 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1287};
1288
1289template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1290 class _A1, class _Up>
1291struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1292{
1293 typedef _Alloc<_Up, _A0, _A1> type;
1294};
1295
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1297 class _A1, class _A2, class _Up>
1298struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1299{
1300 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1301};
1302
1303template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1304 class _A1, class _A2, class _Up>
1305struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1306{
1307 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1308};
1309
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001310#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001311
1312#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
1313
1314template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1315auto
1316__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1317 -> decltype(__a.allocate(__sz, __p), true_type());
1318
1319template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1320auto
1321__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1322 -> false_type;
1323
1324template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1325struct __has_allocate_hint
1326 : integral_constant<bool,
1327 is_same<
1328 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1329 declval<_SizeType>(),
1330 declval<_ConstVoidPtr>())),
1331 true_type>::value>
1332{
1333};
1334
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001335#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336
1337template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1338struct __has_allocate_hint
1339 : true_type
1340{
1341};
1342
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001343#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344
Howard Hinnant986832c2011-07-29 21:35:53 +00001345#if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346
1347template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001348decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1349 _VSTD::declval<_Args>()...),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350 true_type())
1351__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1352
1353template <class _Alloc, class _Pointer, class ..._Args>
1354false_type
1355__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1356
1357template <class _Alloc, class _Pointer, class ..._Args>
1358struct __has_construct
1359 : integral_constant<bool,
1360 is_same<
1361 decltype(__has_construct_test(declval<_Alloc>(),
1362 declval<_Pointer>(),
1363 declval<_Args>()...)),
1364 true_type>::value>
1365{
1366};
1367
1368template <class _Alloc, class _Pointer>
1369auto
1370__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1371 -> decltype(__a.destroy(__p), true_type());
1372
1373template <class _Alloc, class _Pointer>
1374auto
1375__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1376 -> false_type;
1377
1378template <class _Alloc, class _Pointer>
1379struct __has_destroy
1380 : integral_constant<bool,
1381 is_same<
1382 decltype(__has_destroy_test(declval<_Alloc>(),
1383 declval<_Pointer>())),
1384 true_type>::value>
1385{
1386};
1387
1388template <class _Alloc>
1389auto
1390__has_max_size_test(_Alloc&& __a)
1391 -> decltype(__a.max_size(), true_type());
1392
1393template <class _Alloc>
1394auto
1395__has_max_size_test(const volatile _Alloc& __a)
1396 -> false_type;
1397
1398template <class _Alloc>
1399struct __has_max_size
1400 : integral_constant<bool,
1401 is_same<
1402 decltype(__has_max_size_test(declval<_Alloc&>())),
1403 true_type>::value>
1404{
1405};
1406
1407template <class _Alloc>
1408auto
1409__has_select_on_container_copy_construction_test(_Alloc&& __a)
1410 -> decltype(__a.select_on_container_copy_construction(), true_type());
1411
1412template <class _Alloc>
1413auto
1414__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1415 -> false_type;
1416
1417template <class _Alloc>
1418struct __has_select_on_container_copy_construction
1419 : integral_constant<bool,
1420 is_same<
1421 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1422 true_type>::value>
1423{
1424};
1425
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001426#else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427
1428#ifndef _LIBCPP_HAS_NO_VARIADICS
1429
1430template <class _Alloc, class _Pointer, class ..._Args>
1431struct __has_construct
1432 : false_type
1433{
1434};
1435
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001436#else // _LIBCPP_HAS_NO_VARIADICS
1437
1438template <class _Alloc, class _Pointer, class _Args>
1439struct __has_construct
1440 : false_type
1441{
1442};
1443
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001444#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445
1446template <class _Alloc, class _Pointer>
1447struct __has_destroy
1448 : false_type
1449{
1450};
1451
1452template <class _Alloc>
1453struct __has_max_size
1454 : true_type
1455{
1456};
1457
1458template <class _Alloc>
1459struct __has_select_on_container_copy_construction
1460 : false_type
1461{
1462};
1463
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001464#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001466template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1467struct __alloc_traits_difference_type
1468{
1469 typedef typename pointer_traits<_Ptr>::difference_type type;
1470};
1471
1472template <class _Alloc, class _Ptr>
1473struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1474{
1475 typedef typename _Alloc::difference_type type;
1476};
1477
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478template <class _Alloc>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001479struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480{
1481 typedef _Alloc allocator_type;
1482 typedef typename allocator_type::value_type value_type;
1483
1484 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1485 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1486 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1487 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1488
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001489 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1490 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491
1492 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1493 propagate_on_container_copy_assignment;
1494 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1495 propagate_on_container_move_assignment;
1496 typedef typename __propagate_on_container_swap<allocator_type>::type
1497 propagate_on_container_swap;
Marshall Clow0b587562015-06-02 16:34:03 +00001498 typedef typename __is_always_equal<allocator_type>::type
1499 is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500
1501#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1502 template <class _Tp> using rebind_alloc =
Howard Hinnantf09283d2011-05-11 20:21:19 +00001503 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001505#else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506 template <class _Tp> struct rebind_alloc
1507 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1508 template <class _Tp> struct rebind_traits
1509 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001510#endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001511
Howard Hinnant756c69b2010-09-22 16:48:34 +00001512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513 static pointer allocate(allocator_type& __a, size_type __n)
1514 {return __a.allocate(__n);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1517 {return allocate(__a, __n, __hint,
1518 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1519
Howard Hinnant756c69b2010-09-22 16:48:34 +00001520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001521 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001522 {__a.deallocate(__p, __n);}
1523
1524#ifndef _LIBCPP_HAS_NO_VARIADICS
1525 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001527 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow3996b8b2014-11-11 19:22:33 +00001528 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001529 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001530#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533 static void construct(allocator_type& __a, _Tp* __p)
1534 {
1535 ::new ((void*)__p) _Tp();
1536 }
1537 template <class _Tp, class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
1540 {
1541 ::new ((void*)__p) _Tp(__a0);
1542 }
1543 template <class _Tp, class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1546 const _A1& __a1)
1547 {
1548 ::new ((void*)__p) _Tp(__a0, __a1);
1549 }
1550 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
1553 const _A1& __a1, const _A2& __a2)
1554 {
1555 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1556 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001557#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558
1559 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 static void destroy(allocator_type& __a, _Tp* __p)
1562 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1563
Howard Hinnant756c69b2010-09-22 16:48:34 +00001564 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4f834b52013-08-27 20:22:15 +00001565 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1567
Howard Hinnant756c69b2010-09-22 16:48:34 +00001568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 static allocator_type
1570 select_on_container_copy_construction(const allocator_type& __a)
1571 {return select_on_container_copy_construction(
1572 __has_select_on_container_copy_construction<const allocator_type>(),
1573 __a);}
1574
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001575 template <class _Ptr>
1576 _LIBCPP_INLINE_VISIBILITY
1577 static
1578 void
1579 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1580 {
1581 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1582 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1583 }
1584
1585 template <class _Tp>
1586 _LIBCPP_INLINE_VISIBILITY
1587 static
1588 typename enable_if
1589 <
1590 (is_same<allocator_type, allocator<_Tp> >::value
1591 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1592 is_trivially_move_constructible<_Tp>::value,
1593 void
1594 >::type
1595 __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1596 {
1597 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001598 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001599 {
Marshall Clow4907e8f2015-05-31 03:13:31 +00001600 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001601 __begin2 += _Np;
1602 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001603 }
1604
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001605 template <class _Iter, class _Ptr>
1606 _LIBCPP_INLINE_VISIBILITY
1607 static
1608 void
1609 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1610 {
1611 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1612 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1613 }
1614
1615 template <class _Tp>
1616 _LIBCPP_INLINE_VISIBILITY
1617 static
1618 typename enable_if
1619 <
1620 (is_same<allocator_type, allocator<_Tp> >::value
1621 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1622 is_trivially_move_constructible<_Tp>::value,
1623 void
1624 >::type
1625 __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1626 {
1627 typedef typename remove_const<_Tp>::type _Vp;
1628 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001629 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001630 {
Marshall Clow4907e8f2015-05-31 03:13:31 +00001631 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001632 __begin2 += _Np;
1633 }
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001634 }
1635
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001636 template <class _Ptr>
1637 _LIBCPP_INLINE_VISIBILITY
1638 static
1639 void
1640 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1641 {
1642 while (__end1 != __begin1)
Howard Hinnant5adee4c2013-01-11 20:36:59 +00001643 {
1644 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1645 --__end2;
1646 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001647 }
1648
1649 template <class _Tp>
1650 _LIBCPP_INLINE_VISIBILITY
1651 static
1652 typename enable_if
1653 <
1654 (is_same<allocator_type, allocator<_Tp> >::value
1655 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1656 is_trivially_move_constructible<_Tp>::value,
1657 void
1658 >::type
1659 __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1660 {
1661 ptrdiff_t _Np = __end1 - __begin1;
1662 __end2 -= _Np;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001663 if (_Np > 0)
1664 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001665 }
1666
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667private:
1668
Howard Hinnant756c69b2010-09-22 16:48:34 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670 static pointer allocate(allocator_type& __a, size_type __n,
1671 const_void_pointer __hint, true_type)
1672 {return __a.allocate(__n, __hint);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001674 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnant28b24882011-12-01 20:21:04 +00001675 const_void_pointer, false_type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676 {return __a.allocate(__n);}
1677
1678#ifndef _LIBCPP_HAS_NO_VARIADICS
1679 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001681 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001682 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001683 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1686 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001687 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001688 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001689#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690
1691 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001693 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1694 {__a.destroy(__p);}
1695 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001697 static void __destroy(false_type, allocator_type&, _Tp* __p)
1698 {
1699 __p->~_Tp();
1700 }
1701
Howard Hinnant756c69b2010-09-22 16:48:34 +00001702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001703 static size_type __max_size(true_type, const allocator_type& __a)
1704 {return __a.max_size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001706 static size_type __max_size(false_type, const allocator_type&)
Marshall Clow33daa162015-10-25 19:34:04 +00001707 {return numeric_limits<size_type>::max() / sizeof(value_type);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001708
Howard Hinnant756c69b2010-09-22 16:48:34 +00001709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710 static allocator_type
1711 select_on_container_copy_construction(true_type, const allocator_type& __a)
1712 {return __a.select_on_container_copy_construction();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714 static allocator_type
1715 select_on_container_copy_construction(false_type, const allocator_type& __a)
1716 {return __a;}
1717};
1718
Marshall Clow940e01c2015-04-07 05:21:38 +00001719template <class _Traits, class _Tp>
1720struct __rebind_alloc_helper
1721{
1722#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Marshall Clow35cde742015-05-10 13:59:45 +00001723 typedef typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow940e01c2015-04-07 05:21:38 +00001724#else
1725 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1726#endif
1727};
1728
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729// allocator
1730
1731template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001732class _LIBCPP_TYPE_VIS_ONLY allocator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733{
1734public:
1735 typedef size_t size_type;
1736 typedef ptrdiff_t difference_type;
1737 typedef _Tp* pointer;
1738 typedef const _Tp* const_pointer;
1739 typedef _Tp& reference;
1740 typedef const _Tp& const_reference;
1741 typedef _Tp value_type;
1742
Howard Hinnant4931e092011-06-02 21:38:57 +00001743 typedef true_type propagate_on_container_move_assignment;
Marshall Clow0b587562015-06-02 16:34:03 +00001744 typedef true_type is_always_equal;
Howard Hinnant4931e092011-06-02 21:38:57 +00001745
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1747
Howard Hinnant719bda32011-05-28 14:41:13 +00001748 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1749 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1750 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001751 {return _VSTD::addressof(__x);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001752 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001753 {return _VSTD::addressof(__x);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001755 {
1756 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001757 __throw_length_error("allocator<T>::allocate(size_t n)"
1758 " 'n' exceeds maximum supported size");
Marshall Clow813ffb32016-03-03 12:04:39 +00001759 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1760 }
Howard Hinnant719bda32011-05-28 14:41:13 +00001761 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith1f1c1472014-06-04 19:54:15 +00001762 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001763 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1764 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001765#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766 template <class _Up, class... _Args>
1767 _LIBCPP_INLINE_VISIBILITY
1768 void
1769 construct(_Up* __p, _Args&&... __args)
1770 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001771 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001773#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774 _LIBCPP_INLINE_VISIBILITY
1775 void
1776 construct(pointer __p)
1777 {
1778 ::new((void*)__p) _Tp();
1779 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001780# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001781
Howard Hinnantc51e1022010-05-11 19:42:16 +00001782 template <class _A0>
1783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001784 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001785 construct(pointer __p, _A0& __a0)
1786 {
1787 ::new((void*)__p) _Tp(__a0);
1788 }
1789 template <class _A0>
1790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001791 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 construct(pointer __p, const _A0& __a0)
1793 {
1794 ::new((void*)__p) _Tp(__a0);
1795 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001796# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797 template <class _A0, class _A1>
1798 _LIBCPP_INLINE_VISIBILITY
1799 void
1800 construct(pointer __p, _A0& __a0, _A1& __a1)
1801 {
1802 ::new((void*)__p) _Tp(__a0, __a1);
1803 }
1804 template <class _A0, class _A1>
1805 _LIBCPP_INLINE_VISIBILITY
1806 void
1807 construct(pointer __p, const _A0& __a0, _A1& __a1)
1808 {
1809 ::new((void*)__p) _Tp(__a0, __a1);
1810 }
1811 template <class _A0, class _A1>
1812 _LIBCPP_INLINE_VISIBILITY
1813 void
1814 construct(pointer __p, _A0& __a0, const _A1& __a1)
1815 {
1816 ::new((void*)__p) _Tp(__a0, __a1);
1817 }
1818 template <class _A0, class _A1>
1819 _LIBCPP_INLINE_VISIBILITY
1820 void
1821 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1822 {
1823 ::new((void*)__p) _Tp(__a0, __a1);
1824 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001825#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1827};
1828
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001829template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001830class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001831{
1832public:
1833 typedef size_t size_type;
1834 typedef ptrdiff_t difference_type;
1835 typedef const _Tp* pointer;
1836 typedef const _Tp* const_pointer;
1837 typedef const _Tp& reference;
1838 typedef const _Tp& const_reference;
Howard Hinnant9bc95e22013-06-07 01:56:37 +00001839 typedef const _Tp value_type;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001840
1841 typedef true_type propagate_on_container_move_assignment;
Marshall Clowac12fcc2015-07-01 21:23:40 +00001842 typedef true_type is_always_equal;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001843
1844 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1845
1846 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1847 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1848 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1849 {return _VSTD::addressof(__x);}
1850 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001851 {
1852 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001853 __throw_length_error("allocator<const T>::allocate(size_t n)"
1854 " 'n' exceeds maximum supported size");
Marshall Clow813ffb32016-03-03 12:04:39 +00001855 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
Eric Fiselier2db2bd52016-05-07 03:12:24 +00001856 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001857 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Richard Smith1f1c1472014-06-04 19:54:15 +00001858 {_VSTD::__deallocate((void*)__p);}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001859 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1860 {return size_type(~0) / sizeof(_Tp);}
1861#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1862 template <class _Up, class... _Args>
1863 _LIBCPP_INLINE_VISIBILITY
1864 void
1865 construct(_Up* __p, _Args&&... __args)
1866 {
1867 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1868 }
1869#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1870 _LIBCPP_INLINE_VISIBILITY
1871 void
1872 construct(pointer __p)
1873 {
1874 ::new((void*)__p) _Tp();
1875 }
1876# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001877
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001878 template <class _A0>
1879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001880 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001881 construct(pointer __p, _A0& __a0)
1882 {
1883 ::new((void*)__p) _Tp(__a0);
1884 }
1885 template <class _A0>
1886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001887 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001888 construct(pointer __p, const _A0& __a0)
1889 {
1890 ::new((void*)__p) _Tp(__a0);
1891 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001892# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1893 template <class _A0, class _A1>
1894 _LIBCPP_INLINE_VISIBILITY
1895 void
1896 construct(pointer __p, _A0& __a0, _A1& __a1)
1897 {
1898 ::new((void*)__p) _Tp(__a0, __a1);
1899 }
1900 template <class _A0, class _A1>
1901 _LIBCPP_INLINE_VISIBILITY
1902 void
1903 construct(pointer __p, const _A0& __a0, _A1& __a1)
1904 {
1905 ::new((void*)__p) _Tp(__a0, __a1);
1906 }
1907 template <class _A0, class _A1>
1908 _LIBCPP_INLINE_VISIBILITY
1909 void
1910 construct(pointer __p, _A0& __a0, const _A1& __a1)
1911 {
1912 ::new((void*)__p) _Tp(__a0, __a1);
1913 }
1914 template <class _A0, class _A1>
1915 _LIBCPP_INLINE_VISIBILITY
1916 void
1917 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1918 {
1919 ::new((void*)__p) _Tp(__a0, __a1);
1920 }
1921#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1922 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1923};
1924
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925template <class _Tp, class _Up>
1926inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001927bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001928
1929template <class _Tp, class _Up>
1930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001931bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932
1933template <class _OutputIterator, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001934class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001935 : public iterator<output_iterator_tag,
1936 _Tp, // purposefully not C++03
1937 ptrdiff_t, // purposefully not C++03
1938 _Tp*, // purposefully not C++03
1939 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1940{
1941private:
1942 _OutputIterator __x_;
1943public:
1944 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1945 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1946 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1947 {::new(&*__x_) _Tp(__element); return *this;}
Marshall Clow5c3f09e2015-10-25 18:58:07 +00001948#if _LIBCPP_STD_VER >= 14
1949 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1950 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1951#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1953 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1954 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowb949f1b2015-05-10 13:14:08 +00001955#if _LIBCPP_STD_VER >= 14
1956 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1957#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001958};
1959
1960template <class _Tp>
1961pair<_Tp*, ptrdiff_t>
Howard Hinnant719bda32011-05-28 14:41:13 +00001962get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001963{
1964 pair<_Tp*, ptrdiff_t> __r(0, 0);
1965 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1966 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1967 / sizeof(_Tp);
1968 if (__n > __m)
1969 __n = __m;
1970 while (__n > 0)
1971 {
1972 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1973 if (__r.first)
1974 {
1975 __r.second = __n;
1976 break;
1977 }
1978 __n /= 2;
1979 }
1980 return __r;
1981}
1982
1983template <class _Tp>
1984inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001985void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986
1987template <class _Tp>
1988struct auto_ptr_ref
1989{
1990 _Tp* __ptr_;
1991};
1992
1993template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001994class _LIBCPP_TYPE_VIS_ONLY auto_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00001995{
1996private:
1997 _Tp* __ptr_;
1998public:
1999 typedef _Tp element_type;
2000
2001 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2002 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2003 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2004 : __ptr_(__p.release()) {}
2005 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2006 {reset(__p.release()); return *this;}
2007 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2008 {reset(__p.release()); return *this;}
2009 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2010 {reset(__p.__ptr_); return *this;}
2011 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2012
2013 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2014 {return *__ptr_;}
2015 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2016 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2017 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2018 {
2019 _Tp* __t = __ptr_;
2020 __ptr_ = 0;
2021 return __t;
2022 }
2023 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2024 {
2025 if (__ptr_ != __p)
2026 delete __ptr_;
2027 __ptr_ = __p;
2028 }
2029
2030 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2031 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2032 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2033 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2034 {return auto_ptr<_Up>(release());}
2035};
2036
2037template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002038class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039{
2040public:
2041 typedef void element_type;
2042};
2043
Howard Hinnantc51e1022010-05-11 19:42:16 +00002044template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
2045 typename remove_cv<_T2>::type>::value,
Howard Hinnantd0aabf82011-12-11 20:31:33 +00002046 bool = is_empty<_T1>::value
Eric Fiselierf7394302015-06-13 07:08:02 +00002047 && !__libcpp_is_final<_T1>::value,
Howard Hinnantd0aabf82011-12-11 20:31:33 +00002048 bool = is_empty<_T2>::value
Eric Fiselierf7394302015-06-13 07:08:02 +00002049 && !__libcpp_is_final<_T2>::value
Howard Hinnantd0aabf82011-12-11 20:31:33 +00002050 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00002051struct __libcpp_compressed_pair_switch;
2052
2053template <class _T1, class _T2, bool IsSame>
2054struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2055
2056template <class _T1, class _T2, bool IsSame>
2057struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2058
2059template <class _T1, class _T2, bool IsSame>
2060struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2061
2062template <class _T1, class _T2>
2063struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2064
2065template <class _T1, class _T2>
2066struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2067
2068template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2069class __libcpp_compressed_pair_imp;
2070
2071template <class _T1, class _T2>
2072class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2073{
2074private:
2075 _T1 __first_;
2076 _T2 __second_;
2077public:
2078 typedef _T1 _T1_param;
2079 typedef _T2 _T2_param;
2080
2081 typedef typename remove_reference<_T1>::type& _T1_reference;
2082 typedef typename remove_reference<_T2>::type& _T2_reference;
2083
2084 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2085 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2086
Marshall Clowac92bfe2015-07-16 03:05:06 +00002087 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002088 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Marshall Clowac92bfe2015-07-16 03:05:06 +00002089 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002090 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Marshall Clowac92bfe2015-07-16 03:05:06 +00002091 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002093 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002094
Howard Hinnant59f73012013-11-13 00:39:22 +00002095#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002096
2097 _LIBCPP_INLINE_VISIBILITY
2098 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2099 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2100 is_nothrow_copy_constructible<_T2>::value)
2101 : __first_(__p.first()),
2102 __second_(__p.second()) {}
2103
2104 _LIBCPP_INLINE_VISIBILITY
2105 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2106 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2107 is_nothrow_copy_assignable<_T2>::value)
2108 {
2109 __first_ = __p.first();
2110 __second_ = __p.second();
2111 return *this;
2112 }
2113
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002114 _LIBCPP_INLINE_VISIBILITY
2115 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002116 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2117 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002118 : __first_(_VSTD::forward<_T1>(__p.first())),
2119 __second_(_VSTD::forward<_T2>(__p.second())) {}
2120
2121 _LIBCPP_INLINE_VISIBILITY
2122 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2123 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2124 is_nothrow_move_assignable<_T2>::value)
2125 {
2126 __first_ = _VSTD::forward<_T1>(__p.first());
2127 __second_ = _VSTD::forward<_T2>(__p.second());
2128 return *this;
2129 }
2130
Howard Hinnant59f73012013-11-13 00:39:22 +00002131#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002132
Howard Hinnant83b1c052011-12-19 17:58:44 +00002133#ifndef _LIBCPP_HAS_NO_VARIADICS
2134
2135 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2136 _LIBCPP_INLINE_VISIBILITY
2137 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2138 tuple<_Args1...> __first_args,
2139 tuple<_Args2...> __second_args,
2140 __tuple_indices<_I1...>,
2141 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002142 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2143 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002144 {}
2145
2146#endif // _LIBCPP_HAS_NO_VARIADICS
2147
Howard Hinnant719bda32011-05-28 14:41:13 +00002148 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2149 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002150
Howard Hinnant719bda32011-05-28 14:41:13 +00002151 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2152 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153
2154 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002155 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002156 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002158 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002159 swap(__first_, __x.__first_);
2160 swap(__second_, __x.__second_);
2161 }
2162};
2163
2164template <class _T1, class _T2>
2165class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2166 : private _T1
2167{
2168private:
2169 _T2 __second_;
2170public:
2171 typedef _T1 _T1_param;
2172 typedef _T2 _T2_param;
2173
2174 typedef _T1& _T1_reference;
2175 typedef typename remove_reference<_T2>::type& _T2_reference;
2176
2177 typedef const _T1& _T1_const_reference;
2178 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2179
Marshall Clowac92bfe2015-07-16 03:05:06 +00002180 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002181 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Marshall Clowac92bfe2015-07-16 03:05:06 +00002182 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002183 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002184 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002186 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187
Howard Hinnant59f73012013-11-13 00:39:22 +00002188#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002189
2190 _LIBCPP_INLINE_VISIBILITY
2191 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2192 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2193 is_nothrow_copy_constructible<_T2>::value)
2194 : _T1(__p.first()), __second_(__p.second()) {}
2195
2196 _LIBCPP_INLINE_VISIBILITY
2197 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2198 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2199 is_nothrow_copy_assignable<_T2>::value)
2200 {
2201 _T1::operator=(__p.first());
2202 __second_ = __p.second();
2203 return *this;
2204 }
2205
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002206 _LIBCPP_INLINE_VISIBILITY
2207 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002208 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2209 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002210 : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002211
2212 _LIBCPP_INLINE_VISIBILITY
2213 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2214 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2215 is_nothrow_move_assignable<_T2>::value)
2216 {
2217 _T1::operator=(_VSTD::move(__p.first()));
2218 __second_ = _VSTD::forward<_T2>(__p.second());
2219 return *this;
2220 }
2221
Howard Hinnant59f73012013-11-13 00:39:22 +00002222#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002223
Howard Hinnant83b1c052011-12-19 17:58:44 +00002224#ifndef _LIBCPP_HAS_NO_VARIADICS
2225
2226 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2227 _LIBCPP_INLINE_VISIBILITY
2228 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2229 tuple<_Args1...> __first_args,
2230 tuple<_Args2...> __second_args,
2231 __tuple_indices<_I1...>,
2232 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002233 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2234 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002235 {}
2236
2237#endif // _LIBCPP_HAS_NO_VARIADICS
2238
Howard Hinnant719bda32011-05-28 14:41:13 +00002239 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2240 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002241
Howard Hinnant719bda32011-05-28 14:41:13 +00002242 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2243 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002244
2245 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002246 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002247 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002248 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002249 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002250 swap(__second_, __x.__second_);
2251 }
2252};
2253
2254template <class _T1, class _T2>
2255class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2256 : private _T2
2257{
2258private:
2259 _T1 __first_;
2260public:
2261 typedef _T1 _T1_param;
2262 typedef _T2 _T2_param;
2263
2264 typedef typename remove_reference<_T1>::type& _T1_reference;
2265 typedef _T2& _T2_reference;
2266
2267 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2268 typedef const _T2& _T2_const_reference;
2269
Marshall Clowac92bfe2015-07-16 03:05:06 +00002270 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002271 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002272 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002273 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Marshall Clowac92bfe2015-07-16 03:05:06 +00002274 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002275 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant719bda32011-05-28 14:41:13 +00002276 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2277 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002278 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002279
Howard Hinnant59f73012013-11-13 00:39:22 +00002280#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002281
2282 _LIBCPP_INLINE_VISIBILITY
2283 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2284 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2285 is_nothrow_copy_constructible<_T2>::value)
2286 : _T2(__p.second()), __first_(__p.first()) {}
2287
2288 _LIBCPP_INLINE_VISIBILITY
2289 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2290 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2291 is_nothrow_copy_assignable<_T2>::value)
2292 {
2293 _T2::operator=(__p.second());
2294 __first_ = __p.first();
2295 return *this;
2296 }
2297
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002299 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002300 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2301 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002302 : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002303
2304 _LIBCPP_INLINE_VISIBILITY
2305 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2306 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2307 is_nothrow_move_assignable<_T2>::value)
2308 {
2309 _T2::operator=(_VSTD::forward<_T2>(__p.second()));
2310 __first_ = _VSTD::move(__p.first());
2311 return *this;
2312 }
2313
Howard Hinnant59f73012013-11-13 00:39:22 +00002314#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002315
Howard Hinnant83b1c052011-12-19 17:58:44 +00002316#ifndef _LIBCPP_HAS_NO_VARIADICS
2317
2318 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2319 _LIBCPP_INLINE_VISIBILITY
2320 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2321 tuple<_Args1...> __first_args,
2322 tuple<_Args2...> __second_args,
2323 __tuple_indices<_I1...>,
2324 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002325 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2326 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002327
2328 {}
2329
2330#endif // _LIBCPP_HAS_NO_VARIADICS
2331
Howard Hinnant719bda32011-05-28 14:41:13 +00002332 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2333 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002334
Howard Hinnant719bda32011-05-28 14:41:13 +00002335 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2336 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002337
2338 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant719bda32011-05-28 14:41:13 +00002339 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002340 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002341 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002342 using _VSTD::swap;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343 swap(__first_, __x.__first_);
2344 }
2345};
2346
2347template <class _T1, class _T2>
2348class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2349 : private _T1,
2350 private _T2
2351{
2352public:
2353 typedef _T1 _T1_param;
2354 typedef _T2 _T2_param;
2355
2356 typedef _T1& _T1_reference;
2357 typedef _T2& _T2_reference;
2358
2359 typedef const _T1& _T1_const_reference;
2360 typedef const _T2& _T2_const_reference;
2361
2362 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2363 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002364 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002365 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002366 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002367 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002368 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002369
Howard Hinnant59f73012013-11-13 00:39:22 +00002370#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002371
2372 _LIBCPP_INLINE_VISIBILITY
2373 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
2374 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2375 is_nothrow_copy_constructible<_T2>::value)
2376 : _T1(__p.first()), _T2(__p.second()) {}
2377
2378 _LIBCPP_INLINE_VISIBILITY
2379 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
2380 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2381 is_nothrow_copy_assignable<_T2>::value)
2382 {
2383 _T1::operator=(__p.first());
2384 _T2::operator=(__p.second());
2385 return *this;
2386 }
2387
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002388 _LIBCPP_INLINE_VISIBILITY
2389 __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002390 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2391 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002392 : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002393
2394 _LIBCPP_INLINE_VISIBILITY
2395 __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
2396 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2397 is_nothrow_move_assignable<_T2>::value)
2398 {
2399 _T1::operator=(_VSTD::move(__p.first()));
2400 _T2::operator=(_VSTD::move(__p.second()));
2401 return *this;
2402 }
2403
Howard Hinnant59f73012013-11-13 00:39:22 +00002404#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002405
Howard Hinnant83b1c052011-12-19 17:58:44 +00002406#ifndef _LIBCPP_HAS_NO_VARIADICS
2407
2408 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2409 _LIBCPP_INLINE_VISIBILITY
2410 __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
2411 tuple<_Args1...> __first_args,
2412 tuple<_Args2...> __second_args,
2413 __tuple_indices<_I1...>,
2414 __tuple_indices<_I2...>)
Marshall Clow60e4aa72014-06-24 00:46:19 +00002415 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2416 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnant83b1c052011-12-19 17:58:44 +00002417 {}
2418
2419#endif // _LIBCPP_HAS_NO_VARIADICS
2420
Howard Hinnant719bda32011-05-28 14:41:13 +00002421 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2422 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002423
Howard Hinnant719bda32011-05-28 14:41:13 +00002424 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2425 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002426
Howard Hinnant28b24882011-12-01 20:21:04 +00002427 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant719bda32011-05-28 14:41:13 +00002428 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002429 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002430 {
2431 }
2432};
2433
2434template <class _T1, class _T2>
2435class __compressed_pair
2436 : private __libcpp_compressed_pair_imp<_T1, _T2>
2437{
2438 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2439public:
2440 typedef typename base::_T1_param _T1_param;
2441 typedef typename base::_T2_param _T2_param;
2442
2443 typedef typename base::_T1_reference _T1_reference;
2444 typedef typename base::_T2_reference _T2_reference;
2445
2446 typedef typename base::_T1_const_reference _T1_const_reference;
2447 typedef typename base::_T2_const_reference _T2_const_reference;
2448
2449 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002450 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002451 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002452 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002453 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002454 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002455 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002456
Howard Hinnant59f73012013-11-13 00:39:22 +00002457#if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002458
2459 _LIBCPP_INLINE_VISIBILITY
2460 __compressed_pair(const __compressed_pair& __p)
2461 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
2462 is_nothrow_copy_constructible<_T2>::value)
2463 : base(__p) {}
2464
2465 _LIBCPP_INLINE_VISIBILITY
2466 __compressed_pair& operator=(const __compressed_pair& __p)
2467 _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
2468 is_nothrow_copy_assignable<_T2>::value)
2469 {
2470 base::operator=(__p);
2471 return *this;
2472 }
2473
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002475 __compressed_pair(__compressed_pair&& __p)
Howard Hinnant719bda32011-05-28 14:41:13 +00002476 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2477 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002478 : base(_VSTD::move(__p)) {}
Howard Hinnantd3a657f2011-07-01 19:24:36 +00002479
2480 _LIBCPP_INLINE_VISIBILITY
2481 __compressed_pair& operator=(__compressed_pair&& __p)
2482 _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
2483 is_nothrow_move_assignable<_T2>::value)
2484 {
2485 base::operator=(_VSTD::move(__p));
2486 return *this;
2487 }
Howard Hinnant83b1c052011-12-19 17:58:44 +00002488
Howard Hinnant59f73012013-11-13 00:39:22 +00002489#endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant866c4b82013-05-06 16:58:36 +00002490
Howard Hinnant83b1c052011-12-19 17:58:44 +00002491#ifndef _LIBCPP_HAS_NO_VARIADICS
2492
2493 template <class... _Args1, class... _Args2>
2494 _LIBCPP_INLINE_VISIBILITY
2495 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2496 tuple<_Args2...> __second_args)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002497 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnant83b1c052011-12-19 17:58:44 +00002498 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2499 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2500 {}
2501
2502#endif // _LIBCPP_HAS_NO_VARIADICS
2503
Howard Hinnant719bda32011-05-28 14:41:13 +00002504 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2505 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002506
Howard Hinnant719bda32011-05-28 14:41:13 +00002507 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2508 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002509
Howard Hinnant719bda32011-05-28 14:41:13 +00002510 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2511 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002512 __is_nothrow_swappable<_T2>::value)
Howard Hinnant719bda32011-05-28 14:41:13 +00002513 {base::swap(__x);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002514};
2515
2516template <class _T1, class _T2>
2517inline _LIBCPP_INLINE_VISIBILITY
2518void
2519swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant719bda32011-05-28 14:41:13 +00002520 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clow9c1d91f2014-06-30 15:35:09 +00002521 __is_nothrow_swappable<_T2>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002522 {__x.swap(__y);}
2523
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002524// __same_or_less_cv_qualified
2525
2526template <class _Ptr1, class _Ptr2,
2527 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2528 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2529 >::value
2530 >
2531struct __same_or_less_cv_qualified_imp
2532 : is_convertible<_Ptr1, _Ptr2> {};
2533
2534template <class _Ptr1, class _Ptr2>
2535struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2536 : false_type {};
2537
Marshall Clowdf296162014-04-26 05:19:48 +00002538template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2539 is_same<_Ptr1, _Ptr2>::value ||
2540 __has_element_type<_Ptr1>::value>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002541struct __same_or_less_cv_qualified
2542 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2543
2544template <class _Ptr1, class _Ptr2>
Marshall Clowdf296162014-04-26 05:19:48 +00002545struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002546 : false_type {};
2547
2548// default_delete
2549
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002551struct _LIBCPP_TYPE_VIS_ONLY default_delete
Howard Hinnantc51e1022010-05-11 19:42:16 +00002552{
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002553#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2554 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2555#else
2556 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2557#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002558 template <class _Up>
2559 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant719bda32011-05-28 14:41:13 +00002560 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2561 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002562 {
2563 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant14015fd2013-04-24 19:44:26 +00002564 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002565 delete __ptr;
2566 }
2567};
2568
2569template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002570struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002571{
Howard Hinnant4500ca52011-12-18 21:19:44 +00002572public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002573#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2574 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2575#else
2576 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2577#endif
Howard Hinnant4500ca52011-12-18 21:19:44 +00002578 template <class _Up>
2579 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002580 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnant4500ca52011-12-18 21:19:44 +00002581 template <class _Up>
2582 _LIBCPP_INLINE_VISIBILITY
2583 void operator() (_Up* __ptr,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002584 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002585 {
2586 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Marshall Clowff0e4132016-02-25 16:50:51 +00002587 static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002588 delete [] __ptr;
2589 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002590};
2591
2592template <class _Tp, class _Dp = default_delete<_Tp> >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002593class _LIBCPP_TYPE_VIS_ONLY unique_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00002594{
2595public:
2596 typedef _Tp element_type;
2597 typedef _Dp deleter_type;
2598 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2599private:
2600 __compressed_pair<pointer, deleter_type> __ptr_;
2601
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002602#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603 unique_ptr(unique_ptr&);
2604 template <class _Up, class _Ep>
2605 unique_ptr(unique_ptr<_Up, _Ep>&);
2606 unique_ptr& operator=(unique_ptr&);
2607 template <class _Up, class _Ep>
2608 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant74279a52010-09-04 23:28:19 +00002609#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002610
2611 struct __nat {int __for_bool_;};
2612
2613 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2614 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2615public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002616 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002617 : __ptr_(pointer())
2618 {
2619 static_assert(!is_pointer<deleter_type>::value,
2620 "unique_ptr constructed with null function pointer deleter");
2621 }
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002622 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623 : __ptr_(pointer())
2624 {
2625 static_assert(!is_pointer<deleter_type>::value,
2626 "unique_ptr constructed with null function pointer deleter");
2627 }
Howard Hinnant719bda32011-05-28 14:41:13 +00002628 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002629 : __ptr_(_VSTD::move(__p))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002630 {
2631 static_assert(!is_pointer<deleter_type>::value,
2632 "unique_ptr constructed with null function pointer deleter");
2633 }
2634
Howard Hinnant74279a52010-09-04 23:28:19 +00002635#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002636 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2637 is_reference<deleter_type>::value,
2638 deleter_type,
2639 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002640 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002641 : __ptr_(__p, __d) {}
2642
2643 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002644 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002645 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002646 {
2647 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2648 }
Howard Hinnant719bda32011-05-28 14:41:13 +00002649 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002650 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002651 template <class _Up, class _Ep>
2652 _LIBCPP_INLINE_VISIBILITY
2653 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2654 typename enable_if
2655 <
2656 !is_array<_Up>::value &&
2657 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2658 is_convertible<_Ep, deleter_type>::value &&
2659 (
2660 !is_reference<deleter_type>::value ||
2661 is_same<deleter_type, _Ep>::value
2662 ),
2663 __nat
Howard Hinnant719bda32011-05-28 14:41:13 +00002664 >::type = __nat()) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002665 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002666
2667 template <class _Up>
2668 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2669 typename enable_if<
2670 is_convertible<_Up*, _Tp*>::value &&
2671 is_same<_Dp, default_delete<_Tp> >::value,
2672 __nat
Howard Hinnant719bda32011-05-28 14:41:13 +00002673 >::type = __nat()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674 : __ptr_(__p.release())
2675 {
2676 }
2677
Howard Hinnant719bda32011-05-28 14:41:13 +00002678 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002679 {
2680 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002681 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002682 return *this;
2683 }
2684
2685 template <class _Up, class _Ep>
2686 _LIBCPP_INLINE_VISIBILITY
2687 typename enable_if
2688 <
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002689 !is_array<_Up>::value &&
2690 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2691 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002692 unique_ptr&
2693 >::type
Howard Hinnant719bda32011-05-28 14:41:13 +00002694 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002695 {
2696 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002697 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002698 return *this;
2699 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002700#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002701
2702 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2703 {
2704 return __rv<unique_ptr>(*this);
2705 }
2706
2707 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002708 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002709
2710 template <class _Up, class _Ep>
Eric Fiselier6d8c8ed2015-08-28 05:07:06 +00002711 _LIBCPP_INLINE_VISIBILITY
2712 typename enable_if<
2713 !is_array<_Up>::value &&
2714 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2715 is_assignable<deleter_type&, _Ep&>::value,
2716 unique_ptr&
2717 >::type
2718 operator=(unique_ptr<_Up, _Ep> __u)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002719 {
2720 reset(__u.release());
Eric Fiselier6d8c8ed2015-08-28 05:07:06 +00002721 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002722 return *this;
2723 }
2724
2725 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002726 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002727
2728 template <class _Up>
2729 _LIBCPP_INLINE_VISIBILITY
2730 typename enable_if<
2731 is_convertible<_Up*, _Tp*>::value &&
2732 is_same<_Dp, default_delete<_Tp> >::value,
2733 unique_ptr&
2734 >::type
2735 operator=(auto_ptr<_Up> __p)
2736 {reset(__p.release()); return *this;}
2737
Howard Hinnant74279a52010-09-04 23:28:19 +00002738#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002739 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2740
Howard Hinnant719bda32011-05-28 14:41:13 +00002741 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002742 {
2743 reset();
2744 return *this;
2745 }
2746
2747 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2748 {return *__ptr_.first();}
Howard Hinnant719bda32011-05-28 14:41:13 +00002749 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2750 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2751 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2752 {return __ptr_.second();}
2753 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2754 {return __ptr_.second();}
Howard Hinnant86a291f2012-02-21 21:46:43 +00002755 _LIBCPP_INLINE_VISIBILITY
2756 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2757 {return __ptr_.first() != nullptr;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002758
Howard Hinnant719bda32011-05-28 14:41:13 +00002759 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002760 {
2761 pointer __t = __ptr_.first();
2762 __ptr_.first() = pointer();
2763 return __t;
2764 }
2765
Howard Hinnant719bda32011-05-28 14:41:13 +00002766 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002767 {
2768 pointer __tmp = __ptr_.first();
2769 __ptr_.first() = __p;
2770 if (__tmp)
2771 __ptr_.second()(__tmp);
2772 }
2773
Howard Hinnant719bda32011-05-28 14:41:13 +00002774 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2775 {__ptr_.swap(__u.__ptr_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002776};
2777
2778template <class _Tp, class _Dp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002779class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002780{
2781public:
2782 typedef _Tp element_type;
2783 typedef _Dp deleter_type;
2784 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2785private:
2786 __compressed_pair<pointer, deleter_type> __ptr_;
2787
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002788#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789 unique_ptr(unique_ptr&);
2790 template <class _Up>
2791 unique_ptr(unique_ptr<_Up>&);
2792 unique_ptr& operator=(unique_ptr&);
2793 template <class _Up>
2794 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant74279a52010-09-04 23:28:19 +00002795#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002796
2797 struct __nat {int __for_bool_;};
2798
2799 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2800 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2801public:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002802 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002803 : __ptr_(pointer())
2804 {
2805 static_assert(!is_pointer<deleter_type>::value,
2806 "unique_ptr constructed with null function pointer deleter");
2807 }
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002808 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002809 : __ptr_(pointer())
2810 {
2811 static_assert(!is_pointer<deleter_type>::value,
2812 "unique_ptr constructed with null function pointer deleter");
2813 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002814#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00002815 template <class _Pp>
2816 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2817 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002818 : __ptr_(__p)
2819 {
2820 static_assert(!is_pointer<deleter_type>::value,
2821 "unique_ptr constructed with null function pointer deleter");
2822 }
2823
Logan Chiend435f8b2014-01-31 09:30:46 +00002824 template <class _Pp>
Howard Hinnantc834c512011-11-29 18:15:50 +00002825 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826 is_reference<deleter_type>::value,
2827 deleter_type,
Logan Chiend435f8b2014-01-31 09:30:46 +00002828 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2829 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00002830 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002831 : __ptr_(__p, __d) {}
2832
2833 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2834 is_reference<deleter_type>::value,
2835 deleter_type,
2836 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002837 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002838 : __ptr_(pointer(), __d) {}
2839
Logan Chiend435f8b2014-01-31 09:30:46 +00002840 template <class _Pp>
2841 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2842 typename remove_reference<deleter_type>::type&& __d,
2843 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00002844 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002845 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002846 {
2847 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2848 }
2849
2850 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant719bda32011-05-28 14:41:13 +00002851 _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002852 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002853 {
2854 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2855 }
2856
Howard Hinnant719bda32011-05-28 14:41:13 +00002857 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002858 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002859
Howard Hinnant719bda32011-05-28 14:41:13 +00002860 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861 {
2862 reset(__u.release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002863 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002864 return *this;
2865 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002866
2867 template <class _Up, class _Ep>
2868 _LIBCPP_INLINE_VISIBILITY
2869 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2870 typename enable_if
2871 <
2872 is_array<_Up>::value &&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002873 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnant4500ca52011-12-18 21:19:44 +00002874 && is_convertible<_Ep, deleter_type>::value &&
2875 (
2876 !is_reference<deleter_type>::value ||
2877 is_same<deleter_type, _Ep>::value
2878 ),
2879 __nat
2880 >::type = __nat()
2881 ) _NOEXCEPT
2882 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2883
2884
2885 template <class _Up, class _Ep>
2886 _LIBCPP_INLINE_VISIBILITY
2887 typename enable_if
2888 <
2889 is_array<_Up>::value &&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002890 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2891 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant4500ca52011-12-18 21:19:44 +00002892 unique_ptr&
2893 >::type
2894 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2895 {
2896 reset(__u.release());
2897 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2898 return *this;
2899 }
Howard Hinnant74279a52010-09-04 23:28:19 +00002900#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002901
2902 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2903 : __ptr_(__p)
2904 {
2905 static_assert(!is_pointer<deleter_type>::value,
2906 "unique_ptr constructed with null function pointer deleter");
2907 }
2908
2909 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002910 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002911
2912 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002913 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002914
2915 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2916 {
2917 return __rv<unique_ptr>(*this);
2918 }
2919
2920 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002921 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002922
2923 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2924 {
2925 reset(__u->release());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002926 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002927 return *this;
2928 }
2929
Howard Hinnant74279a52010-09-04 23:28:19 +00002930#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002931 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2932
Howard Hinnant719bda32011-05-28 14:41:13 +00002933 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002934 {
2935 reset();
2936 return *this;
2937 }
2938
2939 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2940 {return __ptr_.first()[__i];}
Howard Hinnant719bda32011-05-28 14:41:13 +00002941 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2942 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2943 {return __ptr_.second();}
2944 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2945 {return __ptr_.second();}
Howard Hinnant86a291f2012-02-21 21:46:43 +00002946 _LIBCPP_INLINE_VISIBILITY
2947 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2948 {return __ptr_.first() != nullptr;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949
Howard Hinnant719bda32011-05-28 14:41:13 +00002950 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002951 {
2952 pointer __t = __ptr_.first();
2953 __ptr_.first() = pointer();
2954 return __t;
2955 }
2956
Logan Chiend435f8b2014-01-31 09:30:46 +00002957 template <class _Pp>
2958 _LIBCPP_INLINE_VISIBILITY
2959 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2960 reset(_Pp __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961 {
2962 pointer __tmp = __ptr_.first();
2963 __ptr_.first() = __p;
2964 if (__tmp)
2965 __ptr_.second()(__tmp);
2966 }
Marshall Clowff0e4132016-02-25 16:50:51 +00002967 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002968 {
2969 pointer __tmp = __ptr_.first();
2970 __ptr_.first() = nullptr;
2971 if (__tmp)
2972 __ptr_.second()(__tmp);
2973 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002974
2975 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2976private:
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002977
Howard Hinnant74279a52010-09-04 23:28:19 +00002978#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002979 template <class _Up>
2980 explicit unique_ptr(_Up);
2981 template <class _Up>
2982 unique_ptr(_Up __u,
2983 typename conditional<
2984 is_reference<deleter_type>::value,
2985 deleter_type,
2986 typename add_lvalue_reference<const deleter_type>::type>::type,
2987 typename enable_if
2988 <
2989 is_convertible<_Up, pointer>::value,
2990 __nat
2991 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00002992#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00002993};
2994
2995template <class _Tp, class _Dp>
2996inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +00002997typename enable_if<
2998 __is_swappable<_Dp>::value,
2999 void
3000>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00003001swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003002
3003template <class _T1, class _D1, class _T2, class _D2>
3004inline _LIBCPP_INLINE_VISIBILITY
3005bool
3006operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
3007
3008template <class _T1, class _D1, class _T2, class _D2>
3009inline _LIBCPP_INLINE_VISIBILITY
3010bool
3011operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
3012
3013template <class _T1, class _D1, class _T2, class _D2>
3014inline _LIBCPP_INLINE_VISIBILITY
3015bool
Howard Hinnantb17caf92012-02-21 21:02:58 +00003016operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
3017{
3018 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3019 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselierf8898c82015-02-05 23:01:40 +00003020 typedef typename common_type<_P1, _P2>::type _Vp;
3021 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00003022}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003023
3024template <class _T1, class _D1, class _T2, class _D2>
3025inline _LIBCPP_INLINE_VISIBILITY
3026bool
3027operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
3028
3029template <class _T1, class _D1, class _T2, class _D2>
3030inline _LIBCPP_INLINE_VISIBILITY
3031bool
3032operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
3033
3034template <class _T1, class _D1, class _T2, class _D2>
3035inline _LIBCPP_INLINE_VISIBILITY
3036bool
3037operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
3038
Howard Hinnantb17caf92012-02-21 21:02:58 +00003039template <class _T1, class _D1>
3040inline _LIBCPP_INLINE_VISIBILITY
3041bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003042operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003043{
3044 return !__x;
3045}
3046
3047template <class _T1, class _D1>
3048inline _LIBCPP_INLINE_VISIBILITY
3049bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003050operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003051{
3052 return !__x;
3053}
3054
3055template <class _T1, class _D1>
3056inline _LIBCPP_INLINE_VISIBILITY
3057bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003058operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003059{
3060 return static_cast<bool>(__x);
3061}
3062
3063template <class _T1, class _D1>
3064inline _LIBCPP_INLINE_VISIBILITY
3065bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003066operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003067{
3068 return static_cast<bool>(__x);
3069}
3070
3071template <class _T1, class _D1>
3072inline _LIBCPP_INLINE_VISIBILITY
3073bool
3074operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3075{
3076 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3077 return less<_P1>()(__x.get(), nullptr);
3078}
3079
3080template <class _T1, class _D1>
3081inline _LIBCPP_INLINE_VISIBILITY
3082bool
3083operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3084{
3085 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3086 return less<_P1>()(nullptr, __x.get());
3087}
3088
3089template <class _T1, class _D1>
3090inline _LIBCPP_INLINE_VISIBILITY
3091bool
3092operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3093{
3094 return nullptr < __x;
3095}
3096
3097template <class _T1, class _D1>
3098inline _LIBCPP_INLINE_VISIBILITY
3099bool
3100operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3101{
3102 return __x < nullptr;
3103}
3104
3105template <class _T1, class _D1>
3106inline _LIBCPP_INLINE_VISIBILITY
3107bool
3108operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3109{
3110 return !(nullptr < __x);
3111}
3112
3113template <class _T1, class _D1>
3114inline _LIBCPP_INLINE_VISIBILITY
3115bool
3116operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3117{
3118 return !(__x < nullptr);
3119}
3120
3121template <class _T1, class _D1>
3122inline _LIBCPP_INLINE_VISIBILITY
3123bool
3124operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3125{
3126 return !(__x < nullptr);
3127}
3128
3129template <class _T1, class _D1>
3130inline _LIBCPP_INLINE_VISIBILITY
3131bool
3132operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3133{
3134 return !(nullptr < __x);
3135}
3136
Howard Hinnant9e028f12012-05-01 15:37:54 +00003137#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3138
3139template <class _Tp, class _Dp>
3140inline _LIBCPP_INLINE_VISIBILITY
3141unique_ptr<_Tp, _Dp>
3142move(unique_ptr<_Tp, _Dp>& __t)
3143{
3144 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3145}
3146
3147#endif
3148
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003149#if _LIBCPP_STD_VER > 11
3150
3151template<class _Tp>
3152struct __unique_if
3153{
3154 typedef unique_ptr<_Tp> __unique_single;
3155};
3156
3157template<class _Tp>
3158struct __unique_if<_Tp[]>
3159{
3160 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3161};
3162
3163template<class _Tp, size_t _Np>
3164struct __unique_if<_Tp[_Np]>
3165{
3166 typedef void __unique_array_known_bound;
3167};
3168
3169template<class _Tp, class... _Args>
Marshall Clow724e3df2013-07-02 20:06:09 +00003170inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003171typename __unique_if<_Tp>::__unique_single
3172make_unique(_Args&&... __args)
3173{
3174 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3175}
3176
3177template<class _Tp>
Marshall Clow724e3df2013-07-02 20:06:09 +00003178inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003179typename __unique_if<_Tp>::__unique_array_unknown_bound
3180make_unique(size_t __n)
3181{
3182 typedef typename remove_extent<_Tp>::type _Up;
3183 return unique_ptr<_Tp>(new _Up[__n]());
3184}
3185
3186template<class _Tp, class... _Args>
3187 typename __unique_if<_Tp>::__unique_array_known_bound
3188 make_unique(_Args&&...) = delete;
3189
3190#endif // _LIBCPP_STD_VER > 11
3191
Howard Hinnant6a855442013-07-03 17:39:28 +00003192template <class _Size>
3193inline _LIBCPP_INLINE_VISIBILITY
3194_Size
3195__loadword(const void* __p)
3196{
3197 _Size __r;
3198 std::memcpy(&__r, __p, sizeof(__r));
3199 return __r;
3200}
3201
Howard Hinnantf1973402011-12-10 20:28:56 +00003202// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3203// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3204// multiplication, which can be very slow on 32-bit systems.
Howard Hinnantad71c232011-12-05 00:08:45 +00003205template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnantf1973402011-12-10 20:28:56 +00003206struct __murmur2_or_cityhash;
Howard Hinnantad71c232011-12-05 00:08:45 +00003207
3208template <class _Size>
Howard Hinnantf1973402011-12-10 20:28:56 +00003209struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnantad71c232011-12-05 00:08:45 +00003210{
3211 _Size operator()(const void* __key, _Size __len);
3212};
3213
Howard Hinnantf1973402011-12-10 20:28:56 +00003214// murmur2
Howard Hinnantad71c232011-12-05 00:08:45 +00003215template <class _Size>
3216_Size
Marshall Clow91c7f642016-01-11 19:27:10 +00003217__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantad71c232011-12-05 00:08:45 +00003218{
3219 const _Size __m = 0x5bd1e995;
3220 const _Size __r = 24;
3221 _Size __h = __len;
3222 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3223 for (; __len >= 4; __data += 4, __len -= 4)
3224 {
Howard Hinnant6a855442013-07-03 17:39:28 +00003225 _Size __k = __loadword<_Size>(__data);
Howard Hinnantad71c232011-12-05 00:08:45 +00003226 __k *= __m;
3227 __k ^= __k >> __r;
3228 __k *= __m;
3229 __h *= __m;
3230 __h ^= __k;
3231 }
3232 switch (__len)
3233 {
3234 case 3:
3235 __h ^= __data[2] << 16;
3236 case 2:
3237 __h ^= __data[1] << 8;
3238 case 1:
3239 __h ^= __data[0];
3240 __h *= __m;
3241 }
3242 __h ^= __h >> 13;
3243 __h *= __m;
3244 __h ^= __h >> 15;
3245 return __h;
3246}
3247
3248template <class _Size>
Howard Hinnantf1973402011-12-10 20:28:56 +00003249struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnantad71c232011-12-05 00:08:45 +00003250{
3251 _Size operator()(const void* __key, _Size __len);
Howard Hinnantf1973402011-12-10 20:28:56 +00003252
3253 private:
3254 // Some primes between 2^63 and 2^64.
3255 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3256 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3257 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3258 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3259
3260 static _Size __rotate(_Size __val, int __shift) {
3261 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3262 }
3263
3264 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3265 return (__val >> __shift) | (__val << (64 - __shift));
3266 }
3267
3268 static _Size __shift_mix(_Size __val) {
3269 return __val ^ (__val >> 47);
3270 }
3271
3272 static _Size __hash_len_16(_Size __u, _Size __v) {
3273 const _Size __mul = 0x9ddfea08eb382d69ULL;
3274 _Size __a = (__u ^ __v) * __mul;
3275 __a ^= (__a >> 47);
3276 _Size __b = (__v ^ __a) * __mul;
3277 __b ^= (__b >> 47);
3278 __b *= __mul;
3279 return __b;
3280 }
3281
3282 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3283 if (__len > 8) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003284 const _Size __a = __loadword<_Size>(__s);
3285 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003286 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3287 }
3288 if (__len >= 4) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003289 const uint32_t __a = __loadword<uint32_t>(__s);
3290 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnantf1973402011-12-10 20:28:56 +00003291 return __hash_len_16(__len + (__a << 3), __b);
3292 }
3293 if (__len > 0) {
3294 const unsigned char __a = __s[0];
3295 const unsigned char __b = __s[__len >> 1];
3296 const unsigned char __c = __s[__len - 1];
3297 const uint32_t __y = static_cast<uint32_t>(__a) +
3298 (static_cast<uint32_t>(__b) << 8);
3299 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3300 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3301 }
3302 return __k2;
3303 }
3304
3305 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003306 const _Size __a = __loadword<_Size>(__s) * __k1;
3307 const _Size __b = __loadword<_Size>(__s + 8);
3308 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3309 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnantf1973402011-12-10 20:28:56 +00003310 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3311 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3312 }
3313
3314 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3315 // Callers do best to use "random-looking" values for a and b.
3316 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3317 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3318 __a += __w;
3319 __b = __rotate(__b + __a + __z, 21);
3320 const _Size __c = __a;
3321 __a += __x;
3322 __a += __y;
3323 __b += __rotate(__a, 44);
3324 return pair<_Size, _Size>(__a + __z, __b + __c);
3325 }
3326
3327 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3328 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3329 const char* __s, _Size __a, _Size __b) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003330 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3331 __loadword<_Size>(__s + 8),
3332 __loadword<_Size>(__s + 16),
3333 __loadword<_Size>(__s + 24),
Howard Hinnantf1973402011-12-10 20:28:56 +00003334 __a,
3335 __b);
3336 }
3337
3338 // Return an 8-byte hash for 33 to 64 bytes.
3339 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant6a855442013-07-03 17:39:28 +00003340 _Size __z = __loadword<_Size>(__s + 24);
3341 _Size __a = __loadword<_Size>(__s) +
3342 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnantf1973402011-12-10 20:28:56 +00003343 _Size __b = __rotate(__a + __z, 52);
3344 _Size __c = __rotate(__a, 37);
Howard Hinnant6a855442013-07-03 17:39:28 +00003345 __a += __loadword<_Size>(__s + 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003346 __c += __rotate(__a, 7);
Howard Hinnant6a855442013-07-03 17:39:28 +00003347 __a += __loadword<_Size>(__s + 16);
Howard Hinnantf1973402011-12-10 20:28:56 +00003348 _Size __vf = __a + __z;
3349 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant6a855442013-07-03 17:39:28 +00003350 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3351 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnantf1973402011-12-10 20:28:56 +00003352 __b = __rotate(__a + __z, 52);
3353 __c = __rotate(__a, 37);
Howard Hinnant6a855442013-07-03 17:39:28 +00003354 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnantf1973402011-12-10 20:28:56 +00003355 __c += __rotate(__a, 7);
Howard Hinnant6a855442013-07-03 17:39:28 +00003356 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnantf1973402011-12-10 20:28:56 +00003357 _Size __wf = __a + __z;
3358 _Size __ws = __b + __rotate(__a, 31) + __c;
3359 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3360 return __shift_mix(__r * __k0 + __vs) * __k2;
3361 }
Howard Hinnantad71c232011-12-05 00:08:45 +00003362};
3363
Howard Hinnantf1973402011-12-10 20:28:56 +00003364// cityhash64
Howard Hinnantad71c232011-12-05 00:08:45 +00003365template <class _Size>
3366_Size
Marshall Clow91c7f642016-01-11 19:27:10 +00003367__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantad71c232011-12-05 00:08:45 +00003368{
Howard Hinnantf1973402011-12-10 20:28:56 +00003369 const char* __s = static_cast<const char*>(__key);
3370 if (__len <= 32) {
3371 if (__len <= 16) {
3372 return __hash_len_0_to_16(__s, __len);
3373 } else {
3374 return __hash_len_17_to_32(__s, __len);
Howard Hinnantad71c232011-12-05 00:08:45 +00003375 }
Howard Hinnantf1973402011-12-10 20:28:56 +00003376 } else if (__len <= 64) {
3377 return __hash_len_33_to_64(__s, __len);
3378 }
3379
3380 // For strings over 64 bytes we hash the end first, and then as we
3381 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant6a855442013-07-03 17:39:28 +00003382 _Size __x = __loadword<_Size>(__s + __len - 40);
3383 _Size __y = __loadword<_Size>(__s + __len - 16) +
3384 __loadword<_Size>(__s + __len - 56);
3385 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3386 __loadword<_Size>(__s + __len - 24));
Howard Hinnantf1973402011-12-10 20:28:56 +00003387 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3388 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant6a855442013-07-03 17:39:28 +00003389 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnantf1973402011-12-10 20:28:56 +00003390
3391 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3392 __len = (__len - 1) & ~static_cast<_Size>(63);
3393 do {
Howard Hinnant6a855442013-07-03 17:39:28 +00003394 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3395 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnantf1973402011-12-10 20:28:56 +00003396 __x ^= __w.second;
Howard Hinnant6a855442013-07-03 17:39:28 +00003397 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnantf1973402011-12-10 20:28:56 +00003398 __z = __rotate(__z + __w.first, 33) * __k1;
3399 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3400 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant6a855442013-07-03 17:39:28 +00003401 __y + __loadword<_Size>(__s + 16));
Howard Hinnantf1973402011-12-10 20:28:56 +00003402 std::swap(__z, __x);
3403 __s += 64;
3404 __len -= 64;
3405 } while (__len != 0);
3406 return __hash_len_16(
3407 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3408 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnantad71c232011-12-05 00:08:45 +00003409}
3410
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003411template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3412struct __scalar_hash;
3413
3414template <class _Tp>
3415struct __scalar_hash<_Tp, 0>
3416 : public unary_function<_Tp, size_t>
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003417{
Howard Hinnant756c69b2010-09-22 16:48:34 +00003418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003419 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003420 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003421 union
3422 {
3423 _Tp __t;
3424 size_t __a;
3425 } __u;
3426 __u.__a = 0;
3427 __u.__t = __v;
3428 return __u.__a;
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003429 }
3430};
3431
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003432template <class _Tp>
3433struct __scalar_hash<_Tp, 1>
3434 : public unary_function<_Tp, size_t>
3435{
3436 _LIBCPP_INLINE_VISIBILITY
3437 size_t operator()(_Tp __v) const _NOEXCEPT
3438 {
3439 union
3440 {
3441 _Tp __t;
3442 size_t __a;
3443 } __u;
3444 __u.__t = __v;
3445 return __u.__a;
3446 }
3447};
3448
3449template <class _Tp>
3450struct __scalar_hash<_Tp, 2>
3451 : public unary_function<_Tp, size_t>
3452{
3453 _LIBCPP_INLINE_VISIBILITY
3454 size_t operator()(_Tp __v) const _NOEXCEPT
3455 {
3456 union
3457 {
3458 _Tp __t;
3459 struct
3460 {
3461 size_t __a;
3462 size_t __b;
Eric Fiseliere012bf22015-07-18 20:40:46 +00003463 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003464 } __u;
3465 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003466 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003467 }
3468};
3469
3470template <class _Tp>
3471struct __scalar_hash<_Tp, 3>
3472 : public unary_function<_Tp, size_t>
3473{
3474 _LIBCPP_INLINE_VISIBILITY
3475 size_t operator()(_Tp __v) const _NOEXCEPT
3476 {
3477 union
3478 {
3479 _Tp __t;
3480 struct
3481 {
3482 size_t __a;
3483 size_t __b;
3484 size_t __c;
Eric Fiseliere012bf22015-07-18 20:40:46 +00003485 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003486 } __u;
3487 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003488 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003489 }
3490};
3491
3492template <class _Tp>
3493struct __scalar_hash<_Tp, 4>
3494 : public unary_function<_Tp, size_t>
3495{
3496 _LIBCPP_INLINE_VISIBILITY
3497 size_t operator()(_Tp __v) const _NOEXCEPT
3498 {
3499 union
3500 {
3501 _Tp __t;
3502 struct
3503 {
3504 size_t __a;
3505 size_t __b;
3506 size_t __c;
3507 size_t __d;
Eric Fiseliere012bf22015-07-18 20:40:46 +00003508 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003509 } __u;
3510 __u.__t = __v;
Howard Hinnantf1973402011-12-10 20:28:56 +00003511 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003512 }
3513};
3514
3515template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003516struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
Howard Hinnant9fa30202012-07-30 01:40:57 +00003517 : public unary_function<_Tp*, size_t>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003518{
Howard Hinnant9fa30202012-07-30 01:40:57 +00003519 _LIBCPP_INLINE_VISIBILITY
3520 size_t operator()(_Tp* __v) const _NOEXCEPT
3521 {
3522 union
3523 {
3524 _Tp* __t;
3525 size_t __a;
3526 } __u;
3527 __u.__t = __v;
3528 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3529 }
Howard Hinnant8cf1f942011-12-03 21:11:36 +00003530};
3531
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003532template <class _Tp, class _Dp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003533struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003534{
3535 typedef unique_ptr<_Tp, _Dp> argument_type;
3536 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003538 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003539 {
3540 typedef typename argument_type::pointer pointer;
3541 return hash<pointer>()(__ptr.get());
3542 }
3543};
3544
Howard Hinnantc51e1022010-05-11 19:42:16 +00003545struct __destruct_n
3546{
3547private:
3548 size_t size;
3549
3550 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003551 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003552 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3553
3554 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003555 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003556 {}
3557
Howard Hinnant719bda32011-05-28 14:41:13 +00003558 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003559 {++size;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003560 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003561 {}
3562
Howard Hinnant719bda32011-05-28 14:41:13 +00003563 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003564 {size = __s;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003565 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003566 {}
3567public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003568 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3569 : size(__s) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003570
3571 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003572 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003573 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003574
3575 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003576 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003577 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003578
3579 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003580 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003581 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003582};
3583
3584template <class _Alloc>
3585class __allocator_destructor
3586{
3587 typedef allocator_traits<_Alloc> __alloc_traits;
3588public:
3589 typedef typename __alloc_traits::pointer pointer;
3590 typedef typename __alloc_traits::size_type size_type;
3591private:
3592 _Alloc& __alloc_;
3593 size_type __s_;
3594public:
3595 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant719bda32011-05-28 14:41:13 +00003596 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003597 : __alloc_(__a), __s_(__s) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003599 void operator()(pointer __p) _NOEXCEPT
3600 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003601};
3602
3603template <class _InputIterator, class _ForwardIterator>
3604_ForwardIterator
3605uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3606{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003608#ifndef _LIBCPP_NO_EXCEPTIONS
3609 _ForwardIterator __s = __r;
3610 try
3611 {
3612#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003613 for (; __f != __l; ++__f, (void) ++__r)
3614 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003615#ifndef _LIBCPP_NO_EXCEPTIONS
3616 }
3617 catch (...)
3618 {
3619 for (; __s != __r; ++__s)
3620 __s->~value_type();
3621 throw;
3622 }
3623#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003624 return __r;
3625}
3626
3627template <class _InputIterator, class _Size, class _ForwardIterator>
3628_ForwardIterator
3629uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3630{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003631 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003632#ifndef _LIBCPP_NO_EXCEPTIONS
3633 _ForwardIterator __s = __r;
3634 try
3635 {
3636#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003637 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3638 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003639#ifndef _LIBCPP_NO_EXCEPTIONS
3640 }
3641 catch (...)
3642 {
3643 for (; __s != __r; ++__s)
3644 __s->~value_type();
3645 throw;
3646 }
3647#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003648 return __r;
3649}
3650
3651template <class _ForwardIterator, class _Tp>
3652void
3653uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3654{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003655 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003656#ifndef _LIBCPP_NO_EXCEPTIONS
3657 _ForwardIterator __s = __f;
3658 try
3659 {
3660#endif
3661 for (; __f != __l; ++__f)
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003662 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003663#ifndef _LIBCPP_NO_EXCEPTIONS
3664 }
3665 catch (...)
3666 {
3667 for (; __s != __f; ++__s)
3668 __s->~value_type();
3669 throw;
3670 }
3671#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003672}
3673
3674template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant3c811092010-11-18 16:13:03 +00003675_ForwardIterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3677{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003678 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003679#ifndef _LIBCPP_NO_EXCEPTIONS
3680 _ForwardIterator __s = __f;
3681 try
3682 {
3683#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003684 for (; __n > 0; ++__f, (void) --__n)
3685 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003686#ifndef _LIBCPP_NO_EXCEPTIONS
3687 }
3688 catch (...)
3689 {
3690 for (; __s != __f; ++__s)
3691 __s->~value_type();
3692 throw;
3693 }
3694#endif
Howard Hinnant3c811092010-11-18 16:13:03 +00003695 return __f;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003696}
3697
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003698#if _LIBCPP_STD_VER > 14
3699
3700template <class _ForwardIterator>
3701inline _LIBCPP_INLINE_VISIBILITY
3702void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3703 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3704 for (; __first != __last; ++__first)
3705 ::new((void*)_VSTD::addressof(*__first)) _Vt;
3706}
3707
3708template <class _ForwardIterator, class _Size>
3709inline _LIBCPP_INLINE_VISIBILITY
3710_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3711 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3712 for (; __n > 0; (void)++__first, --__n)
3713 ::new((void*)_VSTD::addressof(*__first)) _Vt;
3714 return __first;
3715}
3716
3717
3718template <class _ForwardIterator>
3719inline _LIBCPP_INLINE_VISIBILITY
3720void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3721 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3722 for (; __first != __last; ++__first)
3723 ::new((void*)_VSTD::addressof(*__first)) _Vt();
3724}
3725
3726template <class _ForwardIterator, class _Size>
3727inline _LIBCPP_INLINE_VISIBILITY
3728_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3729 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3730 for (; __n > 0; (void)++__first, --__n)
3731 ::new((void*)_VSTD::addressof(*__first)) _Vt();
3732 return __first;
3733}
3734
3735
3736template <class _InputIt, class _ForwardIt>
3737inline _LIBCPP_INLINE_VISIBILITY
3738_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __res) {
3739 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3740 for (; __first != __last; (void)++__res, ++__first)
3741 ::new((void*)_VSTD::addressof(*__res)) _Vt(std::move(*__first));
3742 return __res;
3743}
3744
3745template <class _InputIt, class _Size, class _ForwardIt>
3746inline _LIBCPP_INLINE_VISIBILITY
3747pair<_InputIt, _ForwardIt>
3748uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __res) {
3749 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3750 for (; __n > 0; ++__res, (void)++__first, --__n)
3751 ::new((void*)_VSTD::addressof(*__res)) _Vt(std::move(*__first));
3752 return {__first, __res};
3753}
3754
3755template <class _Tp>
3756inline _LIBCPP_INLINE_VISIBILITY
3757void destroy_at(_Tp* __loc) {
3758 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3759 __loc->~_Tp();
3760}
3761
3762template <class _ForwardIterator>
3763inline _LIBCPP_INLINE_VISIBILITY
3764void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3765 for (; __first != __last; ++__first)
3766 _VSTD::destroy_at(_VSTD::addressof(*__first));
3767}
3768
3769template <class _ForwardIterator, class _Size>
3770inline _LIBCPP_INLINE_VISIBILITY
3771_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3772 for (; __n > 0; (void)++__first, --__n)
3773 _VSTD::destroy_at(_VSTD::addressof(*__first));
3774 return __first;
3775}
3776
3777#endif // _LIBCPP_STD_VER > 14
3778
Howard Hinnant756c69b2010-09-22 16:48:34 +00003779class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003780 : public std::exception
3781{
3782public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003783 virtual ~bad_weak_ptr() _NOEXCEPT;
3784 virtual const char* what() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003785};
3786
Marshall Clow8fea1612016-08-25 15:09:01 +00003787_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3788void __throw_bad_weak_ptr()
3789{
3790#ifndef _LIBCPP_NO_EXCEPTIONS
3791 throw bad_weak_ptr();
3792#else
3793 _VSTD::abort();
3794#endif
3795}
3796
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003797template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003798
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003799class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003800{
3801 __shared_count(const __shared_count&);
3802 __shared_count& operator=(const __shared_count&);
3803
3804protected:
3805 long __shared_owners_;
3806 virtual ~__shared_count();
3807private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003808 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003809
3810public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003812 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003813 : __shared_owners_(__refs) {}
3814
Howard Hinnant719bda32011-05-28 14:41:13 +00003815 void __add_shared() _NOEXCEPT;
3816 bool __release_shared() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003817 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier89659d12015-07-07 00:27:16 +00003818 long use_count() const _NOEXCEPT {
3819 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3820 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003821};
3822
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003823class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003824 : private __shared_count
3825{
3826 long __shared_weak_owners_;
3827
3828public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003830 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003831 : __shared_count(__refs),
3832 __shared_weak_owners_(__refs) {}
3833protected:
3834 virtual ~__shared_weak_count();
3835
3836public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003837 void __add_shared() _NOEXCEPT;
3838 void __add_weak() _NOEXCEPT;
3839 void __release_shared() _NOEXCEPT;
3840 void __release_weak() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003842 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3843 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003844
Howard Hinnant807d6332013-02-25 15:50:36 +00003845 // Define the function out only if we build static libc++ without RTTI.
3846 // Otherwise we may break clients who need to compile their projects with
3847 // -fno-rtti and yet link against a libc++.dylib compiled
3848 // without -fno-rtti.
3849#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant719bda32011-05-28 14:41:13 +00003850 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant807d6332013-02-25 15:50:36 +00003851#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003852private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003853 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003854};
3855
3856template <class _Tp, class _Dp, class _Alloc>
3857class __shared_ptr_pointer
3858 : public __shared_weak_count
3859{
3860 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3861public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003863 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003864 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003865
Howard Hinnant72f73582010-08-11 17:04:31 +00003866#ifndef _LIBCPP_NO_RTTI
Howard Hinnant719bda32011-05-28 14:41:13 +00003867 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant72f73582010-08-11 17:04:31 +00003868#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003869
3870private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003871 virtual void __on_zero_shared() _NOEXCEPT;
3872 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003873};
3874
Howard Hinnant72f73582010-08-11 17:04:31 +00003875#ifndef _LIBCPP_NO_RTTI
3876
Howard Hinnantc51e1022010-05-11 19:42:16 +00003877template <class _Tp, class _Dp, class _Alloc>
3878const void*
Howard Hinnant719bda32011-05-28 14:41:13 +00003879__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003880{
Marshall Clowa8dfc942014-11-17 19:05:50 +00003881 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003882}
3883
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003884#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00003885
Howard Hinnantc51e1022010-05-11 19:42:16 +00003886template <class _Tp, class _Dp, class _Alloc>
3887void
Howard Hinnant719bda32011-05-28 14:41:13 +00003888__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003889{
3890 __data_.first().second()(__data_.first().first());
3891 __data_.first().second().~_Dp();
3892}
3893
3894template <class _Tp, class _Dp, class _Alloc>
3895void
Howard Hinnant719bda32011-05-28 14:41:13 +00003896__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003897{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003898 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3899 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003900 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3901
Eric Fiselierf8898c82015-02-05 23:01:40 +00003902 _Al __a(__data_.second());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003903 __data_.second().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003904 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003905}
3906
3907template <class _Tp, class _Alloc>
3908class __shared_ptr_emplace
3909 : public __shared_weak_count
3910{
3911 __compressed_pair<_Alloc, _Tp> __data_;
3912public:
3913#ifndef _LIBCPP_HAS_NO_VARIADICS
3914
Howard Hinnant756c69b2010-09-22 16:48:34 +00003915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003916 __shared_ptr_emplace(_Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003917 : __data_(_VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003918
3919 template <class ..._Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003921 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant83b1c052011-12-19 17:58:44 +00003922 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3923 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003924
3925#else // _LIBCPP_HAS_NO_VARIADICS
3926
Howard Hinnant756c69b2010-09-22 16:48:34 +00003927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003928 __shared_ptr_emplace(_Alloc __a)
3929 : __data_(__a) {}
3930
3931 template <class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003933 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3934 : __data_(__a, _Tp(__a0)) {}
3935
3936 template <class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003938 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3939 : __data_(__a, _Tp(__a0, __a1)) {}
3940
3941 template <class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003943 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3944 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3945
3946#endif // _LIBCPP_HAS_NO_VARIADICS
3947
3948private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003949 virtual void __on_zero_shared() _NOEXCEPT;
3950 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003951public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003952 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003953 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003954};
3955
3956template <class _Tp, class _Alloc>
3957void
Howard Hinnant719bda32011-05-28 14:41:13 +00003958__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003959{
3960 __data_.second().~_Tp();
3961}
3962
3963template <class _Tp, class _Alloc>
3964void
Howard Hinnant719bda32011-05-28 14:41:13 +00003965__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003966{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003967 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3968 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003969 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselierf8898c82015-02-05 23:01:40 +00003970 _Al __a(__data_.first());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003971 __data_.first().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003972 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003973}
3974
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003975template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003976
3977template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003978class _LIBCPP_TYPE_VIS_ONLY shared_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003979{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003980public:
3981 typedef _Tp element_type;
Eric Fiselierae5b6672016-06-27 01:02:43 +00003982#if _LIBCPP_STD_VER > 14
3983 typedef weak_ptr<_Tp> weak_type;
3984#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003985private:
3986 element_type* __ptr_;
3987 __shared_weak_count* __cntrl_;
3988
3989 struct __nat {int __for_bool_;};
3990public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003992 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003994 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiend435f8b2014-01-31 09:30:46 +00003995 template<class _Yp>
3996 explicit shared_ptr(_Yp* __p,
3997 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3998 template<class _Yp, class _Dp>
3999 shared_ptr(_Yp* __p, _Dp __d,
4000 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
4001 template<class _Yp, class _Dp, class _Alloc>
4002 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4003 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004004 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
4005 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004006 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
4007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004008 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004009 template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004011 shared_ptr(const shared_ptr<_Yp>& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004012 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
4013 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00004014#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004016 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004017 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004018 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
4019 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00004020#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004021 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004022 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00004023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004024 template<class _Yp>
4025 shared_ptr(auto_ptr<_Yp>&& __r,
4026 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004027#else
Logan Chiend435f8b2014-01-31 09:30:46 +00004028 template<class _Yp>
4029 shared_ptr(auto_ptr<_Yp> __r,
4030 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004031#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00004032#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004033 template <class _Yp, class _Dp>
4034 shared_ptr(unique_ptr<_Yp, _Dp>&&,
4035 typename enable_if
4036 <
4037 !is_lvalue_reference<_Dp>::value &&
4038 !is_array<_Yp>::value &&
4039 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4040 __nat
4041 >::type = __nat());
4042 template <class _Yp, class _Dp>
4043 shared_ptr(unique_ptr<_Yp, _Dp>&&,
4044 typename enable_if
4045 <
4046 is_lvalue_reference<_Dp>::value &&
4047 !is_array<_Yp>::value &&
4048 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4049 __nat
4050 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00004051#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004052 template <class _Yp, class _Dp>
4053 shared_ptr(unique_ptr<_Yp, _Dp>,
4054 typename enable_if
4055 <
4056 !is_lvalue_reference<_Dp>::value &&
4057 !is_array<_Yp>::value &&
4058 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4059 __nat
4060 >::type = __nat());
4061 template <class _Yp, class _Dp>
4062 shared_ptr(unique_ptr<_Yp, _Dp>,
4063 typename enable_if
4064 <
4065 is_lvalue_reference<_Dp>::value &&
4066 !is_array<_Yp>::value &&
4067 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4068 __nat
4069 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00004070#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004071
4072 ~shared_ptr();
4073
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004075 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004076 template<class _Yp>
4077 typename enable_if
4078 <
4079 is_convertible<_Yp*, element_type*>::value,
4080 shared_ptr&
4081 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004083 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00004084#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004086 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004087 template<class _Yp>
4088 typename enable_if
4089 <
4090 is_convertible<_Yp*, element_type*>::value,
4091 shared_ptr<_Tp>&
4092 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004094 operator=(shared_ptr<_Yp>&& __r);
4095 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00004096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004097 typename enable_if
4098 <
4099 !is_array<_Yp>::value &&
4100 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00004101 shared_ptr
4102 >::type&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004103 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00004104#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004105 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00004106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004107 typename enable_if
4108 <
4109 !is_array<_Yp>::value &&
4110 is_convertible<_Yp*, element_type*>::value,
4111 shared_ptr&
4112 >::type
4113 operator=(auto_ptr<_Yp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004114#endif
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004115 template <class _Yp, class _Dp>
4116 typename enable_if
4117 <
4118 !is_array<_Yp>::value &&
4119 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4120 shared_ptr&
4121 >::type
Howard Hinnant74279a52010-09-04 23:28:19 +00004122#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004124 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00004125#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov03192872015-12-09 22:32:36 +00004126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004127 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004128#endif
4129
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004131 void swap(shared_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004133 void reset() _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004134 template<class _Yp>
4135 typename enable_if
4136 <
4137 is_convertible<_Yp*, element_type*>::value,
4138 void
4139 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004141 reset(_Yp* __p);
4142 template<class _Yp, class _Dp>
4143 typename enable_if
4144 <
4145 is_convertible<_Yp*, element_type*>::value,
4146 void
4147 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004149 reset(_Yp* __p, _Dp __d);
4150 template<class _Yp, class _Dp, class _Alloc>
4151 typename enable_if
4152 <
4153 is_convertible<_Yp*, element_type*>::value,
4154 void
4155 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004157 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004158
Howard Hinnant756c69b2010-09-22 16:48:34 +00004159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004160 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004162 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4163 {return *__ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004165 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004167 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004169 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00004171 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnantc834c512011-11-29 18:15:50 +00004172 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00004174 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00004175 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantc834c512011-11-29 18:15:50 +00004176 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00004178 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00004179 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant9fa30202012-07-30 01:40:57 +00004180 _LIBCPP_INLINE_VISIBILITY
4181 bool
4182 __owner_equivalent(const shared_ptr& __p) const
4183 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00004184
Howard Hinnant72f73582010-08-11 17:04:31 +00004185#ifndef _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004186 template <class _Dp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004188 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004189 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004190#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004191
4192#ifndef _LIBCPP_HAS_NO_VARIADICS
4193
4194 template<class ..._Args>
4195 static
4196 shared_ptr<_Tp>
4197 make_shared(_Args&& ...__args);
4198
4199 template<class _Alloc, class ..._Args>
4200 static
4201 shared_ptr<_Tp>
4202 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4203
4204#else // _LIBCPP_HAS_NO_VARIADICS
4205
4206 static shared_ptr<_Tp> make_shared();
4207
4208 template<class _A0>
4209 static shared_ptr<_Tp> make_shared(_A0&);
4210
4211 template<class _A0, class _A1>
4212 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4213
4214 template<class _A0, class _A1, class _A2>
4215 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4216
4217 template<class _Alloc>
4218 static shared_ptr<_Tp>
4219 allocate_shared(const _Alloc& __a);
4220
4221 template<class _Alloc, class _A0>
4222 static shared_ptr<_Tp>
4223 allocate_shared(const _Alloc& __a, _A0& __a0);
4224
4225 template<class _Alloc, class _A0, class _A1>
4226 static shared_ptr<_Tp>
4227 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4228
4229 template<class _Alloc, class _A0, class _A1, class _A2>
4230 static shared_ptr<_Tp>
4231 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4232
4233#endif // _LIBCPP_HAS_NO_VARIADICS
4234
4235private:
4236
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004237 template <class _Yp, class _OrigPtr>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004239 void
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004240 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4241 _OrigPtr* __ptr) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004242 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004243 typedef typename remove_cv<_Yp>::type _RawYp;
Eric Fiselier84006862016-06-02 00:15:35 +00004244 if (__e && __e->__weak_this_.expired())
Marshall Clow99442fc2015-06-19 15:54:13 +00004245 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004246 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4247 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
Marshall Clow99442fc2015-06-19 15:54:13 +00004248 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249 }
4250
Howard Hinnant756c69b2010-09-22 16:48:34 +00004251 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004252 void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00004253
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004254 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
4255 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004256};
4257
4258template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004259inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004260_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004261shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004262 : __ptr_(0),
4263 __cntrl_(0)
4264{
4265}
4266
4267template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004268inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004269_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004270shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004271 : __ptr_(0),
4272 __cntrl_(0)
4273{
4274}
4275
4276template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004277template<class _Yp>
4278shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4279 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004280 : __ptr_(__p)
4281{
4282 unique_ptr<_Yp> __hold(__p);
4283 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4284 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4285 __hold.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004286 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004287}
4288
4289template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004290template<class _Yp, class _Dp>
4291shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4292 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004293 : __ptr_(__p)
4294{
4295#ifndef _LIBCPP_NO_EXCEPTIONS
4296 try
4297 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004298#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004299 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4300 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004301 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004302#ifndef _LIBCPP_NO_EXCEPTIONS
4303 }
4304 catch (...)
4305 {
4306 __d(__p);
4307 throw;
4308 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004309#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004310}
4311
4312template<class _Tp>
4313template<class _Dp>
4314shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4315 : __ptr_(0)
4316{
4317#ifndef _LIBCPP_NO_EXCEPTIONS
4318 try
4319 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004320#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004321 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4322 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4323#ifndef _LIBCPP_NO_EXCEPTIONS
4324 }
4325 catch (...)
4326 {
4327 __d(__p);
4328 throw;
4329 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004330#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004331}
4332
4333template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004334template<class _Yp, class _Dp, class _Alloc>
4335shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4336 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004337 : __ptr_(__p)
4338{
4339#ifndef _LIBCPP_NO_EXCEPTIONS
4340 try
4341 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004342#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004343 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004344 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004345 typedef __allocator_destructor<_A2> _D2;
4346 _A2 __a2(__a);
4347 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004348 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4349 _CntrlBlk(__p, __d, __a);
4350 __cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004351 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004352#ifndef _LIBCPP_NO_EXCEPTIONS
4353 }
4354 catch (...)
4355 {
4356 __d(__p);
4357 throw;
4358 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004359#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004360}
4361
4362template<class _Tp>
4363template<class _Dp, class _Alloc>
4364shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4365 : __ptr_(0)
4366{
4367#ifndef _LIBCPP_NO_EXCEPTIONS
4368 try
4369 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004370#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004371 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004372 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004373 typedef __allocator_destructor<_A2> _D2;
4374 _A2 __a2(__a);
4375 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004376 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4377 _CntrlBlk(__p, __d, __a);
4378 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004379#ifndef _LIBCPP_NO_EXCEPTIONS
4380 }
4381 catch (...)
4382 {
4383 __d(__p);
4384 throw;
4385 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004386#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004387}
4388
4389template<class _Tp>
4390template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004391inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004392shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004393 : __ptr_(__p),
4394 __cntrl_(__r.__cntrl_)
4395{
4396 if (__cntrl_)
4397 __cntrl_->__add_shared();
4398}
4399
4400template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004401inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004402shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004403 : __ptr_(__r.__ptr_),
4404 __cntrl_(__r.__cntrl_)
4405{
4406 if (__cntrl_)
4407 __cntrl_->__add_shared();
4408}
4409
4410template<class _Tp>
4411template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004412inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004413shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4414 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004415 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004416 : __ptr_(__r.__ptr_),
4417 __cntrl_(__r.__cntrl_)
4418{
4419 if (__cntrl_)
4420 __cntrl_->__add_shared();
4421}
4422
Howard Hinnant74279a52010-09-04 23:28:19 +00004423#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004424
4425template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004426inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004427shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004428 : __ptr_(__r.__ptr_),
4429 __cntrl_(__r.__cntrl_)
4430{
4431 __r.__ptr_ = 0;
4432 __r.__cntrl_ = 0;
4433}
4434
4435template<class _Tp>
4436template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004437inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004438shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4439 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004440 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004441 : __ptr_(__r.__ptr_),
4442 __cntrl_(__r.__cntrl_)
4443{
4444 __r.__ptr_ = 0;
4445 __r.__cntrl_ = 0;
4446}
4447
Howard Hinnant74279a52010-09-04 23:28:19 +00004448#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004449
4450template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004451template<class _Yp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004452#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004453shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004454#else
Logan Chiend435f8b2014-01-31 09:30:46 +00004455shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004456#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004457 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004458 : __ptr_(__r.get())
4459{
4460 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4461 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004462 __enable_weak_this(__r.get(), __r.get());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004463 __r.release();
4464}
4465
4466template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004467template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004468#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004469shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4470#else
4471shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4472#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004473 typename enable_if
4474 <
4475 !is_lvalue_reference<_Dp>::value &&
4476 !is_array<_Yp>::value &&
4477 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4478 __nat
4479 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004480 : __ptr_(__r.get())
4481{
Marshall Clow35cde742015-05-10 13:59:45 +00004482#if _LIBCPP_STD_VER > 11
4483 if (__ptr_ == nullptr)
4484 __cntrl_ = nullptr;
4485 else
4486#endif
4487 {
4488 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4489 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004490 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004491 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004492 __r.release();
4493}
4494
4495template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004496template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004497#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004498shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4499#else
4500shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4501#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004502 typename enable_if
4503 <
4504 is_lvalue_reference<_Dp>::value &&
4505 !is_array<_Yp>::value &&
4506 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4507 __nat
4508 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004509 : __ptr_(__r.get())
4510{
Marshall Clow35cde742015-05-10 13:59:45 +00004511#if _LIBCPP_STD_VER > 11
4512 if (__ptr_ == nullptr)
4513 __cntrl_ = nullptr;
4514 else
4515#endif
4516 {
4517 typedef __shared_ptr_pointer<_Yp*,
4518 reference_wrapper<typename remove_reference<_Dp>::type>,
4519 allocator<_Yp> > _CntrlBlk;
4520 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004521 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004522 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004523 __r.release();
4524}
4525
4526#ifndef _LIBCPP_HAS_NO_VARIADICS
4527
4528template<class _Tp>
4529template<class ..._Args>
4530shared_ptr<_Tp>
4531shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4532{
4533 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4534 typedef allocator<_CntrlBlk> _A2;
4535 typedef __allocator_destructor<_A2> _D2;
4536 _A2 __a2;
4537 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004538 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004539 shared_ptr<_Tp> __r;
4540 __r.__ptr_ = __hold2.get()->get();
4541 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004542 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004543 return __r;
4544}
4545
4546template<class _Tp>
4547template<class _Alloc, class ..._Args>
4548shared_ptr<_Tp>
4549shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4550{
4551 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004552 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004553 typedef __allocator_destructor<_A2> _D2;
4554 _A2 __a2(__a);
4555 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004556 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4557 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004558 shared_ptr<_Tp> __r;
4559 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004560 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004561 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004562 return __r;
4563}
4564
4565#else // _LIBCPP_HAS_NO_VARIADICS
4566
4567template<class _Tp>
4568shared_ptr<_Tp>
4569shared_ptr<_Tp>::make_shared()
4570{
4571 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4572 typedef allocator<_CntrlBlk> _Alloc2;
4573 typedef __allocator_destructor<_Alloc2> _D2;
4574 _Alloc2 __alloc2;
4575 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4576 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4577 shared_ptr<_Tp> __r;
4578 __r.__ptr_ = __hold2.get()->get();
4579 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004580 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004581 return __r;
4582}
4583
4584template<class _Tp>
4585template<class _A0>
4586shared_ptr<_Tp>
4587shared_ptr<_Tp>::make_shared(_A0& __a0)
4588{
4589 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4590 typedef allocator<_CntrlBlk> _Alloc2;
4591 typedef __allocator_destructor<_Alloc2> _D2;
4592 _Alloc2 __alloc2;
4593 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4594 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4595 shared_ptr<_Tp> __r;
4596 __r.__ptr_ = __hold2.get()->get();
4597 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004598 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004599 return __r;
4600}
4601
4602template<class _Tp>
4603template<class _A0, class _A1>
4604shared_ptr<_Tp>
4605shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4606{
4607 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4608 typedef allocator<_CntrlBlk> _Alloc2;
4609 typedef __allocator_destructor<_Alloc2> _D2;
4610 _Alloc2 __alloc2;
4611 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4612 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4613 shared_ptr<_Tp> __r;
4614 __r.__ptr_ = __hold2.get()->get();
4615 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004616 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004617 return __r;
4618}
4619
4620template<class _Tp>
4621template<class _A0, class _A1, class _A2>
4622shared_ptr<_Tp>
4623shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4624{
4625 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4626 typedef allocator<_CntrlBlk> _Alloc2;
4627 typedef __allocator_destructor<_Alloc2> _D2;
4628 _Alloc2 __alloc2;
4629 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4630 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4631 shared_ptr<_Tp> __r;
4632 __r.__ptr_ = __hold2.get()->get();
4633 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004634 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004635 return __r;
4636}
4637
4638template<class _Tp>
4639template<class _Alloc>
4640shared_ptr<_Tp>
4641shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4642{
4643 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004644 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004645 typedef __allocator_destructor<_Alloc2> _D2;
4646 _Alloc2 __alloc2(__a);
4647 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004648 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4649 _CntrlBlk(__a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004650 shared_ptr<_Tp> __r;
4651 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004652 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004653 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004654 return __r;
4655}
4656
4657template<class _Tp>
4658template<class _Alloc, class _A0>
4659shared_ptr<_Tp>
4660shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4661{
4662 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004663 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004664 typedef __allocator_destructor<_Alloc2> _D2;
4665 _Alloc2 __alloc2(__a);
4666 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004667 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4668 _CntrlBlk(__a, __a0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004669 shared_ptr<_Tp> __r;
4670 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004671 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004672 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004673 return __r;
4674}
4675
4676template<class _Tp>
4677template<class _Alloc, class _A0, class _A1>
4678shared_ptr<_Tp>
4679shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4680{
4681 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004682 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004683 typedef __allocator_destructor<_Alloc2> _D2;
4684 _Alloc2 __alloc2(__a);
4685 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004686 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4687 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004688 shared_ptr<_Tp> __r;
4689 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004690 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004691 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004692 return __r;
4693}
4694
4695template<class _Tp>
4696template<class _Alloc, class _A0, class _A1, class _A2>
4697shared_ptr<_Tp>
4698shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4699{
4700 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004701 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004702 typedef __allocator_destructor<_Alloc2> _D2;
4703 _Alloc2 __alloc2(__a);
4704 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004705 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4706 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004707 shared_ptr<_Tp> __r;
4708 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004709 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004710 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004711 return __r;
4712}
4713
4714#endif // _LIBCPP_HAS_NO_VARIADICS
4715
4716template<class _Tp>
4717shared_ptr<_Tp>::~shared_ptr()
4718{
4719 if (__cntrl_)
4720 __cntrl_->__release_shared();
4721}
4722
4723template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004724inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004725shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004726shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004727{
4728 shared_ptr(__r).swap(*this);
4729 return *this;
4730}
4731
4732template<class _Tp>
4733template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004734inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004735typename enable_if
4736<
4737 is_convertible<_Yp*, _Tp*>::value,
4738 shared_ptr<_Tp>&
4739>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004740shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004741{
4742 shared_ptr(__r).swap(*this);
4743 return *this;
4744}
4745
Howard Hinnant74279a52010-09-04 23:28:19 +00004746#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004747
4748template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004749inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004750shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004751shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004752{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004753 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004754 return *this;
4755}
4756
4757template<class _Tp>
4758template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004759inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004760typename enable_if
4761<
4762 is_convertible<_Yp*, _Tp*>::value,
4763 shared_ptr<_Tp>&
4764>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004765shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4766{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004767 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004768 return *this;
4769}
4770
4771template<class _Tp>
4772template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004773inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004774typename enable_if
4775<
4776 !is_array<_Yp>::value &&
4777 is_convertible<_Yp*, _Tp*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00004778 shared_ptr<_Tp>
4779>::type&
Howard Hinnantc51e1022010-05-11 19:42:16 +00004780shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4781{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004782 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004783 return *this;
4784}
4785
4786template<class _Tp>
4787template <class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004788inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004789typename enable_if
4790<
4791 !is_array<_Yp>::value &&
4792 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4793 shared_ptr<_Tp>&
4794>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004795shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4796{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004797 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004798 return *this;
4799}
4800
Howard Hinnant74279a52010-09-04 23:28:19 +00004801#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004802
4803template<class _Tp>
4804template<class _Yp>
4805inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004806typename enable_if
4807<
4808 !is_array<_Yp>::value &&
4809 is_convertible<_Yp*, _Tp*>::value,
4810 shared_ptr<_Tp>&
4811>::type
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004812shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004813{
4814 shared_ptr(__r).swap(*this);
4815 return *this;
4816}
4817
4818template<class _Tp>
4819template <class _Yp, class _Dp>
4820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004821typename enable_if
4822<
4823 !is_array<_Yp>::value &&
4824 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
4825 shared_ptr<_Tp>&
4826>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004827shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4828{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004829 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004830 return *this;
4831}
4832
Howard Hinnant74279a52010-09-04 23:28:19 +00004833#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004834
4835template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004836inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004837void
Howard Hinnant719bda32011-05-28 14:41:13 +00004838shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004839{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004840 _VSTD::swap(__ptr_, __r.__ptr_);
4841 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004842}
4843
4844template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004845inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004846void
Howard Hinnant719bda32011-05-28 14:41:13 +00004847shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004848{
4849 shared_ptr().swap(*this);
4850}
4851
4852template<class _Tp>
4853template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004854inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004855typename enable_if
4856<
4857 is_convertible<_Yp*, _Tp*>::value,
4858 void
4859>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004860shared_ptr<_Tp>::reset(_Yp* __p)
4861{
4862 shared_ptr(__p).swap(*this);
4863}
4864
4865template<class _Tp>
4866template<class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004867inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004868typename enable_if
4869<
4870 is_convertible<_Yp*, _Tp*>::value,
4871 void
4872>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004873shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4874{
4875 shared_ptr(__p, __d).swap(*this);
4876}
4877
4878template<class _Tp>
4879template<class _Yp, class _Dp, class _Alloc>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004880inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004881typename enable_if
4882<
4883 is_convertible<_Yp*, _Tp*>::value,
4884 void
4885>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004886shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4887{
4888 shared_ptr(__p, __d, __a).swap(*this);
4889}
4890
4891#ifndef _LIBCPP_HAS_NO_VARIADICS
4892
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004893template<class _Tp, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004895typename enable_if
4896<
4897 !is_array<_Tp>::value,
4898 shared_ptr<_Tp>
4899>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004900make_shared(_Args&& ...__args)
4901{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004902 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004903}
4904
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004905template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004907typename enable_if
4908<
4909 !is_array<_Tp>::value,
4910 shared_ptr<_Tp>
4911>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004912allocate_shared(const _Alloc& __a, _Args&& ...__args)
4913{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004914 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004915}
4916
4917#else // _LIBCPP_HAS_NO_VARIADICS
4918
4919template<class _Tp>
4920inline _LIBCPP_INLINE_VISIBILITY
4921shared_ptr<_Tp>
4922make_shared()
4923{
4924 return shared_ptr<_Tp>::make_shared();
4925}
4926
4927template<class _Tp, class _A0>
4928inline _LIBCPP_INLINE_VISIBILITY
4929shared_ptr<_Tp>
4930make_shared(_A0& __a0)
4931{
4932 return shared_ptr<_Tp>::make_shared(__a0);
4933}
4934
4935template<class _Tp, class _A0, class _A1>
4936inline _LIBCPP_INLINE_VISIBILITY
4937shared_ptr<_Tp>
4938make_shared(_A0& __a0, _A1& __a1)
4939{
4940 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4941}
4942
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004943template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004944inline _LIBCPP_INLINE_VISIBILITY
4945shared_ptr<_Tp>
4946make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4947{
4948 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4949}
4950
4951template<class _Tp, class _Alloc>
4952inline _LIBCPP_INLINE_VISIBILITY
4953shared_ptr<_Tp>
4954allocate_shared(const _Alloc& __a)
4955{
4956 return shared_ptr<_Tp>::allocate_shared(__a);
4957}
4958
4959template<class _Tp, class _Alloc, class _A0>
4960inline _LIBCPP_INLINE_VISIBILITY
4961shared_ptr<_Tp>
4962allocate_shared(const _Alloc& __a, _A0& __a0)
4963{
4964 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4965}
4966
4967template<class _Tp, class _Alloc, class _A0, class _A1>
4968inline _LIBCPP_INLINE_VISIBILITY
4969shared_ptr<_Tp>
4970allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4971{
4972 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4973}
4974
4975template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4976inline _LIBCPP_INLINE_VISIBILITY
4977shared_ptr<_Tp>
4978allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4979{
4980 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4981}
4982
4983#endif // _LIBCPP_HAS_NO_VARIADICS
4984
4985template<class _Tp, class _Up>
4986inline _LIBCPP_INLINE_VISIBILITY
4987bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004988operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004989{
4990 return __x.get() == __y.get();
4991}
4992
4993template<class _Tp, class _Up>
4994inline _LIBCPP_INLINE_VISIBILITY
4995bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004996operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004997{
4998 return !(__x == __y);
4999}
5000
5001template<class _Tp, class _Up>
5002inline _LIBCPP_INLINE_VISIBILITY
5003bool
Howard Hinnant719bda32011-05-28 14:41:13 +00005004operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005005{
Eric Fiselierf8898c82015-02-05 23:01:40 +00005006 typedef typename common_type<_Tp*, _Up*>::type _Vp;
5007 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00005008}
5009
5010template<class _Tp, class _Up>
5011inline _LIBCPP_INLINE_VISIBILITY
5012bool
5013operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
5014{
5015 return __y < __x;
5016}
5017
5018template<class _Tp, class _Up>
5019inline _LIBCPP_INLINE_VISIBILITY
5020bool
5021operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
5022{
5023 return !(__y < __x);
5024}
5025
5026template<class _Tp, class _Up>
5027inline _LIBCPP_INLINE_VISIBILITY
5028bool
5029operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
5030{
5031 return !(__x < __y);
5032}
5033
5034template<class _Tp>
5035inline _LIBCPP_INLINE_VISIBILITY
5036bool
5037operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5038{
5039 return !__x;
5040}
5041
5042template<class _Tp>
5043inline _LIBCPP_INLINE_VISIBILITY
5044bool
5045operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5046{
5047 return !__x;
5048}
5049
5050template<class _Tp>
5051inline _LIBCPP_INLINE_VISIBILITY
5052bool
5053operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5054{
5055 return static_cast<bool>(__x);
5056}
5057
5058template<class _Tp>
5059inline _LIBCPP_INLINE_VISIBILITY
5060bool
5061operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5062{
5063 return static_cast<bool>(__x);
5064}
5065
5066template<class _Tp>
5067inline _LIBCPP_INLINE_VISIBILITY
5068bool
5069operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5070{
5071 return less<_Tp*>()(__x.get(), nullptr);
5072}
5073
5074template<class _Tp>
5075inline _LIBCPP_INLINE_VISIBILITY
5076bool
5077operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5078{
5079 return less<_Tp*>()(nullptr, __x.get());
5080}
5081
5082template<class _Tp>
5083inline _LIBCPP_INLINE_VISIBILITY
5084bool
5085operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5086{
5087 return nullptr < __x;
5088}
5089
5090template<class _Tp>
5091inline _LIBCPP_INLINE_VISIBILITY
5092bool
5093operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5094{
5095 return __x < nullptr;
5096}
5097
5098template<class _Tp>
5099inline _LIBCPP_INLINE_VISIBILITY
5100bool
5101operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5102{
5103 return !(nullptr < __x);
5104}
5105
5106template<class _Tp>
5107inline _LIBCPP_INLINE_VISIBILITY
5108bool
5109operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5110{
5111 return !(__x < nullptr);
5112}
5113
5114template<class _Tp>
5115inline _LIBCPP_INLINE_VISIBILITY
5116bool
5117operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5118{
5119 return !(__x < nullptr);
5120}
5121
5122template<class _Tp>
5123inline _LIBCPP_INLINE_VISIBILITY
5124bool
5125operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5126{
5127 return !(nullptr < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005128}
5129
5130template<class _Tp>
5131inline _LIBCPP_INLINE_VISIBILITY
5132void
Howard Hinnant719bda32011-05-28 14:41:13 +00005133swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005134{
5135 __x.swap(__y);
5136}
5137
5138template<class _Tp, class _Up>
5139inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005140typename enable_if
5141<
5142 !is_array<_Tp>::value && !is_array<_Up>::value,
5143 shared_ptr<_Tp>
5144>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005145static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005146{
5147 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
5148}
5149
5150template<class _Tp, class _Up>
5151inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005152typename enable_if
5153<
5154 !is_array<_Tp>::value && !is_array<_Up>::value,
5155 shared_ptr<_Tp>
5156>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005157dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005158{
5159 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5160 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5161}
5162
5163template<class _Tp, class _Up>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005164typename enable_if
5165<
5166 is_array<_Tp>::value == is_array<_Up>::value,
5167 shared_ptr<_Tp>
5168>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005169const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005170{
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005171 typedef typename remove_extent<_Tp>::type _RTp;
5172 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00005173}
5174
Howard Hinnant72f73582010-08-11 17:04:31 +00005175#ifndef _LIBCPP_NO_RTTI
5176
Howard Hinnantc51e1022010-05-11 19:42:16 +00005177template<class _Dp, class _Tp>
5178inline _LIBCPP_INLINE_VISIBILITY
5179_Dp*
Howard Hinnant719bda32011-05-28 14:41:13 +00005180get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005181{
5182 return __p.template __get_deleter<_Dp>();
5183}
5184
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005185#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00005186
Howard Hinnantc51e1022010-05-11 19:42:16 +00005187template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005188class _LIBCPP_TYPE_VIS_ONLY weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00005189{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005190public:
5191 typedef _Tp element_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005192private:
5193 element_type* __ptr_;
5194 __shared_weak_count* __cntrl_;
5195
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005196public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005198 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005199 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00005200 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5201 _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005203 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005204 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00005205 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5206 _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005207
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005210 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005211 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005212 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5213 _NOEXCEPT;
5214#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005215 ~weak_ptr();
5216
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005218 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005219 template<class _Yp>
5220 typename enable_if
5221 <
5222 is_convertible<_Yp*, element_type*>::value,
5223 weak_ptr&
5224 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005226 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5227
5228#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5229
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005231 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5232 template<class _Yp>
5233 typename enable_if
5234 <
5235 is_convertible<_Yp*, element_type*>::value,
5236 weak_ptr&
5237 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005239 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5240
5241#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5242
5243 template<class _Yp>
5244 typename enable_if
5245 <
5246 is_convertible<_Yp*, element_type*>::value,
5247 weak_ptr&
5248 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005250 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005251
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005253 void swap(weak_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005255 void reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005256
Howard Hinnant756c69b2010-09-22 16:48:34 +00005257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005258 long use_count() const _NOEXCEPT
5259 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005261 bool expired() const _NOEXCEPT
5262 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5263 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005264 template<class _Up>
5265 _LIBCPP_INLINE_VISIBILITY
5266 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00005267 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005268 template<class _Up>
5269 _LIBCPP_INLINE_VISIBILITY
5270 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00005271 {return __cntrl_ < __r.__cntrl_;}
5272
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005273 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
5274 template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005275};
5276
5277template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005278inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005279_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005280weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005281 : __ptr_(0),
5282 __cntrl_(0)
5283{
5284}
5285
5286template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005287inline
Howard Hinnant719bda32011-05-28 14:41:13 +00005288weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005289 : __ptr_(__r.__ptr_),
5290 __cntrl_(__r.__cntrl_)
5291{
5292 if (__cntrl_)
5293 __cntrl_->__add_weak();
5294}
5295
5296template<class _Tp>
5297template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005298inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005299weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005300 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005301 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005302 : __ptr_(__r.__ptr_),
5303 __cntrl_(__r.__cntrl_)
5304{
5305 if (__cntrl_)
5306 __cntrl_->__add_weak();
5307}
5308
5309template<class _Tp>
5310template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005311inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005312weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005313 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005314 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005315 : __ptr_(__r.__ptr_),
5316 __cntrl_(__r.__cntrl_)
5317{
5318 if (__cntrl_)
5319 __cntrl_->__add_weak();
5320}
5321
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005322#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5323
5324template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005325inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005326weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5327 : __ptr_(__r.__ptr_),
5328 __cntrl_(__r.__cntrl_)
5329{
5330 __r.__ptr_ = 0;
5331 __r.__cntrl_ = 0;
5332}
5333
5334template<class _Tp>
5335template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005336inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005337weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5338 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5339 _NOEXCEPT
5340 : __ptr_(__r.__ptr_),
5341 __cntrl_(__r.__cntrl_)
5342{
5343 __r.__ptr_ = 0;
5344 __r.__cntrl_ = 0;
5345}
5346
5347#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5348
Howard Hinnantc51e1022010-05-11 19:42:16 +00005349template<class _Tp>
5350weak_ptr<_Tp>::~weak_ptr()
5351{
5352 if (__cntrl_)
5353 __cntrl_->__release_weak();
5354}
5355
5356template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005357inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005358weak_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00005359weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005360{
5361 weak_ptr(__r).swap(*this);
5362 return *this;
5363}
5364
5365template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005366template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005367inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005368typename enable_if
5369<
5370 is_convertible<_Yp*, _Tp*>::value,
5371 weak_ptr<_Tp>&
5372>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005373weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005374{
5375 weak_ptr(__r).swap(*this);
5376 return *this;
5377}
5378
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005379#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5380
5381template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005382inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005383weak_ptr<_Tp>&
5384weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5385{
5386 weak_ptr(_VSTD::move(__r)).swap(*this);
5387 return *this;
5388}
5389
Howard Hinnantc51e1022010-05-11 19:42:16 +00005390template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005391template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005392inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005393typename enable_if
5394<
5395 is_convertible<_Yp*, _Tp*>::value,
5396 weak_ptr<_Tp>&
5397>::type
5398weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5399{
5400 weak_ptr(_VSTD::move(__r)).swap(*this);
5401 return *this;
5402}
5403
5404#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5405
5406template<class _Tp>
5407template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005408inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005409typename enable_if
5410<
5411 is_convertible<_Yp*, _Tp*>::value,
5412 weak_ptr<_Tp>&
5413>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005414weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005415{
5416 weak_ptr(__r).swap(*this);
5417 return *this;
5418}
5419
5420template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005421inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005422void
Howard Hinnant719bda32011-05-28 14:41:13 +00005423weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005424{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00005425 _VSTD::swap(__ptr_, __r.__ptr_);
5426 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005427}
5428
5429template<class _Tp>
5430inline _LIBCPP_INLINE_VISIBILITY
5431void
Howard Hinnant719bda32011-05-28 14:41:13 +00005432swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005433{
5434 __x.swap(__y);
5435}
5436
5437template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005438inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005439void
Howard Hinnant719bda32011-05-28 14:41:13 +00005440weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005441{
5442 weak_ptr().swap(*this);
5443}
5444
5445template<class _Tp>
5446template<class _Yp>
5447shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5448 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
5449 : __ptr_(__r.__ptr_),
5450 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5451{
5452 if (__cntrl_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00005453 __throw_bad_weak_ptr();
Howard Hinnantc51e1022010-05-11 19:42:16 +00005454}
5455
5456template<class _Tp>
5457shared_ptr<_Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00005458weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005459{
5460 shared_ptr<_Tp> __r;
5461 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5462 if (__r.__cntrl_)
5463 __r.__ptr_ = __ptr_;
5464 return __r;
5465}
5466
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005467#if _LIBCPP_STD_VER > 14
5468template <class _Tp = void> struct owner_less;
5469#else
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005470template <class _Tp> struct owner_less;
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005471#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00005472
5473template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005474struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005475 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005476{
5477 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005479 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5480 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005482 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5483 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005485 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5486 {return __x.owner_before(__y);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005487};
Howard Hinnantc51e1022010-05-11 19:42:16 +00005488
5489template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005490struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005491 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5492{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005493 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005495 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5496 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005498 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5499 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005501 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5502 {return __x.owner_before(__y);}
5503};
5504
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005505#if _LIBCPP_STD_VER > 14
5506template <>
5507struct _LIBCPP_TYPE_VIS_ONLY owner_less<void>
5508{
5509 template <class _Tp, class _Up>
5510 _LIBCPP_INLINE_VISIBILITY
5511 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5512 {return __x.owner_before(__y);}
5513 template <class _Tp, class _Up>
5514 _LIBCPP_INLINE_VISIBILITY
5515 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5516 {return __x.owner_before(__y);}
5517 template <class _Tp, class _Up>
5518 _LIBCPP_INLINE_VISIBILITY
5519 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5520 {return __x.owner_before(__y);}
5521 template <class _Tp, class _Up>
5522 _LIBCPP_INLINE_VISIBILITY
5523 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5524 {return __x.owner_before(__y);}
5525 typedef void is_transparent;
5526};
5527#endif
5528
Howard Hinnantc51e1022010-05-11 19:42:16 +00005529template<class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005530class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
Howard Hinnantc51e1022010-05-11 19:42:16 +00005531{
5532 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005533protected:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005534 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005535 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005537 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005539 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5540 {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005542 ~enable_shared_from_this() {}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005543public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00005544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005545 shared_ptr<_Tp> shared_from_this()
5546 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005548 shared_ptr<_Tp const> shared_from_this() const
5549 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00005550
Eric Fiselier84006862016-06-02 00:15:35 +00005551#if _LIBCPP_STD_VER > 14
5552 _LIBCPP_INLINE_VISIBILITY
5553 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5554 { return __weak_this_; }
5555
5556 _LIBCPP_INLINE_VISIBILITY
5557 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5558 { return __weak_this_; }
5559#endif // _LIBCPP_STD_VER > 14
5560
Howard Hinnantc51e1022010-05-11 19:42:16 +00005561 template <class _Up> friend class shared_ptr;
5562};
5563
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005564template <class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005565struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005566{
5567 typedef shared_ptr<_Tp> argument_type;
5568 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005570 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005571 {
5572 return hash<_Tp*>()(__ptr.get());
5573 }
5574};
5575
Howard Hinnantc834c512011-11-29 18:15:50 +00005576template<class _CharT, class _Traits, class _Yp>
Howard Hinnantdc095972011-07-18 15:51:59 +00005577inline _LIBCPP_INLINE_VISIBILITY
5578basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00005579operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnantdc095972011-07-18 15:51:59 +00005580
Eric Fiselier9b492672016-06-18 02:12:53 +00005581
5582#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005583
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005584class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant9fa30202012-07-30 01:40:57 +00005585{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005586 void* __lx;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005587public:
5588 void lock() _NOEXCEPT;
5589 void unlock() _NOEXCEPT;
5590
5591private:
5592 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5593 __sp_mut(const __sp_mut&);
5594 __sp_mut& operator=(const __sp_mut&);
5595
Howard Hinnant8331b762013-03-06 23:30:19 +00005596 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005597};
5598
Howard Hinnant8331b762013-03-06 23:30:19 +00005599_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005600
5601template <class _Tp>
5602inline _LIBCPP_INLINE_VISIBILITY
5603bool
5604atomic_is_lock_free(const shared_ptr<_Tp>*)
5605{
5606 return false;
5607}
5608
5609template <class _Tp>
5610shared_ptr<_Tp>
5611atomic_load(const shared_ptr<_Tp>* __p)
5612{
5613 __sp_mut& __m = __get_sp_mut(__p);
5614 __m.lock();
5615 shared_ptr<_Tp> __q = *__p;
5616 __m.unlock();
5617 return __q;
5618}
5619
5620template <class _Tp>
5621inline _LIBCPP_INLINE_VISIBILITY
5622shared_ptr<_Tp>
5623atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5624{
5625 return atomic_load(__p);
5626}
5627
5628template <class _Tp>
5629void
5630atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5631{
5632 __sp_mut& __m = __get_sp_mut(__p);
5633 __m.lock();
5634 __p->swap(__r);
5635 __m.unlock();
5636}
5637
5638template <class _Tp>
5639inline _LIBCPP_INLINE_VISIBILITY
5640void
5641atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5642{
5643 atomic_store(__p, __r);
5644}
5645
5646template <class _Tp>
5647shared_ptr<_Tp>
5648atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5649{
5650 __sp_mut& __m = __get_sp_mut(__p);
5651 __m.lock();
5652 __p->swap(__r);
5653 __m.unlock();
5654 return __r;
5655}
5656
5657template <class _Tp>
5658inline _LIBCPP_INLINE_VISIBILITY
5659shared_ptr<_Tp>
5660atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5661{
5662 return atomic_exchange(__p, __r);
5663}
5664
5665template <class _Tp>
5666bool
5667atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5668{
Marshall Clow4201ee82016-05-18 17:50:13 +00005669 shared_ptr<_Tp> __temp;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005670 __sp_mut& __m = __get_sp_mut(__p);
5671 __m.lock();
5672 if (__p->__owner_equivalent(*__v))
5673 {
Marshall Clow4201ee82016-05-18 17:50:13 +00005674 _VSTD::swap(__temp, *__p);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005675 *__p = __w;
5676 __m.unlock();
5677 return true;
5678 }
Marshall Clow4201ee82016-05-18 17:50:13 +00005679 _VSTD::swap(__temp, *__v);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005680 *__v = *__p;
5681 __m.unlock();
5682 return false;
5683}
5684
5685template <class _Tp>
5686inline _LIBCPP_INLINE_VISIBILITY
5687bool
5688atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5689{
5690 return atomic_compare_exchange_strong(__p, __v, __w);
5691}
5692
5693template <class _Tp>
5694inline _LIBCPP_INLINE_VISIBILITY
5695bool
5696atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5697 shared_ptr<_Tp> __w, memory_order, memory_order)
5698{
5699 return atomic_compare_exchange_strong(__p, __v, __w);
5700}
5701
5702template <class _Tp>
5703inline _LIBCPP_INLINE_VISIBILITY
5704bool
5705atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5706 shared_ptr<_Tp> __w, memory_order, memory_order)
5707{
5708 return atomic_compare_exchange_weak(__p, __v, __w);
5709}
5710
Eric Fiselier9b492672016-06-18 02:12:53 +00005711#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005712
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005713//enum class
Howard Hinnant8331b762013-03-06 23:30:19 +00005714struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantc51e1022010-05-11 19:42:16 +00005715{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005716 enum __lx
Howard Hinnantc51e1022010-05-11 19:42:16 +00005717 {
5718 relaxed,
5719 preferred,
5720 strict
5721 };
5722
Howard Hinnant49e145e2012-10-30 19:06:59 +00005723 __lx __v_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005724
Howard Hinnant756c69b2010-09-22 16:48:34 +00005725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e145e2012-10-30 19:06:59 +00005726 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005728 operator int() const {return __v_;}
5729};
5730
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005731_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5732_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5733_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5734_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5735_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005736
5737template <class _Tp>
5738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005739_Tp*
Howard Hinnantc51e1022010-05-11 19:42:16 +00005740undeclare_reachable(_Tp* __p)
5741{
5742 return static_cast<_Tp*>(__undeclare_reachable(__p));
5743}
5744
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005745_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005746
Marshall Clow8982dcd2015-07-13 20:04:56 +00005747// --- Helper for container swap --
5748template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005749inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005750void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5751#if _LIBCPP_STD_VER >= 14
5752 _NOEXCEPT
5753#else
5754 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5755#endif
5756{
5757 __swap_allocator(__a1, __a2,
5758 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5759}
5760
5761template <typename _Alloc>
5762_LIBCPP_INLINE_VISIBILITY
5763void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5764#if _LIBCPP_STD_VER >= 14
5765 _NOEXCEPT
5766#else
5767 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5768#endif
5769{
5770 using _VSTD::swap;
5771 swap(__a1, __a2);
5772}
5773
5774template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005775inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005776void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5777
Marshall Clowff91de82015-08-18 19:51:37 +00005778template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00005779struct __noexcept_move_assign_container : public integral_constant<bool,
5780 _Traits::propagate_on_container_move_assignment::value
5781#if _LIBCPP_STD_VER > 14
5782 || _Traits::is_always_equal::value
5783#else
5784 && is_nothrow_move_assignable<_Alloc>::value
5785#endif
5786 > {};
Marshall Clow8982dcd2015-07-13 20:04:56 +00005787
Marshall Clowa591b9a2016-07-11 21:38:08 +00005788
5789#ifndef _LIBCPP_HAS_NO_VARIADICS
5790template <class _Tp, class _Alloc>
5791struct __temp_value {
5792 typedef allocator_traits<_Alloc> _Traits;
5793
5794 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5795 _Alloc &__a;
5796
5797 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5798 _Tp & get() { return *__addr(); }
5799
5800 template<class... _Args>
5801 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5802 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5803
5804 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5805 };
5806#endif
5807
Howard Hinnantc51e1022010-05-11 19:42:16 +00005808_LIBCPP_END_NAMESPACE_STD
5809
5810#endif // _LIBCPP_MEMORY