blob: ea52ba2cb6476a90cf525aa049d111723301856f [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MEMORY
12#define _LIBCPP_MEMORY
13
14/*
15 memory synopsis
16
17namespace std
18{
19
20struct allocator_arg_t { };
Marshall Clowf1bf62f2018-01-02 17:17:01 +000021inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
Howard Hinnantc51e1022010-05-11 19:42:16 +000022
23template <class T, class Alloc> struct uses_allocator;
24
25template <class Ptr>
26struct pointer_traits
27{
28 typedef Ptr pointer;
29 typedef <details> element_type;
30 typedef <details> difference_type;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000031
Howard Hinnantc51e1022010-05-11 19:42:16 +000032 template <class U> using rebind = <details>;
Howard Hinnant3b6579a2010-08-22 00:02:43 +000033
Howard Hinnantc51e1022010-05-11 19:42:16 +000034 static pointer pointer_to(<details>);
35};
36
Howard Hinnant719bda32011-05-28 14:41:13 +000037template <class T>
38struct pointer_traits<T*>
39{
40 typedef T* pointer;
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
43
44 template <class U> using rebind = U*;
45
46 static pointer pointer_to(<details>) noexcept;
47};
48
Eric Fiselier45c9aac2017-11-22 19:49:21 +000049template <class T> constexpr T* to_address(T* p) noexcept; // C++20
50template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
51
Howard Hinnantc51e1022010-05-11 19:42:16 +000052template <class Alloc>
53struct allocator_traits
54{
55 typedef Alloc allocator_type;
56 typedef typename allocator_type::value_type
57 value_type;
58
59 typedef Alloc::pointer | value_type* pointer;
60 typedef Alloc::const_pointer
61 | pointer_traits<pointer>::rebind<const value_type>
62 const_pointer;
63 typedef Alloc::void_pointer
64 | pointer_traits<pointer>::rebind<void>
65 void_pointer;
66 typedef Alloc::const_void_pointer
67 | pointer_traits<pointer>::rebind<const void>
68 const_void_pointer;
69 typedef Alloc::difference_type
Howard Hinnant8e4e6002010-11-18 01:40:00 +000070 | pointer_traits<pointer>::difference_type
71 difference_type;
72 typedef Alloc::size_type
73 | make_unsigned<difference_type>::type
74 size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 typedef Alloc::propagate_on_container_copy_assignment
76 | false_type propagate_on_container_copy_assignment;
77 typedef Alloc::propagate_on_container_move_assignment
78 | false_type propagate_on_container_move_assignment;
79 typedef Alloc::propagate_on_container_swap
80 | false_type propagate_on_container_swap;
Marshall Clow0b587562015-06-02 16:34:03 +000081 typedef Alloc::is_always_equal
82 | is_empty is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +000083
84 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
85 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
86
Marshall Clow0e58cae2017-11-26 02:55:38 +000087 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
88 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +000089
Howard Hinnant719bda32011-05-28 14:41:13 +000090 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000091
92 template <class T, class... Args>
93 static void construct(allocator_type& a, T* p, Args&&... args);
94
95 template <class T>
96 static void destroy(allocator_type& a, T* p);
97
Marshall Clow4f834b52013-08-27 20:22:15 +000098 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
100 static allocator_type
101 select_on_container_copy_construction(const allocator_type& a);
102};
103
104template <>
105class allocator<void>
106{
107public:
108 typedef void* pointer;
109 typedef const void* const_pointer;
110 typedef void value_type;
111
112 template <class _Up> struct rebind {typedef allocator<_Up> other;};
113};
114
115template <class T>
116class allocator
117{
118public:
119 typedef size_t size_type;
120 typedef ptrdiff_t difference_type;
121 typedef T* pointer;
122 typedef const T* const_pointer;
123 typedef typename add_lvalue_reference<T>::type reference;
124 typedef typename add_lvalue_reference<const T>::type const_reference;
125 typedef T value_type;
126
127 template <class U> struct rebind {typedef allocator<U> other;};
128
Marshall Clowbc759762018-03-20 23:02:53 +0000129 constexpr allocator() noexcept; // constexpr in C++20
130 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
131 template <class U>
132 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
Howard Hinnant719bda32011-05-28 14:41:13 +0000133 ~allocator();
134 pointer address(reference x) const noexcept;
135 const_pointer address(const_reference x) const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant719bda32011-05-28 14:41:13 +0000137 void deallocate(pointer p, size_type n) noexcept;
138 size_type max_size() const noexcept;
139 template<class U, class... Args>
140 void construct(U* p, Args&&... args);
141 template <class U>
142 void destroy(U* p);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143};
144
145template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000146bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
148template <class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000149bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150
151template <class OutputIterator, class T>
152class raw_storage_iterator
153 : public iterator<output_iterator_tag,
154 T, // purposefully not C++03
155 ptrdiff_t, // purposefully not C++03
156 T*, // purposefully not C++03
157 raw_storage_iterator&> // purposefully not C++03
158{
159public:
160 explicit raw_storage_iterator(OutputIterator x);
161 raw_storage_iterator& operator*();
162 raw_storage_iterator& operator=(const T& element);
163 raw_storage_iterator& operator++();
164 raw_storage_iterator operator++(int);
165};
166
Howard Hinnant719bda32011-05-28 14:41:13 +0000167template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
168template <class T> void return_temporary_buffer(T* p) noexcept;
169
170template <class T> T* addressof(T& r) noexcept;
Marshall Clow78dbe462016-11-14 18:22:19 +0000171template <class T> T* addressof(const T&& r) noexcept = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172
173template <class InputIterator, class ForwardIterator>
174ForwardIterator
175uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
176
Howard Hinnant719bda32011-05-28 14:41:13 +0000177template <class InputIterator, class Size, class ForwardIterator>
178ForwardIterator
179uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
180
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181template <class ForwardIterator, class T>
182void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
183
184template <class ForwardIterator, class Size, class T>
Howard Hinnant3c811092010-11-18 16:13:03 +0000185ForwardIterator
186uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187
Eric Fiselier383f6cf2016-07-24 03:51:39 +0000188template <class T>
189void destroy_at(T* location);
190
191template <class ForwardIterator>
192 void destroy(ForwardIterator first, ForwardIterator last);
193
194template <class ForwardIterator, class Size>
195 ForwardIterator destroy_n(ForwardIterator first, Size n);
196
197template <class InputIterator, class ForwardIterator>
198 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
199
200template <class InputIterator, class Size, class ForwardIterator>
201 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
202
203template <class ForwardIterator>
204 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
205
206template <class ForwardIterator, class Size>
207 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
208
209template <class ForwardIterator>
210 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
211
212template <class ForwardIterator, class Size>
213 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
214
Marshall Clowb22274f2017-01-24 22:22:33 +0000215template <class Y> struct auto_ptr_ref {}; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216
217template<class X>
Marshall Clowb22274f2017-01-24 22:22:33 +0000218class auto_ptr // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219{
220public:
221 typedef X element_type;
222
223 explicit auto_ptr(X* p =0) throw();
224 auto_ptr(auto_ptr&) throw();
225 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
226 auto_ptr& operator=(auto_ptr&) throw();
227 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
228 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
229 ~auto_ptr() throw();
230
231 typename add_lvalue_reference<X>::type operator*() const throw();
232 X* operator->() const throw();
233 X* get() const throw();
234 X* release() throw();
235 void reset(X* p =0) throw();
236
237 auto_ptr(auto_ptr_ref<X>) throw();
238 template<class Y> operator auto_ptr_ref<Y>() throw();
239 template<class Y> operator auto_ptr<Y>() throw();
240};
241
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000242template <class T>
243struct default_delete
244{
Howard Hinnant719bda32011-05-28 14:41:13 +0000245 constexpr default_delete() noexcept = default;
246 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000247
Howard Hinnant719bda32011-05-28 14:41:13 +0000248 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000249};
250
251template <class T>
252struct default_delete<T[]>
253{
Howard Hinnant719bda32011-05-28 14:41:13 +0000254 constexpr default_delete() noexcept = default;
255 void operator()(T*) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000256 template <class U> void operator()(U*) const = delete;
257};
258
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000259template <class T, class D = default_delete<T>>
260class unique_ptr
261{
262public:
263 typedef see below pointer;
264 typedef T element_type;
265 typedef D deleter_type;
266
267 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000268 constexpr unique_ptr() noexcept;
269 explicit unique_ptr(pointer p) noexcept;
270 unique_ptr(pointer p, see below d1) noexcept;
271 unique_ptr(pointer p, see below d2) noexcept;
272 unique_ptr(unique_ptr&& u) noexcept;
273 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000274 template <class U, class E>
Howard Hinnant719bda32011-05-28 14:41:13 +0000275 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000276 template <class U>
Marshall Clowb22274f2017-01-24 22:22:33 +0000277 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000278
279 // destructor
280 ~unique_ptr();
281
282 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000283 unique_ptr& operator=(unique_ptr&& u) noexcept;
284 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
285 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000286
287 // observers
288 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000289 pointer operator->() const noexcept;
290 pointer get() const noexcept;
291 deleter_type& get_deleter() noexcept;
292 const deleter_type& get_deleter() const noexcept;
293 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000294
295 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000296 pointer release() noexcept;
297 void reset(pointer p = pointer()) noexcept;
298 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000299};
300
301template <class T, class D>
302class unique_ptr<T[], D>
303{
304public:
305 typedef implementation-defined pointer;
306 typedef T element_type;
307 typedef D deleter_type;
308
309 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000310 constexpr unique_ptr() noexcept;
311 explicit unique_ptr(pointer p) noexcept;
312 unique_ptr(pointer p, see below d) noexcept;
313 unique_ptr(pointer p, see below d) noexcept;
314 unique_ptr(unique_ptr&& u) noexcept;
315 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000316
317 // destructor
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000318 ~unique_ptr();
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000319
320 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000321 unique_ptr& operator=(unique_ptr&& u) noexcept;
322 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000323
324 // observers
325 T& operator[](size_t i) const;
Howard Hinnant719bda32011-05-28 14:41:13 +0000326 pointer get() const noexcept;
327 deleter_type& get_deleter() noexcept;
328 const deleter_type& get_deleter() const noexcept;
329 explicit operator bool() const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000330
331 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000332 pointer release() noexcept;
333 void reset(pointer p = pointer()) noexcept;
334 void reset(nullptr_t) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000335 template <class U> void reset(U) = delete;
Howard Hinnant719bda32011-05-28 14:41:13 +0000336 void swap(unique_ptr& u) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000337};
338
339template <class T, class D>
Howard Hinnant719bda32011-05-28 14:41:13 +0000340 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000341
342template <class T1, class D1, class T2, class D2>
343 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
344template <class T1, class D1, class T2, class D2>
345 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
346template <class T1, class D1, class T2, class D2>
347 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
348template <class T1, class D1, class T2, class D2>
349 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
350template <class T1, class D1, class T2, class D2>
351 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
352template <class T1, class D1, class T2, class D2>
353 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
354
Howard Hinnant719bda32011-05-28 14:41:13 +0000355template <class T, class D>
356 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
357template <class T, class D>
358 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
359template <class T, class D>
360 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
361template <class T, class D>
362 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
363
364template <class T, class D>
365 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
366template <class T, class D>
367 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
368template <class T, class D>
369 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
370template <class T, class D>
371 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
372template <class T, class D>
373 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
374template <class T, class D>
375 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
376template <class T, class D>
377 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
378template <class T, class D>
379 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
380
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000381class bad_weak_ptr
382 : public std::exception
383{
Howard Hinnant719bda32011-05-28 14:41:13 +0000384 bad_weak_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000385};
386
Marshall Clow9e8f4a92013-07-01 18:16:03 +0000387template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
388template<class T> unique_ptr<T> make_unique(size_t n); // C++14
389template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
390
Marshall Clowe52a3242017-11-27 15:51:36 +0000391template<class E, class T, class Y, class D>
392 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
393
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000394template<class T>
395class shared_ptr
396{
397public:
398 typedef T element_type;
Eric Fiselierae5b6672016-06-27 01:02:43 +0000399 typedef weak_ptr<T> weak_type; // C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000400
401 // constructors:
Howard Hinnant719bda32011-05-28 14:41:13 +0000402 constexpr shared_ptr() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000403 template<class Y> explicit shared_ptr(Y* p);
404 template<class Y, class D> shared_ptr(Y* p, D d);
405 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
406 template <class D> shared_ptr(nullptr_t p, D d);
407 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant719bda32011-05-28 14:41:13 +0000408 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
409 shared_ptr(const shared_ptr& r) noexcept;
410 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
411 shared_ptr(shared_ptr&& r) noexcept;
412 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000413 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
Marshall Clowb22274f2017-01-24 22:22:33 +0000414 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000415 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
416 shared_ptr(nullptr_t) : shared_ptr() { }
417
418 // destructor:
419 ~shared_ptr();
420
421 // assignment:
Howard Hinnant719bda32011-05-28 14:41:13 +0000422 shared_ptr& operator=(const shared_ptr& r) noexcept;
423 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
424 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000425 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
Marshall Clowb22274f2017-01-24 22:22:33 +0000426 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000427 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
428
429 // modifiers:
Howard Hinnant719bda32011-05-28 14:41:13 +0000430 void swap(shared_ptr& r) noexcept;
431 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000432 template<class Y> void reset(Y* p);
433 template<class Y, class D> void reset(Y* p, D d);
434 template<class Y, class D, class A> void reset(Y* p, D d, A a);
435
Howard Hinnant719bda32011-05-28 14:41:13 +0000436 // observers:
437 T* get() const noexcept;
438 T& operator*() const noexcept;
439 T* operator->() const noexcept;
440 long use_count() const noexcept;
441 bool unique() const noexcept;
442 explicit operator bool() const noexcept;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000443 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
444 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000445};
446
447// shared_ptr comparisons:
448template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000449 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000450template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000451 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000452template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000453 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000454template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000455 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000456template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000457 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000458template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000459 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
460
461template <class T>
462 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
463template <class T>
464 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
465template <class T>
466 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
467template <class T>
468 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
469template <class T>
470 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
471template <class T>
472bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
473template <class T>
474 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
475template <class T>
476 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
477template <class T>
478 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
479template <class T>
480 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
481template <class T>
482 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
483template <class T>
484 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000485
486// shared_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000487template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000488
489// shared_ptr casts:
490template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000491 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000492template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000493 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000494template<class T, class U>
Howard Hinnant719bda32011-05-28 14:41:13 +0000495 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000496
497// shared_ptr I/O:
498template<class E, class T, class Y>
499 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
500
501// shared_ptr get_deleter:
Howard Hinnant719bda32011-05-28 14:41:13 +0000502template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000503
504template<class T, class... Args>
505 shared_ptr<T> make_shared(Args&&... args);
506template<class T, class A, class... Args>
507 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
508
509template<class T>
510class weak_ptr
511{
512public:
513 typedef T element_type;
514
515 // constructors
Howard Hinnant719bda32011-05-28 14:41:13 +0000516 constexpr weak_ptr() noexcept;
517 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
518 weak_ptr(weak_ptr const& r) noexcept;
519 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000520 weak_ptr(weak_ptr&& r) noexcept; // C++14
521 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000522
523 // destructor
524 ~weak_ptr();
525
526 // assignment
Howard Hinnant719bda32011-05-28 14:41:13 +0000527 weak_ptr& operator=(weak_ptr const& r) noexcept;
528 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
529 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Marshall Clowe9b0a5c2014-03-05 03:12:04 +0000530 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
531 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000532
533 // modifiers
Howard Hinnant719bda32011-05-28 14:41:13 +0000534 void swap(weak_ptr& r) noexcept;
535 void reset() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000536
537 // observers
Howard Hinnant719bda32011-05-28 14:41:13 +0000538 long use_count() const noexcept;
539 bool expired() const noexcept;
540 shared_ptr<T> lock() const noexcept;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000541 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
542 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000543};
544
545// weak_ptr specialized algorithms:
Howard Hinnant719bda32011-05-28 14:41:13 +0000546template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000547
548// class owner_less:
549template<class T> struct owner_less;
550
551template<class T>
552struct owner_less<shared_ptr<T>>
553 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
554{
555 typedef bool result_type;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000556 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
557 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
558 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000559};
560
561template<class T>
562struct owner_less<weak_ptr<T>>
563 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
564{
565 typedef bool result_type;
Marshall Clow18a7cd52017-04-11 17:08:53 +0000566 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
568 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
569};
570
571template <> // Added in C++14
572struct owner_less<void>
573{
574 template <class _Tp, class _Up>
575 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
576 template <class _Tp, class _Up>
577 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
578 template <class _Tp, class _Up>
579 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
580 template <class _Tp, class _Up>
581 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
582
583 typedef void is_transparent;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000584};
585
586template<class T>
587class enable_shared_from_this
588{
589protected:
Howard Hinnant719bda32011-05-28 14:41:13 +0000590 constexpr enable_shared_from_this() noexcept;
591 enable_shared_from_this(enable_shared_from_this const&) noexcept;
592 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000593 ~enable_shared_from_this();
594public:
595 shared_ptr<T> shared_from_this();
596 shared_ptr<T const> shared_from_this() const;
597};
598
599template<class T>
600 bool atomic_is_lock_free(const shared_ptr<T>* p);
601template<class T>
602 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
603template<class T>
604 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
605template<class T>
606 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
607template<class T>
608 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
609template<class T>
610 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
611template<class T>
612 shared_ptr<T>
613 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
614template<class T>
615 bool
616 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
617template<class T>
618 bool
619 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
620template<class T>
621 bool
622 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
623 shared_ptr<T> w, memory_order success,
624 memory_order failure);
625template<class T>
626 bool
627 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
628 shared_ptr<T> w, memory_order success,
629 memory_order failure);
630// Hash support
631template <class T> struct hash;
632template <class T, class D> struct hash<unique_ptr<T, D> >;
633template <class T> struct hash<shared_ptr<T> >;
634
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000635template <class T, class Alloc>
636 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
637
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000638// Pointer safety
639enum class pointer_safety { relaxed, preferred, strict };
640void declare_reachable(void *p);
641template <class T> T *undeclare_reachable(T *p);
642void declare_no_pointers(char *p, size_t n);
643void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant719bda32011-05-28 14:41:13 +0000644pointer_safety get_pointer_safety() noexcept;
Howard Hinnantd26c01d2010-08-19 18:39:17 +0000645
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
647
648} // std
649
650*/
651
652#include <__config>
653#include <type_traits>
654#include <typeinfo>
655#include <cstddef>
656#include <cstdint>
657#include <new>
658#include <utility>
659#include <limits>
660#include <iterator>
661#include <__functional_base>
Howard Hinnantdc095972011-07-18 15:51:59 +0000662#include <iosfwd>
Howard Hinnant83b1c052011-12-19 17:58:44 +0000663#include <tuple>
Eric Fiselier2db2bd52016-05-07 03:12:24 +0000664#include <stdexcept>
Howard Hinnantd2cab2f2012-02-15 00:41:34 +0000665#include <cstring>
Eric Fiselier9d355982017-04-12 23:45:53 +0000666#include <cassert>
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000667#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +0000668# include <atomic>
669#endif
670
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000671#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000673#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674
Eric Fiselierf4433a32017-05-31 22:07:49 +0000675_LIBCPP_PUSH_MACROS
676#include <__undef_macros>
677
678
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679_LIBCPP_BEGIN_NAMESPACE_STD
680
Eric Fiselier89659d12015-07-07 00:27:16 +0000681template <class _ValueType>
682inline _LIBCPP_ALWAYS_INLINE
683_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
684#if !defined(_LIBCPP_HAS_NO_THREADS) && \
685 defined(__ATOMIC_RELAXED) && \
686 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
687 return __atomic_load_n(__value, __ATOMIC_RELAXED);
688#else
689 return *__value;
690#endif
691}
692
Kuba Breckade9d6792016-09-04 09:55:12 +0000693template <class _ValueType>
694inline _LIBCPP_ALWAYS_INLINE
695_ValueType __libcpp_acquire_load(_ValueType const* __value) {
696#if !defined(_LIBCPP_HAS_NO_THREADS) && \
697 defined(__ATOMIC_ACQUIRE) && \
698 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
699 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
700#else
701 return *__value;
702#endif
703}
704
Marshall Clow78dbe462016-11-14 18:22:19 +0000705// addressof moved to <type_traits>
Douglas Gregor13034442011-06-22 22:17:44 +0000706
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707template <class _Tp> class allocator;
708
709template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000710class _LIBCPP_TEMPLATE_VIS allocator<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000711{
712public:
713 typedef void* pointer;
714 typedef const void* const_pointer;
715 typedef void value_type;
716
717 template <class _Up> struct rebind {typedef allocator<_Up> other;};
718};
719
Howard Hinnant9f771052012-01-19 23:15:22 +0000720template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000721class _LIBCPP_TEMPLATE_VIS allocator<const void>
Howard Hinnant9f771052012-01-19 23:15:22 +0000722{
723public:
724 typedef const void* pointer;
725 typedef const void* const_pointer;
726 typedef const void value_type;
727
728 template <class _Up> struct rebind {typedef allocator<_Up> other;};
729};
730
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731// pointer_traits
732
Marshall Clow0be70c32017-06-14 21:23:57 +0000733template <class _Tp, class = void>
734struct __has_element_type : false_type {};
735
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +0000737struct __has_element_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +0000738 typename __void_t<typename _Tp::element_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739
740template <class _Ptr, bool = __has_element_type<_Ptr>::value>
741struct __pointer_traits_element_type;
742
743template <class _Ptr>
744struct __pointer_traits_element_type<_Ptr, true>
745{
746 typedef typename _Ptr::element_type type;
747};
748
749#ifndef _LIBCPP_HAS_NO_VARIADICS
750
751template <template <class, class...> class _Sp, class _Tp, class ..._Args>
752struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
753{
754 typedef typename _Sp<_Tp, _Args...>::element_type type;
755};
756
757template <template <class, class...> class _Sp, class _Tp, class ..._Args>
758struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
759{
760 typedef _Tp type;
761};
762
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000763#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764
765template <template <class> class _Sp, class _Tp>
766struct __pointer_traits_element_type<_Sp<_Tp>, true>
767{
768 typedef typename _Sp<_Tp>::element_type type;
769};
770
771template <template <class> class _Sp, class _Tp>
772struct __pointer_traits_element_type<_Sp<_Tp>, false>
773{
774 typedef _Tp type;
775};
776
777template <template <class, class> class _Sp, class _Tp, class _A0>
778struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
779{
780 typedef typename _Sp<_Tp, _A0>::element_type type;
781};
782
783template <template <class, class> class _Sp, class _Tp, class _A0>
784struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
785{
786 typedef _Tp type;
787};
788
789template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
790struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
791{
792 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
793};
794
795template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
796struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
797{
798 typedef _Tp type;
799};
800
801template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
802 class _A1, class _A2>
803struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
804{
805 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
806};
807
808template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
809 class _A1, class _A2>
810struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
811{
812 typedef _Tp type;
813};
814
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000815#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816
Marshall Clow0be70c32017-06-14 21:23:57 +0000817template <class _Tp, class = void>
818struct __has_difference_type : false_type {};
819
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +0000821struct __has_difference_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +0000822 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823
824template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
825struct __pointer_traits_difference_type
826{
827 typedef ptrdiff_t type;
828};
829
830template <class _Ptr>
831struct __pointer_traits_difference_type<_Ptr, true>
832{
833 typedef typename _Ptr::difference_type type;
834};
835
836template <class _Tp, class _Up>
837struct __has_rebind
838{
839private:
Howard Hinnant49e145e2012-10-30 19:06:59 +0000840 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841 template <class _Xp> static __two __test(...);
842 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
843public:
844 static const bool value = sizeof(__test<_Tp>(0)) == 1;
845};
846
847template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
848struct __pointer_traits_rebind
849{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000850#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 typedef typename _Tp::template rebind<_Up> type;
852#else
853 typedef typename _Tp::template rebind<_Up>::other type;
854#endif
855};
856
857#ifndef _LIBCPP_HAS_NO_VARIADICS
858
859template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
860struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
861{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000862#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
864#else
865 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
866#endif
867};
868
869template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
870struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
871{
872 typedef _Sp<_Up, _Args...> type;
873};
874
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000875#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876
877template <template <class> class _Sp, class _Tp, class _Up>
878struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
879{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000880#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 typedef typename _Sp<_Tp>::template rebind<_Up> type;
882#else
883 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
884#endif
885};
886
887template <template <class> class _Sp, class _Tp, class _Up>
888struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
889{
890 typedef _Sp<_Up> type;
891};
892
893template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
894struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
895{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000896#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
898#else
899 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
900#endif
901};
902
903template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
904struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
905{
906 typedef _Sp<_Up, _A0> type;
907};
908
909template <template <class, class, class> class _Sp, class _Tp, class _A0,
910 class _A1, class _Up>
911struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
912{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000913#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
915#else
916 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
917#endif
918};
919
920template <template <class, class, class> class _Sp, class _Tp, class _A0,
921 class _A1, class _Up>
922struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
923{
924 typedef _Sp<_Up, _A0, _A1> type;
925};
926
927template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
928 class _A1, class _A2, class _Up>
929struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
930{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000931#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
933#else
934 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
935#endif
936};
937
938template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
939 class _A1, class _A2, class _Up>
940struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
941{
942 typedef _Sp<_Up, _A0, _A1, _A2> type;
943};
944
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000945#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946
947template <class _Ptr>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000948struct _LIBCPP_TEMPLATE_VIS pointer_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949{
950 typedef _Ptr pointer;
951 typedef typename __pointer_traits_element_type<pointer>::type element_type;
952 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
953
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000954#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf09283d2011-05-11 20:21:19 +0000955 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956#else
957 template <class _Up> struct rebind
958 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000959#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960
961private:
962 struct __nat {};
963public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965 static pointer pointer_to(typename conditional<is_void<element_type>::value,
966 __nat, element_type>::type& __r)
967 {return pointer::pointer_to(__r);}
968};
969
970template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000971struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972{
973 typedef _Tp* pointer;
974 typedef _Tp element_type;
975 typedef ptrdiff_t difference_type;
976
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000977#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978 template <class _Up> using rebind = _Up*;
979#else
980 template <class _Up> struct rebind {typedef _Up* other;};
981#endif
982
983private:
984 struct __nat {};
985public:
Howard Hinnant756c69b2010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant719bda32011-05-28 14:41:13 +0000988 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000989 {return _VSTD::addressof(__r);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990};
991
Eric Fiselierae3ab842015-08-23 02:56:05 +0000992template <class _From, class _To>
993struct __rebind_pointer {
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000994#ifndef _LIBCPP_CXX03_LANG
Eric Fiselierae3ab842015-08-23 02:56:05 +0000995 typedef typename pointer_traits<_From>::template rebind<_To> type;
996#else
997 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
998#endif
999};
1000
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001// allocator_traits
1002
Marshall Clow0be70c32017-06-14 21:23:57 +00001003template <class _Tp, class = void>
1004struct __has_pointer_type : false_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005
1006template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001007struct __has_pointer_type<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001008 typename __void_t<typename _Tp::pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009
1010namespace __pointer_type_imp
1011{
1012
1013template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1014struct __pointer_type
1015{
1016 typedef typename _Dp::pointer type;
1017};
1018
1019template <class _Tp, class _Dp>
1020struct __pointer_type<_Tp, _Dp, false>
1021{
1022 typedef _Tp* type;
1023};
1024
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001025} // __pointer_type_imp
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026
1027template <class _Tp, class _Dp>
1028struct __pointer_type
1029{
1030 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1031};
1032
Marshall Clow0be70c32017-06-14 21:23:57 +00001033template <class _Tp, class = void>
1034struct __has_const_pointer : false_type {};
1035
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001037struct __has_const_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001038 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039
1040template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1041struct __const_pointer
1042{
1043 typedef typename _Alloc::const_pointer type;
1044};
1045
1046template <class _Tp, class _Ptr, class _Alloc>
1047struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1048{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001049#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1051#else
1052 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1053#endif
1054};
1055
Marshall Clow0be70c32017-06-14 21:23:57 +00001056template <class _Tp, class = void>
1057struct __has_void_pointer : false_type {};
1058
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001060struct __has_void_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001061 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062
1063template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1064struct __void_pointer
1065{
1066 typedef typename _Alloc::void_pointer type;
1067};
1068
1069template <class _Ptr, class _Alloc>
1070struct __void_pointer<_Ptr, _Alloc, false>
1071{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001072#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1074#else
1075 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1076#endif
1077};
1078
Marshall Clow0be70c32017-06-14 21:23:57 +00001079template <class _Tp, class = void>
1080struct __has_const_void_pointer : false_type {};
1081
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001083struct __has_const_void_pointer<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001084 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085
1086template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1087struct __const_void_pointer
1088{
1089 typedef typename _Alloc::const_void_pointer type;
1090};
1091
1092template <class _Ptr, class _Alloc>
1093struct __const_void_pointer<_Ptr, _Alloc, false>
1094{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001095#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1097#else
1098 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1099#endif
1100};
1101
Howard Hinnantc834c512011-11-29 18:15:50 +00001102template <class _Tp>
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001103inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnantc834c512011-11-29 18:15:50 +00001104_Tp*
1105__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106{
1107 return __p;
1108}
1109
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001110#if _LIBCPP_STD_VER <= 17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111template <class _Pointer>
1112inline _LIBCPP_INLINE_VISIBILITY
1113typename pointer_traits<_Pointer>::element_type*
Howard Hinnant719bda32011-05-28 14:41:13 +00001114__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001116 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117}
Eric Fiselier45c9aac2017-11-22 19:49:21 +00001118#else
1119template <class _Pointer>
1120inline _LIBCPP_INLINE_VISIBILITY
1121auto
1122__to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1123-> decltype(pointer_traits<_Pointer>::to_address(__p))
1124{
1125 return pointer_traits<_Pointer>::to_address(__p);
1126}
1127
1128template <class _Pointer, class... _None>
1129inline _LIBCPP_INLINE_VISIBILITY
1130auto
1131__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1132{
1133 return _VSTD::__to_raw_pointer(__p.operator->());
1134}
1135
1136template <class _Tp>
1137inline _LIBCPP_INLINE_VISIBILITY constexpr
1138_Tp*
1139to_address(_Tp* __p) _NOEXCEPT
1140{
1141 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1142 return __p;
1143}
1144
1145template <class _Pointer>
1146inline _LIBCPP_INLINE_VISIBILITY
1147auto
1148to_address(const _Pointer& __p) _NOEXCEPT
1149{
1150 return _VSTD::__to_raw_pointer(__p);
1151}
1152#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153
Marshall Clow0be70c32017-06-14 21:23:57 +00001154template <class _Tp, class = void>
1155struct __has_size_type : false_type {};
1156
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157template <class _Tp>
Marshall Clow0be70c32017-06-14 21:23:57 +00001158struct __has_size_type<_Tp,
1159 typename __void_t<typename _Tp::size_type>::type> : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001161template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162struct __size_type
1163{
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001164 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165};
1166
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001167template <class _Alloc, class _DiffType>
1168struct __size_type<_Alloc, _DiffType, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169{
1170 typedef typename _Alloc::size_type type;
1171};
1172
Marshall Clow0be70c32017-06-14 21:23:57 +00001173template <class _Tp, class = void>
1174struct __has_propagate_on_container_copy_assignment : false_type {};
1175
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176template <class _Tp>
Marshall Clow0be70c32017-06-14 21:23:57 +00001177struct __has_propagate_on_container_copy_assignment<_Tp,
1178 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1179 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180
1181template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1182struct __propagate_on_container_copy_assignment
1183{
1184 typedef false_type type;
1185};
1186
1187template <class _Alloc>
1188struct __propagate_on_container_copy_assignment<_Alloc, true>
1189{
1190 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1191};
1192
Marshall Clow0be70c32017-06-14 21:23:57 +00001193template <class _Tp, class = void>
1194struct __has_propagate_on_container_move_assignment : false_type {};
1195
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001197struct __has_propagate_on_container_move_assignment<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001198 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1199 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200
1201template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1202struct __propagate_on_container_move_assignment
1203{
1204 typedef false_type type;
1205};
1206
1207template <class _Alloc>
1208struct __propagate_on_container_move_assignment<_Alloc, true>
1209{
1210 typedef typename _Alloc::propagate_on_container_move_assignment type;
1211};
1212
Marshall Clow0be70c32017-06-14 21:23:57 +00001213template <class _Tp, class = void>
1214struct __has_propagate_on_container_swap : false_type {};
1215
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001217struct __has_propagate_on_container_swap<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001218 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1219 : true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001220
1221template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1222struct __propagate_on_container_swap
1223{
1224 typedef false_type type;
1225};
1226
1227template <class _Alloc>
1228struct __propagate_on_container_swap<_Alloc, true>
1229{
1230 typedef typename _Alloc::propagate_on_container_swap type;
1231};
1232
Marshall Clow0be70c32017-06-14 21:23:57 +00001233template <class _Tp, class = void>
1234struct __has_is_always_equal : false_type {};
1235
Marshall Clow0b587562015-06-02 16:34:03 +00001236template <class _Tp>
Aditya Kumar7c5db692017-08-20 10:38:55 +00001237struct __has_is_always_equal<_Tp,
Marshall Clow0be70c32017-06-14 21:23:57 +00001238 typename __void_t<typename _Tp::is_always_equal>::type>
1239 : true_type {};
Marshall Clow0b587562015-06-02 16:34:03 +00001240
1241template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1242struct __is_always_equal
1243{
1244 typedef typename _VSTD::is_empty<_Alloc>::type type;
1245};
1246
1247template <class _Alloc>
1248struct __is_always_equal<_Alloc, true>
1249{
1250 typedef typename _Alloc::is_always_equal type;
1251};
1252
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1254struct __has_rebind_other
1255{
1256private:
Howard Hinnant49e145e2012-10-30 19:06:59 +00001257 struct __two {char __lx; char __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258 template <class _Xp> static __two __test(...);
1259 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1260public:
1261 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1262};
1263
1264template <class _Tp, class _Up>
1265struct __has_rebind_other<_Tp, _Up, false>
1266{
1267 static const bool value = false;
1268};
1269
1270template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1271struct __allocator_traits_rebind
1272{
1273 typedef typename _Tp::template rebind<_Up>::other type;
1274};
1275
1276#ifndef _LIBCPP_HAS_NO_VARIADICS
1277
1278template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1279struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1280{
1281 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1282};
1283
1284template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1285struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1286{
1287 typedef _Alloc<_Up, _Args...> type;
1288};
1289
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001290#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291
1292template <template <class> class _Alloc, class _Tp, class _Up>
1293struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1294{
1295 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1296};
1297
1298template <template <class> class _Alloc, class _Tp, class _Up>
1299struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1300{
1301 typedef _Alloc<_Up> type;
1302};
1303
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1305struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1306{
1307 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1308};
1309
1310template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1311struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1312{
1313 typedef _Alloc<_Up, _A0> type;
1314};
1315
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1317 class _A1, class _Up>
1318struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1319{
1320 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1321};
1322
1323template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1324 class _A1, class _Up>
1325struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1326{
1327 typedef _Alloc<_Up, _A0, _A1> type;
1328};
1329
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1331 class _A1, class _A2, class _Up>
1332struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1333{
1334 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1335};
1336
1337template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1338 class _A1, class _A2, class _Up>
1339struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1340{
1341 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1342};
1343
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001344#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001346#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347
1348template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1349auto
1350__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001351 -> decltype((void)__a.allocate(__sz, __p), true_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352
1353template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1354auto
1355__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1356 -> false_type;
1357
1358template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1359struct __has_allocate_hint
1360 : integral_constant<bool,
1361 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001362 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363 declval<_SizeType>(),
1364 declval<_ConstVoidPtr>())),
1365 true_type>::value>
1366{
1367};
1368
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001369#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370
1371template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1372struct __has_allocate_hint
1373 : true_type
1374{
1375};
1376
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001377#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001379#if !defined(_LIBCPP_CXX03_LANG)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
1381template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001382decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1383 _VSTD::declval<_Args>()...),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384 true_type())
1385__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1386
1387template <class _Alloc, class _Pointer, class ..._Args>
1388false_type
1389__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1390
1391template <class _Alloc, class _Pointer, class ..._Args>
1392struct __has_construct
1393 : integral_constant<bool,
1394 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001395 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396 declval<_Pointer>(),
1397 declval<_Args>()...)),
1398 true_type>::value>
1399{
1400};
1401
1402template <class _Alloc, class _Pointer>
1403auto
1404__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1405 -> decltype(__a.destroy(__p), true_type());
1406
1407template <class _Alloc, class _Pointer>
1408auto
1409__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1410 -> false_type;
1411
1412template <class _Alloc, class _Pointer>
1413struct __has_destroy
1414 : integral_constant<bool,
1415 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001416 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001417 declval<_Pointer>())),
1418 true_type>::value>
1419{
1420};
1421
1422template <class _Alloc>
1423auto
1424__has_max_size_test(_Alloc&& __a)
1425 -> decltype(__a.max_size(), true_type());
1426
1427template <class _Alloc>
1428auto
1429__has_max_size_test(const volatile _Alloc& __a)
1430 -> false_type;
1431
1432template <class _Alloc>
1433struct __has_max_size
1434 : integral_constant<bool,
1435 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001436 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437 true_type>::value>
1438{
1439};
1440
1441template <class _Alloc>
1442auto
1443__has_select_on_container_copy_construction_test(_Alloc&& __a)
1444 -> decltype(__a.select_on_container_copy_construction(), true_type());
1445
1446template <class _Alloc>
1447auto
1448__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1449 -> false_type;
1450
1451template <class _Alloc>
1452struct __has_select_on_container_copy_construction
1453 : integral_constant<bool,
1454 is_same<
Eric Fiselierbe4cb612017-09-15 00:31:38 +00001455 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456 true_type>::value>
1457{
1458};
1459
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001460#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461
1462#ifndef _LIBCPP_HAS_NO_VARIADICS
1463
1464template <class _Alloc, class _Pointer, class ..._Args>
1465struct __has_construct
1466 : false_type
1467{
1468};
1469
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001470#else // _LIBCPP_HAS_NO_VARIADICS
1471
1472template <class _Alloc, class _Pointer, class _Args>
1473struct __has_construct
1474 : false_type
1475{
1476};
1477
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001478#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479
1480template <class _Alloc, class _Pointer>
1481struct __has_destroy
1482 : false_type
1483{
1484};
1485
1486template <class _Alloc>
1487struct __has_max_size
1488 : true_type
1489{
1490};
1491
1492template <class _Alloc>
1493struct __has_select_on_container_copy_construction
1494 : false_type
1495{
1496};
1497
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001498#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001500template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1501struct __alloc_traits_difference_type
1502{
1503 typedef typename pointer_traits<_Ptr>::difference_type type;
1504};
1505
1506template <class _Alloc, class _Ptr>
1507struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1508{
1509 typedef typename _Alloc::difference_type type;
1510};
1511
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512template <class _Alloc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001513struct _LIBCPP_TEMPLATE_VIS allocator_traits
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514{
1515 typedef _Alloc allocator_type;
1516 typedef typename allocator_type::value_type value_type;
1517
1518 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1519 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1520 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1521 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1522
Howard Hinnant8e4e6002010-11-18 01:40:00 +00001523 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1524 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525
1526 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1527 propagate_on_container_copy_assignment;
1528 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1529 propagate_on_container_move_assignment;
1530 typedef typename __propagate_on_container_swap<allocator_type>::type
1531 propagate_on_container_swap;
Marshall Clow0b587562015-06-02 16:34:03 +00001532 typedef typename __is_always_equal<allocator_type>::type
1533 is_always_equal;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001535#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536 template <class _Tp> using rebind_alloc =
Howard Hinnantf09283d2011-05-11 20:21:19 +00001537 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001539#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540 template <class _Tp> struct rebind_alloc
1541 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1542 template <class _Tp> struct rebind_traits
1543 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001544#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545
Marshall Clow0e58cae2017-11-26 02:55:38 +00001546 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547 static pointer allocate(allocator_type& __a, size_type __n)
1548 {return __a.allocate(__n);}
Marshall Clow0e58cae2017-11-26 02:55:38 +00001549 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001551 {return __allocate(__a, __n, __hint,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1553
Howard Hinnant756c69b2010-09-22 16:48:34 +00001554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001555 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001556 {__a.deallocate(__p, __n);}
1557
1558#ifndef _LIBCPP_HAS_NO_VARIADICS
1559 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow3996b8b2014-11-11 19:22:33 +00001562 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001563 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001564#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001565 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001566 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001567 static void construct(allocator_type&, _Tp* __p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 {
1569 ::new ((void*)__p) _Tp();
1570 }
1571 template <class _Tp, class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001572 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001573 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574 {
1575 ::new ((void*)__p) _Tp(__a0);
1576 }
1577 template <class _Tp, class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001578 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001579 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 const _A1& __a1)
1581 {
1582 ::new ((void*)__p) _Tp(__a0, __a1);
1583 }
1584 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001585 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2b2ec3e2017-01-14 01:33:53 +00001586 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587 const _A1& __a1, const _A2& __a2)
1588 {
1589 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1590 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001591#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592
1593 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 static void destroy(allocator_type& __a, _Tp* __p)
1596 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1597
Howard Hinnant756c69b2010-09-22 16:48:34 +00001598 _LIBCPP_INLINE_VISIBILITY
Marshall Clow4f834b52013-08-27 20:22:15 +00001599 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1601
Howard Hinnant756c69b2010-09-22 16:48:34 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001603 static allocator_type
1604 select_on_container_copy_construction(const allocator_type& __a)
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001605 {return __select_on_container_copy_construction(
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606 __has_select_on_container_copy_construction<const allocator_type>(),
1607 __a);}
1608
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001609 template <class _Ptr>
1610 _LIBCPP_INLINE_VISIBILITY
1611 static
1612 void
1613 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1614 {
1615 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1616 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1617 }
1618
1619 template <class _Tp>
1620 _LIBCPP_INLINE_VISIBILITY
1621 static
1622 typename enable_if
1623 <
1624 (is_same<allocator_type, allocator<_Tp> >::value
1625 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1626 is_trivially_move_constructible<_Tp>::value,
1627 void
1628 >::type
Eric Fiselier6003c772016-12-23 23:37:52 +00001629 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001630 {
1631 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001632 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001633 {
Marshall Clow4907e8f2015-05-31 03:13:31 +00001634 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001635 __begin2 += _Np;
1636 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001637 }
1638
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001639 template <class _Iter, class _Ptr>
1640 _LIBCPP_INLINE_VISIBILITY
1641 static
1642 void
1643 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1644 {
1645 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1646 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1647 }
1648
1649 template <class _Tp>
1650 _LIBCPP_INLINE_VISIBILITY
1651 static
1652 typename enable_if
1653 <
1654 (is_same<allocator_type, allocator<_Tp> >::value
1655 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1656 is_trivially_move_constructible<_Tp>::value,
1657 void
1658 >::type
Eric Fiselier6003c772016-12-23 23:37:52 +00001659 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001660 {
1661 typedef typename remove_const<_Tp>::type _Vp;
1662 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001663 if (_Np > 0)
Marshall Clow426d6d22015-06-02 13:04:18 +00001664 {
Marshall Clow4907e8f2015-05-31 03:13:31 +00001665 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
Marshall Clow426d6d22015-06-02 13:04:18 +00001666 __begin2 += _Np;
1667 }
Eric Fiselieracfe6f02015-03-31 16:54:19 +00001668 }
1669
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001670 template <class _Ptr>
1671 _LIBCPP_INLINE_VISIBILITY
1672 static
1673 void
1674 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1675 {
1676 while (__end1 != __begin1)
Howard Hinnant5adee4c2013-01-11 20:36:59 +00001677 {
1678 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1679 --__end2;
1680 }
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001681 }
1682
1683 template <class _Tp>
1684 _LIBCPP_INLINE_VISIBILITY
1685 static
1686 typename enable_if
1687 <
1688 (is_same<allocator_type, allocator<_Tp> >::value
1689 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1690 is_trivially_move_constructible<_Tp>::value,
1691 void
1692 >::type
Eric Fiselier6003c772016-12-23 23:37:52 +00001693 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001694 {
1695 ptrdiff_t _Np = __end1 - __begin1;
1696 __end2 -= _Np;
Marshall Clow4907e8f2015-05-31 03:13:31 +00001697 if (_Np > 0)
1698 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnantd2cab2f2012-02-15 00:41:34 +00001699 }
1700
Howard Hinnantc51e1022010-05-11 19:42:16 +00001701private:
1702
Howard Hinnant756c69b2010-09-22 16:48:34 +00001703 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001704 static pointer __allocate(allocator_type& __a, size_type __n,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001705 const_void_pointer __hint, true_type)
1706 {return __a.allocate(__n, __hint);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001707 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001708 static pointer __allocate(allocator_type& __a, size_type __n,
Howard Hinnant28b24882011-12-01 20:21:04 +00001709 const_void_pointer, false_type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710 {return __a.allocate(__n);}
1711
1712#ifndef _LIBCPP_HAS_NO_VARIADICS
1713 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001716 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001717 template <class _Tp, class... _Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001718 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001719 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1720 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001721 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001723#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001724
1725 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1728 {__a.destroy(__p);}
1729 template <class _Tp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00001730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731 static void __destroy(false_type, allocator_type&, _Tp* __p)
1732 {
1733 __p->~_Tp();
1734 }
1735
Howard Hinnant756c69b2010-09-22 16:48:34 +00001736 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf817a352017-12-05 15:56:26 +00001737 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738 {return __a.max_size();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001739 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf817a352017-12-05 15:56:26 +00001740 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
Marshall Clow33daa162015-10-25 19:34:04 +00001741 {return numeric_limits<size_type>::max() / sizeof(value_type);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742
Howard Hinnant756c69b2010-09-22 16:48:34 +00001743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744 static allocator_type
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001745 __select_on_container_copy_construction(true_type, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 {return __a.select_on_container_copy_construction();}
Howard Hinnant756c69b2010-09-22 16:48:34 +00001747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001748 static allocator_type
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001749 __select_on_container_copy_construction(false_type, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750 {return __a;}
1751};
1752
Marshall Clow940e01c2015-04-07 05:21:38 +00001753template <class _Traits, class _Tp>
1754struct __rebind_alloc_helper
1755{
Eric Fiselierc6f17cc2016-09-25 03:34:28 +00001756#ifndef _LIBCPP_CXX03_LANG
Marshall Clow35cde742015-05-10 13:59:45 +00001757 typedef typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow940e01c2015-04-07 05:21:38 +00001758#else
1759 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1760#endif
1761};
1762
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763// allocator
1764
1765template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001766class _LIBCPP_TEMPLATE_VIS allocator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767{
1768public:
1769 typedef size_t size_type;
1770 typedef ptrdiff_t difference_type;
1771 typedef _Tp* pointer;
1772 typedef const _Tp* const_pointer;
1773 typedef _Tp& reference;
1774 typedef const _Tp& const_reference;
1775 typedef _Tp value_type;
1776
Howard Hinnant4931e092011-06-02 21:38:57 +00001777 typedef true_type propagate_on_container_move_assignment;
Marshall Clow0b587562015-06-02 16:34:03 +00001778 typedef true_type is_always_equal;
Howard Hinnant4931e092011-06-02 21:38:57 +00001779
Howard Hinnantc51e1022010-05-11 19:42:16 +00001780 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1781
Marshall Clowbc759762018-03-20 23:02:53 +00001782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1783 allocator() _NOEXCEPT {}
1784
1785 template <class _Up>
1786 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1787 allocator(const allocator<_Up>&) _NOEXCEPT {}
1788
Howard Hinnant719bda32011-05-28 14:41:13 +00001789 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001790 {return _VSTD::addressof(__x);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001791 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001792 {return _VSTD::addressof(__x);}
Marshall Clow0e58cae2017-11-26 02:55:38 +00001793 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1794 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001795 {
1796 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001797 __throw_length_error("allocator<T>::allocate(size_t n)"
1798 " 'n' exceeds maximum supported size");
Marshall Clow813ffb32016-03-03 12:04:39 +00001799 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1800 }
Howard Hinnant719bda32011-05-28 14:41:13 +00001801 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Eric Fiselier8122fda2017-01-07 03:01:24 +00001802 {_VSTD::__libcpp_deallocate((void*)__p);}
Howard Hinnant719bda32011-05-28 14:41:13 +00001803 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1804 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001805#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806 template <class _Up, class... _Args>
1807 _LIBCPP_INLINE_VISIBILITY
1808 void
1809 construct(_Up* __p, _Args&&... __args)
1810 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001811 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001812 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001813#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814 _LIBCPP_INLINE_VISIBILITY
1815 void
1816 construct(pointer __p)
1817 {
1818 ::new((void*)__p) _Tp();
1819 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001820# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001821
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822 template <class _A0>
1823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001824 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825 construct(pointer __p, _A0& __a0)
1826 {
1827 ::new((void*)__p) _Tp(__a0);
1828 }
1829 template <class _A0>
1830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001831 void
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832 construct(pointer __p, const _A0& __a0)
1833 {
1834 ::new((void*)__p) _Tp(__a0);
1835 }
Michael J. Spencer8d8164e2010-12-10 19:47:54 +00001836# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837 template <class _A0, class _A1>
1838 _LIBCPP_INLINE_VISIBILITY
1839 void
1840 construct(pointer __p, _A0& __a0, _A1& __a1)
1841 {
1842 ::new((void*)__p) _Tp(__a0, __a1);
1843 }
1844 template <class _A0, class _A1>
1845 _LIBCPP_INLINE_VISIBILITY
1846 void
1847 construct(pointer __p, const _A0& __a0, _A1& __a1)
1848 {
1849 ::new((void*)__p) _Tp(__a0, __a1);
1850 }
1851 template <class _A0, class _A1>
1852 _LIBCPP_INLINE_VISIBILITY
1853 void
1854 construct(pointer __p, _A0& __a0, const _A1& __a1)
1855 {
1856 ::new((void*)__p) _Tp(__a0, __a1);
1857 }
1858 template <class _A0, class _A1>
1859 _LIBCPP_INLINE_VISIBILITY
1860 void
1861 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1862 {
1863 ::new((void*)__p) _Tp(__a0, __a1);
1864 }
Howard Hinnant74279a52010-09-04 23:28:19 +00001865#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1867};
1868
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001869template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001870class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001871{
1872public:
1873 typedef size_t size_type;
1874 typedef ptrdiff_t difference_type;
1875 typedef const _Tp* pointer;
1876 typedef const _Tp* const_pointer;
1877 typedef const _Tp& reference;
1878 typedef const _Tp& const_reference;
Howard Hinnant9bc95e22013-06-07 01:56:37 +00001879 typedef const _Tp value_type;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001880
1881 typedef true_type propagate_on_container_move_assignment;
Marshall Clowac12fcc2015-07-01 21:23:40 +00001882 typedef true_type is_always_equal;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001883
1884 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1885
Marshall Clowbc759762018-03-20 23:02:53 +00001886 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1887 allocator() _NOEXCEPT {}
1888
1889 template <class _Up>
1890 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1891 allocator(const allocator<_Up>&) _NOEXCEPT {}
1892
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001893 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1894 {return _VSTD::addressof(__x);}
1895 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow813ffb32016-03-03 12:04:39 +00001896 {
1897 if (__n > max_size())
Marshall Clowed3e2292016-08-25 17:47:09 +00001898 __throw_length_error("allocator<const T>::allocate(size_t n)"
1899 " 'n' exceeds maximum supported size");
Marshall Clow813ffb32016-03-03 12:04:39 +00001900 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
Eric Fiselier2db2bd52016-05-07 03:12:24 +00001901 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001902 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Marshall Clow31350ab2017-06-14 16:54:43 +00001903 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001904 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1905 {return size_type(~0) / sizeof(_Tp);}
1906#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1907 template <class _Up, class... _Args>
1908 _LIBCPP_INLINE_VISIBILITY
1909 void
1910 construct(_Up* __p, _Args&&... __args)
1911 {
1912 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1913 }
1914#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1915 _LIBCPP_INLINE_VISIBILITY
1916 void
1917 construct(pointer __p)
1918 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001919 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001920 }
1921# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant9e028f12012-05-01 15:37:54 +00001922
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001923 template <class _A0>
1924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001925 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001926 construct(pointer __p, _A0& __a0)
1927 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001928 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001929 }
1930 template <class _A0>
1931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9e028f12012-05-01 15:37:54 +00001932 void
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001933 construct(pointer __p, const _A0& __a0)
1934 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001935 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001936 }
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001937# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1938 template <class _A0, class _A1>
1939 _LIBCPP_INLINE_VISIBILITY
1940 void
1941 construct(pointer __p, _A0& __a0, _A1& __a1)
1942 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001943 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001944 }
1945 template <class _A0, class _A1>
1946 _LIBCPP_INLINE_VISIBILITY
1947 void
1948 construct(pointer __p, const _A0& __a0, _A1& __a1)
1949 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001950 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001951 }
1952 template <class _A0, class _A1>
1953 _LIBCPP_INLINE_VISIBILITY
1954 void
1955 construct(pointer __p, _A0& __a0, const _A1& __a1)
1956 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001957 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001958 }
1959 template <class _A0, class _A1>
1960 _LIBCPP_INLINE_VISIBILITY
1961 void
1962 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1963 {
Marshall Clow31350ab2017-06-14 16:54:43 +00001964 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
Howard Hinnant741c8fa2012-01-02 17:56:02 +00001965 }
1966#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1967 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1968};
1969
Howard Hinnantc51e1022010-05-11 19:42:16 +00001970template <class _Tp, class _Up>
1971inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001972bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001973
1974template <class _Tp, class _Up>
1975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00001976bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977
1978template <class _OutputIterator, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001979class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00001980 : public iterator<output_iterator_tag,
1981 _Tp, // purposefully not C++03
1982 ptrdiff_t, // purposefully not C++03
1983 _Tp*, // purposefully not C++03
1984 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1985{
1986private:
1987 _OutputIterator __x_;
1988public:
1989 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1990 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1991 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1992 {::new(&*__x_) _Tp(__element); return *this;}
Marshall Clow5c3f09e2015-10-25 18:58:07 +00001993#if _LIBCPP_STD_VER >= 14
1994 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1995 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1996#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1998 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1999 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clowb949f1b2015-05-10 13:14:08 +00002000#if _LIBCPP_STD_VER >= 14
Aditya Kumar7c5db692017-08-20 10:38:55 +00002001 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
Marshall Clowb949f1b2015-05-10 13:14:08 +00002002#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003};
2004
2005template <class _Tp>
Peter Collingbournecd000192018-01-17 19:32:35 +00002006_LIBCPP_NO_CFI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002007pair<_Tp*, ptrdiff_t>
Howard Hinnant719bda32011-05-28 14:41:13 +00002008get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009{
2010 pair<_Tp*, ptrdiff_t> __r(0, 0);
2011 const ptrdiff_t __m = (~ptrdiff_t(0) ^
2012 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2013 / sizeof(_Tp);
2014 if (__n > __m)
2015 __n = __m;
2016 while (__n > 0)
2017 {
Richard Smith0657be12018-02-01 22:24:45 +00002018#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2019#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
2020 if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
2021#else
2022 if (std::alignment_of<_Tp>::value >
2023 std::alignment_of<std::max_align_t>::value)
2024#endif
2025 {
2026 std::align_val_t __al =
2027 std::align_val_t(std::alignment_of<_Tp>::value);
2028 __r.first = static_cast<_Tp*>(::operator new(
2029 __n * sizeof(_Tp), __al, nothrow));
2030 } else {
2031 __r.first = static_cast<_Tp*>(::operator new(
2032 __n * sizeof(_Tp), nothrow));
2033 }
2034#else
2035#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
2036 if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
2037#else
2038 if (std::alignment_of<_Tp>::value >
2039 std::alignment_of<std::max_align_t>::value)
2040#endif
2041 {
2042 // Since aligned operator new is unavailable, return an empty
2043 // buffer rather than one with invalid alignment.
2044 return __r;
2045 }
2046
Howard Hinnantc51e1022010-05-11 19:42:16 +00002047 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
Richard Smith0657be12018-02-01 22:24:45 +00002048#endif
2049
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050 if (__r.first)
2051 {
2052 __r.second = __n;
2053 break;
2054 }
2055 __n /= 2;
2056 }
2057 return __r;
2058}
2059
2060template <class _Tp>
2061inline _LIBCPP_INLINE_VISIBILITY
Richard Smith0657be12018-02-01 22:24:45 +00002062void return_temporary_buffer(_Tp* __p) _NOEXCEPT
2063{
2064#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2065#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
2066 if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
2067#else
2068 if (std::alignment_of<_Tp>::value >
2069 std::alignment_of<std::max_align_t>::value)
2070#endif
2071 {
2072 std::align_val_t __al = std::align_val_t(std::alignment_of<_Tp>::value);
2073 ::operator delete(__p, __al);
2074 return;
2075 }
2076#endif
2077 ::operator delete(__p);
2078}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002079
Marshall Clowb22274f2017-01-24 22:22:33 +00002080#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002081template <class _Tp>
2082struct auto_ptr_ref
2083{
2084 _Tp* __ptr_;
2085};
2086
2087template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002088class _LIBCPP_TEMPLATE_VIS auto_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00002089{
2090private:
2091 _Tp* __ptr_;
2092public:
2093 typedef _Tp element_type;
2094
2095 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2096 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2097 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2098 : __ptr_(__p.release()) {}
2099 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2100 {reset(__p.release()); return *this;}
2101 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2102 {reset(__p.release()); return *this;}
2103 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2104 {reset(__p.__ptr_); return *this;}
2105 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2106
2107 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2108 {return *__ptr_;}
2109 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2110 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2111 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2112 {
2113 _Tp* __t = __ptr_;
2114 __ptr_ = 0;
2115 return __t;
2116 }
2117 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2118 {
2119 if (__ptr_ != __p)
2120 delete __ptr_;
2121 __ptr_ = __p;
2122 }
2123
2124 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2125 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2126 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2127 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2128 {return auto_ptr<_Up>(release());}
2129};
2130
2131template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002132class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002133{
2134public:
2135 typedef void element_type;
2136};
Marshall Clowb22274f2017-01-24 22:22:33 +00002137#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002138
Eric Fiselier9d355982017-04-12 23:45:53 +00002139template <class _Tp, int _Idx,
2140 bool _CanBeEmptyBase =
2141 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2142struct __compressed_pair_elem {
2143 typedef _Tp _ParamT;
2144 typedef _Tp& reference;
2145 typedef const _Tp& const_reference;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002146
Eric Fiselier9d355982017-04-12 23:45:53 +00002147#ifndef _LIBCPP_CXX03_LANG
Alex Lorenz76132112017-11-09 17:54:49 +00002148 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002149
Eric Fiselier9d355982017-04-12 23:45:53 +00002150 template <class _Up, class = typename enable_if<
Eric Fiselier209ecde2017-04-17 22:32:02 +00002151 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2152 >::type>
Alex Lorenz76132112017-11-09 17:54:49 +00002153 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier209ecde2017-04-17 22:32:02 +00002154 constexpr explicit
Eric Fiselier9d355982017-04-12 23:45:53 +00002155 __compressed_pair_elem(_Up&& __u)
2156 : __value_(_VSTD::forward<_Up>(__u)){};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157
Eric Fiselier9d355982017-04-12 23:45:53 +00002158 template <class... _Args, size_t... _Indexes>
2159 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2160 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2161 __tuple_indices<_Indexes...>)
2162 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2163#else
Alex Lorenz76132112017-11-09 17:54:49 +00002164 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2165 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002166 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2167#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002168
Alex Lorenz76132112017-11-09 17:54:49 +00002169 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2170 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002171 const_reference __get() const _NOEXCEPT { return __value_; }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002172
Howard Hinnantc51e1022010-05-11 19:42:16 +00002173private:
Eric Fiselier9d355982017-04-12 23:45:53 +00002174 _Tp __value_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175};
2176
Eric Fiselier9d355982017-04-12 23:45:53 +00002177template <class _Tp, int _Idx>
2178struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2179 typedef _Tp _ParamT;
2180 typedef _Tp& reference;
2181 typedef const _Tp& const_reference;
2182 typedef _Tp __value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002183
Eric Fiselier9d355982017-04-12 23:45:53 +00002184#ifndef _LIBCPP_CXX03_LANG
Alex Lorenz76132112017-11-09 17:54:49 +00002185 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002186
Eric Fiselier9d355982017-04-12 23:45:53 +00002187 template <class _Up, class = typename enable_if<
Eric Fiselier209ecde2017-04-17 22:32:02 +00002188 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2189 >::type>
Alex Lorenz76132112017-11-09 17:54:49 +00002190 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier209ecde2017-04-17 22:32:02 +00002191 constexpr explicit
Eric Fiselier9d355982017-04-12 23:45:53 +00002192 __compressed_pair_elem(_Up&& __u)
2193 : __value_type(_VSTD::forward<_Up>(__u)){};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002194
Eric Fiselier9d355982017-04-12 23:45:53 +00002195 template <class... _Args, size_t... _Indexes>
2196 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2197 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2198 __tuple_indices<_Indexes...>)
2199 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2200#else
Alex Lorenz76132112017-11-09 17:54:49 +00002201 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2202 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002203 __compressed_pair_elem(_ParamT __p)
2204 : __value_type(std::forward<_ParamT>(__p)) {}
2205#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002206
Alex Lorenz76132112017-11-09 17:54:49 +00002207 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2208 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002209 const_reference __get() const _NOEXCEPT { return *this; }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002210};
2211
Eric Fiselier9d355982017-04-12 23:45:53 +00002212// Tag used to construct the second element of the compressed pair.
2213struct __second_tag {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002214
2215template <class _T1, class _T2>
Eric Fiselier9d355982017-04-12 23:45:53 +00002216class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2217 private __compressed_pair_elem<_T2, 1> {
2218 typedef __compressed_pair_elem<_T1, 0> _Base1;
2219 typedef __compressed_pair_elem<_T2, 1> _Base2;
2220
2221 // NOTE: This static assert should never fire because __compressed_pair
2222 // is *almost never* used in a scenario where it's possible for T1 == T2.
2223 // (The exception is std::function where it is possible that the function
2224 // object and the allocator have the same type).
Eric Fiselierc5adf472017-04-13 01:13:58 +00002225 static_assert((!is_same<_T1, _T2>::value),
Eric Fiselier9d355982017-04-12 23:45:53 +00002226 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2227 "The current implementation is NOT ABI-compatible with the previous "
2228 "implementation for this configuration");
2229
Howard Hinnantc51e1022010-05-11 19:42:16 +00002230public:
Eric Fiselier9d355982017-04-12 23:45:53 +00002231#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier209ecde2017-04-17 22:32:02 +00002232 template <bool _Dummy = true,
2233 class = typename enable_if<
2234 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2235 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2236 >::type
2237 >
Eric Fiselier9d355982017-04-12 23:45:53 +00002238 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier209ecde2017-04-17 22:32:02 +00002239 constexpr __compressed_pair() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002240
Eric Fiselier9d355982017-04-12 23:45:53 +00002241 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2242 __compressed_pair>::value,
2243 bool>::type = true>
2244 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2245 __compressed_pair(_Tp&& __t)
2246 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002247
Eric Fiselier9d355982017-04-12 23:45:53 +00002248 template <class _Tp>
2249 _LIBCPP_INLINE_VISIBILITY constexpr
2250 __compressed_pair(__second_tag, _Tp&& __t)
2251 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002252
Eric Fiselier9d355982017-04-12 23:45:53 +00002253 template <class _U1, class _U2>
2254 _LIBCPP_INLINE_VISIBILITY constexpr
2255 __compressed_pair(_U1&& __t1, _U2&& __t2)
2256 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002257
Eric Fiselier9d355982017-04-12 23:45:53 +00002258 template <class... _Args1, class... _Args2>
2259 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2260 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2261 tuple<_Args2...> __second_args)
2262 : _Base1(__pc, _VSTD::move(__first_args),
2263 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2264 _Base2(__pc, _VSTD::move(__second_args),
2265 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
Howard Hinnant83b1c052011-12-19 17:58:44 +00002266
Eric Fiselier9d355982017-04-12 23:45:53 +00002267#else
2268 _LIBCPP_INLINE_VISIBILITY
2269 __compressed_pair() {}
Howard Hinnant83b1c052011-12-19 17:58:44 +00002270
Eric Fiselier9d355982017-04-12 23:45:53 +00002271 _LIBCPP_INLINE_VISIBILITY explicit
2272 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
Howard Hinnant83b1c052011-12-19 17:58:44 +00002273
Eric Fiselier9d355982017-04-12 23:45:53 +00002274 _LIBCPP_INLINE_VISIBILITY
2275 __compressed_pair(__second_tag, _T2 __t2)
2276 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277
Eric Fiselier9d355982017-04-12 23:45:53 +00002278 _LIBCPP_INLINE_VISIBILITY
2279 __compressed_pair(_T1 __t1, _T2 __t2)
2280 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2281#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002282
Eric Fiselier9d355982017-04-12 23:45:53 +00002283 _LIBCPP_INLINE_VISIBILITY
2284 typename _Base1::reference first() _NOEXCEPT {
2285 return static_cast<_Base1&>(*this).__get();
2286 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002287
Eric Fiselier9d355982017-04-12 23:45:53 +00002288 _LIBCPP_INLINE_VISIBILITY
2289 typename _Base1::const_reference first() const _NOEXCEPT {
2290 return static_cast<_Base1 const&>(*this).__get();
2291 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002292
Eric Fiselier9d355982017-04-12 23:45:53 +00002293 _LIBCPP_INLINE_VISIBILITY
2294 typename _Base2::reference second() _NOEXCEPT {
2295 return static_cast<_Base2&>(*this).__get();
2296 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002297
Eric Fiselier9d355982017-04-12 23:45:53 +00002298 _LIBCPP_INLINE_VISIBILITY
2299 typename _Base2::const_reference second() const _NOEXCEPT {
2300 return static_cast<_Base2 const&>(*this).__get();
2301 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002302
Eric Fiselier9d355982017-04-12 23:45:53 +00002303 _LIBCPP_INLINE_VISIBILITY
2304 void swap(__compressed_pair& __x)
2305 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2306 __is_nothrow_swappable<_T2>::value)
2307 {
2308 using std::swap;
2309 swap(first(), __x.first());
2310 swap(second(), __x.second());
2311 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002312};
2313
2314template <class _T1, class _T2>
2315inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier9d355982017-04-12 23:45:53 +00002316void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2317 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2318 __is_nothrow_swappable<_T2>::value) {
2319 __x.swap(__y);
2320}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002321
Howard Hinnant741c8fa2012-01-02 17:56:02 +00002322// default_delete
2323
Howard Hinnantc51e1022010-05-11 19:42:16 +00002324template <class _Tp>
Eric Fiselier6779b062017-04-16 02:06:25 +00002325struct _LIBCPP_TEMPLATE_VIS default_delete {
Erik Pilkington2a398762017-05-25 15:43:31 +00002326 static_assert(!is_function<_Tp>::value,
2327 "default_delete cannot be instantiated for function types");
Eric Fiselier6779b062017-04-16 02:06:25 +00002328#ifndef _LIBCPP_CXX03_LANG
2329 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002330#else
Eric Fiselier6779b062017-04-16 02:06:25 +00002331 _LIBCPP_INLINE_VISIBILITY default_delete() {}
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002332#endif
Eric Fiselier6779b062017-04-16 02:06:25 +00002333 template <class _Up>
2334 _LIBCPP_INLINE_VISIBILITY
2335 default_delete(const default_delete<_Up>&,
2336 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2337 0) _NOEXCEPT {}
2338
2339 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2340 static_assert(sizeof(_Tp) > 0,
2341 "default_delete can not delete incomplete type");
2342 static_assert(!is_void<_Tp>::value,
2343 "default_delete can not delete incomplete type");
2344 delete __ptr;
2345 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002346};
2347
2348template <class _Tp>
Eric Fiselier6779b062017-04-16 02:06:25 +00002349struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2350private:
2351 template <class _Up>
2352 struct _EnableIfConvertible
2353 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2354
Howard Hinnant4500ca52011-12-18 21:19:44 +00002355public:
Eric Fiselier6779b062017-04-16 02:06:25 +00002356#ifndef _LIBCPP_CXX03_LANG
2357 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002358#else
Eric Fiselier6779b062017-04-16 02:06:25 +00002359 _LIBCPP_INLINE_VISIBILITY default_delete() {}
Howard Hinnantb5fffe82012-07-07 20:56:04 +00002360#endif
Eric Fiselier6779b062017-04-16 02:06:25 +00002361
2362 template <class _Up>
2363 _LIBCPP_INLINE_VISIBILITY
2364 default_delete(const default_delete<_Up[]>&,
2365 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2366
2367 template <class _Up>
2368 _LIBCPP_INLINE_VISIBILITY
2369 typename _EnableIfConvertible<_Up>::type
2370 operator()(_Up* __ptr) const _NOEXCEPT {
2371 static_assert(sizeof(_Tp) > 0,
2372 "default_delete can not delete incomplete type");
2373 static_assert(!is_void<_Tp>::value,
2374 "default_delete can not delete void type");
2375 delete[] __ptr;
2376 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002377};
2378
Howard Hinnantc51e1022010-05-11 19:42:16 +00002379
Eric Fiselier6779b062017-04-16 02:06:25 +00002380
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002381#ifndef _LIBCPP_CXX03_LANG
2382template <class _Deleter>
2383struct __unique_ptr_deleter_sfinae {
2384 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2385 typedef const _Deleter& __lval_ref_type;
2386 typedef _Deleter&& __good_rval_ref_type;
2387 typedef true_type __enable_rval_overload;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002388};
2389
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002390template <class _Deleter>
2391struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2392 typedef const _Deleter& __lval_ref_type;
2393 typedef const _Deleter&& __bad_rval_ref_type;
2394 typedef false_type __enable_rval_overload;
2395};
2396
2397template <class _Deleter>
2398struct __unique_ptr_deleter_sfinae<_Deleter&> {
2399 typedef _Deleter& __lval_ref_type;
2400 typedef _Deleter&& __bad_rval_ref_type;
2401 typedef false_type __enable_rval_overload;
2402};
2403#endif // !defined(_LIBCPP_CXX03_LANG)
2404
2405template <class _Tp, class _Dp = default_delete<_Tp> >
2406class _LIBCPP_TEMPLATE_VIS unique_ptr {
2407public:
2408 typedef _Tp element_type;
2409 typedef _Dp deleter_type;
2410 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2411
2412 static_assert(!is_rvalue_reference<deleter_type>::value,
2413 "the specified deleter type cannot be an rvalue reference");
2414
2415private:
2416 __compressed_pair<pointer, deleter_type> __ptr_;
2417
2418 struct __nat { int __for_bool_; };
2419
2420#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier31127cd2017-04-16 02:14:31 +00002421 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002422
2423 template <bool _Dummy>
2424 using _LValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002425 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002426
2427 template <bool _Dummy>
2428 using _GoodRValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002429 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002430
2431 template <bool _Dummy>
2432 using _BadRValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002433 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002434
2435 template <bool _Dummy, class _Deleter = typename __dependent_type<
2436 __identity<deleter_type>, _Dummy>::type>
2437 using _EnableIfDeleterDefaultConstructible =
2438 typename enable_if<is_default_constructible<_Deleter>::value &&
2439 !is_pointer<_Deleter>::value>::type;
2440
2441 template <class _ArgType>
2442 using _EnableIfDeleterConstructible =
2443 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2444
2445 template <class _UPtr, class _Up>
2446 using _EnableIfMoveConvertible = typename enable_if<
2447 is_convertible<typename _UPtr::pointer, pointer>::value &&
2448 !is_array<_Up>::value
2449 >::type;
2450
2451 template <class _UDel>
2452 using _EnableIfDeleterConvertible = typename enable_if<
2453 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2454 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2455 >::type;
2456
2457 template <class _UDel>
2458 using _EnableIfDeleterAssignable = typename enable_if<
2459 is_assignable<_Dp&, _UDel&&>::value
2460 >::type;
2461
2462public:
2463 template <bool _Dummy = true,
2464 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2465 _LIBCPP_INLINE_VISIBILITY
2466 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2467
2468 template <bool _Dummy = true,
2469 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2470 _LIBCPP_INLINE_VISIBILITY
2471 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2472
2473 template <bool _Dummy = true,
2474 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2475 _LIBCPP_INLINE_VISIBILITY
2476 explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2477
2478 template <bool _Dummy = true,
2479 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2480 _LIBCPP_INLINE_VISIBILITY
2481 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2482 : __ptr_(__p, __d) {}
2483
2484 template <bool _Dummy = true,
2485 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2486 _LIBCPP_INLINE_VISIBILITY
2487 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2488 : __ptr_(__p, _VSTD::move(__d)) {
2489 static_assert(!is_reference<deleter_type>::value,
2490 "rvalue deleter bound to reference");
2491 }
2492
2493 template <bool _Dummy = true,
2494 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2495 _LIBCPP_INLINE_VISIBILITY
2496 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2497
2498 _LIBCPP_INLINE_VISIBILITY
2499 unique_ptr(unique_ptr&& __u) noexcept
2500 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2501 }
2502
2503 template <class _Up, class _Ep,
2504 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2505 class = _EnableIfDeleterConvertible<_Ep>
2506 >
2507 _LIBCPP_INLINE_VISIBILITY
2508 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2509 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2510
2511#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2512 template <class _Up>
2513 _LIBCPP_INLINE_VISIBILITY
2514 unique_ptr(auto_ptr<_Up>&& __p,
2515 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2516 is_same<_Dp, default_delete<_Tp>>::value,
2517 __nat>::type = __nat()) _NOEXCEPT
2518 : __ptr_(__p.release()) {}
2519#endif
2520
2521 _LIBCPP_INLINE_VISIBILITY
2522 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2523 reset(__u.release());
2524 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2525 return *this;
2526 }
2527
2528 template <class _Up, class _Ep,
2529 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2530 class = _EnableIfDeleterAssignable<_Ep>
2531 >
2532 _LIBCPP_INLINE_VISIBILITY
2533 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2534 reset(__u.release());
2535 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2536 return *this;
2537 }
2538
2539#else // _LIBCPP_CXX03_LANG
2540private:
2541 unique_ptr(unique_ptr&);
2542 template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2543
2544 unique_ptr& operator=(unique_ptr&);
2545 template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2546
2547public:
2548 _LIBCPP_INLINE_VISIBILITY
2549 unique_ptr() : __ptr_(pointer())
2550 {
2551 static_assert(!is_pointer<deleter_type>::value,
2552 "unique_ptr constructed with null function pointer deleter");
2553 static_assert(is_default_constructible<deleter_type>::value,
2554 "unique_ptr::deleter_type is not default constructible");
2555 }
2556 _LIBCPP_INLINE_VISIBILITY
2557 unique_ptr(nullptr_t) : __ptr_(pointer())
2558 {
2559 static_assert(!is_pointer<deleter_type>::value,
2560 "unique_ptr constructed with null function pointer deleter");
2561 }
2562 _LIBCPP_INLINE_VISIBILITY
2563 explicit unique_ptr(pointer __p)
2564 : __ptr_(_VSTD::move(__p)) {
2565 static_assert(!is_pointer<deleter_type>::value,
2566 "unique_ptr constructed with null function pointer deleter");
2567 }
2568
2569 _LIBCPP_INLINE_VISIBILITY
2570 operator __rv<unique_ptr>() {
2571 return __rv<unique_ptr>(*this);
2572 }
2573
2574 _LIBCPP_INLINE_VISIBILITY
2575 unique_ptr(__rv<unique_ptr> __u)
2576 : __ptr_(__u->release(),
2577 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2578
2579 template <class _Up, class _Ep>
2580 _LIBCPP_INLINE_VISIBILITY
2581 typename enable_if<
2582 !is_array<_Up>::value &&
2583 is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2584 pointer>::value &&
2585 is_assignable<deleter_type&, _Ep&>::value,
2586 unique_ptr&>::type
2587 operator=(unique_ptr<_Up, _Ep> __u) {
2588 reset(__u.release());
2589 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2590 return *this;
2591 }
2592
2593 _LIBCPP_INLINE_VISIBILITY
2594 unique_ptr(pointer __p, deleter_type __d)
2595 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2596#endif // _LIBCPP_CXX03_LANG
2597
2598#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2599 template <class _Up>
2600 _LIBCPP_INLINE_VISIBILITY
2601 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2602 is_same<_Dp, default_delete<_Tp> >::value,
2603 unique_ptr&>::type
2604 operator=(auto_ptr<_Up> __p) {
2605 reset(__p.release());
2606 return *this;
2607 }
2608#endif
2609
2610 _LIBCPP_INLINE_VISIBILITY
2611 ~unique_ptr() { reset(); }
2612
2613 _LIBCPP_INLINE_VISIBILITY
2614 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2615 reset();
2616 return *this;
2617 }
2618
2619 _LIBCPP_INLINE_VISIBILITY
2620 typename add_lvalue_reference<_Tp>::type
2621 operator*() const {
2622 return *__ptr_.first();
2623 }
2624 _LIBCPP_INLINE_VISIBILITY
2625 pointer operator->() const _NOEXCEPT {
2626 return __ptr_.first();
2627 }
2628 _LIBCPP_INLINE_VISIBILITY
2629 pointer get() const _NOEXCEPT {
2630 return __ptr_.first();
2631 }
2632 _LIBCPP_INLINE_VISIBILITY
2633 deleter_type& get_deleter() _NOEXCEPT {
2634 return __ptr_.second();
2635 }
2636 _LIBCPP_INLINE_VISIBILITY
2637 const deleter_type& get_deleter() const _NOEXCEPT {
2638 return __ptr_.second();
2639 }
2640 _LIBCPP_INLINE_VISIBILITY
2641 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2642 return __ptr_.first() != nullptr;
2643 }
2644
2645 _LIBCPP_INLINE_VISIBILITY
2646 pointer release() _NOEXCEPT {
2647 pointer __t = __ptr_.first();
2648 __ptr_.first() = pointer();
2649 return __t;
2650 }
2651
2652 _LIBCPP_INLINE_VISIBILITY
2653 void reset(pointer __p = pointer()) _NOEXCEPT {
2654 pointer __tmp = __ptr_.first();
2655 __ptr_.first() = __p;
2656 if (__tmp)
2657 __ptr_.second()(__tmp);
2658 }
2659
2660 _LIBCPP_INLINE_VISIBILITY
2661 void swap(unique_ptr& __u) _NOEXCEPT {
2662 __ptr_.swap(__u.__ptr_);
2663 }
2664};
2665
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002666
Howard Hinnantc51e1022010-05-11 19:42:16 +00002667template <class _Tp, class _Dp>
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002668class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669public:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002670 typedef _Tp element_type;
2671 typedef _Dp deleter_type;
2672 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2673
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674private:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002675 __compressed_pair<pointer, deleter_type> __ptr_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002676
Eric Fiselier31127cd2017-04-16 02:14:31 +00002677 template <class _From>
2678 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002679
Eric Fiselier31127cd2017-04-16 02:14:31 +00002680 template <class _FromElem>
2681 struct _CheckArrayPointerConversion<_FromElem*>
2682 : integral_constant<bool,
2683 is_same<_FromElem*, pointer>::value ||
2684 (is_same<pointer, element_type*>::value &&
2685 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2686 >
2687 {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002688
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002689#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier31127cd2017-04-16 02:14:31 +00002690 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002691
2692 template <bool _Dummy>
2693 using _LValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002694 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002695
2696 template <bool _Dummy>
2697 using _GoodRValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002698 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002699
2700 template <bool _Dummy>
2701 using _BadRValRefType =
Eric Fiselier31127cd2017-04-16 02:14:31 +00002702 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002703
2704 template <bool _Dummy, class _Deleter = typename __dependent_type<
2705 __identity<deleter_type>, _Dummy>::type>
2706 using _EnableIfDeleterDefaultConstructible =
2707 typename enable_if<is_default_constructible<_Deleter>::value &&
2708 !is_pointer<_Deleter>::value>::type;
2709
2710 template <class _ArgType>
2711 using _EnableIfDeleterConstructible =
2712 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2713
2714 template <class _Pp>
2715 using _EnableIfPointerConvertible = typename enable_if<
Eric Fiselier31127cd2017-04-16 02:14:31 +00002716 _CheckArrayPointerConversion<_Pp>::value
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002717 >::type;
2718
2719 template <class _UPtr, class _Up,
2720 class _ElemT = typename _UPtr::element_type>
2721 using _EnableIfMoveConvertible = typename enable_if<
2722 is_array<_Up>::value &&
2723 is_same<pointer, element_type*>::value &&
2724 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2725 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2726 >::type;
2727
2728 template <class _UDel>
2729 using _EnableIfDeleterConvertible = typename enable_if<
2730 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2731 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2732 >::type;
2733
2734 template <class _UDel>
2735 using _EnableIfDeleterAssignable = typename enable_if<
2736 is_assignable<_Dp&, _UDel&&>::value
2737 >::type;
2738
Howard Hinnantc51e1022010-05-11 19:42:16 +00002739public:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002740 template <bool _Dummy = true,
2741 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2742 _LIBCPP_INLINE_VISIBILITY
2743 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002744
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002745 template <bool _Dummy = true,
2746 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2747 _LIBCPP_INLINE_VISIBILITY
2748 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002749
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002750 template <class _Pp, bool _Dummy = true,
2751 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2752 class = _EnableIfPointerConvertible<_Pp>>
2753 _LIBCPP_INLINE_VISIBILITY
2754 explicit unique_ptr(_Pp __p) noexcept
2755 : __ptr_(__p) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002757 template <class _Pp, bool _Dummy = true,
2758 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2759 class = _EnableIfPointerConvertible<_Pp>>
2760 _LIBCPP_INLINE_VISIBILITY
2761 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2762 : __ptr_(__p, __d) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002763
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002764 template <bool _Dummy = true,
2765 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2766 _LIBCPP_INLINE_VISIBILITY
2767 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2768 : __ptr_(nullptr, __d) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002769
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002770 template <class _Pp, bool _Dummy = true,
2771 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2772 class = _EnableIfPointerConvertible<_Pp>>
2773 _LIBCPP_INLINE_VISIBILITY
2774 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2775 : __ptr_(__p, _VSTD::move(__d)) {
2776 static_assert(!is_reference<deleter_type>::value,
2777 "rvalue deleter bound to reference");
2778 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002779
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002780 template <bool _Dummy = true,
2781 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2782 _LIBCPP_INLINE_VISIBILITY
2783 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2784 : __ptr_(nullptr, _VSTD::move(__d)) {
2785 static_assert(!is_reference<deleter_type>::value,
2786 "rvalue deleter bound to reference");
2787 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002788
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002789 template <class _Pp, bool _Dummy = true,
2790 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2791 class = _EnableIfPointerConvertible<_Pp>>
2792 _LIBCPP_INLINE_VISIBILITY
2793 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
Howard Hinnant4500ca52011-12-18 21:19:44 +00002794
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002795 _LIBCPP_INLINE_VISIBILITY
2796 unique_ptr(unique_ptr&& __u) noexcept
2797 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2798 }
Howard Hinnant4500ca52011-12-18 21:19:44 +00002799
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002800 _LIBCPP_INLINE_VISIBILITY
2801 unique_ptr& operator=(unique_ptr&& __u) noexcept {
2802 reset(__u.release());
2803 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2804 return *this;
2805 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002806
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002807 template <class _Up, class _Ep,
2808 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2809 class = _EnableIfDeleterConvertible<_Ep>
2810 >
2811 _LIBCPP_INLINE_VISIBILITY
2812 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
Eric Fiselier3827e6a2017-04-17 20:20:27 +00002813 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002814 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002815
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002816 template <class _Up, class _Ep,
2817 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2818 class = _EnableIfDeleterAssignable<_Ep>
2819 >
2820 _LIBCPP_INLINE_VISIBILITY
2821 unique_ptr&
2822 operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2823 reset(__u.release());
2824 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2825 return *this;
2826 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002827
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002828#else // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002829private:
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002830 template <class _Up> explicit unique_ptr(_Up);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002831
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002832 unique_ptr(unique_ptr&);
2833 template <class _Up> unique_ptr(unique_ptr<_Up>&);
2834
2835 unique_ptr& operator=(unique_ptr&);
2836 template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2837
2838 template <class _Up>
2839 unique_ptr(_Up __u,
2840 typename conditional<
2841 is_reference<deleter_type>::value, deleter_type,
2842 typename add_lvalue_reference<const deleter_type>::type>::type,
2843 typename enable_if<is_convertible<_Up, pointer>::value,
2844 __nat>::type = __nat());
2845public:
2846 _LIBCPP_INLINE_VISIBILITY
2847 unique_ptr() : __ptr_(pointer()) {
2848 static_assert(!is_pointer<deleter_type>::value,
2849 "unique_ptr constructed with null function pointer deleter");
2850 }
2851 _LIBCPP_INLINE_VISIBILITY
2852 unique_ptr(nullptr_t) : __ptr_(pointer()) {
2853 static_assert(!is_pointer<deleter_type>::value,
2854 "unique_ptr constructed with null function pointer deleter");
2855 }
2856
2857 _LIBCPP_INLINE_VISIBILITY
2858 explicit unique_ptr(pointer __p) : __ptr_(__p) {
2859 static_assert(!is_pointer<deleter_type>::value,
2860 "unique_ptr constructed with null function pointer deleter");
2861 }
2862
2863 _LIBCPP_INLINE_VISIBILITY
2864 unique_ptr(pointer __p, deleter_type __d)
2865 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2866
2867 _LIBCPP_INLINE_VISIBILITY
2868 unique_ptr(nullptr_t, deleter_type __d)
2869 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2870
2871 _LIBCPP_INLINE_VISIBILITY
2872 operator __rv<unique_ptr>() {
2873 return __rv<unique_ptr>(*this);
2874 }
2875
2876 _LIBCPP_INLINE_VISIBILITY
2877 unique_ptr(__rv<unique_ptr> __u)
2878 : __ptr_(__u->release(),
2879 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2880
2881 _LIBCPP_INLINE_VISIBILITY
2882 unique_ptr& operator=(__rv<unique_ptr> __u) {
2883 reset(__u->release());
2884 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2885 return *this;
2886 }
2887
2888#endif // _LIBCPP_CXX03_LANG
2889
2890public:
2891 _LIBCPP_INLINE_VISIBILITY
2892 ~unique_ptr() { reset(); }
2893
2894 _LIBCPP_INLINE_VISIBILITY
2895 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2896 reset();
2897 return *this;
2898 }
2899
2900 _LIBCPP_INLINE_VISIBILITY
2901 typename add_lvalue_reference<_Tp>::type
2902 operator[](size_t __i) const {
2903 return __ptr_.first()[__i];
2904 }
2905 _LIBCPP_INLINE_VISIBILITY
2906 pointer get() const _NOEXCEPT {
2907 return __ptr_.first();
2908 }
2909
2910 _LIBCPP_INLINE_VISIBILITY
2911 deleter_type& get_deleter() _NOEXCEPT {
2912 return __ptr_.second();
2913 }
2914
2915 _LIBCPP_INLINE_VISIBILITY
2916 const deleter_type& get_deleter() const _NOEXCEPT {
2917 return __ptr_.second();
2918 }
2919 _LIBCPP_INLINE_VISIBILITY
2920 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2921 return __ptr_.first() != nullptr;
2922 }
2923
2924 _LIBCPP_INLINE_VISIBILITY
2925 pointer release() _NOEXCEPT {
2926 pointer __t = __ptr_.first();
2927 __ptr_.first() = pointer();
2928 return __t;
2929 }
2930
2931 template <class _Pp>
2932 _LIBCPP_INLINE_VISIBILITY
2933 typename enable_if<
Eric Fiselier31127cd2017-04-16 02:14:31 +00002934 _CheckArrayPointerConversion<_Pp>::value
Eric Fiselierfecf9ea2017-04-16 01:51:04 +00002935 >::type
2936 reset(_Pp __p) _NOEXCEPT {
2937 pointer __tmp = __ptr_.first();
2938 __ptr_.first() = __p;
2939 if (__tmp)
2940 __ptr_.second()(__tmp);
2941 }
2942
2943 _LIBCPP_INLINE_VISIBILITY
2944 void reset(nullptr_t = nullptr) _NOEXCEPT {
2945 pointer __tmp = __ptr_.first();
2946 __ptr_.first() = nullptr;
2947 if (__tmp)
2948 __ptr_.second()(__tmp);
2949 }
2950
2951 _LIBCPP_INLINE_VISIBILITY
2952 void swap(unique_ptr& __u) _NOEXCEPT {
2953 __ptr_.swap(__u.__ptr_);
2954 }
2955
Howard Hinnantc51e1022010-05-11 19:42:16 +00002956};
2957
2958template <class _Tp, class _Dp>
2959inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier6bfed252016-04-21 23:38:59 +00002960typename enable_if<
2961 __is_swappable<_Dp>::value,
2962 void
2963>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00002964swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002965
2966template <class _T1, class _D1, class _T2, class _D2>
2967inline _LIBCPP_INLINE_VISIBILITY
2968bool
2969operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2970
2971template <class _T1, class _D1, class _T2, class _D2>
2972inline _LIBCPP_INLINE_VISIBILITY
2973bool
2974operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2975
2976template <class _T1, class _D1, class _T2, class _D2>
2977inline _LIBCPP_INLINE_VISIBILITY
2978bool
Howard Hinnantb17caf92012-02-21 21:02:58 +00002979operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2980{
2981 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2982 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselierf8898c82015-02-05 23:01:40 +00002983 typedef typename common_type<_P1, _P2>::type _Vp;
2984 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnantb17caf92012-02-21 21:02:58 +00002985}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986
2987template <class _T1, class _D1, class _T2, class _D2>
2988inline _LIBCPP_INLINE_VISIBILITY
2989bool
2990operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2991
2992template <class _T1, class _D1, class _T2, class _D2>
2993inline _LIBCPP_INLINE_VISIBILITY
2994bool
2995operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2996
2997template <class _T1, class _D1, class _T2, class _D2>
2998inline _LIBCPP_INLINE_VISIBILITY
2999bool
3000operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
3001
Howard Hinnantb17caf92012-02-21 21:02:58 +00003002template <class _T1, class _D1>
3003inline _LIBCPP_INLINE_VISIBILITY
3004bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003005operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003006{
3007 return !__x;
3008}
3009
3010template <class _T1, class _D1>
3011inline _LIBCPP_INLINE_VISIBILITY
3012bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003013operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003014{
3015 return !__x;
3016}
3017
3018template <class _T1, class _D1>
3019inline _LIBCPP_INLINE_VISIBILITY
3020bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003021operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003022{
3023 return static_cast<bool>(__x);
3024}
3025
3026template <class _T1, class _D1>
3027inline _LIBCPP_INLINE_VISIBILITY
3028bool
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003029operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnantb17caf92012-02-21 21:02:58 +00003030{
3031 return static_cast<bool>(__x);
3032}
3033
3034template <class _T1, class _D1>
3035inline _LIBCPP_INLINE_VISIBILITY
3036bool
3037operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3038{
3039 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3040 return less<_P1>()(__x.get(), nullptr);
3041}
3042
3043template <class _T1, class _D1>
3044inline _LIBCPP_INLINE_VISIBILITY
3045bool
3046operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3047{
3048 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3049 return less<_P1>()(nullptr, __x.get());
3050}
3051
3052template <class _T1, class _D1>
3053inline _LIBCPP_INLINE_VISIBILITY
3054bool
3055operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3056{
3057 return nullptr < __x;
3058}
3059
3060template <class _T1, class _D1>
3061inline _LIBCPP_INLINE_VISIBILITY
3062bool
3063operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3064{
3065 return __x < nullptr;
3066}
3067
3068template <class _T1, class _D1>
3069inline _LIBCPP_INLINE_VISIBILITY
3070bool
3071operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3072{
3073 return !(nullptr < __x);
3074}
3075
3076template <class _T1, class _D1>
3077inline _LIBCPP_INLINE_VISIBILITY
3078bool
3079operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3080{
3081 return !(__x < nullptr);
3082}
3083
3084template <class _T1, class _D1>
3085inline _LIBCPP_INLINE_VISIBILITY
3086bool
3087operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3088{
3089 return !(__x < nullptr);
3090}
3091
3092template <class _T1, class _D1>
3093inline _LIBCPP_INLINE_VISIBILITY
3094bool
3095operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3096{
3097 return !(nullptr < __x);
3098}
3099
Howard Hinnant9e028f12012-05-01 15:37:54 +00003100#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3101
3102template <class _Tp, class _Dp>
3103inline _LIBCPP_INLINE_VISIBILITY
3104unique_ptr<_Tp, _Dp>
3105move(unique_ptr<_Tp, _Dp>& __t)
3106{
3107 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3108}
3109
3110#endif
3111
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003112#if _LIBCPP_STD_VER > 11
3113
3114template<class _Tp>
3115struct __unique_if
3116{
3117 typedef unique_ptr<_Tp> __unique_single;
3118};
3119
3120template<class _Tp>
3121struct __unique_if<_Tp[]>
3122{
3123 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3124};
3125
3126template<class _Tp, size_t _Np>
3127struct __unique_if<_Tp[_Np]>
3128{
3129 typedef void __unique_array_known_bound;
3130};
3131
3132template<class _Tp, class... _Args>
Marshall Clow724e3df2013-07-02 20:06:09 +00003133inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003134typename __unique_if<_Tp>::__unique_single
3135make_unique(_Args&&... __args)
3136{
3137 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3138}
3139
3140template<class _Tp>
Marshall Clow724e3df2013-07-02 20:06:09 +00003141inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow9e8f4a92013-07-01 18:16:03 +00003142typename __unique_if<_Tp>::__unique_array_unknown_bound
3143make_unique(size_t __n)
3144{
3145 typedef typename remove_extent<_Tp>::type _Up;
3146 return unique_ptr<_Tp>(new _Up[__n]());
3147}
3148
3149template<class _Tp, class... _Args>
3150 typename __unique_if<_Tp>::__unique_array_known_bound
3151 make_unique(_Args&&...) = delete;
3152
3153#endif // _LIBCPP_STD_VER > 11
3154
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003155template <class _Tp, class _Dp>
Eric Fiselier698a97b2017-01-21 00:02:12 +00003156#ifdef _LIBCPP_CXX03_LANG
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003157struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
Eric Fiselier698a97b2017-01-21 00:02:12 +00003158#else
3159struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3160 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3161#endif
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003162{
3163 typedef unique_ptr<_Tp, _Dp> argument_type;
3164 typedef size_t result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003165 _LIBCPP_INLINE_VISIBILITY
Marshall Clow49036892017-03-23 02:40:28 +00003166 result_type operator()(const argument_type& __ptr) const
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003167 {
3168 typedef typename argument_type::pointer pointer;
3169 return hash<pointer>()(__ptr.get());
3170 }
3171};
3172
Howard Hinnantc51e1022010-05-11 19:42:16 +00003173struct __destruct_n
3174{
3175private:
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003176 size_t __size_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003177
3178 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003179 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003180 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003181
3182 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003183 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003184 {}
3185
Howard Hinnant719bda32011-05-28 14:41:13 +00003186 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003187 {++__size_;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003188 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003189 {}
3190
Howard Hinnant719bda32011-05-28 14:41:13 +00003191 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003192 {__size_ = __s;}
Howard Hinnant719bda32011-05-28 14:41:13 +00003193 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003194 {}
3195public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003196 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00003197 : __size_(__s) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003198
3199 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003200 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003201 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003202
3203 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003204 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003205 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003206
3207 template <class _Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00003208 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnanta9a897e2010-11-19 22:17:28 +00003209 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003210};
3211
3212template <class _Alloc>
3213class __allocator_destructor
3214{
3215 typedef allocator_traits<_Alloc> __alloc_traits;
3216public:
3217 typedef typename __alloc_traits::pointer pointer;
3218 typedef typename __alloc_traits::size_type size_type;
3219private:
3220 _Alloc& __alloc_;
3221 size_type __s_;
3222public:
3223 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant719bda32011-05-28 14:41:13 +00003224 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003225 : __alloc_(__a), __s_(__s) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003227 void operator()(pointer __p) _NOEXCEPT
3228 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003229};
3230
3231template <class _InputIterator, class _ForwardIterator>
3232_ForwardIterator
3233uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3234{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003235 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003236#ifndef _LIBCPP_NO_EXCEPTIONS
3237 _ForwardIterator __s = __r;
3238 try
3239 {
3240#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003241 for (; __f != __l; ++__f, (void) ++__r)
3242 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003243#ifndef _LIBCPP_NO_EXCEPTIONS
3244 }
3245 catch (...)
3246 {
3247 for (; __s != __r; ++__s)
3248 __s->~value_type();
3249 throw;
3250 }
3251#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003252 return __r;
3253}
3254
3255template <class _InputIterator, class _Size, class _ForwardIterator>
3256_ForwardIterator
3257uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3258{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003259 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003260#ifndef _LIBCPP_NO_EXCEPTIONS
3261 _ForwardIterator __s = __r;
3262 try
3263 {
3264#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003265 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3266 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003267#ifndef _LIBCPP_NO_EXCEPTIONS
3268 }
3269 catch (...)
3270 {
3271 for (; __s != __r; ++__s)
3272 __s->~value_type();
3273 throw;
3274 }
3275#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003276 return __r;
3277}
3278
3279template <class _ForwardIterator, class _Tp>
3280void
3281uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3282{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003283 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003284#ifndef _LIBCPP_NO_EXCEPTIONS
3285 _ForwardIterator __s = __f;
3286 try
3287 {
3288#endif
3289 for (; __f != __l; ++__f)
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003290 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003291#ifndef _LIBCPP_NO_EXCEPTIONS
3292 }
3293 catch (...)
3294 {
3295 for (; __s != __f; ++__s)
3296 __s->~value_type();
3297 throw;
3298 }
3299#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003300}
3301
3302template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant3c811092010-11-18 16:13:03 +00003303_ForwardIterator
Howard Hinnantc51e1022010-05-11 19:42:16 +00003304uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3305{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003306 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003307#ifndef _LIBCPP_NO_EXCEPTIONS
3308 _ForwardIterator __s = __f;
3309 try
3310 {
3311#endif
Marshall Clow5e9cb8f2015-05-19 15:01:48 +00003312 for (; __n > 0; ++__f, (void) --__n)
3313 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnant2fa038c2011-12-29 17:45:35 +00003314#ifndef _LIBCPP_NO_EXCEPTIONS
3315 }
3316 catch (...)
3317 {
3318 for (; __s != __f; ++__s)
3319 __s->~value_type();
3320 throw;
3321 }
3322#endif
Howard Hinnant3c811092010-11-18 16:13:03 +00003323 return __f;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003324}
3325
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003326#if _LIBCPP_STD_VER > 14
3327
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003328template <class _Tp>
3329inline _LIBCPP_INLINE_VISIBILITY
3330void destroy_at(_Tp* __loc) {
3331 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3332 __loc->~_Tp();
3333}
3334
3335template <class _ForwardIterator>
3336inline _LIBCPP_INLINE_VISIBILITY
3337void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3338 for (; __first != __last; ++__first)
3339 _VSTD::destroy_at(_VSTD::addressof(*__first));
3340}
3341
3342template <class _ForwardIterator, class _Size>
3343inline _LIBCPP_INLINE_VISIBILITY
3344_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3345 for (; __n > 0; (void)++__first, --__n)
3346 _VSTD::destroy_at(_VSTD::addressof(*__first));
3347 return __first;
3348}
3349
Eric Fiselier290c07c2016-10-11 21:13:44 +00003350template <class _ForwardIterator>
3351inline _LIBCPP_INLINE_VISIBILITY
3352void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3353 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3354 auto __idx = __first;
3355#ifndef _LIBCPP_NO_EXCEPTIONS
3356 try {
3357#endif
3358 for (; __idx != __last; ++__idx)
3359 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3360#ifndef _LIBCPP_NO_EXCEPTIONS
3361 } catch (...) {
3362 _VSTD::destroy(__first, __idx);
3363 throw;
3364 }
3365#endif
3366}
3367
3368template <class _ForwardIterator, class _Size>
3369inline _LIBCPP_INLINE_VISIBILITY
3370_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3371 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3372 auto __idx = __first;
3373#ifndef _LIBCPP_NO_EXCEPTIONS
3374 try {
3375#endif
3376 for (; __n > 0; (void)++__idx, --__n)
3377 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3378 return __idx;
3379#ifndef _LIBCPP_NO_EXCEPTIONS
3380 } catch (...) {
3381 _VSTD::destroy(__first, __idx);
3382 throw;
3383 }
3384#endif
3385}
3386
3387
3388template <class _ForwardIterator>
3389inline _LIBCPP_INLINE_VISIBILITY
3390void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3391 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3392 auto __idx = __first;
3393#ifndef _LIBCPP_NO_EXCEPTIONS
3394 try {
3395#endif
3396 for (; __idx != __last; ++__idx)
3397 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3398#ifndef _LIBCPP_NO_EXCEPTIONS
3399 } catch (...) {
3400 _VSTD::destroy(__first, __idx);
3401 throw;
3402 }
3403#endif
3404}
3405
3406template <class _ForwardIterator, class _Size>
3407inline _LIBCPP_INLINE_VISIBILITY
3408_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3409 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3410 auto __idx = __first;
3411#ifndef _LIBCPP_NO_EXCEPTIONS
3412 try {
3413#endif
3414 for (; __n > 0; (void)++__idx, --__n)
3415 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3416 return __idx;
3417#ifndef _LIBCPP_NO_EXCEPTIONS
3418 } catch (...) {
3419 _VSTD::destroy(__first, __idx);
3420 throw;
3421 }
3422#endif
3423}
3424
3425
3426template <class _InputIt, class _ForwardIt>
3427inline _LIBCPP_INLINE_VISIBILITY
3428_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3429 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3430 auto __idx = __first_res;
3431#ifndef _LIBCPP_NO_EXCEPTIONS
3432 try {
3433#endif
3434 for (; __first != __last; (void)++__idx, ++__first)
3435 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3436 return __idx;
3437#ifndef _LIBCPP_NO_EXCEPTIONS
3438 } catch (...) {
3439 _VSTD::destroy(__first_res, __idx);
3440 throw;
3441 }
3442#endif
3443}
3444
3445template <class _InputIt, class _Size, class _ForwardIt>
3446inline _LIBCPP_INLINE_VISIBILITY
3447pair<_InputIt, _ForwardIt>
3448uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3449 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3450 auto __idx = __first_res;
3451#ifndef _LIBCPP_NO_EXCEPTIONS
3452 try {
3453#endif
3454 for (; __n > 0; ++__idx, (void)++__first, --__n)
3455 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3456 return {__first, __idx};
3457#ifndef _LIBCPP_NO_EXCEPTIONS
3458 } catch (...) {
3459 _VSTD::destroy(__first_res, __idx);
3460 throw;
3461 }
3462#endif
3463}
3464
3465
Eric Fiselier383f6cf2016-07-24 03:51:39 +00003466#endif // _LIBCPP_STD_VER > 14
3467
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003468// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3469// should be sufficient for thread safety.
Eric Fiselier5d604012017-02-17 08:37:03 +00003470// See https://bugs.llvm.org/show_bug.cgi?id=22803
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003471#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3472 && defined(__ATOMIC_RELAXED) \
3473 && defined(__ATOMIC_ACQ_REL)
3474# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3475#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3476# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3477#endif
3478
3479template <class _Tp>
3480inline _LIBCPP_INLINE_VISIBILITY _Tp
3481__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3482{
3483#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3484 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3485#else
3486 return __t += 1;
3487#endif
3488}
3489
3490template <class _Tp>
3491inline _LIBCPP_INLINE_VISIBILITY _Tp
3492__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3493{
3494#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3495 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3496#else
3497 return __t -= 1;
3498#endif
3499}
3500
Howard Hinnant756c69b2010-09-22 16:48:34 +00003501class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003502 : public std::exception
3503{
3504public:
Howard Hinnant719bda32011-05-28 14:41:13 +00003505 virtual ~bad_weak_ptr() _NOEXCEPT;
3506 virtual const char* what() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003507};
3508
Marshall Clow8fea1612016-08-25 15:09:01 +00003509_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3510void __throw_bad_weak_ptr()
3511{
3512#ifndef _LIBCPP_NO_EXCEPTIONS
3513 throw bad_weak_ptr();
3514#else
3515 _VSTD::abort();
3516#endif
3517}
3518
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003519template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003520
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003521class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003522{
3523 __shared_count(const __shared_count&);
3524 __shared_count& operator=(const __shared_count&);
3525
3526protected:
3527 long __shared_owners_;
3528 virtual ~__shared_count();
3529private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003530 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003531
3532public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003534 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003535 : __shared_owners_(__refs) {}
3536
Eric Fiselier98848572017-01-17 03:16:26 +00003537#if defined(_LIBCPP_BUILDING_MEMORY) && \
3538 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliere0700ff2017-01-17 03:05:31 +00003539 void __add_shared() _NOEXCEPT;
3540 bool __release_shared() _NOEXCEPT;
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003541#else
3542 _LIBCPP_INLINE_VISIBILITY
3543 void __add_shared() _NOEXCEPT {
3544 __libcpp_atomic_refcount_increment(__shared_owners_);
3545 }
3546 _LIBCPP_INLINE_VISIBILITY
3547 bool __release_shared() _NOEXCEPT {
3548 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3549 __on_zero_shared();
3550 return true;
3551 }
3552 return false;
3553 }
3554#endif
Howard Hinnant756c69b2010-09-22 16:48:34 +00003555 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier89659d12015-07-07 00:27:16 +00003556 long use_count() const _NOEXCEPT {
3557 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3558 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003559};
3560
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00003561class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnantc51e1022010-05-11 19:42:16 +00003562 : private __shared_count
3563{
3564 long __shared_weak_owners_;
3565
3566public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003568 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003569 : __shared_count(__refs),
3570 __shared_weak_owners_(__refs) {}
3571protected:
3572 virtual ~__shared_weak_count();
3573
3574public:
Eric Fiselier98848572017-01-17 03:16:26 +00003575#if defined(_LIBCPP_BUILDING_MEMORY) && \
3576 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliere0700ff2017-01-17 03:05:31 +00003577 void __add_shared() _NOEXCEPT;
3578 void __add_weak() _NOEXCEPT;
3579 void __release_shared() _NOEXCEPT;
Kevin Hu4bdc8a02017-01-17 02:46:33 +00003580#else
3581 _LIBCPP_INLINE_VISIBILITY
3582 void __add_shared() _NOEXCEPT {
3583 __shared_count::__add_shared();
3584 }
3585 _LIBCPP_INLINE_VISIBILITY
3586 void __add_weak() _NOEXCEPT {
3587 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3588 }
3589 _LIBCPP_INLINE_VISIBILITY
3590 void __release_shared() _NOEXCEPT {
3591 if (__shared_count::__release_shared())
3592 __release_weak();
3593 }
3594#endif
Howard Hinnant719bda32011-05-28 14:41:13 +00003595 void __release_weak() _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00003596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003597 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3598 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003599
Howard Hinnant807d6332013-02-25 15:50:36 +00003600 // Define the function out only if we build static libc++ without RTTI.
3601 // Otherwise we may break clients who need to compile their projects with
3602 // -fno-rtti and yet link against a libc++.dylib compiled
3603 // without -fno-rtti.
3604#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant719bda32011-05-28 14:41:13 +00003605 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant807d6332013-02-25 15:50:36 +00003606#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003608 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003609};
3610
3611template <class _Tp, class _Dp, class _Alloc>
3612class __shared_ptr_pointer
3613 : public __shared_weak_count
3614{
3615 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3616public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003618 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003619 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003620
Howard Hinnant72f73582010-08-11 17:04:31 +00003621#ifndef _LIBCPP_NO_RTTI
Howard Hinnant719bda32011-05-28 14:41:13 +00003622 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant72f73582010-08-11 17:04:31 +00003623#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003624
3625private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003626 virtual void __on_zero_shared() _NOEXCEPT;
3627 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003628};
3629
Howard Hinnant72f73582010-08-11 17:04:31 +00003630#ifndef _LIBCPP_NO_RTTI
3631
Howard Hinnantc51e1022010-05-11 19:42:16 +00003632template <class _Tp, class _Dp, class _Alloc>
3633const void*
Howard Hinnant719bda32011-05-28 14:41:13 +00003634__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003635{
Eric Fiselierc7490d02017-05-04 01:06:56 +00003636 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003637}
3638
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003639#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00003640
Howard Hinnantc51e1022010-05-11 19:42:16 +00003641template <class _Tp, class _Dp, class _Alloc>
3642void
Howard Hinnant719bda32011-05-28 14:41:13 +00003643__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003644{
3645 __data_.first().second()(__data_.first().first());
3646 __data_.first().second().~_Dp();
3647}
3648
3649template <class _Tp, class _Dp, class _Alloc>
3650void
Howard Hinnant719bda32011-05-28 14:41:13 +00003651__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003652{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003653 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3654 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003655 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3656
Eric Fiselierf8898c82015-02-05 23:01:40 +00003657 _Al __a(__data_.second());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003658 __data_.second().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003659 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003660}
3661
3662template <class _Tp, class _Alloc>
3663class __shared_ptr_emplace
3664 : public __shared_weak_count
3665{
3666 __compressed_pair<_Alloc, _Tp> __data_;
3667public:
3668#ifndef _LIBCPP_HAS_NO_VARIADICS
3669
Howard Hinnant756c69b2010-09-22 16:48:34 +00003670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003671 __shared_ptr_emplace(_Alloc __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003672 : __data_(_VSTD::move(__a)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003673
3674 template <class ..._Args>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003676 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnant83b1c052011-12-19 17:58:44 +00003677 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3678 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003679
3680#else // _LIBCPP_HAS_NO_VARIADICS
3681
Howard Hinnant756c69b2010-09-22 16:48:34 +00003682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003683 __shared_ptr_emplace(_Alloc __a)
3684 : __data_(__a) {}
3685
3686 template <class _A0>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003688 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3689 : __data_(__a, _Tp(__a0)) {}
3690
3691 template <class _A0, class _A1>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003693 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3694 : __data_(__a, _Tp(__a0, __a1)) {}
3695
3696 template <class _A0, class _A1, class _A2>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003698 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3699 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3700
3701#endif // _LIBCPP_HAS_NO_VARIADICS
3702
3703private:
Howard Hinnant719bda32011-05-28 14:41:13 +00003704 virtual void __on_zero_shared() _NOEXCEPT;
3705 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003706public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00003707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003708 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003709};
3710
3711template <class _Tp, class _Alloc>
3712void
Howard Hinnant719bda32011-05-28 14:41:13 +00003713__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003714{
3715 __data_.second().~_Tp();
3716}
3717
3718template <class _Tp, class _Alloc>
3719void
Howard Hinnant719bda32011-05-28 14:41:13 +00003720__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003721{
Eric Fiselierf8898c82015-02-05 23:01:40 +00003722 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3723 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003724 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselierf8898c82015-02-05 23:01:40 +00003725 _Al __a(__data_.first());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003726 __data_.first().~_Alloc();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00003727 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003728}
3729
Erik Pilkington2a398762017-05-25 15:43:31 +00003730struct __shared_ptr_dummy_rebind_allocator_type;
3731template <>
3732class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3733{
3734public:
3735 template <class _Other>
3736 struct rebind
3737 {
3738 typedef allocator<_Other> other;
3739 };
3740};
3741
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003742template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003743
3744template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00003745class _LIBCPP_TEMPLATE_VIS shared_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00003746{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003747public:
3748 typedef _Tp element_type;
Marshall Clow7e384b72017-01-10 16:59:33 +00003749
Eric Fiselierae5b6672016-06-27 01:02:43 +00003750#if _LIBCPP_STD_VER > 14
3751 typedef weak_ptr<_Tp> weak_type;
3752#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003753private:
3754 element_type* __ptr_;
3755 __shared_weak_count* __cntrl_;
3756
3757 struct __nat {int __for_bool_;};
3758public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003760 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00003762 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chiend435f8b2014-01-31 09:30:46 +00003763 template<class _Yp>
3764 explicit shared_ptr(_Yp* __p,
3765 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3766 template<class _Yp, class _Dp>
3767 shared_ptr(_Yp* __p, _Dp __d,
3768 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3769 template<class _Yp, class _Dp, class _Alloc>
3770 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3771 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003772 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3773 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003774 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003776 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003777 template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00003779 shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003780 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00003781 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003782#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003784 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003785 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003786 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant719bda32011-05-28 14:41:13 +00003787 _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003788#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003789 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00003790 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
Marshall Clowb22274f2017-01-24 22:22:33 +00003791#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant74279a52010-09-04 23:28:19 +00003792#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003793 template<class _Yp>
3794 shared_ptr(auto_ptr<_Yp>&& __r,
3795 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003796#else
Logan Chiend435f8b2014-01-31 09:30:46 +00003797 template<class _Yp>
3798 shared_ptr(auto_ptr<_Yp> __r,
3799 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003800#endif
Marshall Clowb22274f2017-01-24 22:22:33 +00003801#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00003802#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003803 template <class _Yp, class _Dp>
3804 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3805 typename enable_if
3806 <
3807 !is_lvalue_reference<_Dp>::value &&
3808 !is_array<_Yp>::value &&
3809 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3810 __nat
3811 >::type = __nat());
3812 template <class _Yp, class _Dp>
3813 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3814 typename enable_if
3815 <
3816 is_lvalue_reference<_Dp>::value &&
3817 !is_array<_Yp>::value &&
3818 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3819 __nat
3820 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003821#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00003822 template <class _Yp, class _Dp>
3823 shared_ptr(unique_ptr<_Yp, _Dp>,
3824 typename enable_if
3825 <
3826 !is_lvalue_reference<_Dp>::value &&
3827 !is_array<_Yp>::value &&
3828 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3829 __nat
3830 >::type = __nat());
3831 template <class _Yp, class _Dp>
3832 shared_ptr(unique_ptr<_Yp, _Dp>,
3833 typename enable_if
3834 <
3835 is_lvalue_reference<_Dp>::value &&
3836 !is_array<_Yp>::value &&
3837 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3838 __nat
3839 >::type = __nat());
Howard Hinnant74279a52010-09-04 23:28:19 +00003840#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00003841
3842 ~shared_ptr();
3843
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003845 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003846 template<class _Yp>
3847 typename enable_if
3848 <
3849 is_convertible<_Yp*, element_type*>::value,
3850 shared_ptr&
3851 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003853 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant74279a52010-09-04 23:28:19 +00003854#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003856 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003857 template<class _Yp>
3858 typename enable_if
3859 <
3860 is_convertible<_Yp*, element_type*>::value,
3861 shared_ptr<_Tp>&
3862 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003864 operator=(shared_ptr<_Yp>&& __r);
Marshall Clowb22274f2017-01-24 22:22:33 +00003865#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003866 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00003867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003868 typename enable_if
3869 <
3870 !is_array<_Yp>::value &&
3871 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00003872 shared_ptr
3873 >::type&
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003874 operator=(auto_ptr<_Yp>&& __r);
Marshall Clowb22274f2017-01-24 22:22:33 +00003875#endif
Howard Hinnant74279a52010-09-04 23:28:19 +00003876#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Marshall Clowb22274f2017-01-24 22:22:33 +00003877#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003878 template<class _Yp>
Eric Fiselier6585c752016-04-21 22:54:21 +00003879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003880 typename enable_if
3881 <
3882 !is_array<_Yp>::value &&
3883 is_convertible<_Yp*, element_type*>::value,
3884 shared_ptr&
3885 >::type
3886 operator=(auto_ptr<_Yp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003887#endif
Marshall Clowb22274f2017-01-24 22:22:33 +00003888#endif
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003889 template <class _Yp, class _Dp>
3890 typename enable_if
3891 <
3892 !is_array<_Yp>::value &&
3893 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3894 shared_ptr&
3895 >::type
Howard Hinnant74279a52010-09-04 23:28:19 +00003896#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003898 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant74279a52010-09-04 23:28:19 +00003899#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov03192872015-12-09 22:32:36 +00003900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003901 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003902#endif
3903
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003905 void swap(shared_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003907 void reset() _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003908 template<class _Yp>
3909 typename enable_if
3910 <
3911 is_convertible<_Yp*, element_type*>::value,
3912 void
3913 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003915 reset(_Yp* __p);
3916 template<class _Yp, class _Dp>
3917 typename enable_if
3918 <
3919 is_convertible<_Yp*, element_type*>::value,
3920 void
3921 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003923 reset(_Yp* __p, _Dp __d);
3924 template<class _Yp, class _Dp, class _Alloc>
3925 typename enable_if
3926 <
3927 is_convertible<_Yp*, element_type*>::value,
3928 void
3929 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00003930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00003931 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003932
Howard Hinnant756c69b2010-09-22 16:48:34 +00003933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003934 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003936 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3937 {return *__ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003939 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003941 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003943 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00003944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00003945 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003946 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003947 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00003948 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003949 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantc834c512011-11-29 18:15:50 +00003950 template <class _Up>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003951 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00003952 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003953 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnant9fa30202012-07-30 01:40:57 +00003954 _LIBCPP_INLINE_VISIBILITY
3955 bool
3956 __owner_equivalent(const shared_ptr& __p) const
3957 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003958
Howard Hinnant72f73582010-08-11 17:04:31 +00003959#ifndef _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003960 template <class _Dp>
Howard Hinnant756c69b2010-09-22 16:48:34 +00003961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00003962 _Dp* __get_deleter() const _NOEXCEPT
Marshall Clow31350ab2017-06-14 16:54:43 +00003963 {return static_cast<_Dp*>(__cntrl_
Aditya Kumar7c5db692017-08-20 10:38:55 +00003964 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
Marshall Clow31350ab2017-06-14 16:54:43 +00003965 : nullptr);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00003966#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00003967
3968#ifndef _LIBCPP_HAS_NO_VARIADICS
3969
3970 template<class ..._Args>
3971 static
3972 shared_ptr<_Tp>
3973 make_shared(_Args&& ...__args);
3974
3975 template<class _Alloc, class ..._Args>
3976 static
3977 shared_ptr<_Tp>
3978 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3979
3980#else // _LIBCPP_HAS_NO_VARIADICS
3981
3982 static shared_ptr<_Tp> make_shared();
3983
3984 template<class _A0>
3985 static shared_ptr<_Tp> make_shared(_A0&);
3986
3987 template<class _A0, class _A1>
3988 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3989
3990 template<class _A0, class _A1, class _A2>
3991 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3992
3993 template<class _Alloc>
3994 static shared_ptr<_Tp>
3995 allocate_shared(const _Alloc& __a);
3996
3997 template<class _Alloc, class _A0>
3998 static shared_ptr<_Tp>
3999 allocate_shared(const _Alloc& __a, _A0& __a0);
4000
4001 template<class _Alloc, class _A0, class _A1>
4002 static shared_ptr<_Tp>
4003 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4004
4005 template<class _Alloc, class _A0, class _A1, class _A2>
4006 static shared_ptr<_Tp>
4007 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4008
4009#endif // _LIBCPP_HAS_NO_VARIADICS
4010
4011private:
Erik Pilkington2a398762017-05-25 15:43:31 +00004012 template <class _Yp, bool = is_function<_Yp>::value>
4013 struct __shared_ptr_default_allocator
4014 {
4015 typedef allocator<_Yp> type;
4016 };
4017
4018 template <class _Yp>
4019 struct __shared_ptr_default_allocator<_Yp, true>
4020 {
4021 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
4022 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00004023
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004024 template <class _Yp, class _OrigPtr>
Howard Hinnant756c69b2010-09-22 16:48:34 +00004025 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier30d5ac62017-05-10 19:35:49 +00004026 typename enable_if<is_convertible<_OrigPtr*,
4027 const enable_shared_from_this<_Yp>*
4028 >::value,
4029 void>::type
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004030 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4031 _OrigPtr* __ptr) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004032 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004033 typedef typename remove_cv<_Yp>::type _RawYp;
Eric Fiselier84006862016-06-02 00:15:35 +00004034 if (__e && __e->__weak_this_.expired())
Marshall Clow99442fc2015-06-19 15:54:13 +00004035 {
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004036 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4037 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
Marshall Clow99442fc2015-06-19 15:54:13 +00004038 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004039 }
4040
Erik Pilkington2a398762017-05-25 15:43:31 +00004041 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00004042
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00004043 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4044 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004045};
4046
Eric Fiselier30d5ac62017-05-10 19:35:49 +00004047
Howard Hinnantc51e1022010-05-11 19:42:16 +00004048template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004049inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004050_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004051shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004052 : __ptr_(0),
4053 __cntrl_(0)
4054{
4055}
4056
4057template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004058inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00004059_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00004060shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004061 : __ptr_(0),
4062 __cntrl_(0)
4063{
4064}
4065
4066template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004067template<class _Yp>
4068shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4069 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004070 : __ptr_(__p)
4071{
4072 unique_ptr<_Yp> __hold(__p);
Erik Pilkington2a398762017-05-25 15:43:31 +00004073 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4074 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
4075 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004076 __hold.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004077 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004078}
4079
4080template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004081template<class _Yp, class _Dp>
4082shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4083 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004084 : __ptr_(__p)
4085{
4086#ifndef _LIBCPP_NO_EXCEPTIONS
4087 try
4088 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004089#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkington2a398762017-05-25 15:43:31 +00004090 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4091 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4092 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004093 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004094#ifndef _LIBCPP_NO_EXCEPTIONS
4095 }
4096 catch (...)
4097 {
4098 __d(__p);
4099 throw;
4100 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004101#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004102}
4103
4104template<class _Tp>
4105template<class _Dp>
4106shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4107 : __ptr_(0)
4108{
4109#ifndef _LIBCPP_NO_EXCEPTIONS
4110 try
4111 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004112#endif // _LIBCPP_NO_EXCEPTIONS
Erik Pilkington2a398762017-05-25 15:43:31 +00004113 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4114 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4115 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004116#ifndef _LIBCPP_NO_EXCEPTIONS
4117 }
4118 catch (...)
4119 {
4120 __d(__p);
4121 throw;
4122 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004123#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004124}
4125
4126template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004127template<class _Yp, class _Dp, class _Alloc>
4128shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4129 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004130 : __ptr_(__p)
4131{
4132#ifndef _LIBCPP_NO_EXCEPTIONS
4133 try
4134 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004135#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004136 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004137 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004138 typedef __allocator_destructor<_A2> _D2;
4139 _A2 __a2(__a);
4140 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004141 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4142 _CntrlBlk(__p, __d, __a);
4143 __cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004144 __enable_weak_this(__p, __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004145#ifndef _LIBCPP_NO_EXCEPTIONS
4146 }
4147 catch (...)
4148 {
4149 __d(__p);
4150 throw;
4151 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004152#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004153}
4154
4155template<class _Tp>
4156template<class _Dp, class _Alloc>
4157shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4158 : __ptr_(0)
4159{
4160#ifndef _LIBCPP_NO_EXCEPTIONS
4161 try
4162 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004163#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004164 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004165 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004166 typedef __allocator_destructor<_A2> _D2;
4167 _A2 __a2(__a);
4168 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004169 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4170 _CntrlBlk(__p, __d, __a);
4171 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004172#ifndef _LIBCPP_NO_EXCEPTIONS
4173 }
4174 catch (...)
4175 {
4176 __d(__p);
4177 throw;
4178 }
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004179#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00004180}
4181
4182template<class _Tp>
4183template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004184inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004185shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004186 : __ptr_(__p),
4187 __cntrl_(__r.__cntrl_)
4188{
4189 if (__cntrl_)
4190 __cntrl_->__add_shared();
4191}
4192
4193template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004194inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004195shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004196 : __ptr_(__r.__ptr_),
4197 __cntrl_(__r.__cntrl_)
4198{
4199 if (__cntrl_)
4200 __cntrl_->__add_shared();
4201}
4202
4203template<class _Tp>
4204template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004205inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004206shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00004207 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004208 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004209 : __ptr_(__r.__ptr_),
4210 __cntrl_(__r.__cntrl_)
4211{
4212 if (__cntrl_)
4213 __cntrl_->__add_shared();
4214}
4215
Howard Hinnant74279a52010-09-04 23:28:19 +00004216#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004217
4218template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004219inline
Howard Hinnant719bda32011-05-28 14:41:13 +00004220shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004221 : __ptr_(__r.__ptr_),
4222 __cntrl_(__r.__cntrl_)
4223{
4224 __r.__ptr_ = 0;
4225 __r.__cntrl_ = 0;
4226}
4227
4228template<class _Tp>
4229template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004230inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004231shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00004232 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00004233 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004234 : __ptr_(__r.__ptr_),
4235 __cntrl_(__r.__cntrl_)
4236{
4237 __r.__ptr_ = 0;
4238 __r.__cntrl_ = 0;
4239}
4240
Howard Hinnant74279a52010-09-04 23:28:19 +00004241#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004242
Marshall Clowb22274f2017-01-24 22:22:33 +00004243#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004244template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004245template<class _Yp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004246#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chiend435f8b2014-01-31 09:30:46 +00004247shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004248#else
Logan Chiend435f8b2014-01-31 09:30:46 +00004249shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnantc51e1022010-05-11 19:42:16 +00004250#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004251 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004252 : __ptr_(__r.get())
4253{
4254 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4255 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004256 __enable_weak_this(__r.get(), __r.get());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004257 __r.release();
4258}
Marshall Clowb22274f2017-01-24 22:22:33 +00004259#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004260
4261template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004262template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004263#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004264shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4265#else
4266shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4267#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004268 typename enable_if
4269 <
4270 !is_lvalue_reference<_Dp>::value &&
4271 !is_array<_Yp>::value &&
4272 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4273 __nat
4274 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004275 : __ptr_(__r.get())
4276{
Marshall Clow35cde742015-05-10 13:59:45 +00004277#if _LIBCPP_STD_VER > 11
4278 if (__ptr_ == nullptr)
4279 __cntrl_ = nullptr;
4280 else
4281#endif
4282 {
Erik Pilkington2a398762017-05-25 15:43:31 +00004283 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4284 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4285 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004286 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004287 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004288 __r.release();
4289}
4290
4291template<class _Tp>
Logan Chiend435f8b2014-01-31 09:30:46 +00004292template <class _Yp, class _Dp>
Howard Hinnant74279a52010-09-04 23:28:19 +00004293#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004294shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4295#else
4296shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4297#endif
Logan Chiend435f8b2014-01-31 09:30:46 +00004298 typename enable_if
4299 <
4300 is_lvalue_reference<_Dp>::value &&
4301 !is_array<_Yp>::value &&
4302 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4303 __nat
4304 >::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004305 : __ptr_(__r.get())
4306{
Marshall Clow35cde742015-05-10 13:59:45 +00004307#if _LIBCPP_STD_VER > 11
4308 if (__ptr_ == nullptr)
4309 __cntrl_ = nullptr;
4310 else
4311#endif
4312 {
Erik Pilkington2a398762017-05-25 15:43:31 +00004313 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
Marshall Clow35cde742015-05-10 13:59:45 +00004314 typedef __shared_ptr_pointer<_Yp*,
4315 reference_wrapper<typename remove_reference<_Dp>::type>,
Erik Pilkington2a398762017-05-25 15:43:31 +00004316 _AllocT > _CntrlBlk;
4317 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004318 __enable_weak_this(__r.get(), __r.get());
Marshall Clow35cde742015-05-10 13:59:45 +00004319 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004320 __r.release();
4321}
4322
4323#ifndef _LIBCPP_HAS_NO_VARIADICS
4324
4325template<class _Tp>
4326template<class ..._Args>
4327shared_ptr<_Tp>
4328shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4329{
Marshall Clowdec75c72017-12-05 04:09:49 +00004330 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004331 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4332 typedef allocator<_CntrlBlk> _A2;
4333 typedef __allocator_destructor<_A2> _D2;
4334 _A2 __a2;
4335 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004336 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004337 shared_ptr<_Tp> __r;
4338 __r.__ptr_ = __hold2.get()->get();
4339 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004340 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004341 return __r;
4342}
4343
4344template<class _Tp>
4345template<class _Alloc, class ..._Args>
4346shared_ptr<_Tp>
4347shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4348{
Marshall Clowdec75c72017-12-05 04:09:49 +00004349 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004350 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004351 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004352 typedef __allocator_destructor<_A2> _D2;
4353 _A2 __a2(__a);
4354 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004355 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4356 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004357 shared_ptr<_Tp> __r;
4358 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004359 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004360 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004361 return __r;
4362}
4363
4364#else // _LIBCPP_HAS_NO_VARIADICS
4365
4366template<class _Tp>
4367shared_ptr<_Tp>
4368shared_ptr<_Tp>::make_shared()
4369{
Marshall Clowdec75c72017-12-05 04:09:49 +00004370 static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004371 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4372 typedef allocator<_CntrlBlk> _Alloc2;
4373 typedef __allocator_destructor<_Alloc2> _D2;
4374 _Alloc2 __alloc2;
4375 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4376 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4377 shared_ptr<_Tp> __r;
4378 __r.__ptr_ = __hold2.get()->get();
4379 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004380 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004381 return __r;
4382}
4383
4384template<class _Tp>
4385template<class _A0>
4386shared_ptr<_Tp>
4387shared_ptr<_Tp>::make_shared(_A0& __a0)
4388{
Marshall Clowdec75c72017-12-05 04:09:49 +00004389 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004390 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4391 typedef allocator<_CntrlBlk> _Alloc2;
4392 typedef __allocator_destructor<_Alloc2> _D2;
4393 _Alloc2 __alloc2;
4394 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4395 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4396 shared_ptr<_Tp> __r;
4397 __r.__ptr_ = __hold2.get()->get();
4398 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004399 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004400 return __r;
4401}
4402
4403template<class _Tp>
4404template<class _A0, class _A1>
4405shared_ptr<_Tp>
4406shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4407{
Marshall Clowdec75c72017-12-05 04:09:49 +00004408 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004409 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4410 typedef allocator<_CntrlBlk> _Alloc2;
4411 typedef __allocator_destructor<_Alloc2> _D2;
4412 _Alloc2 __alloc2;
4413 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4414 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4415 shared_ptr<_Tp> __r;
4416 __r.__ptr_ = __hold2.get()->get();
4417 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004418 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004419 return __r;
4420}
4421
4422template<class _Tp>
4423template<class _A0, class _A1, class _A2>
4424shared_ptr<_Tp>
4425shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4426{
Marshall Clowdec75c72017-12-05 04:09:49 +00004427 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004428 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4429 typedef allocator<_CntrlBlk> _Alloc2;
4430 typedef __allocator_destructor<_Alloc2> _D2;
4431 _Alloc2 __alloc2;
4432 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4433 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4434 shared_ptr<_Tp> __r;
4435 __r.__ptr_ = __hold2.get()->get();
4436 __r.__cntrl_ = __hold2.release();
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004437 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004438 return __r;
4439}
4440
4441template<class _Tp>
4442template<class _Alloc>
4443shared_ptr<_Tp>
4444shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4445{
Marshall Clowdec75c72017-12-05 04:09:49 +00004446 static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004447 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004448 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004449 typedef __allocator_destructor<_Alloc2> _D2;
4450 _Alloc2 __alloc2(__a);
4451 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004452 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4453 _CntrlBlk(__a);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004454 shared_ptr<_Tp> __r;
4455 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004456 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004457 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004458 return __r;
4459}
4460
4461template<class _Tp>
4462template<class _Alloc, class _A0>
4463shared_ptr<_Tp>
4464shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4465{
Marshall Clowdec75c72017-12-05 04:09:49 +00004466 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004467 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004468 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004469 typedef __allocator_destructor<_Alloc2> _D2;
4470 _Alloc2 __alloc2(__a);
4471 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004472 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4473 _CntrlBlk(__a, __a0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004474 shared_ptr<_Tp> __r;
4475 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004476 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004477 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004478 return __r;
4479}
4480
4481template<class _Tp>
4482template<class _Alloc, class _A0, class _A1>
4483shared_ptr<_Tp>
4484shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4485{
Marshall Clowdec75c72017-12-05 04:09:49 +00004486 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004487 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004488 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004489 typedef __allocator_destructor<_Alloc2> _D2;
4490 _Alloc2 __alloc2(__a);
4491 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004492 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4493 _CntrlBlk(__a, __a0, __a1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004494 shared_ptr<_Tp> __r;
4495 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004496 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004497 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004498 return __r;
4499}
4500
4501template<class _Tp>
4502template<class _Alloc, class _A0, class _A1, class _A2>
4503shared_ptr<_Tp>
4504shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4505{
Marshall Clowdec75c72017-12-05 04:09:49 +00004506 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
Howard Hinnantc51e1022010-05-11 19:42:16 +00004507 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004508 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004509 typedef __allocator_destructor<_Alloc2> _D2;
4510 _Alloc2 __alloc2(__a);
4511 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004512 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4513 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004514 shared_ptr<_Tp> __r;
4515 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier6bd814f2014-10-23 04:12:28 +00004516 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselierf16c93f2016-06-26 23:56:32 +00004517 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004518 return __r;
4519}
4520
4521#endif // _LIBCPP_HAS_NO_VARIADICS
4522
4523template<class _Tp>
4524shared_ptr<_Tp>::~shared_ptr()
4525{
4526 if (__cntrl_)
4527 __cntrl_->__release_shared();
4528}
4529
4530template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004531inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004532shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004533shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004534{
4535 shared_ptr(__r).swap(*this);
4536 return *this;
4537}
4538
4539template<class _Tp>
4540template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004541inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004542typename enable_if
4543<
Marshall Clow7e384b72017-01-10 16:59:33 +00004544 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004545 shared_ptr<_Tp>&
4546>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004547shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004548{
4549 shared_ptr(__r).swap(*this);
4550 return *this;
4551}
4552
Howard Hinnant74279a52010-09-04 23:28:19 +00004553#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004554
4555template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004556inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004557shared_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00004558shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004559{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004560 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004561 return *this;
4562}
4563
4564template<class _Tp>
4565template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004566inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004567typename enable_if
4568<
Marshall Clow7e384b72017-01-10 16:59:33 +00004569 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004570 shared_ptr<_Tp>&
4571>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004572shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4573{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004574 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004575 return *this;
4576}
4577
Marshall Clowb22274f2017-01-24 22:22:33 +00004578#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004579template<class _Tp>
4580template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004581inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004582typename enable_if
4583<
4584 !is_array<_Yp>::value &&
Marshall Clow7e384b72017-01-10 16:59:33 +00004585 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant25bcaf62013-09-13 23:56:00 +00004586 shared_ptr<_Tp>
4587>::type&
Howard Hinnantc51e1022010-05-11 19:42:16 +00004588shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4589{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004590 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004591 return *this;
4592}
Marshall Clowb22274f2017-01-24 22:22:33 +00004593#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004594
4595template<class _Tp>
4596template <class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004597inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004598typename enable_if
4599<
4600 !is_array<_Yp>::value &&
Aditya Kumar7c5db692017-08-20 10:38:55 +00004601 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
Marshall Clow7e384b72017-01-10 16:59:33 +00004602 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004603 shared_ptr<_Tp>&
4604>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004605shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4606{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004607 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004608 return *this;
4609}
4610
Howard Hinnant74279a52010-09-04 23:28:19 +00004611#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004612
Marshall Clowb22274f2017-01-24 22:22:33 +00004613#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004614template<class _Tp>
4615template<class _Yp>
4616inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004617typename enable_if
4618<
4619 !is_array<_Yp>::value &&
Marshall Clowb89a86e2017-01-10 18:40:01 +00004620 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004621 shared_ptr<_Tp>&
4622>::type
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004623shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004624{
4625 shared_ptr(__r).swap(*this);
4626 return *this;
4627}
Marshall Clowb22274f2017-01-24 22:22:33 +00004628#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004629
4630template<class _Tp>
4631template <class _Yp, class _Dp>
4632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004633typename enable_if
4634<
4635 !is_array<_Yp>::value &&
Aditya Kumar7c5db692017-08-20 10:38:55 +00004636 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
Marshall Clowb89a86e2017-01-10 18:40:01 +00004637 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004638 shared_ptr<_Tp>&
4639>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004640shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4641{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004642 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004643 return *this;
4644}
4645
Howard Hinnant74279a52010-09-04 23:28:19 +00004646#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00004647
4648template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004649inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004650void
Howard Hinnant719bda32011-05-28 14:41:13 +00004651shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004652{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004653 _VSTD::swap(__ptr_, __r.__ptr_);
4654 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004655}
4656
4657template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004658inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00004659void
Howard Hinnant719bda32011-05-28 14:41:13 +00004660shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004661{
4662 shared_ptr().swap(*this);
4663}
4664
4665template<class _Tp>
4666template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004667inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004668typename enable_if
4669<
Marshall Clow7e384b72017-01-10 16:59:33 +00004670 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004671 void
4672>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004673shared_ptr<_Tp>::reset(_Yp* __p)
4674{
4675 shared_ptr(__p).swap(*this);
4676}
4677
4678template<class _Tp>
4679template<class _Yp, class _Dp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004680inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004681typename enable_if
4682<
Marshall Clow7e384b72017-01-10 16:59:33 +00004683 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004684 void
4685>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004686shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4687{
4688 shared_ptr(__p, __d).swap(*this);
4689}
4690
4691template<class _Tp>
4692template<class _Yp, class _Dp, class _Alloc>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00004693inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004694typename enable_if
4695<
Marshall Clow7e384b72017-01-10 16:59:33 +00004696 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004697 void
4698>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004699shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4700{
4701 shared_ptr(__p, __d, __a).swap(*this);
4702}
4703
4704#ifndef _LIBCPP_HAS_NO_VARIADICS
4705
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004706template<class _Tp, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004707inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004708typename enable_if
4709<
4710 !is_array<_Tp>::value,
4711 shared_ptr<_Tp>
4712>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004713make_shared(_Args&& ...__args)
4714{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004715 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004716}
4717
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004718template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004719inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004720typename enable_if
4721<
4722 !is_array<_Tp>::value,
4723 shared_ptr<_Tp>
4724>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00004725allocate_shared(const _Alloc& __a, _Args&& ...__args)
4726{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004727 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004728}
4729
4730#else // _LIBCPP_HAS_NO_VARIADICS
4731
4732template<class _Tp>
4733inline _LIBCPP_INLINE_VISIBILITY
4734shared_ptr<_Tp>
4735make_shared()
4736{
4737 return shared_ptr<_Tp>::make_shared();
4738}
4739
4740template<class _Tp, class _A0>
4741inline _LIBCPP_INLINE_VISIBILITY
4742shared_ptr<_Tp>
4743make_shared(_A0& __a0)
4744{
4745 return shared_ptr<_Tp>::make_shared(__a0);
4746}
4747
4748template<class _Tp, class _A0, class _A1>
4749inline _LIBCPP_INLINE_VISIBILITY
4750shared_ptr<_Tp>
4751make_shared(_A0& __a0, _A1& __a1)
4752{
4753 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4754}
4755
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004756template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004757inline _LIBCPP_INLINE_VISIBILITY
4758shared_ptr<_Tp>
4759make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4760{
4761 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4762}
4763
4764template<class _Tp, class _Alloc>
4765inline _LIBCPP_INLINE_VISIBILITY
4766shared_ptr<_Tp>
4767allocate_shared(const _Alloc& __a)
4768{
4769 return shared_ptr<_Tp>::allocate_shared(__a);
4770}
4771
4772template<class _Tp, class _Alloc, class _A0>
4773inline _LIBCPP_INLINE_VISIBILITY
4774shared_ptr<_Tp>
4775allocate_shared(const _Alloc& __a, _A0& __a0)
4776{
4777 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4778}
4779
4780template<class _Tp, class _Alloc, class _A0, class _A1>
4781inline _LIBCPP_INLINE_VISIBILITY
4782shared_ptr<_Tp>
4783allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4784{
4785 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4786}
4787
4788template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4789inline _LIBCPP_INLINE_VISIBILITY
4790shared_ptr<_Tp>
4791allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4792{
4793 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4794}
4795
4796#endif // _LIBCPP_HAS_NO_VARIADICS
4797
4798template<class _Tp, class _Up>
4799inline _LIBCPP_INLINE_VISIBILITY
4800bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004801operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004802{
4803 return __x.get() == __y.get();
4804}
4805
4806template<class _Tp, class _Up>
4807inline _LIBCPP_INLINE_VISIBILITY
4808bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004809operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004810{
4811 return !(__x == __y);
4812}
4813
4814template<class _Tp, class _Up>
4815inline _LIBCPP_INLINE_VISIBILITY
4816bool
Howard Hinnant719bda32011-05-28 14:41:13 +00004817operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004818{
Marshall Clow8afdf7a2018-02-12 17:26:40 +00004819#if _LIBCPP_STD_VER <= 11
Eric Fiselierf8898c82015-02-05 23:01:40 +00004820 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4821 return less<_Vp>()(__x.get(), __y.get());
Marshall Clow8afdf7a2018-02-12 17:26:40 +00004822#else
4823 return less<>()(__x.get(), __y.get());
4824#endif
4825
Howard Hinnantb17caf92012-02-21 21:02:58 +00004826}
4827
4828template<class _Tp, class _Up>
4829inline _LIBCPP_INLINE_VISIBILITY
4830bool
4831operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4832{
4833 return __y < __x;
4834}
4835
4836template<class _Tp, class _Up>
4837inline _LIBCPP_INLINE_VISIBILITY
4838bool
4839operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4840{
4841 return !(__y < __x);
4842}
4843
4844template<class _Tp, class _Up>
4845inline _LIBCPP_INLINE_VISIBILITY
4846bool
4847operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4848{
4849 return !(__x < __y);
4850}
4851
4852template<class _Tp>
4853inline _LIBCPP_INLINE_VISIBILITY
4854bool
4855operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4856{
4857 return !__x;
4858}
4859
4860template<class _Tp>
4861inline _LIBCPP_INLINE_VISIBILITY
4862bool
4863operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4864{
4865 return !__x;
4866}
4867
4868template<class _Tp>
4869inline _LIBCPP_INLINE_VISIBILITY
4870bool
4871operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4872{
4873 return static_cast<bool>(__x);
4874}
4875
4876template<class _Tp>
4877inline _LIBCPP_INLINE_VISIBILITY
4878bool
4879operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4880{
4881 return static_cast<bool>(__x);
4882}
4883
4884template<class _Tp>
4885inline _LIBCPP_INLINE_VISIBILITY
4886bool
4887operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4888{
4889 return less<_Tp*>()(__x.get(), nullptr);
4890}
4891
4892template<class _Tp>
4893inline _LIBCPP_INLINE_VISIBILITY
4894bool
4895operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4896{
4897 return less<_Tp*>()(nullptr, __x.get());
4898}
4899
4900template<class _Tp>
4901inline _LIBCPP_INLINE_VISIBILITY
4902bool
4903operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4904{
4905 return nullptr < __x;
4906}
4907
4908template<class _Tp>
4909inline _LIBCPP_INLINE_VISIBILITY
4910bool
4911operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4912{
4913 return __x < nullptr;
4914}
4915
4916template<class _Tp>
4917inline _LIBCPP_INLINE_VISIBILITY
4918bool
4919operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4920{
4921 return !(nullptr < __x);
4922}
4923
4924template<class _Tp>
4925inline _LIBCPP_INLINE_VISIBILITY
4926bool
4927operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4928{
4929 return !(__x < nullptr);
4930}
4931
4932template<class _Tp>
4933inline _LIBCPP_INLINE_VISIBILITY
4934bool
4935operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4936{
4937 return !(__x < nullptr);
4938}
4939
4940template<class _Tp>
4941inline _LIBCPP_INLINE_VISIBILITY
4942bool
4943operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4944{
4945 return !(nullptr < __x);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004946}
4947
4948template<class _Tp>
4949inline _LIBCPP_INLINE_VISIBILITY
4950void
Howard Hinnant719bda32011-05-28 14:41:13 +00004951swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004952{
4953 __x.swap(__y);
4954}
4955
4956template<class _Tp, class _Up>
4957inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004958typename enable_if
4959<
4960 !is_array<_Tp>::value && !is_array<_Up>::value,
4961 shared_ptr<_Tp>
4962>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004963static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004964{
4965 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4966}
4967
4968template<class _Tp, class _Up>
4969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004970typename enable_if
4971<
4972 !is_array<_Tp>::value && !is_array<_Up>::value,
4973 shared_ptr<_Tp>
4974>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004975dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004976{
4977 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4978 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4979}
4980
4981template<class _Tp, class _Up>
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004982typename enable_if
4983<
4984 is_array<_Tp>::value == is_array<_Up>::value,
4985 shared_ptr<_Tp>
4986>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00004987const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004988{
Howard Hinnant741c8fa2012-01-02 17:56:02 +00004989 typedef typename remove_extent<_Tp>::type _RTp;
4990 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004991}
4992
Howard Hinnant72f73582010-08-11 17:04:31 +00004993#ifndef _LIBCPP_NO_RTTI
4994
Howard Hinnantc51e1022010-05-11 19:42:16 +00004995template<class _Dp, class _Tp>
4996inline _LIBCPP_INLINE_VISIBILITY
4997_Dp*
Howard Hinnant719bda32011-05-28 14:41:13 +00004998get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004999{
5000 return __p.template __get_deleter<_Dp>();
5001}
5002
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005003#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00005004
Howard Hinnantc51e1022010-05-11 19:42:16 +00005005template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005006class _LIBCPP_TEMPLATE_VIS weak_ptr
Howard Hinnantc51e1022010-05-11 19:42:16 +00005007{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005008public:
5009 typedef _Tp element_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005010private:
5011 element_type* __ptr_;
5012 __shared_weak_count* __cntrl_;
5013
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005014public:
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005016 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005017 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00005018 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5019 _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005021 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005022 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant719bda32011-05-28 14:41:13 +00005023 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5024 _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005025
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005026#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005028 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005029 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005030 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5031 _NOEXCEPT;
5032#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005033 ~weak_ptr();
5034
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005036 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005037 template<class _Yp>
5038 typename enable_if
5039 <
5040 is_convertible<_Yp*, element_type*>::value,
5041 weak_ptr&
5042 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005044 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5045
5046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5047
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005049 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5050 template<class _Yp>
5051 typename enable_if
5052 <
5053 is_convertible<_Yp*, element_type*>::value,
5054 weak_ptr&
5055 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005057 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5058
5059#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5060
5061 template<class _Yp>
5062 typename enable_if
5063 <
5064 is_convertible<_Yp*, element_type*>::value,
5065 weak_ptr&
5066 >::type
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005068 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005069
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005071 void swap(weak_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005073 void reset() _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005074
Howard Hinnant756c69b2010-09-22 16:48:34 +00005075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005076 long use_count() const _NOEXCEPT
5077 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005079 bool expired() const _NOEXCEPT
5080 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5081 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005082 template<class _Up>
5083 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005084 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005085 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005086 template<class _Up>
5087 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005088 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005089 {return __cntrl_ < __r.__cntrl_;}
5090
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005091 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5092 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005093};
5094
5095template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005096inline
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005097_LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005098weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005099 : __ptr_(0),
5100 __cntrl_(0)
5101{
5102}
5103
5104template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005105inline
Howard Hinnant719bda32011-05-28 14:41:13 +00005106weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005107 : __ptr_(__r.__ptr_),
5108 __cntrl_(__r.__cntrl_)
5109{
5110 if (__cntrl_)
5111 __cntrl_->__add_weak();
5112}
5113
5114template<class _Tp>
5115template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005116inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005117weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005118 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005119 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005120 : __ptr_(__r.__ptr_),
5121 __cntrl_(__r.__cntrl_)
5122{
5123 if (__cntrl_)
5124 __cntrl_->__add_weak();
5125}
5126
5127template<class _Tp>
5128template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005129inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005130weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant3a085e82011-05-22 00:09:02 +00005131 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant719bda32011-05-28 14:41:13 +00005132 _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005133 : __ptr_(__r.__ptr_),
5134 __cntrl_(__r.__cntrl_)
5135{
5136 if (__cntrl_)
5137 __cntrl_->__add_weak();
5138}
5139
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005140#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5141
5142template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005143inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005144weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5145 : __ptr_(__r.__ptr_),
5146 __cntrl_(__r.__cntrl_)
5147{
5148 __r.__ptr_ = 0;
5149 __r.__cntrl_ = 0;
5150}
5151
5152template<class _Tp>
5153template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005154inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005155weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5156 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5157 _NOEXCEPT
5158 : __ptr_(__r.__ptr_),
5159 __cntrl_(__r.__cntrl_)
5160{
5161 __r.__ptr_ = 0;
5162 __r.__cntrl_ = 0;
5163}
5164
5165#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5166
Howard Hinnantc51e1022010-05-11 19:42:16 +00005167template<class _Tp>
5168weak_ptr<_Tp>::~weak_ptr()
5169{
5170 if (__cntrl_)
5171 __cntrl_->__release_weak();
5172}
5173
5174template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005175inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005176weak_ptr<_Tp>&
Howard Hinnant719bda32011-05-28 14:41:13 +00005177weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005178{
5179 weak_ptr(__r).swap(*this);
5180 return *this;
5181}
5182
5183template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005184template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005185inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005186typename enable_if
5187<
5188 is_convertible<_Yp*, _Tp*>::value,
5189 weak_ptr<_Tp>&
5190>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005191weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005192{
5193 weak_ptr(__r).swap(*this);
5194 return *this;
5195}
5196
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005197#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5198
5199template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005200inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005201weak_ptr<_Tp>&
5202weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5203{
5204 weak_ptr(_VSTD::move(__r)).swap(*this);
5205 return *this;
5206}
5207
Howard Hinnantc51e1022010-05-11 19:42:16 +00005208template<class _Tp>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005209template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005210inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005211typename enable_if
5212<
5213 is_convertible<_Yp*, _Tp*>::value,
5214 weak_ptr<_Tp>&
5215>::type
5216weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5217{
5218 weak_ptr(_VSTD::move(__r)).swap(*this);
5219 return *this;
5220}
5221
5222#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5223
5224template<class _Tp>
5225template<class _Yp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005226inline
Howard Hinnant741c8fa2012-01-02 17:56:02 +00005227typename enable_if
5228<
5229 is_convertible<_Yp*, _Tp*>::value,
5230 weak_ptr<_Tp>&
5231>::type
Howard Hinnant719bda32011-05-28 14:41:13 +00005232weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005233{
5234 weak_ptr(__r).swap(*this);
5235 return *this;
5236}
5237
5238template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005239inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005240void
Howard Hinnant719bda32011-05-28 14:41:13 +00005241weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005242{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00005243 _VSTD::swap(__ptr_, __r.__ptr_);
5244 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005245}
5246
5247template<class _Tp>
5248inline _LIBCPP_INLINE_VISIBILITY
5249void
Howard Hinnant719bda32011-05-28 14:41:13 +00005250swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005251{
5252 __x.swap(__y);
5253}
5254
5255template<class _Tp>
Evgeniy Stepanov2fb1cb62015-11-07 01:22:13 +00005256inline
Howard Hinnantc51e1022010-05-11 19:42:16 +00005257void
Howard Hinnant719bda32011-05-28 14:41:13 +00005258weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005259{
5260 weak_ptr().swap(*this);
5261}
5262
5263template<class _Tp>
5264template<class _Yp>
5265shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clow7e384b72017-01-10 16:59:33 +00005266 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnantc51e1022010-05-11 19:42:16 +00005267 : __ptr_(__r.__ptr_),
5268 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5269{
5270 if (__cntrl_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00005271 __throw_bad_weak_ptr();
Howard Hinnantc51e1022010-05-11 19:42:16 +00005272}
5273
5274template<class _Tp>
5275shared_ptr<_Tp>
Howard Hinnant719bda32011-05-28 14:41:13 +00005276weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005277{
5278 shared_ptr<_Tp> __r;
5279 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5280 if (__r.__cntrl_)
5281 __r.__ptr_ = __ptr_;
5282 return __r;
5283}
5284
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005285#if _LIBCPP_STD_VER > 14
5286template <class _Tp = void> struct owner_less;
5287#else
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005288template <class _Tp> struct owner_less;
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005289#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00005290
5291template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005292struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005293 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005294{
5295 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005296 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005297 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005298 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005299 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005300 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005301 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005302 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005303 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005304 {return __x.owner_before(__y);}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005305};
Howard Hinnantc51e1022010-05-11 19:42:16 +00005306
5307template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005308struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
Howard Hinnantc51e1022010-05-11 19:42:16 +00005309 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5310{
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005311 typedef bool result_type;
Howard Hinnant756c69b2010-09-22 16:48:34 +00005312 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005313 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005314 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005315 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005316 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005317 {return __x.owner_before(__y);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005318 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005319 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00005320 {return __x.owner_before(__y);}
5321};
5322
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005323#if _LIBCPP_STD_VER > 14
5324template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005325struct _LIBCPP_TEMPLATE_VIS owner_less<void>
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005326{
5327 template <class _Tp, class _Up>
5328 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005329 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005330 {return __x.owner_before(__y);}
5331 template <class _Tp, class _Up>
5332 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005333 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005334 {return __x.owner_before(__y);}
5335 template <class _Tp, class _Up>
5336 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005337 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005338 {return __x.owner_before(__y);}
5339 template <class _Tp, class _Up>
5340 _LIBCPP_INLINE_VISIBILITY
Marshall Clow18a7cd52017-04-11 17:08:53 +00005341 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
Marshall Clow3c2d8a42015-11-12 15:56:44 +00005342 {return __x.owner_before(__y);}
5343 typedef void is_transparent;
5344};
5345#endif
5346
Howard Hinnantc51e1022010-05-11 19:42:16 +00005347template<class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005348class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
Howard Hinnantc51e1022010-05-11 19:42:16 +00005349{
5350 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005351protected:
Howard Hinnantb5fffe82012-07-07 20:56:04 +00005352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant719bda32011-05-28 14:41:13 +00005353 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005355 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005357 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5358 {return *this;}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005360 ~enable_shared_from_this() {}
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005361public:
Howard Hinnant756c69b2010-09-22 16:48:34 +00005362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005363 shared_ptr<_Tp> shared_from_this()
5364 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005366 shared_ptr<_Tp const> shared_from_this() const
5367 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00005368
Eric Fiselier84006862016-06-02 00:15:35 +00005369#if _LIBCPP_STD_VER > 14
5370 _LIBCPP_INLINE_VISIBILITY
5371 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5372 { return __weak_this_; }
5373
5374 _LIBCPP_INLINE_VISIBILITY
5375 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5376 { return __weak_this_; }
5377#endif // _LIBCPP_STD_VER > 14
5378
Howard Hinnantc51e1022010-05-11 19:42:16 +00005379 template <class _Up> friend class shared_ptr;
5380};
5381
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005382template <class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00005383struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005384{
5385 typedef shared_ptr<_Tp> argument_type;
5386 typedef size_t result_type;
Eric Fiselier698a97b2017-01-21 00:02:12 +00005387
Howard Hinnant756c69b2010-09-22 16:48:34 +00005388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant719bda32011-05-28 14:41:13 +00005389 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnant36b31ae2010-06-03 16:42:57 +00005390 {
5391 return hash<_Tp*>()(__ptr.get());
5392 }
5393};
5394
Howard Hinnantc834c512011-11-29 18:15:50 +00005395template<class _CharT, class _Traits, class _Yp>
Howard Hinnantdc095972011-07-18 15:51:59 +00005396inline _LIBCPP_INLINE_VISIBILITY
5397basic_ostream<_CharT, _Traits>&
Howard Hinnantc834c512011-11-29 18:15:50 +00005398operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnantdc095972011-07-18 15:51:59 +00005399
Eric Fiselier9b492672016-06-18 02:12:53 +00005400
5401#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005402
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005403class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnant9fa30202012-07-30 01:40:57 +00005404{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005405 void* __lx;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005406public:
5407 void lock() _NOEXCEPT;
5408 void unlock() _NOEXCEPT;
5409
5410private:
5411 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5412 __sp_mut(const __sp_mut&);
5413 __sp_mut& operator=(const __sp_mut&);
5414
Howard Hinnant8331b762013-03-06 23:30:19 +00005415 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005416};
5417
Mehdi Amini228053d2017-05-04 17:08:54 +00005418_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5419__sp_mut& __get_sp_mut(const void*);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005420
5421template <class _Tp>
5422inline _LIBCPP_INLINE_VISIBILITY
5423bool
5424atomic_is_lock_free(const shared_ptr<_Tp>*)
5425{
5426 return false;
5427}
5428
5429template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005430_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005431shared_ptr<_Tp>
5432atomic_load(const shared_ptr<_Tp>* __p)
5433{
5434 __sp_mut& __m = __get_sp_mut(__p);
5435 __m.lock();
5436 shared_ptr<_Tp> __q = *__p;
5437 __m.unlock();
5438 return __q;
5439}
Aditya Kumar7c5db692017-08-20 10:38:55 +00005440
Howard Hinnant9fa30202012-07-30 01:40:57 +00005441template <class _Tp>
5442inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005443_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005444shared_ptr<_Tp>
5445atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5446{
5447 return atomic_load(__p);
5448}
5449
5450template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005451_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005452void
5453atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5454{
5455 __sp_mut& __m = __get_sp_mut(__p);
5456 __m.lock();
5457 __p->swap(__r);
5458 __m.unlock();
5459}
5460
5461template <class _Tp>
5462inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005463_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005464void
5465atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5466{
5467 atomic_store(__p, __r);
5468}
5469
5470template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005471_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005472shared_ptr<_Tp>
5473atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5474{
5475 __sp_mut& __m = __get_sp_mut(__p);
5476 __m.lock();
5477 __p->swap(__r);
5478 __m.unlock();
5479 return __r;
5480}
Aditya Kumar7c5db692017-08-20 10:38:55 +00005481
Howard Hinnant9fa30202012-07-30 01:40:57 +00005482template <class _Tp>
5483inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005484_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005485shared_ptr<_Tp>
5486atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5487{
5488 return atomic_exchange(__p, __r);
5489}
5490
5491template <class _Tp>
Mehdi Amini228053d2017-05-04 17:08:54 +00005492_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005493bool
5494atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5495{
Marshall Clow4201ee82016-05-18 17:50:13 +00005496 shared_ptr<_Tp> __temp;
Howard Hinnant9fa30202012-07-30 01:40:57 +00005497 __sp_mut& __m = __get_sp_mut(__p);
5498 __m.lock();
5499 if (__p->__owner_equivalent(*__v))
5500 {
Marshall Clow4201ee82016-05-18 17:50:13 +00005501 _VSTD::swap(__temp, *__p);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005502 *__p = __w;
5503 __m.unlock();
5504 return true;
5505 }
Marshall Clow4201ee82016-05-18 17:50:13 +00005506 _VSTD::swap(__temp, *__v);
Howard Hinnant9fa30202012-07-30 01:40:57 +00005507 *__v = *__p;
5508 __m.unlock();
5509 return false;
5510}
5511
5512template <class _Tp>
5513inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005514_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005515bool
5516atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5517{
5518 return atomic_compare_exchange_strong(__p, __v, __w);
5519}
5520
5521template <class _Tp>
5522inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005523_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005524bool
5525atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5526 shared_ptr<_Tp> __w, memory_order, memory_order)
5527{
5528 return atomic_compare_exchange_strong(__p, __v, __w);
5529}
5530
5531template <class _Tp>
5532inline _LIBCPP_INLINE_VISIBILITY
Mehdi Amini228053d2017-05-04 17:08:54 +00005533_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
Howard Hinnant9fa30202012-07-30 01:40:57 +00005534bool
5535atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5536 shared_ptr<_Tp> __w, memory_order, memory_order)
5537{
5538 return atomic_compare_exchange_weak(__p, __v, __w);
5539}
5540
Eric Fiselier9b492672016-06-18 02:12:53 +00005541#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnant9fa30202012-07-30 01:40:57 +00005542
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005543//enum class
Eric Fiselierab6bb302017-01-05 01:15:42 +00005544#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5545# ifndef _LIBCPP_CXX03_LANG
5546enum class pointer_safety : unsigned char {
5547 relaxed,
5548 preferred,
5549 strict
5550};
5551# endif
5552#else
Howard Hinnant8331b762013-03-06 23:30:19 +00005553struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnantc51e1022010-05-11 19:42:16 +00005554{
Howard Hinnant49e145e2012-10-30 19:06:59 +00005555 enum __lx
Howard Hinnantc51e1022010-05-11 19:42:16 +00005556 {
5557 relaxed,
5558 preferred,
5559 strict
5560 };
5561
Howard Hinnant49e145e2012-10-30 19:06:59 +00005562 __lx __v_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00005563
Howard Hinnant756c69b2010-09-22 16:48:34 +00005564 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2fdd22b2017-01-05 01:28:40 +00005565 pointer_safety() : __v_() {}
5566
5567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant49e145e2012-10-30 19:06:59 +00005568 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant756c69b2010-09-22 16:48:34 +00005569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00005570 operator int() const {return __v_;}
5571};
Eric Fiselierab6bb302017-01-05 01:15:42 +00005572#endif
5573
5574#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5575 defined(_LIBCPP_BUILDING_MEMORY)
5576_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5577#else
5578// This function is only offered in C++03 under ABI v1.
5579# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5580inline _LIBCPP_INLINE_VISIBILITY
5581pointer_safety get_pointer_safety() _NOEXCEPT {
5582 return pointer_safety::relaxed;
5583}
5584# endif
5585#endif
5586
Howard Hinnantc51e1022010-05-11 19:42:16 +00005587
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005588_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5589_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5590_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005591_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005592
5593template <class _Tp>
5594inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3b6579a2010-08-22 00:02:43 +00005595_Tp*
Howard Hinnantc51e1022010-05-11 19:42:16 +00005596undeclare_reachable(_Tp* __p)
5597{
5598 return static_cast<_Tp*>(__undeclare_reachable(__p));
5599}
5600
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00005601_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnantc51e1022010-05-11 19:42:16 +00005602
Marshall Clow8982dcd2015-07-13 20:04:56 +00005603// --- Helper for container swap --
5604template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005605inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005606void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5607#if _LIBCPP_STD_VER >= 14
5608 _NOEXCEPT
5609#else
5610 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5611#endif
5612{
Aditya Kumar7c5db692017-08-20 10:38:55 +00005613 __swap_allocator(__a1, __a2,
Marshall Clow8982dcd2015-07-13 20:04:56 +00005614 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5615}
5616
5617template <typename _Alloc>
5618_LIBCPP_INLINE_VISIBILITY
5619void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5620#if _LIBCPP_STD_VER >= 14
5621 _NOEXCEPT
5622#else
5623 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5624#endif
5625{
5626 using _VSTD::swap;
5627 swap(__a1, __a2);
5628}
5629
5630template <typename _Alloc>
Eric Fiselier6585c752016-04-21 22:54:21 +00005631inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8982dcd2015-07-13 20:04:56 +00005632void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5633
Marshall Clowff91de82015-08-18 19:51:37 +00005634template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
Aditya Kumar7c5db692017-08-20 10:38:55 +00005635struct __noexcept_move_assign_container : public integral_constant<bool,
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00005636 _Traits::propagate_on_container_move_assignment::value
5637#if _LIBCPP_STD_VER > 14
5638 || _Traits::is_always_equal::value
5639#else
5640 && is_nothrow_move_assignable<_Alloc>::value
5641#endif
5642 > {};
Marshall Clow8982dcd2015-07-13 20:04:56 +00005643
Marshall Clowa591b9a2016-07-11 21:38:08 +00005644
5645#ifndef _LIBCPP_HAS_NO_VARIADICS
5646template <class _Tp, class _Alloc>
5647struct __temp_value {
5648 typedef allocator_traits<_Alloc> _Traits;
Aditya Kumar7c5db692017-08-20 10:38:55 +00005649
Marshall Clowa591b9a2016-07-11 21:38:08 +00005650 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5651 _Alloc &__a;
5652
5653 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5654 _Tp & get() { return *__addr(); }
Aditya Kumar7c5db692017-08-20 10:38:55 +00005655
Marshall Clowa591b9a2016-07-11 21:38:08 +00005656 template<class... _Args>
5657 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5658 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
Aditya Kumar7c5db692017-08-20 10:38:55 +00005659
Marshall Clowa591b9a2016-07-11 21:38:08 +00005660 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5661 };
5662#endif
5663
Marshall Clow82c90aa2018-01-11 19:36:22 +00005664#if _LIBCPP_STD_VER > 14
5665template<typename _Alloc, typename = void>
5666struct __is_allocator : false_type {};
5667
5668template<typename _Alloc>
5669struct __is_allocator<_Alloc,
5670 void_t<typename _Alloc::value_type, decltype(_VSTD::declval<_Alloc&>().allocate(size_t{}))>>
5671 : true_type {};
5672#endif
5673
Howard Hinnantc51e1022010-05-11 19:42:16 +00005674_LIBCPP_END_NAMESPACE_STD
5675
Eric Fiselierf4433a32017-05-31 22:07:49 +00005676_LIBCPP_POP_MACROS
5677
Howard Hinnantc51e1022010-05-11 19:42:16 +00005678#endif // _LIBCPP_MEMORY