blob: ec309d14f3255b62161d94141340db1d4a85543a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_MEMORY
11#define _LIBCPP_MEMORY
12
13/*
14 memory synopsis
15
16namespace std
17{
18
19struct allocator_arg_t { };
Marshall Clowf1bf62f2018-01-02 17:17:01 +000020inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
Howard Hinnantc51e1022010-05-11 19:42:16 +000021
22template <class T, class Alloc> struct uses_allocator;
23
24template <class Ptr>
25struct pointer_traits
26{
27 typedef Ptr pointer;
28 typedef <details> element_type;
29 typedef <details> difference_type;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000030
Howard Hinnantc51e1022010-05-11 19:42:16 +000031 template <class U> using rebind = <details>;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000032
Howard Hinnantc51e1022010-05-11 19:42:16 +000033 static pointer pointer_to(<details>);
34};
35
Howard Hinnant719bda32011-05-28 14:41:13 +000036template <class T>
37struct pointer_traits<T*>
38{
39 typedef T* pointer;
40 typedef T element_type;
41 typedef ptrdiff_t difference_type;
42
43 template <class U> using rebind = U*;
44
Louis Dionne44e1ea82018-11-13 17:04:05 +000045 static pointer pointer_to(<details>) noexcept; // constexpr in C++20
Howard Hinnant719bda32011-05-28 14:41:13 +000046};
47
Eric Fiselier45c9aac2017-11-22 19:49:21 +000048template <class T> constexpr T* to_address(T* p) noexcept; // C++20
49template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
50
Howard Hinnantc51e1022010-05-11 19:42:16 +000051template <class Alloc>
52struct allocator_traits
53{
54 typedef Alloc allocator_type;
55 typedef typename allocator_type::value_type
56 value_type;
57
58 typedef Alloc::pointer | value_type* pointer;
59 typedef Alloc::const_pointer
60 | pointer_traits<pointer>::rebind<const value_type>
61 const_pointer;
62 typedef Alloc::void_pointer
63 | pointer_traits<pointer>::rebind<void>
64 void_pointer;
65 typedef Alloc::const_void_pointer
66 | pointer_traits<pointer>::rebind<const void>
67 const_void_pointer;
68 typedef Alloc::difference_type
Howard Hinnant8e4e6002010-11-18 01:40:00 +000069 | pointer_traits<pointer>::difference_type
70 difference_type;
71 typedef Alloc::size_type
72 | make_unsigned<difference_type>::type
73 size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +000074 typedef Alloc::propagate_on_container_copy_assignment
75 | false_type propagate_on_container_copy_assignment;
76 typedef Alloc::propagate_on_container_move_assignment
77 | false_type propagate_on_container_move_assignment;
78 typedef Alloc::propagate_on_container_swap
79 | false_type propagate_on_container_swap;
Marshall Clow0b587562015-06-02 16:34:03 +000080 typedef Alloc::is_always_equal
81 | is_empty is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +000082
83 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
84 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
85
Marshall Clow0e58cae2017-11-26 02:55:38 +000086 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
87 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Howard Hinnant719bda32011-05-28 14:41:13 +000089 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
91 template <class T, class... Args>
92 static void construct(allocator_type& a, T* p, Args&&... args);
93
94 template <class T>
95 static void destroy(allocator_type& a, T* p);
96
Marshall Clow4f834b52013-08-27 20:22:15 +000097 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000098
99 static allocator_type
100 select_on_container_copy_construction(const allocator_type& a);
101};
102
103template <>
104class allocator<void>
105{
106public:
107 typedef void* pointer;
108 typedef const void* const_pointer;
109 typedef void value_type;
110
111 template <class _Up> struct rebind {typedef allocator<_Up> other;};
112};
113
114template <class T>
115class allocator
116{
117public:
118 typedef size_t size_type;
119 typedef ptrdiff_t difference_type;
120 typedef T* pointer;
121 typedef const T* const_pointer;
122 typedef typename add_lvalue_reference<T>::type reference;
123 typedef typename add_lvalue_reference<const T>::type const_reference;
124 typedef T value_type;
125
126 template <class U> struct rebind {typedef allocator<U> other;};
127
Marshall Clowbc759762018-03-20 23:02:53 +0000128 constexpr allocator() noexcept; // constexpr in C++20
129 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
130 template <class U>
131 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
Howard Hinnant719bda32011-05-28 14:41:13 +0000132 ~allocator();
133 pointer address(reference x) const noexcept;
134 const_pointer address(const_reference x) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant719bda32011-05-28 14:41:13 +0000136 void deallocate(pointer p, size_type n) noexcept;
137 size_type max_size() const noexcept;
138 template<class U, class... Args>
139 void construct(U* p, Args&&... args);
140 template <class U>
141 void destroy(U* p);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142};
143
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 T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000148bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000149
150template <class OutputIterator, class T>
151class raw_storage_iterator
152 : public iterator<output_iterator_tag,
153 T, // purposefully not C++03
154 ptrdiff_t, // purposefully not C++03
155 T*, // purposefully not C++03
156 raw_storage_iterator&> // purposefully not C++03
157{
158public:
159 explicit raw_storage_iterator(OutputIterator x);
160 raw_storage_iterator& operator*();
161 raw_storage_iterator& operator=(const T& element);
162 raw_storage_iterator& operator++();
163 raw_storage_iterator operator++(int);
164};
165
Howard Hinnant719bda32011-05-28 14:41:13 +0000166template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
167template <class T> void return_temporary_buffer(T* p) noexcept;
168
169template <class T> T* addressof(T& r) noexcept;
Marshall Clow78dbe462016-11-14 18:22:19 +0000170template <class T> T* addressof(const T&& r) noexcept = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000171
172template <class InputIterator, class ForwardIterator>
173ForwardIterator
174uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
175
Howard Hinnant719bda32011-05-28 14:41:13 +0000176template <class InputIterator, class Size, class ForwardIterator>
177ForwardIterator
178uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
179
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180template <class ForwardIterator, class T>
181void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
182
183template <class ForwardIterator, class Size, class T>
Howard Hinnant3c811092010-11-18 16:13:03 +0000184ForwardIterator
185uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
Eric Fiselier383f6cf2016-07-24 03:51:39 +0000187template <class T>
188void destroy_at(T* location);
189
190template <class ForwardIterator>
191 void destroy(ForwardIterator first, ForwardIterator last);
192
193template <class ForwardIterator, class Size>
194 ForwardIterator destroy_n(ForwardIterator first, Size n);
195
196template <class InputIterator, class ForwardIterator>
197 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
198
199template <class InputIterator, class Size, class ForwardIterator>
200 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
201
202template <class ForwardIterator>
203 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
204
205template <class ForwardIterator, class Size>
206 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
207
208template <class ForwardIterator>
209 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
210
211template <class ForwardIterator, class Size>
212 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
213
Louis Dionne481a2662018-09-23 18:35:00 +0000214template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000215
216template<class X>
Louis Dionne481a2662018-09-23 18:35:00 +0000217class auto_ptr // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218{
219public:
220 typedef X element_type;
221
222 explicit auto_ptr(X* p =0) throw();
223 auto_ptr(auto_ptr&) throw();
224 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
225 auto_ptr& operator=(auto_ptr&) throw();
226 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
227 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
228 ~auto_ptr() throw();
229
230 typename add_lvalue_reference<X>::type operator*() const throw();
231 X* operator->() const throw();
232 X* get() const throw();
233 X* release() throw();
234 void reset(X* p =0) throw();
235
236 auto_ptr(auto_ptr_ref<X>) throw();
237 template<class Y> operator auto_ptr_ref<Y>() throw();
238 template<class Y> operator auto_ptr<Y>() throw();
239};
240
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000241template <class T>
242struct default_delete
243{
Howard Hinnant719bda32011-05-28 14:41:13 +0000244 constexpr default_delete() noexcept = default;
245 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000246
Howard Hinnant719bda32011-05-28 14:41:13 +0000247 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000248};
249
250template <class T>
251struct default_delete<T[]>
252{
Howard Hinnant719bda32011-05-28 14:41:13 +0000253 constexpr default_delete() noexcept = default;
254 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000255 template <class U> void operator()(U*) const = delete;
256};
257
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000258template <class T, class D = default_delete<T>>
259class unique_ptr
260{
261public:
262 typedef see below pointer;
263 typedef T element_type;
264 typedef D deleter_type;
265
266 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000267 constexpr unique_ptr() noexcept;
268 explicit unique_ptr(pointer p) noexcept;
269 unique_ptr(pointer p, see below d1) noexcept;
270 unique_ptr(pointer p, see below d2) noexcept;
271 unique_ptr(unique_ptr&& u) noexcept;
272 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000273 template <class U, class E>
Howard Hinnant719bda32011-05-28 14:41:13 +0000274 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000275 template <class U>
Marshall Clowb22274f2017-01-24 22:22:33 +0000276 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000277
278 // destructor
279 ~unique_ptr();
280
281 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000282 unique_ptr& operator=(unique_ptr&& u) noexcept;
283 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
284 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000285
286 // observers
287 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000288 pointer operator->() const noexcept;
289 pointer get() const noexcept;
290 deleter_type& get_deleter() noexcept;
291 const deleter_type& get_deleter() const noexcept;
292 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000293
294 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000295 pointer release() noexcept;
296 void reset(pointer p = pointer()) noexcept;
297 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000298};
299
300template <class T, class D>
301class unique_ptr<T[], D>
302{
303public:
304 typedef implementation-defined pointer;
305 typedef T element_type;
306 typedef D deleter_type;
307
308 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000309 constexpr unique_ptr() noexcept;
310 explicit unique_ptr(pointer p) noexcept;
311 unique_ptr(pointer p, see below d) noexcept;
312 unique_ptr(pointer p, see below d) noexcept;
313 unique_ptr(unique_ptr&& u) noexcept;
314 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000315
316 // destructor
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000317 ~unique_ptr();
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000318
319 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000320 unique_ptr& operator=(unique_ptr&& u) noexcept;
321 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000322
323 // observers
324 T& operator[](size_t i) const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000325 pointer get() const noexcept;
326 deleter_type& get_deleter() noexcept;
327 const deleter_type& get_deleter() const noexcept;
328 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000329
330 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000331 pointer release() noexcept;
332 void reset(pointer p = pointer()) noexcept;
333 void reset(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000334 template <class U> void reset(U) = delete;
Howard Hinnant719bda32011-05-28 14:41:13 +0000335 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000336};
337
338template <class T, class D>
Howard Hinnant719bda32011-05-28 14:41:13 +0000339 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000340
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);
349template <class T1, class D1, class T2, class D2>
350 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
351template <class T1, class D1, class T2, class D2>
352 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
353
Howard Hinnant719bda32011-05-28 14:41:13 +0000354template <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;
358template <class T, class D>
359 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
360template <class T, class D>
361 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
362
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);
375template <class T, class D>
376 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
377template <class T, class D>
378 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
379
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000380class bad_weak_ptr
381 : public std::exception
382{
Howard Hinnant719bda32011-05-28 14:41:13 +0000383 bad_weak_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000384};
385
Marshall Clow9e8f4a92013-07-01 18:16:03 +0000386template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
387template<class T> unique_ptr<T> make_unique(size_t n); // C++14
388template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
389
Marshall Clowe52a3242017-11-27 15:51:36 +0000390template<class E, class T, class Y, class D>
391 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
392
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000393template<class T>
394class shared_ptr
395{
396public:
397 typedef T element_type;
Eric Fiselierae5b6672016-06-27 01:02:43 +0000398 typedef weak_ptr<T> weak_type; // C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000399
400 // constructors:
Howard Hinnant719bda32011-05-28 14:41:13 +0000401 constexpr shared_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000402 template<class Y> explicit shared_ptr(Y* p);
403 template<class Y, class D> shared_ptr(Y* p, D d);
404 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
405 template <class D> shared_ptr(nullptr_t p, D d);
406 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant719bda32011-05-28 14:41:13 +0000407 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
408 shared_ptr(const shared_ptr& r) noexcept;
409 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
410 shared_ptr(shared_ptr&& r) noexcept;
411 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000412 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
Marshall Clowb22274f2017-01-24 22:22:33 +0000413 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000414 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
415 shared_ptr(nullptr_t) : shared_ptr() { }
416
417 // destructor:
418 ~shared_ptr();
419
420 // assignment:
Howard Hinnant719bda32011-05-28 14:41:13 +0000421 shared_ptr& operator=(const shared_ptr& r) noexcept;
422 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
423 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000424 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
Marshall Clowb22274f2017-01-24 22:22:33 +0000425 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000426 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
427
428 // modifiers:
Howard Hinnant719bda32011-05-28 14:41:13 +0000429 void swap(shared_ptr& r) noexcept;
430 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000431 template<class Y> void reset(Y* p);
432 template<class Y, class D> void reset(Y* p, D d);
433 template<class Y, class D, class A> void reset(Y* p, D d, A a);
434
Howard Hinnant719bda32011-05-28 14:41:13 +0000435 // observers:
436 T* get() const noexcept;
437 T& operator*() const noexcept;
438 T* operator->() const noexcept;
439 long use_count() const noexcept;
440 bool unique() const noexcept;
441 explicit operator bool() const noexcept;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000442 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
443 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000444};
445
446// shared_ptr comparisons:
447template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000448 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000449template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000450 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000451template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000452 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000453template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000454 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000455template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000456 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000457template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000458 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
459
460template <class T>
461 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
462template <class T>
463 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
464template <class T>
465 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
466template <class T>
467 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
468template <class T>
469 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
470template <class T>
471bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
472template <class T>
473 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
474template <class T>
475 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
476template <class T>
477 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
478template <class T>
479 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
480template <class T>
481 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
482template <class T>
483 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000484
485// shared_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000486template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000487
488// shared_ptr casts:
489template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000490 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000491template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000492 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000493template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000494 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000495
496// shared_ptr I/O:
497template<class E, class T, class Y>
498 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
499
500// shared_ptr get_deleter:
Howard Hinnant719bda32011-05-28 14:41:13 +0000501template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000502
503template<class T, class... Args>
504 shared_ptr<T> make_shared(Args&&... args);
505template<class T, class A, class... Args>
506 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
507
508template<class T>
509class weak_ptr
510{
511public:
512 typedef T element_type;
513
514 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000515 constexpr weak_ptr() noexcept;
516 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
517 weak_ptr(weak_ptr const& r) noexcept;
518 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000519 weak_ptr(weak_ptr&& r) noexcept; // C++14
520 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000521
522 // destructor
523 ~weak_ptr();
524
525 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000526 weak_ptr& operator=(weak_ptr const& r) noexcept;
527 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
528 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000529 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
530 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000531
532 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000533 void swap(weak_ptr& r) noexcept;
534 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000535
536 // observers
Howard Hinnant719bda32011-05-28 14:41:13 +0000537 long use_count() const noexcept;
538 bool expired() const noexcept;
539 shared_ptr<T> lock() const noexcept;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000540 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
541 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000542};
543
544// weak_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000545template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000546
547// class owner_less:
548template<class T> struct owner_less;
549
550template<class T>
Eric Fiselierea6fdf62019-06-23 20:47:21 +0000551struct owner_less<shared_ptr<T> >
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000552 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
553{
554 typedef bool result_type;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000555 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
556 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
557 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000558};
559
560template<class T>
Eric Fiselierea6fdf62019-06-23 20:47:21 +0000561struct owner_less<weak_ptr<T> >
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000562 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
563{
564 typedef bool result_type;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000565 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
566 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
568};
569
570template <> // Added in C++14
571struct owner_less<void>
572{
573 template <class _Tp, class _Up>
574 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
575 template <class _Tp, class _Up>
576 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
577 template <class _Tp, class _Up>
578 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
579 template <class _Tp, class _Up>
580 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
581
582 typedef void is_transparent;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000583};
584
585template<class T>
586class enable_shared_from_this
587{
588protected:
Howard Hinnant719bda32011-05-28 14:41:13 +0000589 constexpr enable_shared_from_this() noexcept;
590 enable_shared_from_this(enable_shared_from_this const&) noexcept;
591 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000592 ~enable_shared_from_this();
593public:
594 shared_ptr<T> shared_from_this();
595 shared_ptr<T const> shared_from_this() const;
596};
597
598template<class T>
599 bool atomic_is_lock_free(const shared_ptr<T>* p);
600template<class T>
601 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
602template<class T>
603 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
604template<class T>
605 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
606template<class T>
607 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
608template<class T>
609 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
610template<class T>
611 shared_ptr<T>
612 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
613template<class T>
614 bool
615 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
616template<class T>
617 bool
618 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
619template<class T>
620 bool
621 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
622 shared_ptr<T> w, memory_order success,
623 memory_order failure);
624template<class T>
625 bool
626 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
627 shared_ptr<T> w, memory_order success,
628 memory_order failure);
629// Hash support
630template <class T> struct hash;
631template <class T, class D> struct hash<unique_ptr<T, D> >;
632template <class T> struct hash<shared_ptr<T> >;
633
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000634template <class T, class Alloc>
635 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
636
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000637// Pointer safety
638enum class pointer_safety { relaxed, preferred, strict };
639void declare_reachable(void *p);
640template <class T> T *undeclare_reachable(T *p);
641void declare_no_pointers(char *p, size_t n);
642void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant719bda32011-05-28 14:41:13 +0000643pointer_safety get_pointer_safety() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000644
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
646
647} // std
648
649*/
650
651#include <__config>
652#include <type_traits>
653#include <typeinfo>
654#include <cstddef>
655#include <cstdint>
656#include <new>
657#include <utility>
658#include <limits>
659#include <iterator>
660#include <__functional_base>
Howard Hinnantdc095972011-07-18 15:51:59 +0000661#include <iosfwd>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000662#include <tuple>
Eric Fiselier2db2bd52016-05-07 03:12:24 +0000663#include <stdexcept>
Howard Hinnantd2cab2f2012-02-15 00:41:34 +0000664#include <cstring>
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000665#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +0000666# include <atomic>
667#endif
Marshall Clow0a1e7502018-09-12 19:41:40 +0000668#include <version>
Howard Hinnant9fa30202012-07-30 01:40:57 +0000669
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000670#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000672#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673
Eric Fiselierf4433a32017-05-31 22:07:49 +0000674_LIBCPP_PUSH_MACROS
675#include <__undef_macros>
676
677
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678_LIBCPP_BEGIN_NAMESPACE_STD
679
Eric Fiselier89659d12015-07-07 00:27:16 +0000680template <class _ValueType>
Louis Dionne16fe2952018-07-11 23:14:33 +0000681inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier89659d12015-07-07 00:27:16 +0000682_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
683#if !defined(_LIBCPP_HAS_NO_THREADS) && \
684 defined(__ATOMIC_RELAXED) && \
Richard Smithca47d0f2019-04-25 20:02:10 +0000685 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
Eric Fiselier89659d12015-07-07 00:27:16 +0000686 return __atomic_load_n(__value, __ATOMIC_RELAXED);
687#else
688 return *__value;
689#endif
690}
691
Kuba Breckade9d6792016-09-04 09:55:12 +0000692template <class _ValueType>
Louis Dionne16fe2952018-07-11 23:14:33 +0000693inline _LIBCPP_INLINE_VISIBILITY
Kuba Breckade9d6792016-09-04 09:55:12 +0000694_ValueType __libcpp_acquire_load(_ValueType const* __value) {
695#if !defined(_LIBCPP_HAS_NO_THREADS) && \
696 defined(__ATOMIC_ACQUIRE) && \
Richard Smithca47d0f2019-04-25 20:02:10 +0000697 (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
Kuba Breckade9d6792016-09-04 09:55:12 +0000698 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
699#else
700 return *__value;
701#endif
702}
703
Marshall Clow78dbe462016-11-14 18:22:19 +0000704// addressof moved to <type_traits>
Douglas Gregor13034442011-06-22 22:17:44 +0000705
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706template <class _Tp> class allocator;
707
708template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000709class _LIBCPP_TEMPLATE_VIS allocator<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710{
711public:
712 typedef void* pointer;
713 typedef const void* const_pointer;
714 typedef void value_type;
715
716 template <class _Up> struct rebind {typedef allocator<_Up> other;};
717};
718
Howard Hinnant9f771052012-01-19 23:15:22 +0000719template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000720class _LIBCPP_TEMPLATE_VIS allocator<const void>
Howard Hinnant9f771052012-01-19 23:15:22 +0000721{
722public:
723 typedef const void* pointer;
724 typedef const void* const_pointer;
725 typedef const void value_type;
726
727 template <class _Up> struct rebind {typedef allocator<_Up> other;};
728};
729
Howard Hinnantc51e1022010-05-11 19:42:16 +0000730// pointer_traits
731
Marshall Clow0be70c32017-06-14 21:23:57 +0000732template <class _Tp, class = void>
733struct __has_element_type : false_type {};
734
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +0000736struct __has_element_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +0000737 typename __void_t<typename _Tp::element_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000738
739template <class _Ptr, bool = __has_element_type<_Ptr>::value>
740struct __pointer_traits_element_type;
741
742template <class _Ptr>
743struct __pointer_traits_element_type<_Ptr, true>
744{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000745 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746};
747
748#ifndef _LIBCPP_HAS_NO_VARIADICS
749
750template <template <class, class...> class _Sp, class _Tp, class ..._Args>
751struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
752{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000753 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754};
755
756template <template <class, class...> class _Sp, class _Tp, class ..._Args>
757struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
758{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000759 typedef _LIBCPP_NODEBUG_TYPE _Tp type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760};
761
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000762#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763
764template <template <class> class _Sp, class _Tp>
765struct __pointer_traits_element_type<_Sp<_Tp>, true>
766{
767 typedef typename _Sp<_Tp>::element_type type;
768};
769
770template <template <class> class _Sp, class _Tp>
771struct __pointer_traits_element_type<_Sp<_Tp>, false>
772{
773 typedef _Tp type;
774};
775
776template <template <class, class> class _Sp, class _Tp, class _A0>
777struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
778{
779 typedef typename _Sp<_Tp, _A0>::element_type type;
780};
781
782template <template <class, class> class _Sp, class _Tp, class _A0>
783struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
784{
785 typedef _Tp type;
786};
787
788template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
789struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
790{
791 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
792};
793
794template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
795struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
796{
797 typedef _Tp type;
798};
799
800template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
801 class _A1, class _A2>
802struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
803{
804 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
805};
806
807template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
808 class _A1, class _A2>
809struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
810{
811 typedef _Tp type;
812};
813
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000814#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815
Marshall Clow0be70c32017-06-14 21:23:57 +0000816template <class _Tp, class = void>
817struct __has_difference_type : false_type {};
818
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +0000820struct __has_difference_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +0000821 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
823template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
824struct __pointer_traits_difference_type
825{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000826 typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827};
828
829template <class _Ptr>
830struct __pointer_traits_difference_type<_Ptr, true>
831{
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000832 typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833};
834
835template <class _Tp, class _Up>
836struct __has_rebind
837{
838private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000839 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 template <class _Xp> static __two __test(...);
841 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
842public:
843 static const bool value = sizeof(__test<_Tp>(0)) == 1;
844};
845
846template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
847struct __pointer_traits_rebind
848{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000849#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000850 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851#else
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000852 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853#endif
854};
855
856#ifndef _LIBCPP_HAS_NO_VARIADICS
857
858template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
859struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
860{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000861#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000862 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863#else
Eric Fiselier4fc82a22019-06-12 02:03:31 +0000864 typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000865#endif
866};
867
868template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
869struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
870{
871 typedef _Sp<_Up, _Args...> type;
872};
873
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000874#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875
876template <template <class> class _Sp, class _Tp, class _Up>
877struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
878{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000879#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 typedef typename _Sp<_Tp>::template rebind<_Up> type;
881#else
882 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
883#endif
884};
885
886template <template <class> class _Sp, class _Tp, class _Up>
887struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
888{
889 typedef _Sp<_Up> type;
890};
891
892template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
893struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
894{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000895#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
897#else
898 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
899#endif
900};
901
902template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
903struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
904{
905 typedef _Sp<_Up, _A0> type;
906};
907
908template <template <class, class, class> class _Sp, class _Tp, class _A0,
909 class _A1, class _Up>
910struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
911{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000912#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
914#else
915 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
916#endif
917};
918
919template <template <class, class, class> class _Sp, class _Tp, class _A0,
920 class _A1, class _Up>
921struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
922{
923 typedef _Sp<_Up, _A0, _A1> type;
924};
925
926template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
927 class _A1, class _A2, class _Up>
928struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
929{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000930#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
932#else
933 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
934#endif
935};
936
937template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
938 class _A1, class _A2, class _Up>
939struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
940{
941 typedef _Sp<_Up, _A0, _A1, _A2> type;
942};
943
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000944#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945
946template <class _Ptr>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000947struct _LIBCPP_TEMPLATE_VIS pointer_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948{
949 typedef _Ptr pointer;
950 typedef typename __pointer_traits_element_type<pointer>::type element_type;
951 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
952
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000953#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf09283d2011-05-11 20:21:19 +0000954 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955#else
956 template <class _Up> struct rebind
957 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000958#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959
960private:
961 struct __nat {};
962public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 static pointer pointer_to(typename conditional<is_void<element_type>::value,
965 __nat, element_type>::type& __r)
966 {return pointer::pointer_to(__r);}
967};
968
969template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000970struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971{
972 typedef _Tp* pointer;
973 typedef _Tp element_type;
974 typedef ptrdiff_t difference_type;
975
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000976#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 template <class _Up> using rebind = _Up*;
978#else
979 template <class _Up> struct rebind {typedef _Up* other;};
980#endif
981
982private:
983 struct __nat {};
984public:
Louis Dionne44e1ea82018-11-13 17:04:05 +0000985 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant719bda32011-05-28 14:41:13 +0000987 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000988 {return _VSTD::addressof(__r);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989};
990
Eric Fiselierae3ab842015-08-23 02:56:05 +0000991template <class _From, class _To>
992struct __rebind_pointer {
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000993#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierae3ab842015-08-23 02:56:05 +0000994 typedef typename pointer_traits<_From>::template rebind<_To> type;
995#else
996 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
997#endif
998};
999
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000// allocator_traits
1001
Marshall Clow0be70c32017-06-14 21:23:57 +00001002template <class _Tp, class = void>
1003struct __has_pointer_type : false_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004
1005template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001006struct __has_pointer_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001007 typename __void_t<typename _Tp::pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008
1009namespace __pointer_type_imp
1010{
1011
1012template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1013struct __pointer_type
1014{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001015 typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016};
1017
1018template <class _Tp, class _Dp>
1019struct __pointer_type<_Tp, _Dp, false>
1020{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001021 typedef _LIBCPP_NODEBUG_TYPE _Tp* type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022};
1023
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001024} // __pointer_type_imp
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025
1026template <class _Tp, class _Dp>
1027struct __pointer_type
1028{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001029 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030};
1031
Marshall Clow0be70c32017-06-14 21:23:57 +00001032template <class _Tp, class = void>
1033struct __has_const_pointer : false_type {};
1034
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001036struct __has_const_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001037 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038
1039template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1040struct __const_pointer
1041{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001042 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043};
1044
1045template <class _Tp, class _Ptr, class _Alloc>
1046struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1047{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001048#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001049 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050#else
1051 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1052#endif
1053};
1054
Marshall Clow0be70c32017-06-14 21:23:57 +00001055template <class _Tp, class = void>
1056struct __has_void_pointer : false_type {};
1057
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001059struct __has_void_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001060 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061
1062template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1063struct __void_pointer
1064{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001065 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066};
1067
1068template <class _Ptr, class _Alloc>
1069struct __void_pointer<_Ptr, _Alloc, false>
1070{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001071#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001072 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073#else
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001074 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075#endif
1076};
1077
Marshall Clow0be70c32017-06-14 21:23:57 +00001078template <class _Tp, class = void>
1079struct __has_const_void_pointer : false_type {};
1080
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001082struct __has_const_void_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001083 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084
1085template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1086struct __const_void_pointer
1087{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001088 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089};
1090
1091template <class _Ptr, class _Alloc>
1092struct __const_void_pointer<_Ptr, _Alloc, false>
1093{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001094#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001095 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096#else
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001097 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098#endif
1099};
1100
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001101
1102template <bool _UsePointerTraits> struct __to_address_helper;
1103
1104template <> struct __to_address_helper<true> {
1105 template <class _Pointer>
1106 using __return_type = decltype(pointer_traits<_Pointer>::to_address(std::declval<const _Pointer&>()));
1107
1108 template <class _Pointer>
1109 _LIBCPP_CONSTEXPR
1110 static __return_type<_Pointer>
1111 __do_it(const _Pointer &__p) _NOEXCEPT { return pointer_traits<_Pointer>::to_address(__p); }
1112};
1113
1114template <class _Pointer, bool _Dummy = true>
1115using __choose_to_address = __to_address_helper<_IsValidExpansion<__to_address_helper<_Dummy>::template __return_type, _Pointer>::value>;
1116
1117
Howard Hinnantc834c512011-11-29 18:15:50 +00001118template <class _Tp>
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001119inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc834c512011-11-29 18:15:50 +00001120_Tp*
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001121__to_address(_Tp* __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001123 static_assert(!is_function<_Tp>::value, "_Tp is a function type");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124 return __p;
1125}
1126
1127template <class _Pointer>
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001128inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1129typename __choose_to_address<_Pointer>::template __return_type<_Pointer>
1130__to_address(const _Pointer& __p) _NOEXCEPT {
1131 return __choose_to_address<_Pointer>::__do_it(__p);
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001132}
1133
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001134template <> struct __to_address_helper<false> {
1135 template <class _Pointer>
1136 using __return_type = typename pointer_traits<_Pointer>::element_type*;
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001137
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001138 template <class _Pointer>
1139 _LIBCPP_CONSTEXPR
1140 static __return_type<_Pointer>
1141 __do_it(const _Pointer &__p) _NOEXCEPT { return std::__to_address(__p.operator->()); }
1142};
1143
1144
1145#if _LIBCPP_STD_VER > 17
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001146template <class _Tp>
1147inline _LIBCPP_INLINE_VISIBILITY constexpr
1148_Tp*
1149to_address(_Tp* __p) _NOEXCEPT
1150{
1151 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1152 return __p;
1153}
1154
1155template <class _Pointer>
1156inline _LIBCPP_INLINE_VISIBILITY
1157auto
1158to_address(const _Pointer& __p) _NOEXCEPT
1159{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001160 return _VSTD::__to_address(__p);
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001161}
1162#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163
Marshall Clow0be70c32017-06-14 21:23:57 +00001164template <class _Tp, class = void>
1165struct __has_size_type : false_type {};
1166
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167template <class _Tp>
Marshall Clow0be70c32017-06-14 21:23:57 +00001168struct __has_size_type<_Tp,
1169 typename __void_t<typename _Tp::size_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001171template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172struct __size_type
1173{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001174 typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175};
1176
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001177template <class _Alloc, class _DiffType>
1178struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001180 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181};
1182
Marshall Clow0be70c32017-06-14 21:23:57 +00001183template <class _Tp, class = void>
1184struct __has_propagate_on_container_copy_assignment : false_type {};
1185
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186template <class _Tp>
Marshall Clow0be70c32017-06-14 21:23:57 +00001187struct __has_propagate_on_container_copy_assignment<_Tp,
1188 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1189 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190
1191template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1192struct __propagate_on_container_copy_assignment
1193{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001194 typedef _LIBCPP_NODEBUG_TYPE false_type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195};
1196
1197template <class _Alloc>
1198struct __propagate_on_container_copy_assignment<_Alloc, true>
1199{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001200 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201};
1202
Marshall Clow0be70c32017-06-14 21:23:57 +00001203template <class _Tp, class = void>
1204struct __has_propagate_on_container_move_assignment : false_type {};
1205
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001207struct __has_propagate_on_container_move_assignment<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001208 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1209 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210
1211template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1212struct __propagate_on_container_move_assignment
1213{
1214 typedef false_type type;
1215};
1216
1217template <class _Alloc>
1218struct __propagate_on_container_move_assignment<_Alloc, true>
1219{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001220 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221};
1222
Marshall Clow0be70c32017-06-14 21:23:57 +00001223template <class _Tp, class = void>
1224struct __has_propagate_on_container_swap : false_type {};
1225
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001227struct __has_propagate_on_container_swap<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001228 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1229 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230
1231template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1232struct __propagate_on_container_swap
1233{
1234 typedef false_type type;
1235};
1236
1237template <class _Alloc>
1238struct __propagate_on_container_swap<_Alloc, true>
1239{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001240 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241};
1242
Marshall Clow0be70c32017-06-14 21:23:57 +00001243template <class _Tp, class = void>
1244struct __has_is_always_equal : false_type {};
1245
Marshall Clow0b587562015-06-02 16:34:03 +00001246template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001247struct __has_is_always_equal<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001248 typename __void_t<typename _Tp::is_always_equal>::type>
1249 : true_type {};
Marshall Clow0b587562015-06-02 16:34:03 +00001250
1251template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1252struct __is_always_equal
1253{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001254 typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type;
Marshall Clow0b587562015-06-02 16:34:03 +00001255};
1256
1257template <class _Alloc>
1258struct __is_always_equal<_Alloc, true>
1259{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001260 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type;
Marshall Clow0b587562015-06-02 16:34:03 +00001261};
1262
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1264struct __has_rebind_other
1265{
1266private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001267 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 template <class _Xp> static __two __test(...);
1269 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1270public:
1271 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1272};
1273
1274template <class _Tp, class _Up>
1275struct __has_rebind_other<_Tp, _Up, false>
1276{
1277 static const bool value = false;
1278};
1279
1280template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1281struct __allocator_traits_rebind
1282{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001283 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284};
1285
1286#ifndef _LIBCPP_HAS_NO_VARIADICS
1287
1288template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1289struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1290{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001291 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292};
1293
1294template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1295struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1296{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001297 typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298};
1299
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001300#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301
1302template <template <class> class _Alloc, class _Tp, class _Up>
1303struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1304{
1305 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1306};
1307
1308template <template <class> class _Alloc, class _Tp, class _Up>
1309struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1310{
1311 typedef _Alloc<_Up> type;
1312};
1313
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1315struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1316{
1317 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1318};
1319
1320template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1321struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1322{
1323 typedef _Alloc<_Up, _A0> type;
1324};
1325
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1327 class _A1, class _Up>
1328struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1329{
1330 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1331};
1332
1333template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1334 class _A1, class _Up>
1335struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1336{
1337 typedef _Alloc<_Up, _A0, _A1> type;
1338};
1339
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1341 class _A1, class _A2, class _Up>
1342struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1343{
1344 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1345};
1346
1347template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1348 class _A1, class _A2, class _Up>
1349struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1350{
1351 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1352};
1353
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001354#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001356#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357
1358template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1359auto
1360__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001361 -> decltype((void)__a.allocate(__sz, __p), true_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362
1363template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1364auto
1365__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1366 -> false_type;
1367
1368template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1369struct __has_allocate_hint
1370 : integral_constant<bool,
1371 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001372 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373 declval<_SizeType>(),
1374 declval<_ConstVoidPtr>())),
1375 true_type>::value>
1376{
1377};
1378
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001379#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
1381template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1382struct __has_allocate_hint
1383 : true_type
1384{
1385};
1386
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001387#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001389#if !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390
1391template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001392decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1393 _VSTD::declval<_Args>()...),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394 true_type())
1395__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1396
1397template <class _Alloc, class _Pointer, class ..._Args>
1398false_type
1399__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1400
1401template <class _Alloc, class _Pointer, class ..._Args>
1402struct __has_construct
1403 : integral_constant<bool,
1404 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001405 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406 declval<_Pointer>(),
1407 declval<_Args>()...)),
1408 true_type>::value>
1409{
1410};
1411
1412template <class _Alloc, class _Pointer>
1413auto
1414__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1415 -> decltype(__a.destroy(__p), true_type());
1416
1417template <class _Alloc, class _Pointer>
1418auto
1419__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1420 -> false_type;
1421
1422template <class _Alloc, class _Pointer>
1423struct __has_destroy
1424 : integral_constant<bool,
1425 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001426 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427 declval<_Pointer>())),
1428 true_type>::value>
1429{
1430};
1431
1432template <class _Alloc>
1433auto
1434__has_max_size_test(_Alloc&& __a)
1435 -> decltype(__a.max_size(), true_type());
1436
1437template <class _Alloc>
1438auto
1439__has_max_size_test(const volatile _Alloc& __a)
1440 -> false_type;
1441
1442template <class _Alloc>
1443struct __has_max_size
1444 : integral_constant<bool,
1445 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001446 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 true_type>::value>
1448{
1449};
1450
1451template <class _Alloc>
1452auto
1453__has_select_on_container_copy_construction_test(_Alloc&& __a)
1454 -> decltype(__a.select_on_container_copy_construction(), true_type());
1455
1456template <class _Alloc>
1457auto
1458__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1459 -> false_type;
1460
1461template <class _Alloc>
1462struct __has_select_on_container_copy_construction
1463 : integral_constant<bool,
1464 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001465 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466 true_type>::value>
1467{
1468};
1469
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001470#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001472template <class _Alloc, class _Pointer, class _Tp, class = void>
1473struct __has_construct : std::false_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001475template <class _Alloc, class _Pointer, class _Tp>
1476struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
1477 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
1478>::type> : std::true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001480template <class _Alloc, class _Pointer, class = void>
1481struct __has_destroy : false_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482
1483template <class _Alloc, class _Pointer>
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001484struct __has_destroy<_Alloc, _Pointer, typename __void_t<
1485 decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
1486>::type> : std::true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487
1488template <class _Alloc>
1489struct __has_max_size
1490 : true_type
1491{
1492};
1493
1494template <class _Alloc>
1495struct __has_select_on_container_copy_construction
1496 : false_type
1497{
1498};
1499
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001500#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001502template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1503struct __alloc_traits_difference_type
1504{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001505 typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001506};
1507
1508template <class _Alloc, class _Ptr>
1509struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1510{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001511 typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type;
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001512};
1513
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001514template <class _Tp>
1515struct __is_default_allocator : false_type {};
1516
1517template <class _Tp>
1518struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
1519
Eric Fiselier909fe962019-09-13 16:09:33 +00001520
1521
1522template <class _Alloc,
1523 bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value
1524 >
1525struct __is_cpp17_move_insertable;
1526template <class _Alloc>
1527struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {};
1528template <class _Alloc>
1529struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {};
1530
1531template <class _Alloc,
1532 bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value
1533 >
1534struct __is_cpp17_copy_insertable;
1535template <class _Alloc>
1536struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {};
1537template <class _Alloc>
1538struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool,
1539 std::is_copy_constructible<typename _Alloc::value_type>::value &&
1540 __is_cpp17_move_insertable<_Alloc>::value>
1541 {};
1542
1543
1544
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545template <class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001546struct _LIBCPP_TEMPLATE_VIS allocator_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547{
1548 typedef _Alloc allocator_type;
1549 typedef typename allocator_type::value_type value_type;
1550
1551 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1552 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1553 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1554 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1555
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001556 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1557 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558
1559 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1560 propagate_on_container_copy_assignment;
1561 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1562 propagate_on_container_move_assignment;
1563 typedef typename __propagate_on_container_swap<allocator_type>::type
1564 propagate_on_container_swap;
Marshall Clow0b587562015-06-02 16:34:03 +00001565 typedef typename __is_always_equal<allocator_type>::type
1566 is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001568#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569 template <class _Tp> using rebind_alloc =
Howard Hinnantf09283d2011-05-11 20:21:19 +00001570 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Eric Fiselierea6fdf62019-06-23 20:47:21 +00001571 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >;
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001572#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 template <class _Tp> struct rebind_alloc
1574 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1575 template <class _Tp> struct rebind_traits
1576 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001577#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578
Marshall Clow0e58cae2017-11-26 02:55:38 +00001579 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 static pointer allocate(allocator_type& __a, size_type __n)
1581 {return __a.allocate(__n);}
Marshall Clow0e58cae2017-11-26 02:55:38 +00001582 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001584 {return __allocate(__a, __n, __hint,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1586
Howard Hinnant756c69b2010-09-22 16:48:34 +00001587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001588 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589 {__a.deallocate(__p, __n);}
1590
1591#ifndef _LIBCPP_HAS_NO_VARIADICS
1592 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001594 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow3996b8b2014-11-11 19:22:33 +00001595 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001596 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001597#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001599 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001600 static void construct(allocator_type&, _Tp* __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601 {
1602 ::new ((void*)__p) _Tp();
1603 }
1604 template <class _Tp, class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001605 _LIBCPP_INLINE_VISIBILITY
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001606 static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607 {
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001608 __construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
1609 __a, __p, __a0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610 }
1611 template <class _Tp, class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001612 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001613 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 const _A1& __a1)
1615 {
1616 ::new ((void*)__p) _Tp(__a0, __a1);
1617 }
1618 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001619 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001620 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621 const _A1& __a1, const _A2& __a2)
1622 {
1623 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1624 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001625#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001626
1627 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629 static void destroy(allocator_type& __a, _Tp* __p)
1630 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1631
Howard Hinnant756c69b2010-09-22 16:48:34 +00001632 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4f834b52013-08-27 20:22:15 +00001633 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1635
Howard Hinnant756c69b2010-09-22 16:48:34 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637 static allocator_type
1638 select_on_container_copy_construction(const allocator_type& __a)
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001639 {return __select_on_container_copy_construction(
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640 __has_select_on_container_copy_construction<const allocator_type>(),
1641 __a);}
1642
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001643 template <class _Ptr>
1644 _LIBCPP_INLINE_VISIBILITY
1645 static
1646 void
Eric Fiselier909fe962019-09-13 16:09:33 +00001647 __construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001648 {
Eric Fiselier909fe962019-09-13 16:09:33 +00001649 static_assert(__is_cpp17_move_insertable<allocator_type>::value,
1650 "The specified type does not meet the requirements of Cpp17MoveInsertible");
Louis Dionne301a6772018-12-07 16:42:28 +00001651 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001652 construct(__a, _VSTD::__to_address(__begin2),
Eric Fiselier909fe962019-09-13 16:09:33 +00001653#ifdef _LIBCPP_NO_EXCEPTIONS
1654 _VSTD::move(*__begin1)
1655#else
1656 _VSTD::move_if_noexcept(*__begin1)
1657#endif
1658 );
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001659 }
1660
1661 template <class _Tp>
1662 _LIBCPP_INLINE_VISIBILITY
1663 static
1664 typename enable_if
1665 <
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001666 (__is_default_allocator<allocator_type>::value
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001667 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1668 is_trivially_move_constructible<_Tp>::value,
1669 void
1670 >::type
Eric Fiselier909fe962019-09-13 16:09:33 +00001671 __construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001672 {
1673 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001674 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001675 {
Marshall Clow4907e8f2015-05-31 03:13:31 +00001676 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001677 __begin2 += _Np;
1678 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001679 }
1680
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001681 template <class _Iter, class _Ptr>
1682 _LIBCPP_INLINE_VISIBILITY
1683 static
1684 void
1685 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1686 {
1687 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001688 construct(__a, _VSTD::__to_address(__begin2), *__begin1);
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001689 }
1690
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001691 template <class _SourceTp, class _DestTp,
1692 class _RawSourceTp = typename remove_const<_SourceTp>::type,
1693 class _RawDestTp = typename remove_const<_DestTp>::type>
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001694 _LIBCPP_INLINE_VISIBILITY
1695 static
1696 typename enable_if
1697 <
Louis Dionne358c6cb2020-02-11 17:11:00 +01001698 is_trivially_copy_constructible<_DestTp>::value &&
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001699 is_same<_RawSourceTp, _RawDestTp>::value &&
1700 (__is_default_allocator<allocator_type>::value ||
1701 !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001702 void
1703 >::type
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001704 __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001705 {
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001706 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001707 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001708 {
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001709 _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001710 __begin2 += _Np;
1711 }
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001712 }
1713
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001714 template <class _Ptr>
1715 _LIBCPP_INLINE_VISIBILITY
1716 static
1717 void
Eric Fiselier909fe962019-09-13 16:09:33 +00001718 __construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001719 {
Eric Fiselier909fe962019-09-13 16:09:33 +00001720 static_assert(__is_cpp17_move_insertable<allocator_type>::value,
1721 "The specified type does not meet the requirements of Cpp17MoveInsertable");
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001722 while (__end1 != __begin1)
Howard Hinnant5adee4c2013-01-11 20:36:59 +00001723 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001724 construct(__a, _VSTD::__to_address(__end2 - 1),
Eric Fiselier909fe962019-09-13 16:09:33 +00001725#ifdef _LIBCPP_NO_EXCEPTIONS
1726 _VSTD::move(*--__end1)
1727#else
1728 _VSTD::move_if_noexcept(*--__end1)
1729#endif
1730 );
1731 --__end2;
Howard Hinnant5adee4c2013-01-11 20:36:59 +00001732 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001733 }
1734
1735 template <class _Tp>
1736 _LIBCPP_INLINE_VISIBILITY
1737 static
1738 typename enable_if
1739 <
Volodymyr Sapsai5c163022019-01-08 00:03:16 +00001740 (__is_default_allocator<allocator_type>::value
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001741 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1742 is_trivially_move_constructible<_Tp>::value,
1743 void
1744 >::type
Eric Fiselier909fe962019-09-13 16:09:33 +00001745 __construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001746 {
1747 ptrdiff_t _Np = __end1 - __begin1;
1748 __end2 -= _Np;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001749 if (_Np > 0)
1750 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001751 }
1752
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753private:
1754
Howard Hinnant756c69b2010-09-22 16:48:34 +00001755 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001756 static pointer __allocate(allocator_type& __a, size_type __n,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757 const_void_pointer __hint, true_type)
1758 {return __a.allocate(__n, __hint);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001759 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001760 static pointer __allocate(allocator_type& __a, size_type __n,
Howard Hinnant28b24882011-12-01 20:21:04 +00001761 const_void_pointer, false_type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762 {return __a.allocate(__n);}
1763
1764#ifndef _LIBCPP_HAS_NO_VARIADICS
1765 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001768 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001771 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1772 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001773 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774 }
Volodymyr Sapsai2b1eb842018-12-19 20:08:43 +00001775#else // _LIBCPP_HAS_NO_VARIADICS
1776 template <class _Tp, class _A0>
1777 _LIBCPP_INLINE_VISIBILITY
1778 static void __construct(true_type, allocator_type& __a, _Tp* __p,
1779 const _A0& __a0)
1780 {__a.construct(__p, __a0);}
1781 template <class _Tp, class _A0>
1782 _LIBCPP_INLINE_VISIBILITY
1783 static void __construct(false_type, allocator_type&, _Tp* __p,
1784 const _A0& __a0)
1785 {
1786 ::new ((void*)__p) _Tp(__a0);
1787 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001788#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001789
1790 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1793 {__a.destroy(__p);}
1794 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001796 static void __destroy(false_type, allocator_type&, _Tp* __p)
1797 {
1798 __p->~_Tp();
1799 }
1800
Howard Hinnant756c69b2010-09-22 16:48:34 +00001801 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf817a352017-12-05 15:56:26 +00001802 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001803 {return __a.max_size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001804 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf817a352017-12-05 15:56:26 +00001805 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
Marshall Clow33daa162015-10-25 19:34:04 +00001806 {return numeric_limits<size_type>::max() / sizeof(value_type);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807
Howard Hinnant756c69b2010-09-22 16:48:34 +00001808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001809 static allocator_type
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001810 __select_on_container_copy_construction(true_type, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811 {return __a.select_on_container_copy_construction();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813 static allocator_type
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001814 __select_on_container_copy_construction(false_type, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001815 {return __a;}
1816};
1817
Marshall Clow940e01c2015-04-07 05:21:38 +00001818template <class _Traits, class _Tp>
1819struct __rebind_alloc_helper
1820{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001821#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001822 typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow940e01c2015-04-07 05:21:38 +00001823#else
1824 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1825#endif
1826};
1827
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828// allocator
1829
1830template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001831class _LIBCPP_TEMPLATE_VIS allocator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832{
1833public:
1834 typedef size_t size_type;
1835 typedef ptrdiff_t difference_type;
1836 typedef _Tp* pointer;
1837 typedef const _Tp* const_pointer;
1838 typedef _Tp& reference;
1839 typedef const _Tp& const_reference;
1840 typedef _Tp value_type;
1841
Howard Hinnant4931e092011-06-02 21:38:57 +00001842 typedef true_type propagate_on_container_move_assignment;
Marshall Clow0b587562015-06-02 16:34:03 +00001843 typedef true_type is_always_equal;
Howard Hinnant4931e092011-06-02 21:38:57 +00001844
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1846
Marshall Clowbc759762018-03-20 23:02:53 +00001847 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1848 allocator() _NOEXCEPT {}
1849
Louis Dionne481a2662018-09-23 18:35:00 +00001850 template <class _Up>
Marshall Clowbc759762018-03-20 23:02:53 +00001851 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1852 allocator(const allocator<_Up>&) _NOEXCEPT {}
1853
Howard Hinnant719bda32011-05-28 14:41:13 +00001854 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001855 {return _VSTD::addressof(__x);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001856 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001857 {return _VSTD::addressof(__x);}
Louis Dionne481a2662018-09-23 18:35:00 +00001858 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0e58cae2017-11-26 02:55:38 +00001859 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001860 {
1861 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001862 __throw_length_error("allocator<T>::allocate(size_t n)"
1863 " 'n' exceeds maximum supported size");
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001864 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
Marshall Clow813ffb32016-03-03 12:04:39 +00001865 }
Eric Fiselier2856ef82018-10-25 17:21:30 +00001866 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001867 {_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
Howard Hinnant719bda32011-05-28 14:41:13 +00001868 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1869 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001870#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001871 template <class _Up, class... _Args>
1872 _LIBCPP_INLINE_VISIBILITY
1873 void
1874 construct(_Up* __p, _Args&&... __args)
1875 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001876 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001878#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879 _LIBCPP_INLINE_VISIBILITY
1880 void
1881 construct(pointer __p)
1882 {
1883 ::new((void*)__p) _Tp();
1884 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001885# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001886
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 template <class _A0>
1888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001889 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001890 construct(pointer __p, _A0& __a0)
1891 {
1892 ::new((void*)__p) _Tp(__a0);
1893 }
1894 template <class _A0>
1895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001896 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897 construct(pointer __p, const _A0& __a0)
1898 {
1899 ::new((void*)__p) _Tp(__a0);
1900 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001901# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001902 template <class _A0, class _A1>
1903 _LIBCPP_INLINE_VISIBILITY
1904 void
1905 construct(pointer __p, _A0& __a0, _A1& __a1)
1906 {
1907 ::new((void*)__p) _Tp(__a0, __a1);
1908 }
1909 template <class _A0, class _A1>
1910 _LIBCPP_INLINE_VISIBILITY
1911 void
1912 construct(pointer __p, const _A0& __a0, _A1& __a1)
1913 {
1914 ::new((void*)__p) _Tp(__a0, __a1);
1915 }
1916 template <class _A0, class _A1>
1917 _LIBCPP_INLINE_VISIBILITY
1918 void
1919 construct(pointer __p, _A0& __a0, const _A1& __a1)
1920 {
1921 ::new((void*)__p) _Tp(__a0, __a1);
1922 }
1923 template <class _A0, class _A1>
1924 _LIBCPP_INLINE_VISIBILITY
1925 void
1926 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1927 {
1928 ::new((void*)__p) _Tp(__a0, __a1);
1929 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001930#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1932};
1933
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001934template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001935class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001936{
1937public:
1938 typedef size_t size_type;
1939 typedef ptrdiff_t difference_type;
1940 typedef const _Tp* pointer;
1941 typedef const _Tp* const_pointer;
1942 typedef const _Tp& reference;
1943 typedef const _Tp& const_reference;
Howard Hinnant9bc95e22013-06-07 01:56:37 +00001944 typedef const _Tp value_type;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001945
1946 typedef true_type propagate_on_container_move_assignment;
Marshall Clowac12fcc2015-07-01 21:23:40 +00001947 typedef true_type is_always_equal;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001948
1949 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1950
Marshall Clowbc759762018-03-20 23:02:53 +00001951 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1952 allocator() _NOEXCEPT {}
1953
1954 template <class _Up>
Louis Dionne481a2662018-09-23 18:35:00 +00001955 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowbc759762018-03-20 23:02:53 +00001956 allocator(const allocator<_Up>&) _NOEXCEPT {}
1957
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001958 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1959 {return _VSTD::addressof(__x);}
1960 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001961 {
1962 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001963 __throw_length_error("allocator<const T>::allocate(size_t n)"
1964 " 'n' exceeds maximum supported size");
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001965 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
Eric Fiselier2db2bd52016-05-07 03:12:24 +00001966 }
Eric Fiselier2856ef82018-10-25 17:21:30 +00001967 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001968 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001969 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1970 {return size_type(~0) / sizeof(_Tp);}
1971#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1972 template <class _Up, class... _Args>
1973 _LIBCPP_INLINE_VISIBILITY
1974 void
1975 construct(_Up* __p, _Args&&... __args)
1976 {
1977 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1978 }
1979#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1980 _LIBCPP_INLINE_VISIBILITY
1981 void
1982 construct(pointer __p)
1983 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001984 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001985 }
1986# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001987
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001988 template <class _A0>
1989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001990 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001991 construct(pointer __p, _A0& __a0)
1992 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001993 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001994 }
1995 template <class _A0>
1996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001997 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001998 construct(pointer __p, const _A0& __a0)
1999 {
Marshall Clow31350ab2017-06-14 16:54:43 +00002000 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002001 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002002# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
2003 template <class _A0, class _A1>
2004 _LIBCPP_INLINE_VISIBILITY
2005 void
2006 construct(pointer __p, _A0& __a0, _A1& __a1)
2007 {
Marshall Clow31350ab2017-06-14 16:54:43 +00002008 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002009 }
2010 template <class _A0, class _A1>
2011 _LIBCPP_INLINE_VISIBILITY
2012 void
2013 construct(pointer __p, const _A0& __a0, _A1& __a1)
2014 {
Marshall Clow31350ab2017-06-14 16:54:43 +00002015 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002016 }
2017 template <class _A0, class _A1>
2018 _LIBCPP_INLINE_VISIBILITY
2019 void
2020 construct(pointer __p, _A0& __a0, const _A1& __a1)
2021 {
Marshall Clow31350ab2017-06-14 16:54:43 +00002022 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002023 }
2024 template <class _A0, class _A1>
2025 _LIBCPP_INLINE_VISIBILITY
2026 void
2027 construct(pointer __p, const _A0& __a0, const _A1& __a1)
2028 {
Marshall Clow31350ab2017-06-14 16:54:43 +00002029 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002030 }
2031#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
2032 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
2033};
2034
Howard Hinnantc51e1022010-05-11 19:42:16 +00002035template <class _Tp, class _Up>
2036inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00002037bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002038
2039template <class _Tp, class _Up>
2040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00002041bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002042
2043template <class _OutputIterator, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002044class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045 : public iterator<output_iterator_tag,
2046 _Tp, // purposefully not C++03
2047 ptrdiff_t, // purposefully not C++03
2048 _Tp*, // purposefully not C++03
2049 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
2050{
2051private:
2052 _OutputIterator __x_;
2053public:
2054 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
2055 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
2056 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
Marshall Clowbdfdea82018-08-28 13:29:30 +00002057 {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
Marshall Clow5c3f09e2015-10-25 18:58:07 +00002058#if _LIBCPP_STD_VER >= 14
2059 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
Marshall Clowbdfdea82018-08-28 13:29:30 +00002060 {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
Marshall Clow5c3f09e2015-10-25 18:58:07 +00002061#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
2063 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
2064 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowb949f1b2015-05-10 13:14:08 +00002065#if _LIBCPP_STD_VER >= 14
Aditya Kumar7c5db692017-08-20 10:38:55 +00002066 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
Marshall Clowb949f1b2015-05-10 13:14:08 +00002067#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002068};
2069
2070template <class _Tp>
Roman Lebedevb5959fa2018-09-22 17:54:48 +00002071_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002072pair<_Tp*, ptrdiff_t>
Howard Hinnant719bda32011-05-28 14:41:13 +00002073get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002074{
2075 pair<_Tp*, ptrdiff_t> __r(0, 0);
2076 const ptrdiff_t __m = (~ptrdiff_t(0) ^
2077 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2078 / sizeof(_Tp);
2079 if (__n > __m)
2080 __n = __m;
2081 while (__n > 0)
2082 {
Eric Fiselier6a07b342018-10-26 17:12:32 +00002083#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002084 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
Richard Smith0657be12018-02-01 22:24:45 +00002085 {
2086 std::align_val_t __al =
2087 std::align_val_t(std::alignment_of<_Tp>::value);
2088 __r.first = static_cast<_Tp*>(::operator new(
2089 __n * sizeof(_Tp), __al, nothrow));
2090 } else {
2091 __r.first = static_cast<_Tp*>(::operator new(
2092 __n * sizeof(_Tp), nothrow));
2093 }
2094#else
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002095 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
Richard Smith0657be12018-02-01 22:24:45 +00002096 {
2097 // Since aligned operator new is unavailable, return an empty
2098 // buffer rather than one with invalid alignment.
2099 return __r;
2100 }
2101
Howard Hinnantc51e1022010-05-11 19:42:16 +00002102 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
Richard Smith0657be12018-02-01 22:24:45 +00002103#endif
2104
Howard Hinnantc51e1022010-05-11 19:42:16 +00002105 if (__r.first)
2106 {
2107 __r.second = __n;
2108 break;
2109 }
2110 __n /= 2;
2111 }
2112 return __r;
2113}
2114
2115template <class _Tp>
2116inline _LIBCPP_INLINE_VISIBILITY
Richard Smith0657be12018-02-01 22:24:45 +00002117void return_temporary_buffer(_Tp* __p) _NOEXCEPT
2118{
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002119 _VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
Richard Smith0657be12018-02-01 22:24:45 +00002120}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121
Marshall Clowb22274f2017-01-24 22:22:33 +00002122#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002123template <class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00002124struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125{
2126 _Tp* __ptr_;
2127};
2128
2129template<class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00002130class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00002131{
2132private:
2133 _Tp* __ptr_;
2134public:
2135 typedef _Tp element_type;
2136
2137 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2138 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2139 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2140 : __ptr_(__p.release()) {}
2141 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2142 {reset(__p.release()); return *this;}
2143 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2144 {reset(__p.release()); return *this;}
2145 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2146 {reset(__p.__ptr_); return *this;}
2147 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2148
2149 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2150 {return *__ptr_;}
2151 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2152 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2153 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2154 {
2155 _Tp* __t = __ptr_;
2156 __ptr_ = 0;
2157 return __t;
2158 }
2159 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2160 {
2161 if (__ptr_ != __p)
2162 delete __ptr_;
2163 __ptr_ = __p;
2164 }
2165
2166 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2167 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2168 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2169 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2170 {return auto_ptr<_Up>(release());}
2171};
2172
2173template <>
Louis Dionne481a2662018-09-23 18:35:00 +00002174class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175{
2176public:
2177 typedef void element_type;
2178};
Marshall Clowb22274f2017-01-24 22:22:33 +00002179#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180
Eric Fiselier15eae3b2019-12-16 17:00:10 -05002181// Tag used to default initialize one or both of the pair's elements.
2182struct __default_init_tag {};
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002183struct __value_init_tag {};
Eric Fiselier15eae3b2019-12-16 17:00:10 -05002184
Eric Fiselier9d355982017-04-12 23:45:53 +00002185template <class _Tp, int _Idx,
2186 bool _CanBeEmptyBase =
2187 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2188struct __compressed_pair_elem {
2189 typedef _Tp _ParamT;
2190 typedef _Tp& reference;
2191 typedef const _Tp& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002192
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002193 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Eric Fiselier15eae3b2019-12-16 17:00:10 -05002194 __compressed_pair_elem(__default_init_tag) {}
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002195 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2196 __compressed_pair_elem(__value_init_tag) : __value_() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002197
Eric Fiselier9d355982017-04-12 23:45:53 +00002198 template <class _Up, class = typename enable_if<
Eric Fiselier209ecde2017-04-17 22:32:02 +00002199 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2200 >::type>
Alex Lorenz76132112017-11-09 17:54:49 +00002201 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002202 _LIBCPP_CONSTEXPR explicit
Eric Fiselier9d355982017-04-12 23:45:53 +00002203 __compressed_pair_elem(_Up&& __u)
Eric Fiselierb41db9a2018-10-01 01:59:37 +00002204 : __value_(_VSTD::forward<_Up>(__u))
2205 {
2206 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002207
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002208
2209#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier9d355982017-04-12 23:45:53 +00002210 template <class... _Args, size_t... _Indexes>
2211 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2212 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2213 __tuple_indices<_Indexes...>)
2214 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
Eric Fiselier9d355982017-04-12 23:45:53 +00002215#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002217
Alex Lorenz76132112017-11-09 17:54:49 +00002218 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2219 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002220 const_reference __get() const _NOEXCEPT { return __value_; }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002221
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222private:
Eric Fiselier9d355982017-04-12 23:45:53 +00002223 _Tp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002224};
2225
Eric Fiselier9d355982017-04-12 23:45:53 +00002226template <class _Tp, int _Idx>
2227struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2228 typedef _Tp _ParamT;
2229 typedef _Tp& reference;
2230 typedef const _Tp& const_reference;
2231 typedef _Tp __value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002232
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002233 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __compressed_pair_elem() = default;
2234 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2235 __compressed_pair_elem(__default_init_tag) {}
2236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2237 __compressed_pair_elem(__value_init_tag) : __value_type() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002238
Eric Fiselier9d355982017-04-12 23:45:53 +00002239 template <class _Up, class = typename enable_if<
Eric Fiselier209ecde2017-04-17 22:32:02 +00002240 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2241 >::type>
Alex Lorenz76132112017-11-09 17:54:49 +00002242 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002243 _LIBCPP_CONSTEXPR explicit
Eric Fiselier9d355982017-04-12 23:45:53 +00002244 __compressed_pair_elem(_Up&& __u)
Eric Fiselierb41db9a2018-10-01 01:59:37 +00002245 : __value_type(_VSTD::forward<_Up>(__u))
2246 {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002247
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002248#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier9d355982017-04-12 23:45:53 +00002249 template <class... _Args, size_t... _Indexes>
2250 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2251 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2252 __tuple_indices<_Indexes...>)
2253 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
Eric Fiselier9d355982017-04-12 23:45:53 +00002254#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255
Alex Lorenz76132112017-11-09 17:54:49 +00002256 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2257 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002258 const_reference __get() const _NOEXCEPT { return *this; }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002259};
2260
Howard Hinnantc51e1022010-05-11 19:42:16 +00002261template <class _T1, class _T2>
Eric Fiselier9d355982017-04-12 23:45:53 +00002262class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2263 private __compressed_pair_elem<_T2, 1> {
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002264 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
2265 typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
Eric Fiselier9d355982017-04-12 23:45:53 +00002266
2267 // NOTE: This static assert should never fire because __compressed_pair
2268 // is *almost never* used in a scenario where it's possible for T1 == T2.
2269 // (The exception is std::function where it is possible that the function
2270 // object and the allocator have the same type).
Eric Fiselierc5adf472017-04-13 01:13:58 +00002271 static_assert((!is_same<_T1, _T2>::value),
Eric Fiselier9d355982017-04-12 23:45:53 +00002272 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2273 "The current implementation is NOT ABI-compatible with the previous "
2274 "implementation for this configuration");
2275
Howard Hinnantc51e1022010-05-11 19:42:16 +00002276public:
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002277 template <bool _Dummy = true,
Eric Fiselier209ecde2017-04-17 22:32:02 +00002278 class = typename enable_if<
2279 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2280 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2281 >::type
2282 >
Eric Fiselier9d355982017-04-12 23:45:53 +00002283 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002284 _LIBCPP_CONSTEXPR __compressed_pair() : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002285
Eric Fiselier9d355982017-04-12 23:45:53 +00002286 template <class _U1, class _U2>
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Eric Fiselier9d355982017-04-12 23:45:53 +00002288 __compressed_pair(_U1&& __t1, _U2&& __t2)
2289 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002290
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002291#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier9d355982017-04-12 23:45:53 +00002292 template <class... _Args1, class... _Args2>
2293 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2294 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2295 tuple<_Args2...> __second_args)
2296 : _Base1(__pc, _VSTD::move(__first_args),
2297 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2298 _Base2(__pc, _VSTD::move(__second_args),
2299 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
Eric Fiselier9d355982017-04-12 23:45:53 +00002300#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002301
Eric Fiselier9d355982017-04-12 23:45:53 +00002302 _LIBCPP_INLINE_VISIBILITY
2303 typename _Base1::reference first() _NOEXCEPT {
2304 return static_cast<_Base1&>(*this).__get();
2305 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002306
Eric Fiselier9d355982017-04-12 23:45:53 +00002307 _LIBCPP_INLINE_VISIBILITY
2308 typename _Base1::const_reference first() const _NOEXCEPT {
2309 return static_cast<_Base1 const&>(*this).__get();
2310 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002311
Eric Fiselier9d355982017-04-12 23:45:53 +00002312 _LIBCPP_INLINE_VISIBILITY
2313 typename _Base2::reference second() _NOEXCEPT {
2314 return static_cast<_Base2&>(*this).__get();
2315 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002316
Eric Fiselier9d355982017-04-12 23:45:53 +00002317 _LIBCPP_INLINE_VISIBILITY
2318 typename _Base2::const_reference second() const _NOEXCEPT {
2319 return static_cast<_Base2 const&>(*this).__get();
2320 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002321
Eric Fiselier9d355982017-04-12 23:45:53 +00002322 _LIBCPP_INLINE_VISIBILITY
2323 void swap(__compressed_pair& __x)
2324 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2325 __is_nothrow_swappable<_T2>::value)
2326 {
2327 using std::swap;
2328 swap(first(), __x.first());
2329 swap(second(), __x.second());
2330 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002331};
2332
2333template <class _T1, class _T2>
2334inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002335void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2336 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2337 __is_nothrow_swappable<_T2>::value) {
2338 __x.swap(__y);
2339}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002341// default_delete
2342
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343template <class _Tp>
Eric Fiselier6779b062017-04-16 02:06:25 +00002344struct _LIBCPP_TEMPLATE_VIS default_delete {
Erik Pilkington2a398762017-05-25 15:43:31 +00002345 static_assert(!is_function<_Tp>::value,
2346 "default_delete cannot be instantiated for function types");
Eric Fiselier6779b062017-04-16 02:06:25 +00002347#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002348 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002349#else
Eric Fiselier6779b062017-04-16 02:06:25 +00002350 _LIBCPP_INLINE_VISIBILITY default_delete() {}
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002351#endif
Eric Fiselier6779b062017-04-16 02:06:25 +00002352 template <class _Up>
2353 _LIBCPP_INLINE_VISIBILITY
2354 default_delete(const default_delete<_Up>&,
2355 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2356 0) _NOEXCEPT {}
2357
2358 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2359 static_assert(sizeof(_Tp) > 0,
2360 "default_delete can not delete incomplete type");
2361 static_assert(!is_void<_Tp>::value,
2362 "default_delete can not delete incomplete type");
2363 delete __ptr;
2364 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002365};
2366
2367template <class _Tp>
Eric Fiselier6779b062017-04-16 02:06:25 +00002368struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2369private:
2370 template <class _Up>
2371 struct _EnableIfConvertible
2372 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2373
Howard Hinnant4500ca52011-12-18 21:19:44 +00002374public:
Eric Fiselier6779b062017-04-16 02:06:25 +00002375#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002376 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002377#else
Eric Fiselier6779b062017-04-16 02:06:25 +00002378 _LIBCPP_INLINE_VISIBILITY default_delete() {}
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002379#endif
Eric Fiselier6779b062017-04-16 02:06:25 +00002380
2381 template <class _Up>
2382 _LIBCPP_INLINE_VISIBILITY
2383 default_delete(const default_delete<_Up[]>&,
2384 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2385
2386 template <class _Up>
2387 _LIBCPP_INLINE_VISIBILITY
2388 typename _EnableIfConvertible<_Up>::type
2389 operator()(_Up* __ptr) const _NOEXCEPT {
2390 static_assert(sizeof(_Tp) > 0,
2391 "default_delete can not delete incomplete type");
2392 static_assert(!is_void<_Tp>::value,
2393 "default_delete can not delete void type");
2394 delete[] __ptr;
2395 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002396};
2397
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002398template <class _Deleter>
2399struct __unique_ptr_deleter_sfinae {
2400 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2401 typedef const _Deleter& __lval_ref_type;
2402 typedef _Deleter&& __good_rval_ref_type;
2403 typedef true_type __enable_rval_overload;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002404};
2405
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002406template <class _Deleter>
2407struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2408 typedef const _Deleter& __lval_ref_type;
2409 typedef const _Deleter&& __bad_rval_ref_type;
2410 typedef false_type __enable_rval_overload;
2411};
2412
2413template <class _Deleter>
2414struct __unique_ptr_deleter_sfinae<_Deleter&> {
2415 typedef _Deleter& __lval_ref_type;
2416 typedef _Deleter&& __bad_rval_ref_type;
2417 typedef false_type __enable_rval_overload;
2418};
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002419
2420template <class _Tp, class _Dp = default_delete<_Tp> >
2421class _LIBCPP_TEMPLATE_VIS unique_ptr {
2422public:
2423 typedef _Tp element_type;
2424 typedef _Dp deleter_type;
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002425 typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002426
2427 static_assert(!is_rvalue_reference<deleter_type>::value,
2428 "the specified deleter type cannot be an rvalue reference");
2429
2430private:
2431 __compressed_pair<pointer, deleter_type> __ptr_;
2432
2433 struct __nat { int __for_bool_; };
2434
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002435 typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002436
2437 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002438 using _LValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002439 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002440
2441 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002442 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002443 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002444
2445 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002446 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002447 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002448
2449 template <bool _Dummy, class _Deleter = typename __dependent_type<
2450 __identity<deleter_type>, _Dummy>::type>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002451 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002452 typename enable_if<is_default_constructible<_Deleter>::value &&
2453 !is_pointer<_Deleter>::value>::type;
2454
2455 template <class _ArgType>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002456 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002457 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2458
2459 template <class _UPtr, class _Up>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002460 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002461 is_convertible<typename _UPtr::pointer, pointer>::value &&
2462 !is_array<_Up>::value
2463 >::type;
2464
2465 template <class _UDel>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002466 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002467 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2468 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2469 >::type;
2470
2471 template <class _UDel>
2472 using _EnableIfDeleterAssignable = typename enable_if<
2473 is_assignable<_Dp&, _UDel&&>::value
2474 >::type;
2475
2476public:
2477 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002478 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002479 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002480 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002481
2482 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002483 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002484 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002485 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002486
2487 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002488 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002489 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002490 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __default_init_tag()) {}
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002491
2492 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002493 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002494 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002495 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002496 : __ptr_(__p, __d) {}
2497
2498 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002499 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002500 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002501 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002502 : __ptr_(__p, _VSTD::move(__d)) {
2503 static_assert(!is_reference<deleter_type>::value,
2504 "rvalue deleter bound to reference");
2505 }
2506
2507 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002508 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002509 _LIBCPP_INLINE_VISIBILITY
2510 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2511
2512 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002513 unique_ptr(unique_ptr&& __u) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002514 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2515 }
2516
2517 template <class _Up, class _Ep,
2518 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2519 class = _EnableIfDeleterConvertible<_Ep>
2520 >
2521 _LIBCPP_INLINE_VISIBILITY
2522 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2523 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2524
2525#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2526 template <class _Up>
2527 _LIBCPP_INLINE_VISIBILITY
2528 unique_ptr(auto_ptr<_Up>&& __p,
2529 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002530 is_same<_Dp, default_delete<_Tp> >::value,
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002531 __nat>::type = __nat()) _NOEXCEPT
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002532 : __ptr_(__p.release(), __default_init_tag()) {}
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002533#endif
2534
2535 _LIBCPP_INLINE_VISIBILITY
2536 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2537 reset(__u.release());
2538 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2539 return *this;
2540 }
2541
2542 template <class _Up, class _Ep,
2543 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2544 class = _EnableIfDeleterAssignable<_Ep>
2545 >
2546 _LIBCPP_INLINE_VISIBILITY
2547 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2548 reset(__u.release());
2549 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2550 return *this;
2551 }
2552
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002553#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2554 template <class _Up>
2555 _LIBCPP_INLINE_VISIBILITY
2556 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2557 is_same<_Dp, default_delete<_Tp> >::value,
2558 unique_ptr&>::type
2559 operator=(auto_ptr<_Up> __p) {
2560 reset(__p.release());
2561 return *this;
2562 }
2563#endif
2564
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002565#ifdef _LIBCPP_CXX03_LANG
2566 unique_ptr(unique_ptr const&) = delete;
2567 unique_ptr& operator=(unique_ptr const&) = delete;
2568#endif
2569
2570
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002571 _LIBCPP_INLINE_VISIBILITY
2572 ~unique_ptr() { reset(); }
2573
2574 _LIBCPP_INLINE_VISIBILITY
2575 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2576 reset();
2577 return *this;
2578 }
2579
2580 _LIBCPP_INLINE_VISIBILITY
2581 typename add_lvalue_reference<_Tp>::type
2582 operator*() const {
2583 return *__ptr_.first();
2584 }
2585 _LIBCPP_INLINE_VISIBILITY
2586 pointer operator->() const _NOEXCEPT {
2587 return __ptr_.first();
2588 }
2589 _LIBCPP_INLINE_VISIBILITY
2590 pointer get() const _NOEXCEPT {
2591 return __ptr_.first();
2592 }
2593 _LIBCPP_INLINE_VISIBILITY
2594 deleter_type& get_deleter() _NOEXCEPT {
2595 return __ptr_.second();
2596 }
2597 _LIBCPP_INLINE_VISIBILITY
2598 const deleter_type& get_deleter() const _NOEXCEPT {
2599 return __ptr_.second();
2600 }
2601 _LIBCPP_INLINE_VISIBILITY
2602 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2603 return __ptr_.first() != nullptr;
2604 }
2605
2606 _LIBCPP_INLINE_VISIBILITY
2607 pointer release() _NOEXCEPT {
2608 pointer __t = __ptr_.first();
2609 __ptr_.first() = pointer();
2610 return __t;
2611 }
2612
2613 _LIBCPP_INLINE_VISIBILITY
2614 void reset(pointer __p = pointer()) _NOEXCEPT {
2615 pointer __tmp = __ptr_.first();
2616 __ptr_.first() = __p;
2617 if (__tmp)
2618 __ptr_.second()(__tmp);
2619 }
2620
2621 _LIBCPP_INLINE_VISIBILITY
2622 void swap(unique_ptr& __u) _NOEXCEPT {
2623 __ptr_.swap(__u.__ptr_);
2624 }
2625};
2626
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002627
Howard Hinnantc51e1022010-05-11 19:42:16 +00002628template <class _Tp, class _Dp>
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002629class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002630public:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002631 typedef _Tp element_type;
2632 typedef _Dp deleter_type;
2633 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2634
Howard Hinnantc51e1022010-05-11 19:42:16 +00002635private:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002636 __compressed_pair<pointer, deleter_type> __ptr_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002637
Eric Fiselier31127cd2017-04-16 02:14:31 +00002638 template <class _From>
2639 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002640
Eric Fiselier31127cd2017-04-16 02:14:31 +00002641 template <class _FromElem>
2642 struct _CheckArrayPointerConversion<_FromElem*>
2643 : integral_constant<bool,
2644 is_same<_FromElem*, pointer>::value ||
2645 (is_same<pointer, element_type*>::value &&
2646 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2647 >
2648 {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002649
Eric Fiselier31127cd2017-04-16 02:14:31 +00002650 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002651
2652 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002653 using _LValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002654 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002655
2656 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002657 using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002658 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002659
2660 template <bool _Dummy>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002661 using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002662 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002663
2664 template <bool _Dummy, class _Deleter = typename __dependent_type<
2665 __identity<deleter_type>, _Dummy>::type>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002666 using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002667 typename enable_if<is_default_constructible<_Deleter>::value &&
2668 !is_pointer<_Deleter>::value>::type;
2669
2670 template <class _ArgType>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002671 using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002672 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2673
2674 template <class _Pp>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002675 using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselier31127cd2017-04-16 02:14:31 +00002676 _CheckArrayPointerConversion<_Pp>::value
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002677 >::type;
2678
2679 template <class _UPtr, class _Up,
2680 class _ElemT = typename _UPtr::element_type>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002681 using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002682 is_array<_Up>::value &&
2683 is_same<pointer, element_type*>::value &&
2684 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2685 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2686 >::type;
2687
2688 template <class _UDel>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002689 using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002690 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2691 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2692 >::type;
2693
2694 template <class _UDel>
Eric Fiselier4fc82a22019-06-12 02:03:31 +00002695 using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002696 is_assignable<_Dp&, _UDel&&>::value
2697 >::type;
2698
Howard Hinnantc51e1022010-05-11 19:42:16 +00002699public:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002700 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002701 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002702 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002703 _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002704
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002705 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002706 class = _EnableIfDeleterDefaultConstructible<_Dummy> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002707 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002708 _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer(), __default_init_tag()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002709
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002710 template <class _Pp, bool _Dummy = true,
2711 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002712 class = _EnableIfPointerConvertible<_Pp> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002713 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002714 explicit unique_ptr(_Pp __p) _NOEXCEPT
Eric Fiselier33ebfb62019-12-16 18:23:39 -05002715 : __ptr_(__p, __default_init_tag()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002716
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002717 template <class _Pp, bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002718 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
2719 class = _EnableIfPointerConvertible<_Pp> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002720 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002721 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002722 : __ptr_(__p, __d) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002723
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002724 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002725 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002726 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002727 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002728 : __ptr_(nullptr, __d) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002730 template <class _Pp, bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002731 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
2732 class = _EnableIfPointerConvertible<_Pp> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002733 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002734 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002735 : __ptr_(__p, _VSTD::move(__d)) {
2736 static_assert(!is_reference<deleter_type>::value,
2737 "rvalue deleter bound to reference");
2738 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002739
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002740 template <bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002741 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002742 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002743 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002744 : __ptr_(nullptr, _VSTD::move(__d)) {
2745 static_assert(!is_reference<deleter_type>::value,
2746 "rvalue deleter bound to reference");
2747 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002748
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002749 template <class _Pp, bool _Dummy = true,
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002750 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
2751 class = _EnableIfPointerConvertible<_Pp> >
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002752 _LIBCPP_INLINE_VISIBILITY
2753 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
Howard Hinnant4500ca52011-12-18 21:19:44 +00002754
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002755 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002756 unique_ptr(unique_ptr&& __u) _NOEXCEPT
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002757 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2758 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002759
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002760 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002761 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002762 reset(__u.release());
2763 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2764 return *this;
2765 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002767 template <class _Up, class _Ep,
2768 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2769 class = _EnableIfDeleterConvertible<_Ep>
2770 >
2771 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002772 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Eric Fiselier3827e6a2017-04-17 20:20:27 +00002773 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002774 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002775
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002776 template <class _Up, class _Ep,
2777 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2778 class = _EnableIfDeleterAssignable<_Ep>
2779 >
2780 _LIBCPP_INLINE_VISIBILITY
2781 unique_ptr&
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002782 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002783 reset(__u.release());
2784 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2785 return *this;
2786 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002787
Eric Fiselierea6fdf62019-06-23 20:47:21 +00002788#ifdef _LIBCPP_CXX03_LANG
2789 unique_ptr(unique_ptr const&) = delete;
2790 unique_ptr& operator=(unique_ptr const&) = delete;
2791#endif
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002792
2793public:
2794 _LIBCPP_INLINE_VISIBILITY
2795 ~unique_ptr() { reset(); }
2796
2797 _LIBCPP_INLINE_VISIBILITY
2798 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2799 reset();
2800 return *this;
2801 }
2802
2803 _LIBCPP_INLINE_VISIBILITY
2804 typename add_lvalue_reference<_Tp>::type
2805 operator[](size_t __i) const {
2806 return __ptr_.first()[__i];
2807 }
2808 _LIBCPP_INLINE_VISIBILITY
2809 pointer get() const _NOEXCEPT {
2810 return __ptr_.first();
2811 }
2812
2813 _LIBCPP_INLINE_VISIBILITY
2814 deleter_type& get_deleter() _NOEXCEPT {
2815 return __ptr_.second();
2816 }
2817
2818 _LIBCPP_INLINE_VISIBILITY
2819 const deleter_type& get_deleter() const _NOEXCEPT {
2820 return __ptr_.second();
2821 }
2822 _LIBCPP_INLINE_VISIBILITY
2823 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2824 return __ptr_.first() != nullptr;
2825 }
2826
2827 _LIBCPP_INLINE_VISIBILITY
2828 pointer release() _NOEXCEPT {
2829 pointer __t = __ptr_.first();
2830 __ptr_.first() = pointer();
2831 return __t;
2832 }
2833
2834 template <class _Pp>
2835 _LIBCPP_INLINE_VISIBILITY
2836 typename enable_if<
Eric Fiselier31127cd2017-04-16 02:14:31 +00002837 _CheckArrayPointerConversion<_Pp>::value
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002838 >::type
2839 reset(_Pp __p) _NOEXCEPT {
2840 pointer __tmp = __ptr_.first();
2841 __ptr_.first() = __p;
2842 if (__tmp)
2843 __ptr_.second()(__tmp);
2844 }
2845
2846 _LIBCPP_INLINE_VISIBILITY
2847 void reset(nullptr_t = nullptr) _NOEXCEPT {
2848 pointer __tmp = __ptr_.first();
2849 __ptr_.first() = nullptr;
2850 if (__tmp)
2851 __ptr_.second()(__tmp);
2852 }
2853
2854 _LIBCPP_INLINE_VISIBILITY
2855 void swap(unique_ptr& __u) _NOEXCEPT {
2856 __ptr_.swap(__u.__ptr_);
2857 }
2858
Howard Hinnantc51e1022010-05-11 19:42:16 +00002859};
2860
2861template <class _Tp, class _Dp>
2862inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +00002863typename enable_if<
2864 __is_swappable<_Dp>::value,
2865 void
2866>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00002867swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002868
2869template <class _T1, class _D1, class _T2, class _D2>
2870inline _LIBCPP_INLINE_VISIBILITY
2871bool
2872operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2873
2874template <class _T1, class _D1, class _T2, class _D2>
2875inline _LIBCPP_INLINE_VISIBILITY
2876bool
2877operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2878
2879template <class _T1, class _D1, class _T2, class _D2>
2880inline _LIBCPP_INLINE_VISIBILITY
2881bool
Howard Hinnantb17caf92012-02-21 21:02:58 +00002882operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2883{
2884 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2885 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselierf8898c82015-02-05 23:01:40 +00002886 typedef typename common_type<_P1, _P2>::type _Vp;
2887 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00002888}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002889
2890template <class _T1, class _D1, class _T2, class _D2>
2891inline _LIBCPP_INLINE_VISIBILITY
2892bool
2893operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2894
2895template <class _T1, class _D1, class _T2, class _D2>
2896inline _LIBCPP_INLINE_VISIBILITY
2897bool
2898operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2899
2900template <class _T1, class _D1, class _T2, class _D2>
2901inline _LIBCPP_INLINE_VISIBILITY
2902bool
2903operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2904
Howard Hinnantb17caf92012-02-21 21:02:58 +00002905template <class _T1, class _D1>
2906inline _LIBCPP_INLINE_VISIBILITY
2907bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002908operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002909{
2910 return !__x;
2911}
2912
2913template <class _T1, class _D1>
2914inline _LIBCPP_INLINE_VISIBILITY
2915bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002916operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002917{
2918 return !__x;
2919}
2920
2921template <class _T1, class _D1>
2922inline _LIBCPP_INLINE_VISIBILITY
2923bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002924operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002925{
2926 return static_cast<bool>(__x);
2927}
2928
2929template <class _T1, class _D1>
2930inline _LIBCPP_INLINE_VISIBILITY
2931bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002932operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00002933{
2934 return static_cast<bool>(__x);
2935}
2936
2937template <class _T1, class _D1>
2938inline _LIBCPP_INLINE_VISIBILITY
2939bool
2940operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2941{
2942 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2943 return less<_P1>()(__x.get(), nullptr);
2944}
2945
2946template <class _T1, class _D1>
2947inline _LIBCPP_INLINE_VISIBILITY
2948bool
2949operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2950{
2951 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2952 return less<_P1>()(nullptr, __x.get());
2953}
2954
2955template <class _T1, class _D1>
2956inline _LIBCPP_INLINE_VISIBILITY
2957bool
2958operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2959{
2960 return nullptr < __x;
2961}
2962
2963template <class _T1, class _D1>
2964inline _LIBCPP_INLINE_VISIBILITY
2965bool
2966operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2967{
2968 return __x < nullptr;
2969}
2970
2971template <class _T1, class _D1>
2972inline _LIBCPP_INLINE_VISIBILITY
2973bool
2974operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2975{
2976 return !(nullptr < __x);
2977}
2978
2979template <class _T1, class _D1>
2980inline _LIBCPP_INLINE_VISIBILITY
2981bool
2982operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2983{
2984 return !(__x < nullptr);
2985}
2986
2987template <class _T1, class _D1>
2988inline _LIBCPP_INLINE_VISIBILITY
2989bool
2990operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2991{
2992 return !(__x < nullptr);
2993}
2994
2995template <class _T1, class _D1>
2996inline _LIBCPP_INLINE_VISIBILITY
2997bool
2998operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2999{
3000 return !(nullptr < __x);
3001}
3002
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003003#if _LIBCPP_STD_VER > 11
3004
3005template<class _Tp>
3006struct __unique_if
3007{
3008 typedef unique_ptr<_Tp> __unique_single;
3009};
3010
3011template<class _Tp>
3012struct __unique_if<_Tp[]>
3013{
3014 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3015};
3016
3017template<class _Tp, size_t _Np>
3018struct __unique_if<_Tp[_Np]>
3019{
3020 typedef void __unique_array_known_bound;
3021};
3022
3023template<class _Tp, class... _Args>
Marshall Clow724e3df2013-07-02 20:06:09 +00003024inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003025typename __unique_if<_Tp>::__unique_single
3026make_unique(_Args&&... __args)
3027{
3028 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3029}
3030
3031template<class _Tp>
Marshall Clow724e3df2013-07-02 20:06:09 +00003032inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003033typename __unique_if<_Tp>::__unique_array_unknown_bound
3034make_unique(size_t __n)
3035{
3036 typedef typename remove_extent<_Tp>::type _Up;
3037 return unique_ptr<_Tp>(new _Up[__n]());
3038}
3039
3040template<class _Tp, class... _Args>
3041 typename __unique_if<_Tp>::__unique_array_known_bound
3042 make_unique(_Args&&...) = delete;
3043
3044#endif // _LIBCPP_STD_VER > 11
3045
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003046template <class _Tp, class _Dp>
Eric Fiselier698a97b2017-01-21 00:02:12 +00003047#ifdef _LIBCPP_CXX03_LANG
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003048struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
Eric Fiselier698a97b2017-01-21 00:02:12 +00003049#else
3050struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
Eric Fiselierea6fdf62019-06-23 20:47:21 +00003051 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
Eric Fiselier698a97b2017-01-21 00:02:12 +00003052#endif
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003053{
3054 typedef unique_ptr<_Tp, _Dp> argument_type;
3055 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003056 _LIBCPP_INLINE_VISIBILITY
Marshall Clow49036892017-03-23 02:40:28 +00003057 result_type operator()(const argument_type& __ptr) const
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003058 {
3059 typedef typename argument_type::pointer pointer;
3060 return hash<pointer>()(__ptr.get());
3061 }
3062};
3063
Howard Hinnantc51e1022010-05-11 19:42:16 +00003064struct __destruct_n
3065{
3066private:
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003067 size_t __size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003068
3069 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003070 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003071 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003072
3073 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003074 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003075 {}
3076
Howard Hinnant719bda32011-05-28 14:41:13 +00003077 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003078 {++__size_;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003079 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003080 {}
3081
Howard Hinnant719bda32011-05-28 14:41:13 +00003082 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003083 {__size_ = __s;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003084 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003085 {}
3086public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003087 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003088 : __size_(__s) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003089
3090 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003091 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003092 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003093
3094 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003095 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003096 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003097
3098 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003099 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003100 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003101};
3102
3103template <class _Alloc>
3104class __allocator_destructor
3105{
Eric Fiselier4fc82a22019-06-12 02:03:31 +00003106 typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003107public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00003108 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
3109 typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003110private:
3111 _Alloc& __alloc_;
3112 size_type __s_;
3113public:
3114 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant719bda32011-05-28 14:41:13 +00003115 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003116 : __alloc_(__a), __s_(__s) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003118 void operator()(pointer __p) _NOEXCEPT
3119 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003120};
3121
3122template <class _InputIterator, class _ForwardIterator>
3123_ForwardIterator
3124uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3125{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003126 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003127#ifndef _LIBCPP_NO_EXCEPTIONS
3128 _ForwardIterator __s = __r;
3129 try
3130 {
3131#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003132 for (; __f != __l; ++__f, (void) ++__r)
3133 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003134#ifndef _LIBCPP_NO_EXCEPTIONS
3135 }
3136 catch (...)
3137 {
3138 for (; __s != __r; ++__s)
3139 __s->~value_type();
3140 throw;
3141 }
3142#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003143 return __r;
3144}
3145
3146template <class _InputIterator, class _Size, class _ForwardIterator>
3147_ForwardIterator
3148uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3149{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003150 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003151#ifndef _LIBCPP_NO_EXCEPTIONS
3152 _ForwardIterator __s = __r;
3153 try
3154 {
3155#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003156 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3157 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003158#ifndef _LIBCPP_NO_EXCEPTIONS
3159 }
3160 catch (...)
3161 {
3162 for (; __s != __r; ++__s)
3163 __s->~value_type();
3164 throw;
3165 }
3166#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003167 return __r;
3168}
3169
3170template <class _ForwardIterator, class _Tp>
3171void
3172uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3173{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003175#ifndef _LIBCPP_NO_EXCEPTIONS
3176 _ForwardIterator __s = __f;
3177 try
3178 {
3179#endif
3180 for (; __f != __l; ++__f)
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003181 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003182#ifndef _LIBCPP_NO_EXCEPTIONS
3183 }
3184 catch (...)
3185 {
3186 for (; __s != __f; ++__s)
3187 __s->~value_type();
3188 throw;
3189 }
3190#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003191}
3192
3193template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant3c811092010-11-18 16:13:03 +00003194_ForwardIterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00003195uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3196{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003197 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003198#ifndef _LIBCPP_NO_EXCEPTIONS
3199 _ForwardIterator __s = __f;
3200 try
3201 {
3202#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003203 for (; __n > 0; ++__f, (void) --__n)
3204 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003205#ifndef _LIBCPP_NO_EXCEPTIONS
3206 }
3207 catch (...)
3208 {
3209 for (; __s != __f; ++__s)
3210 __s->~value_type();
3211 throw;
3212 }
3213#endif
Howard Hinnant3c811092010-11-18 16:13:03 +00003214 return __f;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003215}
3216
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003217#if _LIBCPP_STD_VER > 14
3218
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003219template <class _Tp>
3220inline _LIBCPP_INLINE_VISIBILITY
3221void destroy_at(_Tp* __loc) {
3222 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3223 __loc->~_Tp();
3224}
3225
3226template <class _ForwardIterator>
3227inline _LIBCPP_INLINE_VISIBILITY
3228void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3229 for (; __first != __last; ++__first)
3230 _VSTD::destroy_at(_VSTD::addressof(*__first));
3231}
3232
3233template <class _ForwardIterator, class _Size>
3234inline _LIBCPP_INLINE_VISIBILITY
3235_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3236 for (; __n > 0; (void)++__first, --__n)
3237 _VSTD::destroy_at(_VSTD::addressof(*__first));
3238 return __first;
3239}
3240
Eric Fiselier290c07c2016-10-11 21:13:44 +00003241template <class _ForwardIterator>
3242inline _LIBCPP_INLINE_VISIBILITY
3243void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3244 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3245 auto __idx = __first;
3246#ifndef _LIBCPP_NO_EXCEPTIONS
3247 try {
3248#endif
3249 for (; __idx != __last; ++__idx)
3250 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3251#ifndef _LIBCPP_NO_EXCEPTIONS
3252 } catch (...) {
3253 _VSTD::destroy(__first, __idx);
3254 throw;
3255 }
3256#endif
3257}
3258
3259template <class _ForwardIterator, class _Size>
3260inline _LIBCPP_INLINE_VISIBILITY
3261_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3262 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3263 auto __idx = __first;
3264#ifndef _LIBCPP_NO_EXCEPTIONS
3265 try {
3266#endif
3267 for (; __n > 0; (void)++__idx, --__n)
3268 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3269 return __idx;
3270#ifndef _LIBCPP_NO_EXCEPTIONS
3271 } catch (...) {
3272 _VSTD::destroy(__first, __idx);
3273 throw;
3274 }
3275#endif
3276}
3277
3278
3279template <class _ForwardIterator>
3280inline _LIBCPP_INLINE_VISIBILITY
3281void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3282 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3283 auto __idx = __first;
3284#ifndef _LIBCPP_NO_EXCEPTIONS
3285 try {
3286#endif
3287 for (; __idx != __last; ++__idx)
3288 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3289#ifndef _LIBCPP_NO_EXCEPTIONS
3290 } catch (...) {
3291 _VSTD::destroy(__first, __idx);
3292 throw;
3293 }
3294#endif
3295}
3296
3297template <class _ForwardIterator, class _Size>
3298inline _LIBCPP_INLINE_VISIBILITY
3299_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3300 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3301 auto __idx = __first;
3302#ifndef _LIBCPP_NO_EXCEPTIONS
3303 try {
3304#endif
3305 for (; __n > 0; (void)++__idx, --__n)
3306 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3307 return __idx;
3308#ifndef _LIBCPP_NO_EXCEPTIONS
3309 } catch (...) {
3310 _VSTD::destroy(__first, __idx);
3311 throw;
3312 }
3313#endif
3314}
3315
3316
3317template <class _InputIt, class _ForwardIt>
3318inline _LIBCPP_INLINE_VISIBILITY
3319_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3320 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3321 auto __idx = __first_res;
3322#ifndef _LIBCPP_NO_EXCEPTIONS
3323 try {
3324#endif
3325 for (; __first != __last; (void)++__idx, ++__first)
3326 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3327 return __idx;
3328#ifndef _LIBCPP_NO_EXCEPTIONS
3329 } catch (...) {
3330 _VSTD::destroy(__first_res, __idx);
3331 throw;
3332 }
3333#endif
3334}
3335
3336template <class _InputIt, class _Size, class _ForwardIt>
3337inline _LIBCPP_INLINE_VISIBILITY
3338pair<_InputIt, _ForwardIt>
3339uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3340 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3341 auto __idx = __first_res;
3342#ifndef _LIBCPP_NO_EXCEPTIONS
3343 try {
3344#endif
3345 for (; __n > 0; ++__idx, (void)++__first, --__n)
3346 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3347 return {__first, __idx};
3348#ifndef _LIBCPP_NO_EXCEPTIONS
3349 } catch (...) {
3350 _VSTD::destroy(__first_res, __idx);
3351 throw;
3352 }
3353#endif
3354}
3355
3356
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003357#endif // _LIBCPP_STD_VER > 14
3358
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003359// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3360// should be sufficient for thread safety.
Eric Fiselier5d604012017-02-17 08:37:03 +00003361// See https://bugs.llvm.org/show_bug.cgi?id=22803
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003362#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3363 && defined(__ATOMIC_RELAXED) \
3364 && defined(__ATOMIC_ACQ_REL)
3365# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
Richard Smithca47d0f2019-04-25 20:02:10 +00003366#elif defined(_LIBCPP_COMPILER_GCC)
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003367# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3368#endif
3369
3370template <class _Tp>
3371inline _LIBCPP_INLINE_VISIBILITY _Tp
3372__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3373{
3374#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3375 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3376#else
3377 return __t += 1;
3378#endif
3379}
3380
3381template <class _Tp>
3382inline _LIBCPP_INLINE_VISIBILITY _Tp
3383__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3384{
3385#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3386 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3387#else
3388 return __t -= 1;
3389#endif
3390}
3391
Howard Hinnant756c69b2010-09-22 16:48:34 +00003392class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003393 : public std::exception
3394{
3395public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003396 virtual ~bad_weak_ptr() _NOEXCEPT;
3397 virtual const char* what() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003398};
3399
Louis Dionne16fe2952018-07-11 23:14:33 +00003400_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00003401void __throw_bad_weak_ptr()
3402{
3403#ifndef _LIBCPP_NO_EXCEPTIONS
3404 throw bad_weak_ptr();
3405#else
3406 _VSTD::abort();
3407#endif
3408}
3409
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003410template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003411
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003412class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003413{
3414 __shared_count(const __shared_count&);
3415 __shared_count& operator=(const __shared_count&);
3416
3417protected:
3418 long __shared_owners_;
3419 virtual ~__shared_count();
3420private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003421 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003422
3423public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003425 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003426 : __shared_owners_(__refs) {}
3427
Louis Dionne5e0eadd2018-08-01 02:08:59 +00003428#if defined(_LIBCPP_BUILDING_LIBRARY) && \
Eric Fiselier98848572017-01-17 03:16:26 +00003429 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliere0700ff2017-01-17 03:05:31 +00003430 void __add_shared() _NOEXCEPT;
3431 bool __release_shared() _NOEXCEPT;
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003432#else
3433 _LIBCPP_INLINE_VISIBILITY
3434 void __add_shared() _NOEXCEPT {
3435 __libcpp_atomic_refcount_increment(__shared_owners_);
3436 }
3437 _LIBCPP_INLINE_VISIBILITY
3438 bool __release_shared() _NOEXCEPT {
3439 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3440 __on_zero_shared();
3441 return true;
3442 }
3443 return false;
3444 }
3445#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00003446 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier89659d12015-07-07 00:27:16 +00003447 long use_count() const _NOEXCEPT {
3448 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3449 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003450};
3451
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003452class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003453 : private __shared_count
3454{
3455 long __shared_weak_owners_;
3456
3457public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003459 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003460 : __shared_count(__refs),
3461 __shared_weak_owners_(__refs) {}
3462protected:
3463 virtual ~__shared_weak_count();
3464
3465public:
Louis Dionne5e0eadd2018-08-01 02:08:59 +00003466#if defined(_LIBCPP_BUILDING_LIBRARY) && \
Eric Fiselier98848572017-01-17 03:16:26 +00003467 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliere0700ff2017-01-17 03:05:31 +00003468 void __add_shared() _NOEXCEPT;
3469 void __add_weak() _NOEXCEPT;
3470 void __release_shared() _NOEXCEPT;
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003471#else
3472 _LIBCPP_INLINE_VISIBILITY
3473 void __add_shared() _NOEXCEPT {
3474 __shared_count::__add_shared();
3475 }
3476 _LIBCPP_INLINE_VISIBILITY
3477 void __add_weak() _NOEXCEPT {
3478 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3479 }
3480 _LIBCPP_INLINE_VISIBILITY
3481 void __release_shared() _NOEXCEPT {
3482 if (__shared_count::__release_shared())
3483 __release_weak();
3484 }
3485#endif
Howard Hinnant719bda32011-05-28 14:41:13 +00003486 void __release_weak() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003488 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3489 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003490
Howard Hinnant807d6332013-02-25 15:50:36 +00003491 // Define the function out only if we build static libc++ without RTTI.
3492 // Otherwise we may break clients who need to compile their projects with
3493 // -fno-rtti and yet link against a libc++.dylib compiled
3494 // without -fno-rtti.
3495#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant719bda32011-05-28 14:41:13 +00003496 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant807d6332013-02-25 15:50:36 +00003497#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003498private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003499 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003500};
3501
3502template <class _Tp, class _Dp, class _Alloc>
3503class __shared_ptr_pointer
3504 : public __shared_weak_count
3505{
3506 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3507public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003509 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003510 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003511
Howard Hinnant72f73582010-08-11 17:04:31 +00003512#ifndef _LIBCPP_NO_RTTI
Howard Hinnant719bda32011-05-28 14:41:13 +00003513 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant72f73582010-08-11 17:04:31 +00003514#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003515
3516private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003517 virtual void __on_zero_shared() _NOEXCEPT;
3518 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003519};
3520
Howard Hinnant72f73582010-08-11 17:04:31 +00003521#ifndef _LIBCPP_NO_RTTI
3522
Howard Hinnantc51e1022010-05-11 19:42:16 +00003523template <class _Tp, class _Dp, class _Alloc>
3524const void*
Howard Hinnant719bda32011-05-28 14:41:13 +00003525__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003526{
Eric Fiselierc7490d02017-05-04 01:06:56 +00003527 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003528}
3529
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003530#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00003531
Howard Hinnantc51e1022010-05-11 19:42:16 +00003532template <class _Tp, class _Dp, class _Alloc>
3533void
Howard Hinnant719bda32011-05-28 14:41:13 +00003534__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003535{
3536 __data_.first().second()(__data_.first().first());
3537 __data_.first().second().~_Dp();
3538}
3539
3540template <class _Tp, class _Dp, class _Alloc>
3541void
Howard Hinnant719bda32011-05-28 14:41:13 +00003542__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003543{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003544 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3545 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003546 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3547
Eric Fiselierf8898c82015-02-05 23:01:40 +00003548 _Al __a(__data_.second());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003549 __data_.second().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003550 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003551}
3552
3553template <class _Tp, class _Alloc>
3554class __shared_ptr_emplace
3555 : public __shared_weak_count
3556{
3557 __compressed_pair<_Alloc, _Tp> __data_;
3558public:
Howard Hinnantc51e1022010-05-11 19:42:16 +00003559
Howard Hinnant756c69b2010-09-22 16:48:34 +00003560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003561 __shared_ptr_emplace(_Alloc __a)
Eric Fiselier33ebfb62019-12-16 18:23:39 -05003562 : __data_(_VSTD::move(__a), __value_init_tag()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003563
Eric Fiselier33ebfb62019-12-16 18:23:39 -05003564
3565#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003566 template <class ..._Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003568 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant83b1c052011-12-19 17:58:44 +00003569 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3570 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003571#else // _LIBCPP_HAS_NO_VARIADICS
3572
Howard Hinnantc51e1022010-05-11 19:42:16 +00003573 template <class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003575 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3576 : __data_(__a, _Tp(__a0)) {}
3577
3578 template <class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003580 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3581 : __data_(__a, _Tp(__a0, __a1)) {}
3582
3583 template <class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003585 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3586 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3587
3588#endif // _LIBCPP_HAS_NO_VARIADICS
3589
3590private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003591 virtual void __on_zero_shared() _NOEXCEPT;
3592 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003593public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003594 _LIBCPP_INLINE_VISIBILITY
Marshall Clowbdfdea82018-08-28 13:29:30 +00003595 _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003596};
3597
3598template <class _Tp, class _Alloc>
3599void
Howard Hinnant719bda32011-05-28 14:41:13 +00003600__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003601{
3602 __data_.second().~_Tp();
3603}
3604
3605template <class _Tp, class _Alloc>
3606void
Howard Hinnant719bda32011-05-28 14:41:13 +00003607__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003608{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003609 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3610 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003611 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselierf8898c82015-02-05 23:01:40 +00003612 _Al __a(__data_.first());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003613 __data_.first().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003614 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003615}
3616
Erik Pilkington2a398762017-05-25 15:43:31 +00003617struct __shared_ptr_dummy_rebind_allocator_type;
3618template <>
3619class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3620{
3621public:
3622 template <class _Other>
3623 struct rebind
3624 {
3625 typedef allocator<_Other> other;
3626 };
3627};
3628
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003629template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003630
3631template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003632class _LIBCPP_TEMPLATE_VIS shared_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003633{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003634public:
3635 typedef _Tp element_type;
Marshall Clow7e384b72017-01-10 16:59:33 +00003636
Eric Fiselierae5b6672016-06-27 01:02:43 +00003637#if _LIBCPP_STD_VER > 14
3638 typedef weak_ptr<_Tp> weak_type;
3639#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640private:
3641 element_type* __ptr_;
3642 __shared_weak_count* __cntrl_;
3643
3644 struct __nat {int __for_bool_;};
3645public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003647 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003649 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiend435f8b2014-01-31 09:30:46 +00003650 template<class _Yp>
3651 explicit shared_ptr(_Yp* __p,
3652 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3653 template<class _Yp, class _Dp>
3654 shared_ptr(_Yp* __p, _Dp __d,
3655 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3656 template<class _Yp, class _Dp, class _Alloc>
3657 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3658 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003659 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3660 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003661 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003663 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003664 template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003666 shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003667 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00003668 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003669#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003671 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003672 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003673 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00003674 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003675#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003677 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
Marshall Clowb22274f2017-01-24 22:22:33 +00003678#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant74279a52010-09-04 23:28:19 +00003679#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003680 template<class _Yp>
3681 shared_ptr(auto_ptr<_Yp>&& __r,
3682 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003683#else
Logan Chiend435f8b2014-01-31 09:30:46 +00003684 template<class _Yp>
3685 shared_ptr(auto_ptr<_Yp> __r,
3686 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003687#endif
Marshall Clowb22274f2017-01-24 22:22:33 +00003688#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00003689#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003690 template <class _Yp, class _Dp>
3691 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3692 typename enable_if
3693 <
3694 !is_lvalue_reference<_Dp>::value &&
3695 !is_array<_Yp>::value &&
3696 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3697 __nat
3698 >::type = __nat());
3699 template <class _Yp, class _Dp>
3700 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3701 typename enable_if
3702 <
3703 is_lvalue_reference<_Dp>::value &&
3704 !is_array<_Yp>::value &&
3705 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3706 __nat
3707 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003708#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003709 template <class _Yp, class _Dp>
3710 shared_ptr(unique_ptr<_Yp, _Dp>,
3711 typename enable_if
3712 <
3713 !is_lvalue_reference<_Dp>::value &&
3714 !is_array<_Yp>::value &&
3715 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3716 __nat
3717 >::type = __nat());
3718 template <class _Yp, class _Dp>
3719 shared_ptr(unique_ptr<_Yp, _Dp>,
3720 typename enable_if
3721 <
3722 is_lvalue_reference<_Dp>::value &&
3723 !is_array<_Yp>::value &&
3724 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3725 __nat
3726 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003727#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003728
3729 ~shared_ptr();
3730
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003732 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003733 template<class _Yp>
3734 typename enable_if
3735 <
3736 is_convertible<_Yp*, element_type*>::value,
3737 shared_ptr&
3738 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003740 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003741#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003743 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003744 template<class _Yp>
3745 typename enable_if
3746 <
3747 is_convertible<_Yp*, element_type*>::value,
3748 shared_ptr<_Tp>&
3749 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003751 operator=(shared_ptr<_Yp>&& __r);
Marshall Clowb22274f2017-01-24 22:22:33 +00003752#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003753 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00003754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003755 typename enable_if
3756 <
3757 !is_array<_Yp>::value &&
3758 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00003759 shared_ptr
3760 >::type&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003761 operator=(auto_ptr<_Yp>&& __r);
Marshall Clowb22274f2017-01-24 22:22:33 +00003762#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00003763#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowb22274f2017-01-24 22:22:33 +00003764#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003765 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00003766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003767 typename enable_if
3768 <
3769 !is_array<_Yp>::value &&
3770 is_convertible<_Yp*, element_type*>::value,
3771 shared_ptr&
3772 >::type
3773 operator=(auto_ptr<_Yp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003774#endif
Marshall Clowb22274f2017-01-24 22:22:33 +00003775#endif
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003776 template <class _Yp, class _Dp>
3777 typename enable_if
3778 <
3779 !is_array<_Yp>::value &&
3780 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3781 shared_ptr&
3782 >::type
Howard Hinnant74279a52010-09-04 23:28:19 +00003783#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003785 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00003786#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov03192872015-12-09 22:32:36 +00003787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003788 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003789#endif
3790
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003792 void swap(shared_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003794 void reset() _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003795 template<class _Yp>
3796 typename enable_if
3797 <
3798 is_convertible<_Yp*, element_type*>::value,
3799 void
3800 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003802 reset(_Yp* __p);
3803 template<class _Yp, class _Dp>
3804 typename enable_if
3805 <
3806 is_convertible<_Yp*, element_type*>::value,
3807 void
3808 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003810 reset(_Yp* __p, _Dp __d);
3811 template<class _Yp, class _Dp, class _Alloc>
3812 typename enable_if
3813 <
3814 is_convertible<_Yp*, element_type*>::value,
3815 void
3816 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003818 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003819
Howard Hinnant756c69b2010-09-22 16:48:34 +00003820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003821 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003823 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3824 {return *__ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003826 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003828 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003829 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003830 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00003832 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003833 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003834 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00003835 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003836 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003837 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003838 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00003839 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003840 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant9fa30202012-07-30 01:40:57 +00003841 _LIBCPP_INLINE_VISIBILITY
3842 bool
3843 __owner_equivalent(const shared_ptr& __p) const
3844 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003845
Howard Hinnant72f73582010-08-11 17:04:31 +00003846#ifndef _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003847 template <class _Dp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003849 _Dp* __get_deleter() const _NOEXCEPT
Marshall Clow31350ab2017-06-14 16:54:43 +00003850 {return static_cast<_Dp*>(__cntrl_
Aditya Kumar7c5db692017-08-20 10:38:55 +00003851 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
Marshall Clow31350ab2017-06-14 16:54:43 +00003852 : nullptr);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003853#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003854
Zoe Carverd9040c72019-10-22 15:16:49 +00003855 template<class _Yp, class _CntrlBlk>
3856 static shared_ptr<_Tp>
3857 __create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
3858 {
3859 shared_ptr<_Tp> __r;
3860 __r.__ptr_ = __p;
3861 __r.__cntrl_ = __cntrl;
3862 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
3863 return __r;
3864 }
Zoe Carver6cd05c32019-08-19 15:47:16 +00003865
Howard Hinnantc51e1022010-05-11 19:42:16 +00003866private:
Erik Pilkington2a398762017-05-25 15:43:31 +00003867 template <class _Yp, bool = is_function<_Yp>::value>
3868 struct __shared_ptr_default_allocator
3869 {
3870 typedef allocator<_Yp> type;
3871 };
3872
3873 template <class _Yp>
3874 struct __shared_ptr_default_allocator<_Yp, true>
3875 {
3876 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3877 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00003878
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003879 template <class _Yp, class _OrigPtr>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003880 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier30d5ac62017-05-10 19:35:49 +00003881 typename enable_if<is_convertible<_OrigPtr*,
3882 const enable_shared_from_this<_Yp>*
3883 >::value,
3884 void>::type
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003885 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3886 _OrigPtr* __ptr) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003887 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003888 typedef typename remove_cv<_Yp>::type _RawYp;
Eric Fiselier84006862016-06-02 00:15:35 +00003889 if (__e && __e->__weak_this_.expired())
Marshall Clow99442fc2015-06-19 15:54:13 +00003890 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003891 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3892 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
Marshall Clow99442fc2015-06-19 15:54:13 +00003893 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003894 }
3895
Erik Pilkington2a398762017-05-25 15:43:31 +00003896 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003897
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003898 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3899 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003900};
3901
Eric Fiselier30d5ac62017-05-10 19:35:49 +00003902
Howard Hinnantc51e1022010-05-11 19:42:16 +00003903template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003904inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003905_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00003906shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003907 : __ptr_(0),
3908 __cntrl_(0)
3909{
3910}
3911
3912template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003913inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003914_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00003915shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003916 : __ptr_(0),
3917 __cntrl_(0)
3918{
3919}
3920
3921template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00003922template<class _Yp>
3923shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3924 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003925 : __ptr_(__p)
3926{
3927 unique_ptr<_Yp> __hold(__p);
Erik Pilkington2a398762017-05-25 15:43:31 +00003928 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3929 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
3930 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003931 __hold.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003932 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003933}
3934
3935template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00003936template<class _Yp, class _Dp>
3937shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
3938 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003939 : __ptr_(__p)
3940{
3941#ifndef _LIBCPP_NO_EXCEPTIONS
3942 try
3943 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003944#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkington2a398762017-05-25 15:43:31 +00003945 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3946 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
3947 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003948 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003949#ifndef _LIBCPP_NO_EXCEPTIONS
3950 }
3951 catch (...)
3952 {
3953 __d(__p);
3954 throw;
3955 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003956#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003957}
3958
3959template<class _Tp>
3960template<class _Dp>
3961shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
3962 : __ptr_(0)
3963{
3964#ifndef _LIBCPP_NO_EXCEPTIONS
3965 try
3966 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003967#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkington2a398762017-05-25 15:43:31 +00003968 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
3969 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
3970 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003971#ifndef _LIBCPP_NO_EXCEPTIONS
3972 }
3973 catch (...)
3974 {
3975 __d(__p);
3976 throw;
3977 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003978#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003979}
3980
3981template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00003982template<class _Yp, class _Dp, class _Alloc>
3983shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3984 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003985 : __ptr_(__p)
3986{
3987#ifndef _LIBCPP_NO_EXCEPTIONS
3988 try
3989 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003990#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00003991 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003992 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003993 typedef __allocator_destructor<_A2> _D2;
3994 _A2 __a2(__a);
3995 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003996 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
3997 _CntrlBlk(__p, __d, __a);
3998 __cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00003999 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004000#ifndef _LIBCPP_NO_EXCEPTIONS
4001 }
4002 catch (...)
4003 {
4004 __d(__p);
4005 throw;
4006 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004007#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004008}
4009
4010template<class _Tp>
4011template<class _Dp, class _Alloc>
4012shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4013 : __ptr_(0)
4014{
4015#ifndef _LIBCPP_NO_EXCEPTIONS
4016 try
4017 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004018#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004019 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004020 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004021 typedef __allocator_destructor<_A2> _D2;
4022 _A2 __a2(__a);
4023 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004024 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4025 _CntrlBlk(__p, __d, __a);
4026 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004027#ifndef _LIBCPP_NO_EXCEPTIONS
4028 }
4029 catch (...)
4030 {
4031 __d(__p);
4032 throw;
4033 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004034#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004035}
4036
4037template<class _Tp>
4038template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004039inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004040shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004041 : __ptr_(__p),
4042 __cntrl_(__r.__cntrl_)
4043{
4044 if (__cntrl_)
4045 __cntrl_->__add_shared();
4046}
4047
4048template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004049inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004050shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004051 : __ptr_(__r.__ptr_),
4052 __cntrl_(__r.__cntrl_)
4053{
4054 if (__cntrl_)
4055 __cntrl_->__add_shared();
4056}
4057
4058template<class _Tp>
4059template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004060inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004061shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00004062 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004063 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004064 : __ptr_(__r.__ptr_),
4065 __cntrl_(__r.__cntrl_)
4066{
4067 if (__cntrl_)
4068 __cntrl_->__add_shared();
4069}
4070
Howard Hinnant74279a52010-09-04 23:28:19 +00004071#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004072
4073template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004074inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004075shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004076 : __ptr_(__r.__ptr_),
4077 __cntrl_(__r.__cntrl_)
4078{
4079 __r.__ptr_ = 0;
4080 __r.__cntrl_ = 0;
4081}
4082
4083template<class _Tp>
4084template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004085inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004086shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00004087 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004088 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004089 : __ptr_(__r.__ptr_),
4090 __cntrl_(__r.__cntrl_)
4091{
4092 __r.__ptr_ = 0;
4093 __r.__cntrl_ = 0;
4094}
4095
Howard Hinnant74279a52010-09-04 23:28:19 +00004096#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004097
Marshall Clowb22274f2017-01-24 22:22:33 +00004098#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004099template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004100template<class _Yp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004101#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004102shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004103#else
Logan Chiend435f8b2014-01-31 09:30:46 +00004104shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004105#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004106 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004107 : __ptr_(__r.get())
4108{
4109 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4110 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004111 __enable_weak_this(__r.get(), __r.get());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004112 __r.release();
4113}
Marshall Clowb22274f2017-01-24 22:22:33 +00004114#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004115
4116template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004117template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004118#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004119shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4120#else
4121shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4122#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004123 typename enable_if
4124 <
4125 !is_lvalue_reference<_Dp>::value &&
4126 !is_array<_Yp>::value &&
4127 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4128 __nat
4129 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004130 : __ptr_(__r.get())
4131{
Marshall Clow35cde742015-05-10 13:59:45 +00004132#if _LIBCPP_STD_VER > 11
4133 if (__ptr_ == nullptr)
4134 __cntrl_ = nullptr;
4135 else
4136#endif
4137 {
Erik Pilkington2a398762017-05-25 15:43:31 +00004138 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4139 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4140 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004141 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004142 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004143 __r.release();
4144}
4145
4146template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004147template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004148#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004149shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4150#else
4151shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4152#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004153 typename enable_if
4154 <
4155 is_lvalue_reference<_Dp>::value &&
4156 !is_array<_Yp>::value &&
4157 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4158 __nat
4159 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004160 : __ptr_(__r.get())
4161{
Marshall Clow35cde742015-05-10 13:59:45 +00004162#if _LIBCPP_STD_VER > 11
4163 if (__ptr_ == nullptr)
4164 __cntrl_ = nullptr;
4165 else
4166#endif
4167 {
Erik Pilkington2a398762017-05-25 15:43:31 +00004168 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
Marshall Clow35cde742015-05-10 13:59:45 +00004169 typedef __shared_ptr_pointer<_Yp*,
4170 reference_wrapper<typename remove_reference<_Dp>::type>,
Erik Pilkington2a398762017-05-25 15:43:31 +00004171 _AllocT > _CntrlBlk;
Logan Smith85cb0812020-02-20 12:23:36 -05004172 __cntrl_ = new _CntrlBlk(__r.get(), _VSTD::ref(__r.get_deleter()), _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004173 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004174 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004175 __r.release();
4176}
4177
Zoe Carver6cd05c32019-08-19 15:47:16 +00004178template<class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004179shared_ptr<_Tp>::~shared_ptr()
4180{
4181 if (__cntrl_)
4182 __cntrl_->__release_shared();
4183}
4184
4185template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004186inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004187shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004188shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004189{
4190 shared_ptr(__r).swap(*this);
4191 return *this;
4192}
4193
4194template<class _Tp>
4195template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004196inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004197typename enable_if
4198<
Marshall Clow7e384b72017-01-10 16:59:33 +00004199 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004200 shared_ptr<_Tp>&
4201>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004202shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004203{
4204 shared_ptr(__r).swap(*this);
4205 return *this;
4206}
4207
Howard Hinnant74279a52010-09-04 23:28:19 +00004208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004209
4210template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004211inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004212shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004213shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004214{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004215 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004216 return *this;
4217}
4218
4219template<class _Tp>
4220template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004221inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004222typename enable_if
4223<
Marshall Clow7e384b72017-01-10 16:59:33 +00004224 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004225 shared_ptr<_Tp>&
4226>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004227shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4228{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004229 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004230 return *this;
4231}
4232
Marshall Clowb22274f2017-01-24 22:22:33 +00004233#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004234template<class _Tp>
4235template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004236inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004237typename enable_if
4238<
4239 !is_array<_Yp>::value &&
Marshall Clow7e384b72017-01-10 16:59:33 +00004240 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00004241 shared_ptr<_Tp>
4242>::type&
Howard Hinnantc51e1022010-05-11 19:42:16 +00004243shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4244{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004245 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004246 return *this;
4247}
Marshall Clowb22274f2017-01-24 22:22:33 +00004248#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249
4250template<class _Tp>
4251template <class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004252inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004253typename enable_if
4254<
4255 !is_array<_Yp>::value &&
Aditya Kumar7c5db692017-08-20 10:38:55 +00004256 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
Marshall Clow7e384b72017-01-10 16:59:33 +00004257 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004258 shared_ptr<_Tp>&
4259>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004260shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4261{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004262 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004263 return *this;
4264}
4265
Howard Hinnant74279a52010-09-04 23:28:19 +00004266#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004267
Marshall Clowb22274f2017-01-24 22:22:33 +00004268#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004269template<class _Tp>
4270template<class _Yp>
4271inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004272typename enable_if
4273<
4274 !is_array<_Yp>::value &&
Marshall Clowb89a86e2017-01-10 18:40:01 +00004275 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004276 shared_ptr<_Tp>&
4277>::type
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004278shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004279{
4280 shared_ptr(__r).swap(*this);
4281 return *this;
4282}
Marshall Clowb22274f2017-01-24 22:22:33 +00004283#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004284
4285template<class _Tp>
4286template <class _Yp, class _Dp>
4287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004288typename enable_if
4289<
4290 !is_array<_Yp>::value &&
Aditya Kumar7c5db692017-08-20 10:38:55 +00004291 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
Marshall Clowb89a86e2017-01-10 18:40:01 +00004292 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004293 shared_ptr<_Tp>&
4294>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004295shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4296{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004297 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004298 return *this;
4299}
4300
Howard Hinnant74279a52010-09-04 23:28:19 +00004301#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004302
4303template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004304inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004305void
Howard Hinnant719bda32011-05-28 14:41:13 +00004306shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004307{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004308 _VSTD::swap(__ptr_, __r.__ptr_);
4309 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004310}
4311
4312template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004313inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004314void
Howard Hinnant719bda32011-05-28 14:41:13 +00004315shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004316{
4317 shared_ptr().swap(*this);
4318}
4319
4320template<class _Tp>
4321template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004322inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004323typename enable_if
4324<
Marshall Clow7e384b72017-01-10 16:59:33 +00004325 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004326 void
4327>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004328shared_ptr<_Tp>::reset(_Yp* __p)
4329{
4330 shared_ptr(__p).swap(*this);
4331}
4332
4333template<class _Tp>
4334template<class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004335inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004336typename enable_if
4337<
Marshall Clow7e384b72017-01-10 16:59:33 +00004338 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004339 void
4340>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004341shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4342{
4343 shared_ptr(__p, __d).swap(*this);
4344}
4345
4346template<class _Tp>
4347template<class _Yp, class _Dp, class _Alloc>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004348inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004349typename enable_if
4350<
Marshall Clow7e384b72017-01-10 16:59:33 +00004351 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004352 void
4353>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004354shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4355{
4356 shared_ptr(__p, __d, __a).swap(*this);
4357}
4358
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004359template<class _Tp, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004361typename enable_if
4362<
4363 !is_array<_Tp>::value,
4364 shared_ptr<_Tp>
4365>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004366make_shared(_Args&& ...__args)
4367{
Zoe Carverd9040c72019-10-22 15:16:49 +00004368 static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
4369 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4370 typedef allocator<_CntrlBlk> _A2;
4371 typedef __allocator_destructor<_A2> _D2;
4372
4373 _A2 __a2;
4374 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4375 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4376
4377 _Tp *__ptr = __hold2.get()->get();
4378 return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004379}
4380
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004381template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004382inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004383typename enable_if
4384<
4385 !is_array<_Tp>::value,
4386 shared_ptr<_Tp>
4387>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004388allocate_shared(const _Alloc& __a, _Args&& ...__args)
4389{
zoecarver505730a2020-02-25 16:50:57 -08004390 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared");
4391
4392 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4393 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4394 typedef __allocator_destructor<_A2> _D2;
4395
4396 _A2 __a2(__a);
4397 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4398 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4399 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4400
4401 typename shared_ptr<_Tp>::element_type *__p = __hold2.get()->get();
4402 return shared_ptr<_Tp>::__create_with_control_block(__p, _VSTD::addressof(*__hold2.release()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004403}
4404
Howard Hinnantc51e1022010-05-11 19:42:16 +00004405template<class _Tp, class _Up>
4406inline _LIBCPP_INLINE_VISIBILITY
4407bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004408operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004409{
4410 return __x.get() == __y.get();
4411}
4412
4413template<class _Tp, class _Up>
4414inline _LIBCPP_INLINE_VISIBILITY
4415bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004416operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004417{
4418 return !(__x == __y);
4419}
4420
4421template<class _Tp, class _Up>
4422inline _LIBCPP_INLINE_VISIBILITY
4423bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004424operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004425{
Marshall Clow8afdf7a2018-02-12 17:26:40 +00004426#if _LIBCPP_STD_VER <= 11
Eric Fiselierf8898c82015-02-05 23:01:40 +00004427 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4428 return less<_Vp>()(__x.get(), __y.get());
Marshall Clow8afdf7a2018-02-12 17:26:40 +00004429#else
4430 return less<>()(__x.get(), __y.get());
4431#endif
4432
Howard Hinnantb17caf92012-02-21 21:02:58 +00004433}
4434
4435template<class _Tp, class _Up>
4436inline _LIBCPP_INLINE_VISIBILITY
4437bool
4438operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4439{
4440 return __y < __x;
4441}
4442
4443template<class _Tp, class _Up>
4444inline _LIBCPP_INLINE_VISIBILITY
4445bool
4446operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4447{
4448 return !(__y < __x);
4449}
4450
4451template<class _Tp, class _Up>
4452inline _LIBCPP_INLINE_VISIBILITY
4453bool
4454operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4455{
4456 return !(__x < __y);
4457}
4458
4459template<class _Tp>
4460inline _LIBCPP_INLINE_VISIBILITY
4461bool
4462operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4463{
4464 return !__x;
4465}
4466
4467template<class _Tp>
4468inline _LIBCPP_INLINE_VISIBILITY
4469bool
4470operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4471{
4472 return !__x;
4473}
4474
4475template<class _Tp>
4476inline _LIBCPP_INLINE_VISIBILITY
4477bool
4478operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4479{
4480 return static_cast<bool>(__x);
4481}
4482
4483template<class _Tp>
4484inline _LIBCPP_INLINE_VISIBILITY
4485bool
4486operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4487{
4488 return static_cast<bool>(__x);
4489}
4490
4491template<class _Tp>
4492inline _LIBCPP_INLINE_VISIBILITY
4493bool
4494operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4495{
4496 return less<_Tp*>()(__x.get(), nullptr);
4497}
4498
4499template<class _Tp>
4500inline _LIBCPP_INLINE_VISIBILITY
4501bool
4502operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4503{
4504 return less<_Tp*>()(nullptr, __x.get());
4505}
4506
4507template<class _Tp>
4508inline _LIBCPP_INLINE_VISIBILITY
4509bool
4510operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4511{
4512 return nullptr < __x;
4513}
4514
4515template<class _Tp>
4516inline _LIBCPP_INLINE_VISIBILITY
4517bool
4518operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4519{
4520 return __x < nullptr;
4521}
4522
4523template<class _Tp>
4524inline _LIBCPP_INLINE_VISIBILITY
4525bool
4526operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4527{
4528 return !(nullptr < __x);
4529}
4530
4531template<class _Tp>
4532inline _LIBCPP_INLINE_VISIBILITY
4533bool
4534operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4535{
4536 return !(__x < nullptr);
4537}
4538
4539template<class _Tp>
4540inline _LIBCPP_INLINE_VISIBILITY
4541bool
4542operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4543{
4544 return !(__x < nullptr);
4545}
4546
4547template<class _Tp>
4548inline _LIBCPP_INLINE_VISIBILITY
4549bool
4550operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4551{
4552 return !(nullptr < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004553}
4554
4555template<class _Tp>
4556inline _LIBCPP_INLINE_VISIBILITY
4557void
Howard Hinnant719bda32011-05-28 14:41:13 +00004558swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004559{
4560 __x.swap(__y);
4561}
4562
4563template<class _Tp, class _Up>
4564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004565typename enable_if
4566<
4567 !is_array<_Tp>::value && !is_array<_Up>::value,
4568 shared_ptr<_Tp>
4569>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004570static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004571{
4572 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4573}
4574
4575template<class _Tp, class _Up>
4576inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004577typename enable_if
4578<
4579 !is_array<_Tp>::value && !is_array<_Up>::value,
4580 shared_ptr<_Tp>
4581>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004582dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004583{
4584 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4585 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4586}
4587
4588template<class _Tp, class _Up>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004589typename enable_if
4590<
4591 is_array<_Tp>::value == is_array<_Up>::value,
4592 shared_ptr<_Tp>
4593>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004594const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004595{
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004596 typedef typename remove_extent<_Tp>::type _RTp;
4597 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004598}
4599
Howard Hinnant72f73582010-08-11 17:04:31 +00004600#ifndef _LIBCPP_NO_RTTI
4601
Howard Hinnantc51e1022010-05-11 19:42:16 +00004602template<class _Dp, class _Tp>
4603inline _LIBCPP_INLINE_VISIBILITY
4604_Dp*
Howard Hinnant719bda32011-05-28 14:41:13 +00004605get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004606{
4607 return __p.template __get_deleter<_Dp>();
4608}
4609
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004610#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00004611
Howard Hinnantc51e1022010-05-11 19:42:16 +00004612template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004613class _LIBCPP_TEMPLATE_VIS weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00004614{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004615public:
4616 typedef _Tp element_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004617private:
4618 element_type* __ptr_;
4619 __shared_weak_count* __cntrl_;
4620
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004621public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004623 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004624 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004625 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4626 _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004628 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004629 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00004630 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4631 _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004632
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004633#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004635 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004636 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004637 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4638 _NOEXCEPT;
4639#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004640 ~weak_ptr();
4641
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004643 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004644 template<class _Yp>
4645 typename enable_if
4646 <
4647 is_convertible<_Yp*, element_type*>::value,
4648 weak_ptr&
4649 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004651 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4652
4653#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4654
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004656 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4657 template<class _Yp>
4658 typename enable_if
4659 <
4660 is_convertible<_Yp*, element_type*>::value,
4661 weak_ptr&
4662 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004664 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4665
4666#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4667
4668 template<class _Yp>
4669 typename enable_if
4670 <
4671 is_convertible<_Yp*, element_type*>::value,
4672 weak_ptr&
4673 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004675 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004676
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004678 void swap(weak_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004680 void reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004681
Howard Hinnant756c69b2010-09-22 16:48:34 +00004682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004683 long use_count() const _NOEXCEPT
4684 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004686 bool expired() const _NOEXCEPT
4687 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4688 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00004689 template<class _Up>
4690 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004691 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004692 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004693 template<class _Up>
4694 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004695 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004696 {return __cntrl_ < __r.__cntrl_;}
4697
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004698 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4699 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004700};
4701
4702template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004703inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004704_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004705weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004706 : __ptr_(0),
4707 __cntrl_(0)
4708{
4709}
4710
4711template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004712inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004713weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004714 : __ptr_(__r.__ptr_),
4715 __cntrl_(__r.__cntrl_)
4716{
4717 if (__cntrl_)
4718 __cntrl_->__add_weak();
4719}
4720
4721template<class _Tp>
4722template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004723inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004724weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00004725 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004726 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004727 : __ptr_(__r.__ptr_),
4728 __cntrl_(__r.__cntrl_)
4729{
4730 if (__cntrl_)
4731 __cntrl_->__add_weak();
4732}
4733
4734template<class _Tp>
4735template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004736inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004737weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00004738 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004739 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004740 : __ptr_(__r.__ptr_),
4741 __cntrl_(__r.__cntrl_)
4742{
4743 if (__cntrl_)
4744 __cntrl_->__add_weak();
4745}
4746
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004747#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4748
4749template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004750inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004751weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
4752 : __ptr_(__r.__ptr_),
4753 __cntrl_(__r.__cntrl_)
4754{
4755 __r.__ptr_ = 0;
4756 __r.__cntrl_ = 0;
4757}
4758
4759template<class _Tp>
4760template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004761inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004762weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
4763 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4764 _NOEXCEPT
4765 : __ptr_(__r.__ptr_),
4766 __cntrl_(__r.__cntrl_)
4767{
4768 __r.__ptr_ = 0;
4769 __r.__cntrl_ = 0;
4770}
4771
4772#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4773
Howard Hinnantc51e1022010-05-11 19:42:16 +00004774template<class _Tp>
4775weak_ptr<_Tp>::~weak_ptr()
4776{
4777 if (__cntrl_)
4778 __cntrl_->__release_weak();
4779}
4780
4781template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004782inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004783weak_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004784weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004785{
4786 weak_ptr(__r).swap(*this);
4787 return *this;
4788}
4789
4790template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004791template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004792inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004793typename enable_if
4794<
4795 is_convertible<_Yp*, _Tp*>::value,
4796 weak_ptr<_Tp>&
4797>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004798weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004799{
4800 weak_ptr(__r).swap(*this);
4801 return *this;
4802}
4803
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004804#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4805
4806template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004807inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004808weak_ptr<_Tp>&
4809weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
4810{
4811 weak_ptr(_VSTD::move(__r)).swap(*this);
4812 return *this;
4813}
4814
Howard Hinnantc51e1022010-05-11 19:42:16 +00004815template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004816template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004817inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004818typename enable_if
4819<
4820 is_convertible<_Yp*, _Tp*>::value,
4821 weak_ptr<_Tp>&
4822>::type
4823weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
4824{
4825 weak_ptr(_VSTD::move(__r)).swap(*this);
4826 return *this;
4827}
4828
4829#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4830
4831template<class _Tp>
4832template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004833inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004834typename enable_if
4835<
4836 is_convertible<_Yp*, _Tp*>::value,
4837 weak_ptr<_Tp>&
4838>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004839weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004840{
4841 weak_ptr(__r).swap(*this);
4842 return *this;
4843}
4844
4845template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004846inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004847void
Howard Hinnant719bda32011-05-28 14:41:13 +00004848weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004849{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004850 _VSTD::swap(__ptr_, __r.__ptr_);
4851 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004852}
4853
4854template<class _Tp>
4855inline _LIBCPP_INLINE_VISIBILITY
4856void
Howard Hinnant719bda32011-05-28 14:41:13 +00004857swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004858{
4859 __x.swap(__y);
4860}
4861
4862template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004863inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004864void
Howard Hinnant719bda32011-05-28 14:41:13 +00004865weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004866{
4867 weak_ptr().swap(*this);
4868}
4869
4870template<class _Tp>
4871template<class _Yp>
4872shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00004873 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004874 : __ptr_(__r.__ptr_),
4875 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
4876{
4877 if (__cntrl_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00004878 __throw_bad_weak_ptr();
Howard Hinnantc51e1022010-05-11 19:42:16 +00004879}
4880
4881template<class _Tp>
4882shared_ptr<_Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00004883weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004884{
4885 shared_ptr<_Tp> __r;
4886 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
4887 if (__r.__cntrl_)
4888 __r.__ptr_ = __ptr_;
4889 return __r;
4890}
4891
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004892#if _LIBCPP_STD_VER > 14
4893template <class _Tp = void> struct owner_less;
4894#else
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004895template <class _Tp> struct owner_less;
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004896#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004897
4898template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004899struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00004900 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004901{
4902 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00004903 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004904 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004905 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004906 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004907 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004908 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004909 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004910 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004911 {return __x.owner_before(__y);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004912};
Howard Hinnantc51e1022010-05-11 19:42:16 +00004913
4914template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004915struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00004916 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
4917{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004918 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00004919 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004920 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004921 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004922 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004923 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004924 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004925 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004926 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004927 {return __x.owner_before(__y);}
4928};
4929
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004930#if _LIBCPP_STD_VER > 14
4931template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004932struct _LIBCPP_TEMPLATE_VIS owner_less<void>
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004933{
4934 template <class _Tp, class _Up>
4935 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004936 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004937 {return __x.owner_before(__y);}
4938 template <class _Tp, class _Up>
4939 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004940 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004941 {return __x.owner_before(__y);}
4942 template <class _Tp, class _Up>
4943 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004944 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004945 {return __x.owner_before(__y);}
4946 template <class _Tp, class _Up>
4947 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00004948 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00004949 {return __x.owner_before(__y);}
4950 typedef void is_transparent;
4951};
4952#endif
4953
Howard Hinnantc51e1022010-05-11 19:42:16 +00004954template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004955class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
Howard Hinnantc51e1022010-05-11 19:42:16 +00004956{
4957 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004958protected:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004959 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004960 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004962 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004964 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
4965 {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004967 ~enable_shared_from_this() {}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004968public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00004969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004970 shared_ptr<_Tp> shared_from_this()
4971 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00004972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004973 shared_ptr<_Tp const> shared_from_this() const
4974 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00004975
Eric Fiselier84006862016-06-02 00:15:35 +00004976#if _LIBCPP_STD_VER > 14
4977 _LIBCPP_INLINE_VISIBILITY
4978 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
4979 { return __weak_this_; }
4980
4981 _LIBCPP_INLINE_VISIBILITY
4982 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
4983 { return __weak_this_; }
4984#endif // _LIBCPP_STD_VER > 14
4985
Howard Hinnantc51e1022010-05-11 19:42:16 +00004986 template <class _Up> friend class shared_ptr;
4987};
4988
Howard Hinnant36b31ae2010-06-03 16:42:57 +00004989template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004990struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00004991{
4992 typedef shared_ptr<_Tp> argument_type;
4993 typedef size_t result_type;
Eric Fiselier698a97b2017-01-21 00:02:12 +00004994
Howard Hinnant756c69b2010-09-22 16:48:34 +00004995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00004996 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00004997 {
4998 return hash<_Tp*>()(__ptr.get());
4999 }
5000};
5001
Howard Hinnantc834c512011-11-29 18:15:50 +00005002template<class _CharT, class _Traits, class _Yp>
Howard Hinnantdc095972011-07-18 15:51:59 +00005003inline _LIBCPP_INLINE_VISIBILITY
5004basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00005005operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnantdc095972011-07-18 15:51:59 +00005006
Eric Fiselier9b492672016-06-18 02:12:53 +00005007
5008#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005009
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005010class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant9fa30202012-07-30 01:40:57 +00005011{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005012 void* __lx;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005013public:
5014 void lock() _NOEXCEPT;
5015 void unlock() _NOEXCEPT;
5016
5017private:
5018 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5019 __sp_mut(const __sp_mut&);
5020 __sp_mut& operator=(const __sp_mut&);
5021
Howard Hinnant8331b762013-03-06 23:30:19 +00005022 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005023};
5024
Mehdi Amini228053d2017-05-04 17:08:54 +00005025_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5026__sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005027
5028template <class _Tp>
5029inline _LIBCPP_INLINE_VISIBILITY
5030bool
5031atomic_is_lock_free(const shared_ptr<_Tp>*)
5032{
5033 return false;
5034}
5035
5036template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005037_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005038shared_ptr<_Tp>
5039atomic_load(const shared_ptr<_Tp>* __p)
5040{
5041 __sp_mut& __m = __get_sp_mut(__p);
5042 __m.lock();
5043 shared_ptr<_Tp> __q = *__p;
5044 __m.unlock();
5045 return __q;
5046}
Aditya Kumar7c5db692017-08-20 10:38:55 +00005047
Howard Hinnant9fa30202012-07-30 01:40:57 +00005048template <class _Tp>
5049inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005050_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005051shared_ptr<_Tp>
5052atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5053{
5054 return atomic_load(__p);
5055}
5056
5057template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005058_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005059void
5060atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5061{
5062 __sp_mut& __m = __get_sp_mut(__p);
5063 __m.lock();
5064 __p->swap(__r);
5065 __m.unlock();
5066}
5067
5068template <class _Tp>
5069inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005070_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005071void
5072atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5073{
5074 atomic_store(__p, __r);
5075}
5076
5077template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005078_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005079shared_ptr<_Tp>
5080atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5081{
5082 __sp_mut& __m = __get_sp_mut(__p);
5083 __m.lock();
5084 __p->swap(__r);
5085 __m.unlock();
5086 return __r;
5087}
Aditya Kumar7c5db692017-08-20 10:38:55 +00005088
Howard Hinnant9fa30202012-07-30 01:40:57 +00005089template <class _Tp>
5090inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005091_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005092shared_ptr<_Tp>
5093atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5094{
5095 return atomic_exchange(__p, __r);
5096}
5097
5098template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005099_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005100bool
5101atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5102{
Marshall Clow4201ee82016-05-18 17:50:13 +00005103 shared_ptr<_Tp> __temp;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005104 __sp_mut& __m = __get_sp_mut(__p);
5105 __m.lock();
5106 if (__p->__owner_equivalent(*__v))
5107 {
Marshall Clow4201ee82016-05-18 17:50:13 +00005108 _VSTD::swap(__temp, *__p);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005109 *__p = __w;
5110 __m.unlock();
5111 return true;
5112 }
Marshall Clow4201ee82016-05-18 17:50:13 +00005113 _VSTD::swap(__temp, *__v);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005114 *__v = *__p;
5115 __m.unlock();
5116 return false;
5117}
5118
5119template <class _Tp>
5120inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005121_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005122bool
5123atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5124{
5125 return atomic_compare_exchange_strong(__p, __v, __w);
5126}
5127
5128template <class _Tp>
5129inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005130_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005131bool
5132atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5133 shared_ptr<_Tp> __w, memory_order, memory_order)
5134{
5135 return atomic_compare_exchange_strong(__p, __v, __w);
5136}
5137
5138template <class _Tp>
5139inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005140_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005141bool
5142atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5143 shared_ptr<_Tp> __w, memory_order, memory_order)
5144{
5145 return atomic_compare_exchange_weak(__p, __v, __w);
5146}
5147
Eric Fiselier9b492672016-06-18 02:12:53 +00005148#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005149
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005150//enum class
Eric Fiselierab6bb302017-01-05 01:15:42 +00005151#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5152# ifndef _LIBCPP_CXX03_LANG
5153enum class pointer_safety : unsigned char {
5154 relaxed,
5155 preferred,
5156 strict
5157};
5158# endif
5159#else
Howard Hinnant8331b762013-03-06 23:30:19 +00005160struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantc51e1022010-05-11 19:42:16 +00005161{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005162 enum __lx
Howard Hinnantc51e1022010-05-11 19:42:16 +00005163 {
5164 relaxed,
5165 preferred,
5166 strict
5167 };
5168
Howard Hinnant49e145e2012-10-30 19:06:59 +00005169 __lx __v_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005170
Howard Hinnant756c69b2010-09-22 16:48:34 +00005171 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2fdd22b2017-01-05 01:28:40 +00005172 pointer_safety() : __v_() {}
5173
5174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e145e2012-10-30 19:06:59 +00005175 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005177 operator int() const {return __v_;}
5178};
Eric Fiselierab6bb302017-01-05 01:15:42 +00005179#endif
5180
5181#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
Louis Dionne5e0eadd2018-08-01 02:08:59 +00005182 defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierab6bb302017-01-05 01:15:42 +00005183_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5184#else
5185// This function is only offered in C++03 under ABI v1.
5186# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5187inline _LIBCPP_INLINE_VISIBILITY
5188pointer_safety get_pointer_safety() _NOEXCEPT {
5189 return pointer_safety::relaxed;
5190}
5191# endif
5192#endif
5193
Howard Hinnantc51e1022010-05-11 19:42:16 +00005194
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005195_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5196_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5197_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005198_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005199
5200template <class _Tp>
5201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005202_Tp*
Howard Hinnantc51e1022010-05-11 19:42:16 +00005203undeclare_reachable(_Tp* __p)
5204{
5205 return static_cast<_Tp*>(__undeclare_reachable(__p));
5206}
5207
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005208_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005209
Marshall Clow8982dcd2015-07-13 20:04:56 +00005210// --- Helper for container swap --
5211template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005212inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005213void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5214#if _LIBCPP_STD_VER >= 14
5215 _NOEXCEPT
5216#else
5217 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5218#endif
5219{
Aditya Kumar7c5db692017-08-20 10:38:55 +00005220 __swap_allocator(__a1, __a2,
Marshall Clow8982dcd2015-07-13 20:04:56 +00005221 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5222}
5223
5224template <typename _Alloc>
5225_LIBCPP_INLINE_VISIBILITY
5226void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5227#if _LIBCPP_STD_VER >= 14
5228 _NOEXCEPT
5229#else
5230 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5231#endif
5232{
5233 using _VSTD::swap;
5234 swap(__a1, __a2);
5235}
5236
5237template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005238inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005239void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5240
Marshall Clowff91de82015-08-18 19:51:37 +00005241template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
Aditya Kumar7c5db692017-08-20 10:38:55 +00005242struct __noexcept_move_assign_container : public integral_constant<bool,
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00005243 _Traits::propagate_on_container_move_assignment::value
5244#if _LIBCPP_STD_VER > 14
5245 || _Traits::is_always_equal::value
5246#else
5247 && is_nothrow_move_assignable<_Alloc>::value
5248#endif
5249 > {};
Marshall Clow8982dcd2015-07-13 20:04:56 +00005250
Marshall Clowa591b9a2016-07-11 21:38:08 +00005251
5252#ifndef _LIBCPP_HAS_NO_VARIADICS
5253template <class _Tp, class _Alloc>
5254struct __temp_value {
5255 typedef allocator_traits<_Alloc> _Traits;
Aditya Kumar7c5db692017-08-20 10:38:55 +00005256
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00005257 typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
Marshall Clowa591b9a2016-07-11 21:38:08 +00005258 _Alloc &__a;
5259
5260 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5261 _Tp & get() { return *__addr(); }
Aditya Kumar7c5db692017-08-20 10:38:55 +00005262
Marshall Clowa591b9a2016-07-11 21:38:08 +00005263 template<class... _Args>
Peter Collingbournecb126152018-08-15 17:49:30 +00005264 _LIBCPP_NO_CFI
5265 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
5266 _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
5267 _VSTD::forward<_Args>(__args)...);
5268 }
Aditya Kumar7c5db692017-08-20 10:38:55 +00005269
Marshall Clowa591b9a2016-07-11 21:38:08 +00005270 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5271 };
5272#endif
5273
Marshall Clowe46031a2018-07-02 18:41:15 +00005274template<typename _Alloc, typename = void, typename = void>
Marshall Clow82c90aa2018-01-11 19:36:22 +00005275struct __is_allocator : false_type {};
5276
5277template<typename _Alloc>
5278struct __is_allocator<_Alloc,
Marshall Clowe46031a2018-07-02 18:41:15 +00005279 typename __void_t<typename _Alloc::value_type>::type,
5280 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
5281 >
Marshall Clow82c90aa2018-01-11 19:36:22 +00005282 : true_type {};
Marshall Clow82c90aa2018-01-11 19:36:22 +00005283
Eric Fiselier74ebee62019-06-08 01:31:19 +00005284// __builtin_new_allocator -- A non-templated helper for allocating and
5285// deallocating memory using __builtin_operator_new and
5286// __builtin_operator_delete. It should be used in preference to
5287// `std::allocator<T>` to avoid additional instantiations.
5288struct __builtin_new_allocator {
5289 struct __builtin_new_deleter {
5290 typedef void* pointer_type;
5291
5292 _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
5293 : __size_(__size), __align_(__align) {}
5294
5295 void operator()(void* p) const _NOEXCEPT {
5296 std::__libcpp_deallocate(p, __size_, __align_);
5297 }
5298
5299 private:
5300 size_t __size_;
5301 size_t __align_;
5302 };
5303
5304 typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
5305
5306 static __holder_t __allocate_bytes(size_t __s, size_t __align) {
5307 return __holder_t(std::__libcpp_allocate(__s, __align),
5308 __builtin_new_deleter(__s, __align));
5309 }
5310
5311 static void __deallocate_bytes(void* __p, size_t __s,
5312 size_t __align) _NOEXCEPT {
5313 std::__libcpp_deallocate(__p, __s, __align);
5314 }
5315
5316 template <class _Tp>
5317 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5318 static __holder_t __allocate_type(size_t __n) {
5319 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5320 }
5321
5322 template <class _Tp>
5323 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
5324 static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
5325 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
5326 }
5327};
5328
5329
Howard Hinnantc51e1022010-05-11 19:42:16 +00005330_LIBCPP_END_NAMESPACE_STD
5331
Eric Fiselierf4433a32017-05-31 22:07:49 +00005332_LIBCPP_POP_MACROS
5333
Louis Dionne59d0b3c2019-08-05 18:29:14 +00005334#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
Louis Dionned53d8c02019-08-06 21:11:24 +00005335# include <__pstl_memory>
Louis Dionne59d0b3c2019-08-05 18:29:14 +00005336#endif
5337
Howard Hinnantc51e1022010-05-11 19:42:16 +00005338#endif // _LIBCPP_MEMORY