blob: 1b58550bc9549e686981bde85eea8da63401d58c [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
2//===-------------------------- memory ------------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:165//
Howard Hinnant412dbeb2010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_MEMORY
12#define _LIBCPP_MEMORY
13
14/*
15 memory synopsis
16
17namespace std
18{
19
20struct allocator_arg_t { };
21constexpr allocator_arg_t allocator_arg = allocator_arg_t();
22
23template <class T, class Alloc> struct uses_allocator;
24
25template <class Ptr>
26struct pointer_traits
27{
28 typedef Ptr pointer;
29 typedef <details> element_type;
30 typedef <details> difference_type;
Howard Hinnantb3371f62010-08-22 00:02:4331
Howard Hinnant3e519522010-05-11 19:42:1632 template <class U> using rebind = <details>;
Howard Hinnantb3371f62010-08-22 00:02:4333
Howard Hinnant3e519522010-05-11 19:42:1634 static pointer pointer_to(<details>);
35};
36
Howard Hinnant3739fe72011-05-28 14:41:1337template <class T>
38struct pointer_traits<T*>
39{
40 typedef T* pointer;
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
43
44 template <class U> using rebind = U*;
45
46 static pointer pointer_to(<details>) noexcept;
47};
48
Howard Hinnant3e519522010-05-11 19:42:1649template <class Alloc>
50struct allocator_traits
51{
52 typedef Alloc allocator_type;
53 typedef typename allocator_type::value_type
54 value_type;
55
56 typedef Alloc::pointer | value_type* pointer;
57 typedef Alloc::const_pointer
58 | pointer_traits<pointer>::rebind<const value_type>
59 const_pointer;
60 typedef Alloc::void_pointer
61 | pointer_traits<pointer>::rebind<void>
62 void_pointer;
63 typedef Alloc::const_void_pointer
64 | pointer_traits<pointer>::rebind<const void>
65 const_void_pointer;
66 typedef Alloc::difference_type
Howard Hinnanta4a1ef12010-11-18 01:40:0067 | pointer_traits<pointer>::difference_type
68 difference_type;
69 typedef Alloc::size_type
70 | make_unsigned<difference_type>::type
71 size_type;
Howard Hinnant3e519522010-05-11 19:42:1672 typedef Alloc::propagate_on_container_copy_assignment
73 | false_type propagate_on_container_copy_assignment;
74 typedef Alloc::propagate_on_container_move_assignment
75 | false_type propagate_on_container_move_assignment;
76 typedef Alloc::propagate_on_container_swap
77 | false_type propagate_on_container_swap;
Marshall Clow31a47312015-06-02 16:34:0378 typedef Alloc::is_always_equal
79 | is_empty is_always_equal;
Howard Hinnant3e519522010-05-11 19:42:1680
81 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
82 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
83
84 static pointer allocate(allocator_type& a, size_type n);
85 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
86
Howard Hinnant3739fe72011-05-28 14:41:1387 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
Howard Hinnant3e519522010-05-11 19:42:1688
89 template <class T, class... Args>
90 static void construct(allocator_type& a, T* p, Args&&... args);
91
92 template <class T>
93 static void destroy(allocator_type& a, T* p);
94
Marshall Clow06fbed02013-08-27 20:22:1595 static size_type max_size(const allocator_type& a); // noexcept in C++14
Howard Hinnant3e519522010-05-11 19:42:1696
97 static allocator_type
98 select_on_container_copy_construction(const allocator_type& a);
99};
100
101template <>
102class allocator<void>
103{
104public:
105 typedef void* pointer;
106 typedef const void* const_pointer;
107 typedef void value_type;
108
109 template <class _Up> struct rebind {typedef allocator<_Up> other;};
110};
111
112template <class T>
113class allocator
114{
115public:
116 typedef size_t size_type;
117 typedef ptrdiff_t difference_type;
118 typedef T* pointer;
119 typedef const T* const_pointer;
120 typedef typename add_lvalue_reference<T>::type reference;
121 typedef typename add_lvalue_reference<const T>::type const_reference;
122 typedef T value_type;
123
124 template <class U> struct rebind {typedef allocator<U> other;};
125
Howard Hinnant3739fe72011-05-28 14:41:13126 allocator() noexcept;
127 allocator(const allocator&) noexcept;
128 template <class U> allocator(const allocator<U>&) noexcept;
129 ~allocator();
130 pointer address(reference x) const noexcept;
131 const_pointer address(const_reference x) const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16132 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
Howard Hinnant3739fe72011-05-28 14:41:13133 void deallocate(pointer p, size_type n) noexcept;
134 size_type max_size() const noexcept;
135 template<class U, class... Args>
136 void construct(U* p, Args&&... args);
137 template <class U>
138 void destroy(U* p);
Howard Hinnant3e519522010-05-11 19:42:16139};
140
141template <class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13142bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16143
144template <class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13145bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
Howard Hinnant3e519522010-05-11 19:42:16146
147template <class OutputIterator, class T>
148class raw_storage_iterator
149 : public iterator<output_iterator_tag,
150 T, // purposefully not C++03
151 ptrdiff_t, // purposefully not C++03
152 T*, // purposefully not C++03
153 raw_storage_iterator&> // purposefully not C++03
154{
155public:
156 explicit raw_storage_iterator(OutputIterator x);
157 raw_storage_iterator& operator*();
158 raw_storage_iterator& operator=(const T& element);
159 raw_storage_iterator& operator++();
160 raw_storage_iterator operator++(int);
161};
162
Howard Hinnant3739fe72011-05-28 14:41:13163template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
164template <class T> void return_temporary_buffer(T* p) noexcept;
165
166template <class T> T* addressof(T& r) noexcept;
Marshall Clow1c7fe122016-11-14 18:22:19167template <class T> T* addressof(const T&& r) noexcept = delete;
Howard Hinnant3e519522010-05-11 19:42:16168
169template <class InputIterator, class ForwardIterator>
170ForwardIterator
171uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
172
Howard Hinnant3739fe72011-05-28 14:41:13173template <class InputIterator, class Size, class ForwardIterator>
174ForwardIterator
175uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
176
Howard Hinnant3e519522010-05-11 19:42:16177template <class ForwardIterator, class T>
178void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
179
180template <class ForwardIterator, class Size, class T>
Howard Hinnant48d05bd2010-11-18 16:13:03181ForwardIterator
182uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
Howard Hinnant3e519522010-05-11 19:42:16183
Eric Fiseliere4d9c312016-07-24 03:51:39184template <class T>
185void destroy_at(T* location);
186
187template <class ForwardIterator>
188 void destroy(ForwardIterator first, ForwardIterator last);
189
190template <class ForwardIterator, class Size>
191 ForwardIterator destroy_n(ForwardIterator first, Size n);
192
193template <class InputIterator, class ForwardIterator>
194 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
195
196template <class InputIterator, class Size, class ForwardIterator>
197 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
198
199template <class ForwardIterator>
200 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
201
202template <class ForwardIterator, class Size>
203 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
204
205template <class ForwardIterator>
206 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
207
208template <class ForwardIterator, class Size>
209 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
210
Howard Hinnant3e519522010-05-11 19:42:16211template <class Y> struct auto_ptr_ref {};
212
213template<class X>
214class auto_ptr
215{
216public:
217 typedef X element_type;
218
219 explicit auto_ptr(X* p =0) throw();
220 auto_ptr(auto_ptr&) throw();
221 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
222 auto_ptr& operator=(auto_ptr&) throw();
223 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
224 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
225 ~auto_ptr() throw();
226
227 typename add_lvalue_reference<X>::type operator*() const throw();
228 X* operator->() const throw();
229 X* get() const throw();
230 X* release() throw();
231 void reset(X* p =0) throw();
232
233 auto_ptr(auto_ptr_ref<X>) throw();
234 template<class Y> operator auto_ptr_ref<Y>() throw();
235 template<class Y> operator auto_ptr<Y>() throw();
236};
237
Howard Hinnant20cc2a42010-08-19 18:39:17238template <class T>
239struct default_delete
240{
Howard Hinnant3739fe72011-05-28 14:41:13241 constexpr default_delete() noexcept = default;
242 template <class U> default_delete(const default_delete<U>&) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17243
Howard Hinnant3739fe72011-05-28 14:41:13244 void operator()(T*) const noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17245};
246
247template <class T>
248struct default_delete<T[]>
249{
Howard Hinnant3739fe72011-05-28 14:41:13250 constexpr default_delete() noexcept = default;
251 void operator()(T*) const noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17252 template <class U> void operator()(U*) const = delete;
253};
254
Howard Hinnant20cc2a42010-08-19 18:39:17255template <class T, class D = default_delete<T>>
256class unique_ptr
257{
258public:
259 typedef see below pointer;
260 typedef T element_type;
261 typedef D deleter_type;
262
263 // constructors
Howard Hinnant3739fe72011-05-28 14:41:13264 constexpr unique_ptr() noexcept;
265 explicit unique_ptr(pointer p) noexcept;
266 unique_ptr(pointer p, see below d1) noexcept;
267 unique_ptr(pointer p, see below d2) noexcept;
268 unique_ptr(unique_ptr&& u) noexcept;
269 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnant20cc2a42010-08-19 18:39:17270 template <class U, class E>
Howard Hinnant3739fe72011-05-28 14:41:13271 unique_ptr(unique_ptr<U, E>&& u) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17272 template <class U>
Howard Hinnant3739fe72011-05-28 14:41:13273 unique_ptr(auto_ptr<U>&& u) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17274
275 // destructor
276 ~unique_ptr();
277
278 // assignment
Howard Hinnant3739fe72011-05-28 14:41:13279 unique_ptr& operator=(unique_ptr&& u) noexcept;
280 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
281 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17282
283 // observers
284 typename add_lvalue_reference<T>::type operator*() const;
Howard Hinnant3739fe72011-05-28 14:41:13285 pointer operator->() const noexcept;
286 pointer get() const noexcept;
287 deleter_type& get_deleter() noexcept;
288 const deleter_type& get_deleter() const noexcept;
289 explicit operator bool() const noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17290
291 // modifiers
Howard Hinnant3739fe72011-05-28 14:41:13292 pointer release() noexcept;
293 void reset(pointer p = pointer()) noexcept;
294 void swap(unique_ptr& u) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17295};
296
297template <class T, class D>
298class unique_ptr<T[], D>
299{
300public:
301 typedef implementation-defined pointer;
302 typedef T element_type;
303 typedef D deleter_type;
304
305 // constructors
Howard Hinnant3739fe72011-05-28 14:41:13306 constexpr unique_ptr() noexcept;
307 explicit unique_ptr(pointer p) noexcept;
308 unique_ptr(pointer p, see below d) noexcept;
309 unique_ptr(pointer p, see below d) noexcept;
310 unique_ptr(unique_ptr&& u) noexcept;
311 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
Howard Hinnant20cc2a42010-08-19 18:39:17312
313 // destructor
Howard Hinnantb3371f62010-08-22 00:02:43314 ~unique_ptr();
Howard Hinnant20cc2a42010-08-19 18:39:17315
316 // assignment
Howard Hinnant3739fe72011-05-28 14:41:13317 unique_ptr& operator=(unique_ptr&& u) noexcept;
318 unique_ptr& operator=(nullptr_t) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17319
320 // observers
321 T& operator[](size_t i) const;
Howard Hinnant3739fe72011-05-28 14:41:13322 pointer get() const noexcept;
323 deleter_type& get_deleter() noexcept;
324 const deleter_type& get_deleter() const noexcept;
325 explicit operator bool() const noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17326
327 // modifiers
Howard Hinnant3739fe72011-05-28 14:41:13328 pointer release() noexcept;
329 void reset(pointer p = pointer()) noexcept;
330 void reset(nullptr_t) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17331 template <class U> void reset(U) = delete;
Howard Hinnant3739fe72011-05-28 14:41:13332 void swap(unique_ptr& u) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17333};
334
335template <class T, class D>
Howard Hinnant3739fe72011-05-28 14:41:13336 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17337
338template <class T1, class D1, class T2, class D2>
339 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
340template <class T1, class D1, class T2, class D2>
341 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
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);
350
Howard Hinnant3739fe72011-05-28 14:41:13351template <class T, class D>
352 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
353template <class T, class D>
354 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
355template <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;
359
360template <class T, class D>
361 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
362template <class T, class D>
363 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
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);
376
Howard Hinnant20cc2a42010-08-19 18:39:17377class bad_weak_ptr
378 : public std::exception
379{
Howard Hinnant3739fe72011-05-28 14:41:13380 bad_weak_ptr() noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17381};
382
Marshall Clow28d8ba52013-07-01 18:16:03383template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
384template<class T> unique_ptr<T> make_unique(size_t n); // C++14
385template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
386
Howard Hinnant20cc2a42010-08-19 18:39:17387template<class T>
388class shared_ptr
389{
390public:
391 typedef T element_type;
Eric Fiselier68436a92016-06-27 01:02:43392 typedef weak_ptr<T> weak_type; // C++17
Howard Hinnant20cc2a42010-08-19 18:39:17393
394 // constructors:
Howard Hinnant3739fe72011-05-28 14:41:13395 constexpr shared_ptr() noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17396 template<class Y> explicit shared_ptr(Y* p);
397 template<class Y, class D> shared_ptr(Y* p, D d);
398 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
399 template <class D> shared_ptr(nullptr_t p, D d);
400 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
Howard Hinnant3739fe72011-05-28 14:41:13401 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
402 shared_ptr(const shared_ptr& r) noexcept;
403 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
404 shared_ptr(shared_ptr&& r) noexcept;
405 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17406 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
407 template<class Y> shared_ptr(auto_ptr<Y>&& r);
408 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
409 shared_ptr(nullptr_t) : shared_ptr() { }
410
411 // destructor:
412 ~shared_ptr();
413
414 // assignment:
Howard Hinnant3739fe72011-05-28 14:41:13415 shared_ptr& operator=(const shared_ptr& r) noexcept;
416 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
417 shared_ptr& operator=(shared_ptr&& r) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17418 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
419 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
420 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
421
422 // modifiers:
Howard Hinnant3739fe72011-05-28 14:41:13423 void swap(shared_ptr& r) noexcept;
424 void reset() noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17425 template<class Y> void reset(Y* p);
426 template<class Y, class D> void reset(Y* p, D d);
427 template<class Y, class D, class A> void reset(Y* p, D d, A a);
428
Howard Hinnant3739fe72011-05-28 14:41:13429 // observers:
430 T* get() const noexcept;
431 T& operator*() const noexcept;
432 T* operator->() const noexcept;
433 long use_count() const noexcept;
434 bool unique() const noexcept;
435 explicit operator bool() const noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17436 template<class U> bool owner_before(shared_ptr<U> const& b) const;
437 template<class U> bool owner_before(weak_ptr<U> const& b) const;
438};
439
440// shared_ptr comparisons:
441template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13442 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17443template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13444 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17445template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13446 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17447template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13448 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17449template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13450 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17451template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13452 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
453
454template <class T>
455 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
456template <class T>
457 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
458template <class T>
459 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
460template <class T>
461 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
462template <class T>
463 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
464template <class T>
465bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
466template <class T>
467 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
468template <class T>
469 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
470template <class T>
471 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
472template <class T>
473 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
474template <class T>
475 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
476template <class T>
477 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17478
479// shared_ptr specialized algorithms:
Howard Hinnant3739fe72011-05-28 14:41:13480template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17481
482// shared_ptr casts:
483template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13484 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17485template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13486 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17487template<class T, class U>
Howard Hinnant3739fe72011-05-28 14:41:13488 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17489
490// shared_ptr I/O:
491template<class E, class T, class Y>
492 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
493
494// shared_ptr get_deleter:
Howard Hinnant3739fe72011-05-28 14:41:13495template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17496
497template<class T, class... Args>
498 shared_ptr<T> make_shared(Args&&... args);
499template<class T, class A, class... Args>
500 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
501
502template<class T>
503class weak_ptr
504{
505public:
506 typedef T element_type;
507
508 // constructors
Howard Hinnant3739fe72011-05-28 14:41:13509 constexpr weak_ptr() noexcept;
510 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
511 weak_ptr(weak_ptr const& r) noexcept;
512 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
Marshall Clow4703f762014-03-05 03:12:04513 weak_ptr(weak_ptr&& r) noexcept; // C++14
514 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnant20cc2a42010-08-19 18:39:17515
516 // destructor
517 ~weak_ptr();
518
519 // assignment
Howard Hinnant3739fe72011-05-28 14:41:13520 weak_ptr& operator=(weak_ptr const& r) noexcept;
521 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
522 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
Marshall Clow4703f762014-03-05 03:12:04523 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
524 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
Howard Hinnant20cc2a42010-08-19 18:39:17525
526 // modifiers
Howard Hinnant3739fe72011-05-28 14:41:13527 void swap(weak_ptr& r) noexcept;
528 void reset() noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17529
530 // observers
Howard Hinnant3739fe72011-05-28 14:41:13531 long use_count() const noexcept;
532 bool expired() const noexcept;
533 shared_ptr<T> lock() const noexcept;
Marshall Clow710a9022013-09-03 14:37:50534 template<class U> bool owner_before(shared_ptr<U> const& b) const;
535 template<class U> bool owner_before(weak_ptr<U> const& b) const;
Howard Hinnant20cc2a42010-08-19 18:39:17536};
537
538// weak_ptr specialized algorithms:
Howard Hinnant3739fe72011-05-28 14:41:13539template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17540
541// class owner_less:
542template<class T> struct owner_less;
543
544template<class T>
545struct owner_less<shared_ptr<T>>
546 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
547{
548 typedef bool result_type;
549 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
550 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
551 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
552};
553
554template<class T>
555struct owner_less<weak_ptr<T>>
556 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
557{
558 typedef bool result_type;
559 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
560 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
561 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
562};
563
564template<class T>
565class enable_shared_from_this
566{
567protected:
Howard Hinnant3739fe72011-05-28 14:41:13568 constexpr enable_shared_from_this() noexcept;
569 enable_shared_from_this(enable_shared_from_this const&) noexcept;
570 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17571 ~enable_shared_from_this();
572public:
573 shared_ptr<T> shared_from_this();
574 shared_ptr<T const> shared_from_this() const;
575};
576
577template<class T>
578 bool atomic_is_lock_free(const shared_ptr<T>* p);
579template<class T>
580 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
581template<class T>
582 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
583template<class T>
584 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
585template<class T>
586 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
587template<class T>
588 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
589template<class T>
590 shared_ptr<T>
591 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
592template<class T>
593 bool
594 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
595template<class T>
596 bool
597 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
598template<class T>
599 bool
600 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
601 shared_ptr<T> w, memory_order success,
602 memory_order failure);
603template<class T>
604 bool
605 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
606 shared_ptr<T> w, memory_order success,
607 memory_order failure);
608// Hash support
609template <class T> struct hash;
610template <class T, class D> struct hash<unique_ptr<T, D> >;
611template <class T> struct hash<shared_ptr<T> >;
612
613// Pointer safety
614enum class pointer_safety { relaxed, preferred, strict };
615void declare_reachable(void *p);
616template <class T> T *undeclare_reachable(T *p);
617void declare_no_pointers(char *p, size_t n);
618void undeclare_no_pointers(char *p, size_t n);
Howard Hinnant3739fe72011-05-28 14:41:13619pointer_safety get_pointer_safety() noexcept;
Howard Hinnant20cc2a42010-08-19 18:39:17620
Howard Hinnant3e519522010-05-11 19:42:16621void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
622
623} // std
624
625*/
626
627#include <__config>
628#include <type_traits>
629#include <typeinfo>
630#include <cstddef>
631#include <cstdint>
632#include <new>
633#include <utility>
634#include <limits>
635#include <iterator>
636#include <__functional_base>
Howard Hinnante3163f52011-07-18 15:51:59637#include <iosfwd>
Howard Hinnanta87b5e32011-12-19 17:58:44638#include <tuple>
Eric Fiselier4524d6e2016-05-07 03:12:24639#include <stdexcept>
Howard Hinnant9741d6c92012-02-15 00:41:34640#include <cstring>
Howard Hinnant3e519522010-05-11 19:42:16641
Eric Fiselier749adeb2015-08-19 17:21:46642#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnantd77851e2012-07-30 01:40:57643# include <atomic>
644#endif
645
Howard Hinnantab4f4382011-11-29 16:45:27646#include <__undef_min_max>
647
Howard Hinnant073458b2011-10-17 20:05:10648#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16649#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10650#endif
Howard Hinnant3e519522010-05-11 19:42:16651
652_LIBCPP_BEGIN_NAMESPACE_STD
653
Eric Fiselier1faf2892015-07-07 00:27:16654template <class _ValueType>
655inline _LIBCPP_ALWAYS_INLINE
656_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
657#if !defined(_LIBCPP_HAS_NO_THREADS) && \
658 defined(__ATOMIC_RELAXED) && \
659 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
660 return __atomic_load_n(__value, __ATOMIC_RELAXED);
661#else
662 return *__value;
663#endif
664}
665
Kuba Brecka224264a2016-09-04 09:55:12666template <class _ValueType>
667inline _LIBCPP_ALWAYS_INLINE
668_ValueType __libcpp_acquire_load(_ValueType const* __value) {
669#if !defined(_LIBCPP_HAS_NO_THREADS) && \
670 defined(__ATOMIC_ACQUIRE) && \
671 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
672 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
673#else
674 return *__value;
675#endif
676}
677
Marshall Clow1c7fe122016-11-14 18:22:19678// addressof moved to <type_traits>
Douglas Gregor64ec1012011-06-22 22:17:44679
Howard Hinnant3e519522010-05-11 19:42:16680template <class _Tp> class allocator;
681
682template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00683class _LIBCPP_TEMPLATE_VIS allocator<void>
Howard Hinnant3e519522010-05-11 19:42:16684{
685public:
686 typedef void* pointer;
687 typedef const void* const_pointer;
688 typedef void value_type;
689
690 template <class _Up> struct rebind {typedef allocator<_Up> other;};
691};
692
Howard Hinnant21fa1882012-01-19 23:15:22693template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00694class _LIBCPP_TEMPLATE_VIS allocator<const void>
Howard Hinnant21fa1882012-01-19 23:15:22695{
696public:
697 typedef const void* pointer;
698 typedef const void* const_pointer;
699 typedef const void value_type;
700
701 template <class _Up> struct rebind {typedef allocator<_Up> other;};
702};
703
Howard Hinnant3e519522010-05-11 19:42:16704// pointer_traits
705
706template <class _Tp>
707struct __has_element_type
708{
709private:
Howard Hinnant54d333a2012-10-30 19:06:59710 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16711 template <class _Up> static __two __test(...);
712 template <class _Up> static char __test(typename _Up::element_type* = 0);
713public:
714 static const bool value = sizeof(__test<_Tp>(0)) == 1;
715};
716
717template <class _Ptr, bool = __has_element_type<_Ptr>::value>
718struct __pointer_traits_element_type;
719
720template <class _Ptr>
721struct __pointer_traits_element_type<_Ptr, true>
722{
723 typedef typename _Ptr::element_type type;
724};
725
726#ifndef _LIBCPP_HAS_NO_VARIADICS
727
728template <template <class, class...> class _Sp, class _Tp, class ..._Args>
729struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
730{
731 typedef typename _Sp<_Tp, _Args...>::element_type type;
732};
733
734template <template <class, class...> class _Sp, class _Tp, class ..._Args>
735struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
736{
737 typedef _Tp type;
738};
739
Howard Hinnantb3371f62010-08-22 00:02:43740#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16741
742template <template <class> class _Sp, class _Tp>
743struct __pointer_traits_element_type<_Sp<_Tp>, true>
744{
745 typedef typename _Sp<_Tp>::element_type type;
746};
747
748template <template <class> class _Sp, class _Tp>
749struct __pointer_traits_element_type<_Sp<_Tp>, false>
750{
751 typedef _Tp type;
752};
753
754template <template <class, class> class _Sp, class _Tp, class _A0>
755struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
756{
757 typedef typename _Sp<_Tp, _A0>::element_type type;
758};
759
760template <template <class, class> class _Sp, class _Tp, class _A0>
761struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
762{
763 typedef _Tp type;
764};
765
766template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
767struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
768{
769 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
770};
771
772template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
773struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
774{
775 typedef _Tp type;
776};
777
778template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
779 class _A1, class _A2>
780struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
781{
782 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
783};
784
785template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
786 class _A1, class _A2>
787struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
788{
789 typedef _Tp type;
790};
791
Howard Hinnantb3371f62010-08-22 00:02:43792#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16793
794template <class _Tp>
795struct __has_difference_type
796{
797private:
Howard Hinnant54d333a2012-10-30 19:06:59798 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16799 template <class _Up> static __two __test(...);
800 template <class _Up> static char __test(typename _Up::difference_type* = 0);
801public:
802 static const bool value = sizeof(__test<_Tp>(0)) == 1;
803};
804
805template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
806struct __pointer_traits_difference_type
807{
808 typedef ptrdiff_t type;
809};
810
811template <class _Ptr>
812struct __pointer_traits_difference_type<_Ptr, true>
813{
814 typedef typename _Ptr::difference_type type;
815};
816
817template <class _Tp, class _Up>
818struct __has_rebind
819{
820private:
Howard Hinnant54d333a2012-10-30 19:06:59821 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16822 template <class _Xp> static __two __test(...);
823 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
824public:
825 static const bool value = sizeof(__test<_Tp>(0)) == 1;
826};
827
828template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
829struct __pointer_traits_rebind
830{
Eric Fiselier54613ab2016-09-25 03:34:28831#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16832 typedef typename _Tp::template rebind<_Up> type;
833#else
834 typedef typename _Tp::template rebind<_Up>::other type;
835#endif
836};
837
838#ifndef _LIBCPP_HAS_NO_VARIADICS
839
840template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
841struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
842{
Eric Fiselier54613ab2016-09-25 03:34:28843#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16844 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
845#else
846 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
847#endif
848};
849
850template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
851struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
852{
853 typedef _Sp<_Up, _Args...> type;
854};
855
Howard Hinnantb3371f62010-08-22 00:02:43856#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16857
858template <template <class> class _Sp, class _Tp, class _Up>
859struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
860{
Eric Fiselier54613ab2016-09-25 03:34:28861#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16862 typedef typename _Sp<_Tp>::template rebind<_Up> type;
863#else
864 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
865#endif
866};
867
868template <template <class> class _Sp, class _Tp, class _Up>
869struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
870{
871 typedef _Sp<_Up> type;
872};
873
874template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
875struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
876{
Eric Fiselier54613ab2016-09-25 03:34:28877#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16878 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
879#else
880 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
881#endif
882};
883
884template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
885struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
886{
887 typedef _Sp<_Up, _A0> type;
888};
889
890template <template <class, class, class> class _Sp, class _Tp, class _A0,
891 class _A1, class _Up>
892struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
893{
Eric Fiselier54613ab2016-09-25 03:34:28894#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16895 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
896#else
897 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
898#endif
899};
900
901template <template <class, class, class> class _Sp, class _Tp, class _A0,
902 class _A1, class _Up>
903struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
904{
905 typedef _Sp<_Up, _A0, _A1> type;
906};
907
908template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
909 class _A1, class _A2, class _Up>
910struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
911{
Eric Fiselier54613ab2016-09-25 03:34:28912#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16913 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
914#else
915 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
916#endif
917};
918
919template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
920 class _A1, class _A2, class _Up>
921struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
922{
923 typedef _Sp<_Up, _A0, _A1, _A2> type;
924};
925
Howard Hinnantb3371f62010-08-22 00:02:43926#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16927
928template <class _Ptr>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00929struct _LIBCPP_TEMPLATE_VIS pointer_traits
Howard Hinnant3e519522010-05-11 19:42:16930{
931 typedef _Ptr pointer;
932 typedef typename __pointer_traits_element_type<pointer>::type element_type;
933 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
934
Eric Fiselier54613ab2016-09-25 03:34:28935#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantf7384972011-05-11 20:21:19936 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
Howard Hinnant3e519522010-05-11 19:42:16937#else
938 template <class _Up> struct rebind
939 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
Eric Fiselier54613ab2016-09-25 03:34:28940#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16941
942private:
943 struct __nat {};
944public:
Howard Hinnant848a5372010-09-22 16:48:34945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16946 static pointer pointer_to(typename conditional<is_void<element_type>::value,
947 __nat, element_type>::type& __r)
948 {return pointer::pointer_to(__r);}
949};
950
951template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:00952struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
Howard Hinnant3e519522010-05-11 19:42:16953{
954 typedef _Tp* pointer;
955 typedef _Tp element_type;
956 typedef ptrdiff_t difference_type;
957
Eric Fiselier54613ab2016-09-25 03:34:28958#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16959 template <class _Up> using rebind = _Up*;
960#else
961 template <class _Up> struct rebind {typedef _Up* other;};
962#endif
963
964private:
965 struct __nat {};
966public:
Howard Hinnant848a5372010-09-22 16:48:34967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16968 static pointer pointer_to(typename conditional<is_void<element_type>::value,
Howard Hinnant3739fe72011-05-28 14:41:13969 __nat, element_type>::type& __r) _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:19970 {return _VSTD::addressof(__r);}
Howard Hinnant3e519522010-05-11 19:42:16971};
972
Eric Fiselier1c813402015-08-23 02:56:05973template <class _From, class _To>
974struct __rebind_pointer {
Eric Fiselier54613ab2016-09-25 03:34:28975#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier1c813402015-08-23 02:56:05976 typedef typename pointer_traits<_From>::template rebind<_To> type;
977#else
978 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
979#endif
980};
981
Howard Hinnant3e519522010-05-11 19:42:16982// allocator_traits
983
984namespace __has_pointer_type_imp
985{
Howard Hinnantb1c82cd2013-09-21 01:45:05986 template <class _Up> static __two __test(...);
987 template <class _Up> static char __test(typename _Up::pointer* = 0);
Howard Hinnant3e519522010-05-11 19:42:16988}
989
990template <class _Tp>
991struct __has_pointer_type
Howard Hinnantb1c82cd2013-09-21 01:45:05992 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
Howard Hinnant3e519522010-05-11 19:42:16993{
994};
995
996namespace __pointer_type_imp
997{
998
999template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1000struct __pointer_type
1001{
1002 typedef typename _Dp::pointer type;
1003};
1004
1005template <class _Tp, class _Dp>
1006struct __pointer_type<_Tp, _Dp, false>
1007{
1008 typedef _Tp* type;
1009};
1010
Howard Hinnanta4a1ef12010-11-18 01:40:001011} // __pointer_type_imp
Howard Hinnant3e519522010-05-11 19:42:161012
1013template <class _Tp, class _Dp>
1014struct __pointer_type
1015{
1016 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1017};
1018
1019template <class _Tp>
1020struct __has_const_pointer
1021{
1022private:
Howard Hinnant54d333a2012-10-30 19:06:591023 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161024 template <class _Up> static __two __test(...);
1025 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1026public:
1027 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1028};
1029
1030template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1031struct __const_pointer
1032{
1033 typedef typename _Alloc::const_pointer type;
1034};
1035
1036template <class _Tp, class _Ptr, class _Alloc>
1037struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1038{
Eric Fiselier54613ab2016-09-25 03:34:281039#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161040 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1041#else
1042 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1043#endif
1044};
1045
1046template <class _Tp>
1047struct __has_void_pointer
1048{
1049private:
Howard Hinnant54d333a2012-10-30 19:06:591050 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161051 template <class _Up> static __two __test(...);
1052 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1053public:
1054 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1055};
1056
1057template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1058struct __void_pointer
1059{
1060 typedef typename _Alloc::void_pointer type;
1061};
1062
1063template <class _Ptr, class _Alloc>
1064struct __void_pointer<_Ptr, _Alloc, false>
1065{
Eric Fiselier54613ab2016-09-25 03:34:281066#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161067 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1068#else
1069 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1070#endif
1071};
1072
1073template <class _Tp>
1074struct __has_const_void_pointer
1075{
1076private:
Howard Hinnant54d333a2012-10-30 19:06:591077 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161078 template <class _Up> static __two __test(...);
1079 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1080public:
1081 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1082};
1083
1084template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1085struct __const_void_pointer
1086{
1087 typedef typename _Alloc::const_void_pointer type;
1088};
1089
1090template <class _Ptr, class _Alloc>
1091struct __const_void_pointer<_Ptr, _Alloc, false>
1092{
Eric Fiselier54613ab2016-09-25 03:34:281093#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161094 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1095#else
1096 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1097#endif
1098};
1099
Howard Hinnantc003db12011-11-29 18:15:501100template <class _Tp>
Howard Hinnant3e519522010-05-11 19:42:161101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:501102_Tp*
1103__to_raw_pointer(_Tp* __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161104{
1105 return __p;
1106}
1107
1108template <class _Pointer>
1109inline _LIBCPP_INLINE_VISIBILITY
1110typename pointer_traits<_Pointer>::element_type*
Howard Hinnant3739fe72011-05-28 14:41:131111__to_raw_pointer(_Pointer __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161112{
Howard Hinnantce48a112011-06-30 21:18:191113 return _VSTD::__to_raw_pointer(__p.operator->());
Howard Hinnant3e519522010-05-11 19:42:161114}
1115
1116template <class _Tp>
1117struct __has_size_type
1118{
1119private:
Howard Hinnant54d333a2012-10-30 19:06:591120 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161121 template <class _Up> static __two __test(...);
1122 template <class _Up> static char __test(typename _Up::size_type* = 0);
1123public:
1124 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1125};
1126
Howard Hinnanta4a1ef12010-11-18 01:40:001127template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
Howard Hinnant3e519522010-05-11 19:42:161128struct __size_type
1129{
Howard Hinnanta4a1ef12010-11-18 01:40:001130 typedef typename make_unsigned<_DiffType>::type type;
Howard Hinnant3e519522010-05-11 19:42:161131};
1132
Howard Hinnanta4a1ef12010-11-18 01:40:001133template <class _Alloc, class _DiffType>
1134struct __size_type<_Alloc, _DiffType, true>
Howard Hinnant3e519522010-05-11 19:42:161135{
1136 typedef typename _Alloc::size_type type;
1137};
1138
1139template <class _Tp>
1140struct __has_propagate_on_container_copy_assignment
1141{
1142private:
Howard Hinnant54d333a2012-10-30 19:06:591143 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161144 template <class _Up> static __two __test(...);
1145 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1146public:
1147 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1148};
1149
1150template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1151struct __propagate_on_container_copy_assignment
1152{
1153 typedef false_type type;
1154};
1155
1156template <class _Alloc>
1157struct __propagate_on_container_copy_assignment<_Alloc, true>
1158{
1159 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1160};
1161
1162template <class _Tp>
1163struct __has_propagate_on_container_move_assignment
1164{
1165private:
Howard Hinnant54d333a2012-10-30 19:06:591166 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161167 template <class _Up> static __two __test(...);
1168 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1169public:
1170 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1171};
1172
1173template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1174struct __propagate_on_container_move_assignment
1175{
1176 typedef false_type type;
1177};
1178
1179template <class _Alloc>
1180struct __propagate_on_container_move_assignment<_Alloc, true>
1181{
1182 typedef typename _Alloc::propagate_on_container_move_assignment type;
1183};
1184
1185template <class _Tp>
1186struct __has_propagate_on_container_swap
1187{
1188private:
Howard Hinnant54d333a2012-10-30 19:06:591189 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161190 template <class _Up> static __two __test(...);
1191 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1192public:
1193 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1194};
1195
1196template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1197struct __propagate_on_container_swap
1198{
1199 typedef false_type type;
1200};
1201
1202template <class _Alloc>
1203struct __propagate_on_container_swap<_Alloc, true>
1204{
1205 typedef typename _Alloc::propagate_on_container_swap type;
1206};
1207
Marshall Clow31a47312015-06-02 16:34:031208template <class _Tp>
1209struct __has_is_always_equal
1210{
1211private:
1212 struct __two {char __lx; char __lxx;};
1213 template <class _Up> static __two __test(...);
1214 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1215public:
1216 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1217};
1218
1219template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1220struct __is_always_equal
1221{
1222 typedef typename _VSTD::is_empty<_Alloc>::type type;
1223};
1224
1225template <class _Alloc>
1226struct __is_always_equal<_Alloc, true>
1227{
1228 typedef typename _Alloc::is_always_equal type;
1229};
1230
Howard Hinnant3e519522010-05-11 19:42:161231template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1232struct __has_rebind_other
1233{
1234private:
Howard Hinnant54d333a2012-10-30 19:06:591235 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:161236 template <class _Xp> static __two __test(...);
1237 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1238public:
1239 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1240};
1241
1242template <class _Tp, class _Up>
1243struct __has_rebind_other<_Tp, _Up, false>
1244{
1245 static const bool value = false;
1246};
1247
1248template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1249struct __allocator_traits_rebind
1250{
1251 typedef typename _Tp::template rebind<_Up>::other type;
1252};
1253
1254#ifndef _LIBCPP_HAS_NO_VARIADICS
1255
1256template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1257struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1258{
1259 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1260};
1261
1262template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1263struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1264{
1265 typedef _Alloc<_Up, _Args...> type;
1266};
1267
Howard Hinnantb3371f62010-08-22 00:02:431268#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161269
1270template <template <class> class _Alloc, class _Tp, class _Up>
1271struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1272{
1273 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1274};
1275
1276template <template <class> class _Alloc, class _Tp, class _Up>
1277struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1278{
1279 typedef _Alloc<_Up> type;
1280};
1281
Howard Hinnant3e519522010-05-11 19:42:161282template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1283struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1284{
1285 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1286};
1287
1288template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1289struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1290{
1291 typedef _Alloc<_Up, _A0> type;
1292};
1293
Howard Hinnant3e519522010-05-11 19:42:161294template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1295 class _A1, class _Up>
1296struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1297{
1298 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1299};
1300
1301template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1302 class _A1, class _Up>
1303struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1304{
1305 typedef _Alloc<_Up, _A0, _A1> type;
1306};
1307
Howard Hinnant3e519522010-05-11 19:42:161308template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1309 class _A1, class _A2, class _Up>
1310struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1311{
1312 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1313};
1314
1315template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1316 class _A1, class _A2, class _Up>
1317struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1318{
1319 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1320};
1321
Howard Hinnantb3371f62010-08-22 00:02:431322#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161323
Eric Fiselier54613ab2016-09-25 03:34:281324#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161325
1326template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1327auto
1328__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1329 -> decltype(__a.allocate(__sz, __p), true_type());
1330
1331template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1332auto
1333__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1334 -> false_type;
1335
1336template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1337struct __has_allocate_hint
1338 : integral_constant<bool,
1339 is_same<
1340 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1341 declval<_SizeType>(),
1342 declval<_ConstVoidPtr>())),
1343 true_type>::value>
1344{
1345};
1346
Eric Fiselier54613ab2016-09-25 03:34:281347#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161348
1349template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350struct __has_allocate_hint
1351 : true_type
1352{
1353};
1354
Eric Fiselier54613ab2016-09-25 03:34:281355#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161356
Eric Fiselier54613ab2016-09-25 03:34:281357#if !defined(_LIBCPP_CXX03_LANG)
Howard Hinnant3e519522010-05-11 19:42:161358
1359template <class _Alloc, class _Tp, class ..._Args>
Howard Hinnantce48a112011-06-30 21:18:191360decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1361 _VSTD::declval<_Args>()...),
Howard Hinnant3e519522010-05-11 19:42:161362 true_type())
1363__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1364
1365template <class _Alloc, class _Pointer, class ..._Args>
1366false_type
1367__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1368
1369template <class _Alloc, class _Pointer, class ..._Args>
1370struct __has_construct
1371 : integral_constant<bool,
1372 is_same<
1373 decltype(__has_construct_test(declval<_Alloc>(),
1374 declval<_Pointer>(),
1375 declval<_Args>()...)),
1376 true_type>::value>
1377{
1378};
1379
1380template <class _Alloc, class _Pointer>
1381auto
1382__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1383 -> decltype(__a.destroy(__p), true_type());
1384
1385template <class _Alloc, class _Pointer>
1386auto
1387__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1388 -> false_type;
1389
1390template <class _Alloc, class _Pointer>
1391struct __has_destroy
1392 : integral_constant<bool,
1393 is_same<
1394 decltype(__has_destroy_test(declval<_Alloc>(),
1395 declval<_Pointer>())),
1396 true_type>::value>
1397{
1398};
1399
1400template <class _Alloc>
1401auto
1402__has_max_size_test(_Alloc&& __a)
1403 -> decltype(__a.max_size(), true_type());
1404
1405template <class _Alloc>
1406auto
1407__has_max_size_test(const volatile _Alloc& __a)
1408 -> false_type;
1409
1410template <class _Alloc>
1411struct __has_max_size
1412 : integral_constant<bool,
1413 is_same<
1414 decltype(__has_max_size_test(declval<_Alloc&>())),
1415 true_type>::value>
1416{
1417};
1418
1419template <class _Alloc>
1420auto
1421__has_select_on_container_copy_construction_test(_Alloc&& __a)
1422 -> decltype(__a.select_on_container_copy_construction(), true_type());
1423
1424template <class _Alloc>
1425auto
1426__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1427 -> false_type;
1428
1429template <class _Alloc>
1430struct __has_select_on_container_copy_construction
1431 : integral_constant<bool,
1432 is_same<
1433 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1434 true_type>::value>
1435{
1436};
1437
Eric Fiselier54613ab2016-09-25 03:34:281438#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161439
1440#ifndef _LIBCPP_HAS_NO_VARIADICS
1441
1442template <class _Alloc, class _Pointer, class ..._Args>
1443struct __has_construct
1444 : false_type
1445{
1446};
1447
Howard Hinnant9741d6c92012-02-15 00:41:341448#else // _LIBCPP_HAS_NO_VARIADICS
1449
1450template <class _Alloc, class _Pointer, class _Args>
1451struct __has_construct
1452 : false_type
1453{
1454};
1455
Howard Hinnantb3371f62010-08-22 00:02:431456#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161457
1458template <class _Alloc, class _Pointer>
1459struct __has_destroy
1460 : false_type
1461{
1462};
1463
1464template <class _Alloc>
1465struct __has_max_size
1466 : true_type
1467{
1468};
1469
1470template <class _Alloc>
1471struct __has_select_on_container_copy_construction
1472 : false_type
1473{
1474};
1475
Eric Fiselier54613ab2016-09-25 03:34:281476#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161477
Howard Hinnanta4a1ef12010-11-18 01:40:001478template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1479struct __alloc_traits_difference_type
1480{
1481 typedef typename pointer_traits<_Ptr>::difference_type type;
1482};
1483
1484template <class _Alloc, class _Ptr>
1485struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1486{
1487 typedef typename _Alloc::difference_type type;
1488};
1489
Howard Hinnant3e519522010-05-11 19:42:161490template <class _Alloc>
Eric Fiseliere2f2d1ed2017-01-04 23:56:001491struct _LIBCPP_TEMPLATE_VIS allocator_traits
Howard Hinnant3e519522010-05-11 19:42:161492{
1493 typedef _Alloc allocator_type;
1494 typedef typename allocator_type::value_type value_type;
1495
1496 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1497 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1498 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1499 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1500
Howard Hinnanta4a1ef12010-11-18 01:40:001501 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1502 typedef typename __size_type<allocator_type, difference_type>::type size_type;
Howard Hinnant3e519522010-05-11 19:42:161503
1504 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1505 propagate_on_container_copy_assignment;
1506 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1507 propagate_on_container_move_assignment;
1508 typedef typename __propagate_on_container_swap<allocator_type>::type
1509 propagate_on_container_swap;
Marshall Clow31a47312015-06-02 16:34:031510 typedef typename __is_always_equal<allocator_type>::type
1511 is_always_equal;
Howard Hinnant3e519522010-05-11 19:42:161512
Eric Fiselier54613ab2016-09-25 03:34:281513#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161514 template <class _Tp> using rebind_alloc =
Howard Hinnantf7384972011-05-11 20:21:191515 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
Howard Hinnant3e519522010-05-11 19:42:161516 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
Eric Fiselier54613ab2016-09-25 03:34:281517#else // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161518 template <class _Tp> struct rebind_alloc
1519 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1520 template <class _Tp> struct rebind_traits
1521 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
Eric Fiselier54613ab2016-09-25 03:34:281522#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:161523
Howard Hinnant848a5372010-09-22 16:48:341524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161525 static pointer allocate(allocator_type& __a, size_type __n)
1526 {return __a.allocate(__n);}
Howard Hinnant848a5372010-09-22 16:48:341527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161528 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1529 {return allocate(__a, __n, __hint,
1530 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1531
Howard Hinnant848a5372010-09-22 16:48:341532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:131533 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161534 {__a.deallocate(__p, __n);}
1535
1536#ifndef _LIBCPP_HAS_NO_VARIADICS
1537 template <class _Tp, class... _Args>
Howard Hinnant848a5372010-09-22 16:48:341538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161539 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
Marshall Clow981f31a2014-11-11 19:22:331540 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
Howard Hinnantce48a112011-06-30 21:18:191541 __a, __p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnantb3371f62010-08-22 00:02:431542#else // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161543 template <class _Tp>
Howard Hinnant848a5372010-09-22 16:48:341544 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera595b7f2017-01-14 01:33:531545 static void construct(allocator_type&, _Tp* __p)
Howard Hinnant3e519522010-05-11 19:42:161546 {
1547 ::new ((void*)__p) _Tp();
1548 }
1549 template <class _Tp, class _A0>
Howard Hinnant848a5372010-09-22 16:48:341550 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera595b7f2017-01-14 01:33:531551 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
Howard Hinnant3e519522010-05-11 19:42:161552 {
1553 ::new ((void*)__p) _Tp(__a0);
1554 }
1555 template <class _Tp, class _A0, class _A1>
Howard Hinnant848a5372010-09-22 16:48:341556 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera595b7f2017-01-14 01:33:531557 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnant3e519522010-05-11 19:42:161558 const _A1& __a1)
1559 {
1560 ::new ((void*)__p) _Tp(__a0, __a1);
1561 }
1562 template <class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant848a5372010-09-22 16:48:341563 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliera595b7f2017-01-14 01:33:531564 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
Howard Hinnant3e519522010-05-11 19:42:161565 const _A1& __a1, const _A2& __a2)
1566 {
1567 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1568 }
Howard Hinnantb3371f62010-08-22 00:02:431569#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161570
1571 template <class _Tp>
Howard Hinnant848a5372010-09-22 16:48:341572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161573 static void destroy(allocator_type& __a, _Tp* __p)
1574 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1575
Howard Hinnant848a5372010-09-22 16:48:341576 _LIBCPP_INLINE_VISIBILITY
Marshall Clow06fbed02013-08-27 20:22:151577 static size_type max_size(const allocator_type& __a) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161578 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1579
Howard Hinnant848a5372010-09-22 16:48:341580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161581 static allocator_type
1582 select_on_container_copy_construction(const allocator_type& __a)
1583 {return select_on_container_copy_construction(
1584 __has_select_on_container_copy_construction<const allocator_type>(),
1585 __a);}
1586
Howard Hinnant9741d6c92012-02-15 00:41:341587 template <class _Ptr>
1588 _LIBCPP_INLINE_VISIBILITY
1589 static
1590 void
1591 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1592 {
1593 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1594 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1595 }
1596
1597 template <class _Tp>
1598 _LIBCPP_INLINE_VISIBILITY
1599 static
1600 typename enable_if
1601 <
1602 (is_same<allocator_type, allocator<_Tp> >::value
1603 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1604 is_trivially_move_constructible<_Tp>::value,
1605 void
1606 >::type
Eric Fiselierfd838222016-12-23 23:37:521607 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
Howard Hinnant9741d6c92012-02-15 00:41:341608 {
1609 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow87601be2015-05-31 03:13:311610 if (_Np > 0)
Marshall Clowe6230742015-06-02 13:04:181611 {
Marshall Clow87601be2015-05-31 03:13:311612 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
Marshall Clowe6230742015-06-02 13:04:181613 __begin2 += _Np;
1614 }
Howard Hinnant9741d6c92012-02-15 00:41:341615 }
1616
Eric Fiseliere7821782015-03-31 16:54:191617 template <class _Iter, class _Ptr>
1618 _LIBCPP_INLINE_VISIBILITY
1619 static
1620 void
1621 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1622 {
1623 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1624 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1625 }
1626
1627 template <class _Tp>
1628 _LIBCPP_INLINE_VISIBILITY
1629 static
1630 typename enable_if
1631 <
1632 (is_same<allocator_type, allocator<_Tp> >::value
1633 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1634 is_trivially_move_constructible<_Tp>::value,
1635 void
1636 >::type
Eric Fiselierfd838222016-12-23 23:37:521637 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
Eric Fiseliere7821782015-03-31 16:54:191638 {
1639 typedef typename remove_const<_Tp>::type _Vp;
1640 ptrdiff_t _Np = __end1 - __begin1;
Marshall Clow87601be2015-05-31 03:13:311641 if (_Np > 0)
Marshall Clowe6230742015-06-02 13:04:181642 {
Marshall Clow87601be2015-05-31 03:13:311643 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
Marshall Clowe6230742015-06-02 13:04:181644 __begin2 += _Np;
1645 }
Eric Fiseliere7821782015-03-31 16:54:191646 }
1647
Howard Hinnant9741d6c92012-02-15 00:41:341648 template <class _Ptr>
1649 _LIBCPP_INLINE_VISIBILITY
1650 static
1651 void
1652 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1653 {
1654 while (__end1 != __begin1)
Howard Hinnant8d9aec82013-01-11 20:36:591655 {
1656 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1657 --__end2;
1658 }
Howard Hinnant9741d6c92012-02-15 00:41:341659 }
1660
1661 template <class _Tp>
1662 _LIBCPP_INLINE_VISIBILITY
1663 static
1664 typename enable_if
1665 <
1666 (is_same<allocator_type, allocator<_Tp> >::value
1667 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1668 is_trivially_move_constructible<_Tp>::value,
1669 void
1670 >::type
Eric Fiselierfd838222016-12-23 23:37:521671 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
Howard Hinnant9741d6c92012-02-15 00:41:341672 {
1673 ptrdiff_t _Np = __end1 - __begin1;
1674 __end2 -= _Np;
Marshall Clow87601be2015-05-31 03:13:311675 if (_Np > 0)
1676 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
Howard Hinnant9741d6c92012-02-15 00:41:341677 }
1678
Howard Hinnant3e519522010-05-11 19:42:161679private:
1680
Howard Hinnant848a5372010-09-22 16:48:341681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161682 static pointer allocate(allocator_type& __a, size_type __n,
1683 const_void_pointer __hint, true_type)
1684 {return __a.allocate(__n, __hint);}
Howard Hinnant848a5372010-09-22 16:48:341685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161686 static pointer allocate(allocator_type& __a, size_type __n,
Howard Hinnantc2063662011-12-01 20:21:041687 const_void_pointer, false_type)
Howard Hinnant3e519522010-05-11 19:42:161688 {return __a.allocate(__n);}
1689
1690#ifndef _LIBCPP_HAS_NO_VARIADICS
1691 template <class _Tp, class... _Args>
Howard Hinnant848a5372010-09-22 16:48:341692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161693 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
Howard Hinnantce48a112011-06-30 21:18:191694 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant3e519522010-05-11 19:42:161695 template <class _Tp, class... _Args>
Howard Hinnant848a5372010-09-22 16:48:341696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161697 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1698 {
Howard Hinnantce48a112011-06-30 21:18:191699 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161700 }
Howard Hinnantb3371f62010-08-22 00:02:431701#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:161702
1703 template <class _Tp>
Howard Hinnant848a5372010-09-22 16:48:341704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161705 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1706 {__a.destroy(__p);}
1707 template <class _Tp>
Howard Hinnant848a5372010-09-22 16:48:341708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161709 static void __destroy(false_type, allocator_type&, _Tp* __p)
1710 {
1711 __p->~_Tp();
1712 }
1713
Howard Hinnant848a5372010-09-22 16:48:341714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161715 static size_type __max_size(true_type, const allocator_type& __a)
1716 {return __a.max_size();}
Howard Hinnant848a5372010-09-22 16:48:341717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161718 static size_type __max_size(false_type, const allocator_type&)
Marshall Clowb631c242015-10-25 19:34:041719 {return numeric_limits<size_type>::max() / sizeof(value_type);}
Howard Hinnant3e519522010-05-11 19:42:161720
Howard Hinnant848a5372010-09-22 16:48:341721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161722 static allocator_type
1723 select_on_container_copy_construction(true_type, const allocator_type& __a)
1724 {return __a.select_on_container_copy_construction();}
Howard Hinnant848a5372010-09-22 16:48:341725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:161726 static allocator_type
1727 select_on_container_copy_construction(false_type, const allocator_type& __a)
1728 {return __a;}
1729};
1730
Marshall Clow1f508012015-04-07 05:21:381731template <class _Traits, class _Tp>
1732struct __rebind_alloc_helper
1733{
Eric Fiselier54613ab2016-09-25 03:34:281734#ifndef _LIBCPP_CXX03_LANG
Marshall Clowc34f8472015-05-10 13:59:451735 typedef typename _Traits::template rebind_alloc<_Tp> type;
Marshall Clow1f508012015-04-07 05:21:381736#else
1737 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1738#endif
1739};
1740
Howard Hinnant3e519522010-05-11 19:42:161741// allocator
1742
1743template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:001744class _LIBCPP_TEMPLATE_VIS allocator
Howard Hinnant3e519522010-05-11 19:42:161745{
1746public:
1747 typedef size_t size_type;
1748 typedef ptrdiff_t difference_type;
1749 typedef _Tp* pointer;
1750 typedef const _Tp* const_pointer;
1751 typedef _Tp& reference;
1752 typedef const _Tp& const_reference;
1753 typedef _Tp value_type;
1754
Howard Hinnantb58f59c2011-06-02 21:38:571755 typedef true_type propagate_on_container_move_assignment;
Marshall Clow31a47312015-06-02 16:34:031756 typedef true_type is_always_equal;
Howard Hinnantb58f59c2011-06-02 21:38:571757
Howard Hinnant3e519522010-05-11 19:42:161758 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1759
Howard Hinnant3739fe72011-05-28 14:41:131760 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1761 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1762 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:191763 {return _VSTD::addressof(__x);}
Howard Hinnant3739fe72011-05-28 14:41:131764 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:191765 {return _VSTD::addressof(__x);}
Howard Hinnant3e519522010-05-11 19:42:161766 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow4cec7092016-03-03 12:04:391767 {
1768 if (__n > max_size())
Marshall Clow0fc8cec2016-08-25 17:47:091769 __throw_length_error("allocator<T>::allocate(size_t n)"
1770 " 'n' exceeds maximum supported size");
Marshall Clow4cec7092016-03-03 12:04:391771 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1772 }
Howard Hinnant3739fe72011-05-28 14:41:131773 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Eric Fiseliercd71f442017-01-07 03:01:241774 {_VSTD::__libcpp_deallocate((void*)__p);}
Howard Hinnant3739fe72011-05-28 14:41:131775 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1776 {return size_type(~0) / sizeof(_Tp);}
Howard Hinnant7609c9b2010-09-04 23:28:191777#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:161778 template <class _Up, class... _Args>
1779 _LIBCPP_INLINE_VISIBILITY
1780 void
1781 construct(_Up* __p, _Args&&... __args)
1782 {
Howard Hinnantce48a112011-06-30 21:18:191783 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:161784 }
Howard Hinnant7609c9b2010-09-04 23:28:191785#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:161786 _LIBCPP_INLINE_VISIBILITY
1787 void
1788 construct(pointer __p)
1789 {
1790 ::new((void*)__p) _Tp();
1791 }
Michael J. Spencerf5799be2010-12-10 19:47:541792# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbff1bfc2012-05-01 15:37:541793
Howard Hinnant3e519522010-05-11 19:42:161794 template <class _A0>
1795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbff1bfc2012-05-01 15:37:541796 void
Howard Hinnant3e519522010-05-11 19:42:161797 construct(pointer __p, _A0& __a0)
1798 {
1799 ::new((void*)__p) _Tp(__a0);
1800 }
1801 template <class _A0>
1802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbff1bfc2012-05-01 15:37:541803 void
Howard Hinnant3e519522010-05-11 19:42:161804 construct(pointer __p, const _A0& __a0)
1805 {
1806 ::new((void*)__p) _Tp(__a0);
1807 }
Michael J. Spencerf5799be2010-12-10 19:47:541808# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnant3e519522010-05-11 19:42:161809 template <class _A0, class _A1>
1810 _LIBCPP_INLINE_VISIBILITY
1811 void
1812 construct(pointer __p, _A0& __a0, _A1& __a1)
1813 {
1814 ::new((void*)__p) _Tp(__a0, __a1);
1815 }
1816 template <class _A0, class _A1>
1817 _LIBCPP_INLINE_VISIBILITY
1818 void
1819 construct(pointer __p, const _A0& __a0, _A1& __a1)
1820 {
1821 ::new((void*)__p) _Tp(__a0, __a1);
1822 }
1823 template <class _A0, class _A1>
1824 _LIBCPP_INLINE_VISIBILITY
1825 void
1826 construct(pointer __p, _A0& __a0, const _A1& __a1)
1827 {
1828 ::new((void*)__p) _Tp(__a0, __a1);
1829 }
1830 template <class _A0, class _A1>
1831 _LIBCPP_INLINE_VISIBILITY
1832 void
1833 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1834 {
1835 ::new((void*)__p) _Tp(__a0, __a1);
1836 }
Howard Hinnant7609c9b2010-09-04 23:28:191837#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant3e519522010-05-11 19:42:161838 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1839};
1840
Howard Hinnant8e251042012-01-02 17:56:021841template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:001842class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
Howard Hinnant8e251042012-01-02 17:56:021843{
1844public:
1845 typedef size_t size_type;
1846 typedef ptrdiff_t difference_type;
1847 typedef const _Tp* pointer;
1848 typedef const _Tp* const_pointer;
1849 typedef const _Tp& reference;
1850 typedef const _Tp& const_reference;
Howard Hinnant30444ad2013-06-07 01:56:371851 typedef const _Tp value_type;
Howard Hinnant8e251042012-01-02 17:56:021852
1853 typedef true_type propagate_on_container_move_assignment;
Marshall Clowf43a42d2015-07-01 21:23:401854 typedef true_type is_always_equal;
Howard Hinnant8e251042012-01-02 17:56:021855
1856 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1857
1858 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1859 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1860 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1861 {return _VSTD::addressof(__x);}
1862 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
Marshall Clow4cec7092016-03-03 12:04:391863 {
1864 if (__n > max_size())
Marshall Clow0fc8cec2016-08-25 17:47:091865 __throw_length_error("allocator<const T>::allocate(size_t n)"
1866 " 'n' exceeds maximum supported size");
Marshall Clow4cec7092016-03-03 12:04:391867 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
Eric Fiselier4524d6e2016-05-07 03:12:241868 }
Howard Hinnant8e251042012-01-02 17:56:021869 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
Eric Fiseliercd71f442017-01-07 03:01:241870 {_VSTD::__libcpp_deallocate((void*)__p);}
Howard Hinnant8e251042012-01-02 17:56:021871 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1872 {return size_type(~0) / sizeof(_Tp);}
1873#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1874 template <class _Up, class... _Args>
1875 _LIBCPP_INLINE_VISIBILITY
1876 void
1877 construct(_Up* __p, _Args&&... __args)
1878 {
1879 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1880 }
1881#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1882 _LIBCPP_INLINE_VISIBILITY
1883 void
1884 construct(pointer __p)
1885 {
1886 ::new((void*)__p) _Tp();
1887 }
1888# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
Howard Hinnantbff1bfc2012-05-01 15:37:541889
Howard Hinnant8e251042012-01-02 17:56:021890 template <class _A0>
1891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbff1bfc2012-05-01 15:37:541892 void
Howard Hinnant8e251042012-01-02 17:56:021893 construct(pointer __p, _A0& __a0)
1894 {
1895 ::new((void*)__p) _Tp(__a0);
1896 }
1897 template <class _A0>
1898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbff1bfc2012-05-01 15:37:541899 void
Howard Hinnant8e251042012-01-02 17:56:021900 construct(pointer __p, const _A0& __a0)
1901 {
1902 ::new((void*)__p) _Tp(__a0);
1903 }
Howard Hinnant8e251042012-01-02 17:56:021904# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1905 template <class _A0, class _A1>
1906 _LIBCPP_INLINE_VISIBILITY
1907 void
1908 construct(pointer __p, _A0& __a0, _A1& __a1)
1909 {
1910 ::new((void*)__p) _Tp(__a0, __a1);
1911 }
1912 template <class _A0, class _A1>
1913 _LIBCPP_INLINE_VISIBILITY
1914 void
1915 construct(pointer __p, const _A0& __a0, _A1& __a1)
1916 {
1917 ::new((void*)__p) _Tp(__a0, __a1);
1918 }
1919 template <class _A0, class _A1>
1920 _LIBCPP_INLINE_VISIBILITY
1921 void
1922 construct(pointer __p, _A0& __a0, const _A1& __a1)
1923 {
1924 ::new((void*)__p) _Tp(__a0, __a1);
1925 }
1926 template <class _A0, class _A1>
1927 _LIBCPP_INLINE_VISIBILITY
1928 void
1929 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1930 {
1931 ::new((void*)__p) _Tp(__a0, __a1);
1932 }
1933#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1934 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1935};
1936
Howard Hinnant3e519522010-05-11 19:42:161937template <class _Tp, class _Up>
1938inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:131939bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
Howard Hinnant3e519522010-05-11 19:42:161940
1941template <class _Tp, class _Up>
1942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:131943bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
Howard Hinnant3e519522010-05-11 19:42:161944
1945template <class _OutputIterator, class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:001946class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
Howard Hinnant3e519522010-05-11 19:42:161947 : public iterator<output_iterator_tag,
1948 _Tp, // purposefully not C++03
1949 ptrdiff_t, // purposefully not C++03
1950 _Tp*, // purposefully not C++03
1951 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1952{
1953private:
1954 _OutputIterator __x_;
1955public:
1956 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1957 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1958 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1959 {::new(&*__x_) _Tp(__element); return *this;}
Marshall Clow2603b072015-10-25 18:58:071960#if _LIBCPP_STD_VER >= 14
1961 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1962 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1963#endif
Howard Hinnant3e519522010-05-11 19:42:161964 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1965 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1966 {raw_storage_iterator __t(*this); ++__x_; return __t;}
Marshall Clow783b3722015-05-10 13:14:081967#if _LIBCPP_STD_VER >= 14
1968 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1969#endif
Howard Hinnant3e519522010-05-11 19:42:161970};
1971
1972template <class _Tp>
1973pair<_Tp*, ptrdiff_t>
Howard Hinnant3739fe72011-05-28 14:41:131974get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:161975{
1976 pair<_Tp*, ptrdiff_t> __r(0, 0);
1977 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1978 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1979 / sizeof(_Tp);
1980 if (__n > __m)
1981 __n = __m;
1982 while (__n > 0)
1983 {
1984 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1985 if (__r.first)
1986 {
1987 __r.second = __n;
1988 break;
1989 }
1990 __n /= 2;
1991 }
1992 return __r;
1993}
1994
1995template <class _Tp>
1996inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:131997void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
Howard Hinnant3e519522010-05-11 19:42:161998
1999template <class _Tp>
2000struct auto_ptr_ref
2001{
2002 _Tp* __ptr_;
2003};
2004
2005template<class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:002006class _LIBCPP_TEMPLATE_VIS auto_ptr
Howard Hinnant3e519522010-05-11 19:42:162007{
2008private:
2009 _Tp* __ptr_;
2010public:
2011 typedef _Tp element_type;
2012
2013 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2014 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2015 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2016 : __ptr_(__p.release()) {}
2017 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2018 {reset(__p.release()); return *this;}
2019 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2020 {reset(__p.release()); return *this;}
2021 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2022 {reset(__p.__ptr_); return *this;}
2023 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2024
2025 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2026 {return *__ptr_;}
2027 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2028 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2029 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2030 {
2031 _Tp* __t = __ptr_;
2032 __ptr_ = 0;
2033 return __t;
2034 }
2035 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2036 {
2037 if (__ptr_ != __p)
2038 delete __ptr_;
2039 __ptr_ = __p;
2040 }
2041
2042 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2043 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2044 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2045 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2046 {return auto_ptr<_Up>(release());}
2047};
2048
2049template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:002050class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
Howard Hinnant3e519522010-05-11 19:42:162051{
2052public:
2053 typedef void element_type;
2054};
2055
Howard Hinnant3e519522010-05-11 19:42:162056template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
2057 typename remove_cv<_T2>::type>::value,
Howard Hinnant42b8bb52011-12-11 20:31:332058 bool = is_empty<_T1>::value
Eric Fiselieree187e22015-06-13 07:08:022059 && !__libcpp_is_final<_T1>::value,
Howard Hinnant42b8bb52011-12-11 20:31:332060 bool = is_empty<_T2>::value
Eric Fiselieree187e22015-06-13 07:08:022061 && !__libcpp_is_final<_T2>::value
Howard Hinnant42b8bb52011-12-11 20:31:332062 >
Howard Hinnant3e519522010-05-11 19:42:162063struct __libcpp_compressed_pair_switch;
2064
2065template <class _T1, class _T2, bool IsSame>
2066struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
2067
2068template <class _T1, class _T2, bool IsSame>
2069struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
2070
2071template <class _T1, class _T2, bool IsSame>
2072struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
2073
2074template <class _T1, class _T2>
2075struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
2076
2077template <class _T1, class _T2>
2078struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
2079
2080template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
2081class __libcpp_compressed_pair_imp;
2082
2083template <class _T1, class _T2>
2084class __libcpp_compressed_pair_imp<_T1, _T2, 0>
2085{
2086private:
2087 _T1 __first_;
2088 _T2 __second_;
2089public:
2090 typedef _T1 _T1_param;
2091 typedef _T2 _T2_param;
2092
2093 typedef typename remove_reference<_T1>::type& _T1_reference;
2094 typedef typename remove_reference<_T2>::type& _T2_reference;
2095
2096 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2097 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2098
Marshall Clow05fc0f22015-07-16 03:05:062099 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
Howard Hinnant8e251042012-01-02 17:56:022100 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Marshall Clow05fc0f22015-07-16 03:05:062101 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
Howard Hinnant8e251042012-01-02 17:56:022102 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Marshall Clow05fc0f22015-07-16 03:05:062103 : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162104 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192105 : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162106
Howard Hinnanta87b5e32011-12-19 17:58:442107#ifndef _LIBCPP_HAS_NO_VARIADICS
2108
2109 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2110 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:522111 __libcpp_compressed_pair_imp(piecewise_construct_t,
Howard Hinnanta87b5e32011-12-19 17:58:442112 tuple<_Args1...> __first_args,
2113 tuple<_Args2...> __second_args,
2114 __tuple_indices<_I1...>,
2115 __tuple_indices<_I2...>)
Marshall Clowf9af6142014-06-24 00:46:192116 : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2117 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnanta87b5e32011-12-19 17:58:442118 {}
2119
2120#endif // _LIBCPP_HAS_NO_VARIADICS
2121
Howard Hinnant3739fe72011-05-28 14:41:132122 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2123 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnant3e519522010-05-11 19:42:162124
Howard Hinnant3739fe72011-05-28 14:41:132125 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2126 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnant3e519522010-05-11 19:42:162127
2128 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant3739fe72011-05-28 14:41:132129 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092130 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3e519522010-05-11 19:42:162131 {
Howard Hinnantce48a112011-06-30 21:18:192132 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:162133 swap(__first_, __x.__first_);
2134 swap(__second_, __x.__second_);
2135 }
2136};
2137
2138template <class _T1, class _T2>
2139class __libcpp_compressed_pair_imp<_T1, _T2, 1>
2140 : private _T1
2141{
2142private:
2143 _T2 __second_;
2144public:
2145 typedef _T1 _T1_param;
2146 typedef _T2 _T2_param;
2147
2148 typedef _T1& _T1_reference;
2149 typedef typename remove_reference<_T2>::type& _T2_reference;
2150
2151 typedef const _T1& _T1_const_reference;
2152 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
2153
Marshall Clow05fc0f22015-07-16 03:05:062154 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
Howard Hinnant8e251042012-01-02 17:56:022155 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Marshall Clow05fc0f22015-07-16 03:05:062156 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
Howard Hinnant8e251042012-01-02 17:56:022157 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192158 : __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162159 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192160 : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162161
Howard Hinnanta87b5e32011-12-19 17:58:442162#ifndef _LIBCPP_HAS_NO_VARIADICS
2163
2164 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2165 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:522166 __libcpp_compressed_pair_imp(piecewise_construct_t,
Howard Hinnanta87b5e32011-12-19 17:58:442167 tuple<_Args1...> __first_args,
2168 tuple<_Args2...> __second_args,
2169 __tuple_indices<_I1...>,
2170 __tuple_indices<_I2...>)
Marshall Clowf9af6142014-06-24 00:46:192171 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2172 __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnanta87b5e32011-12-19 17:58:442173 {}
2174
2175#endif // _LIBCPP_HAS_NO_VARIADICS
2176
Howard Hinnant3739fe72011-05-28 14:41:132177 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2178 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnant3e519522010-05-11 19:42:162179
Howard Hinnant3739fe72011-05-28 14:41:132180 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
2181 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
Howard Hinnant3e519522010-05-11 19:42:162182
2183 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant3739fe72011-05-28 14:41:132184 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092185 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3e519522010-05-11 19:42:162186 {
Howard Hinnantce48a112011-06-30 21:18:192187 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:162188 swap(__second_, __x.__second_);
2189 }
2190};
2191
2192template <class _T1, class _T2>
2193class __libcpp_compressed_pair_imp<_T1, _T2, 2>
2194 : private _T2
2195{
2196private:
2197 _T1 __first_;
2198public:
2199 typedef _T1 _T1_param;
2200 typedef _T2 _T2_param;
2201
2202 typedef typename remove_reference<_T1>::type& _T1_reference;
2203 typedef _T2& _T2_reference;
2204
2205 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
2206 typedef const _T2& _T2_const_reference;
2207
Marshall Clow05fc0f22015-07-16 03:05:062208 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
Howard Hinnant3e519522010-05-11 19:42:162209 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantce48a112011-06-30 21:18:192210 : __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant3e519522010-05-11 19:42:162211 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Marshall Clow05fc0f22015-07-16 03:05:062212 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
Howard Hinnant3e519522010-05-11 19:42:162213 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnant3739fe72011-05-28 14:41:132214 _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
2215 is_nothrow_move_constructible<_T2>::value)
Howard Hinnantce48a112011-06-30 21:18:192216 : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant3e519522010-05-11 19:42:162217
Howard Hinnanta87b5e32011-12-19 17:58:442218#ifndef _LIBCPP_HAS_NO_VARIADICS
2219
2220 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2221 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:522222 __libcpp_compressed_pair_imp(piecewise_construct_t,
Howard Hinnanta87b5e32011-12-19 17:58:442223 tuple<_Args1...> __first_args,
2224 tuple<_Args2...> __second_args,
2225 __tuple_indices<_I1...>,
2226 __tuple_indices<_I2...>)
Marshall Clowf9af6142014-06-24 00:46:192227 : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
2228 __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
Howard Hinnanta87b5e32011-12-19 17:58:442229
2230 {}
2231
2232#endif // _LIBCPP_HAS_NO_VARIADICS
2233
Howard Hinnant3739fe72011-05-28 14:41:132234 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
2235 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
Howard Hinnant3e519522010-05-11 19:42:162236
Howard Hinnant3739fe72011-05-28 14:41:132237 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2238 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnant3e519522010-05-11 19:42:162239
2240 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
Howard Hinnant3739fe72011-05-28 14:41:132241 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092242 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3e519522010-05-11 19:42:162243 {
Howard Hinnantce48a112011-06-30 21:18:192244 using _VSTD::swap;
Howard Hinnant3e519522010-05-11 19:42:162245 swap(__first_, __x.__first_);
2246 }
2247};
2248
2249template <class _T1, class _T2>
2250class __libcpp_compressed_pair_imp<_T1, _T2, 3>
2251 : private _T1,
2252 private _T2
2253{
2254public:
2255 typedef _T1 _T1_param;
2256 typedef _T2 _T2_param;
2257
2258 typedef _T1& _T1_reference;
2259 typedef _T2& _T2_reference;
2260
2261 typedef const _T1& _T1_const_reference;
2262 typedef const _T2& _T2_const_reference;
2263
2264 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
2265 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
Howard Hinnantce48a112011-06-30 21:18:192266 : _T1(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant3e519522010-05-11 19:42:162267 _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192268 : _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162269 _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192270 : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162271
Howard Hinnanta87b5e32011-12-19 17:58:442272#ifndef _LIBCPP_HAS_NO_VARIADICS
2273
2274 template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
2275 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierfd838222016-12-23 23:37:522276 __libcpp_compressed_pair_imp(piecewise_construct_t,
Howard Hinnanta87b5e32011-12-19 17:58:442277 tuple<_Args1...> __first_args,
2278 tuple<_Args2...> __second_args,
2279 __tuple_indices<_I1...>,
2280 __tuple_indices<_I2...>)
Marshall Clowf9af6142014-06-24 00:46:192281 : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
2282 _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
Howard Hinnanta87b5e32011-12-19 17:58:442283 {}
2284
2285#endif // _LIBCPP_HAS_NO_VARIADICS
2286
Howard Hinnant3739fe72011-05-28 14:41:132287 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
2288 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
Howard Hinnant3e519522010-05-11 19:42:162289
Howard Hinnant3739fe72011-05-28 14:41:132290 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
2291 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
Howard Hinnant3e519522010-05-11 19:42:162292
Howard Hinnantc2063662011-12-01 20:21:042293 _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
Howard Hinnant3739fe72011-05-28 14:41:132294 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092295 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3e519522010-05-11 19:42:162296 {
2297 }
2298};
2299
2300template <class _T1, class _T2>
2301class __compressed_pair
2302 : private __libcpp_compressed_pair_imp<_T1, _T2>
2303{
2304 typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
2305public:
2306 typedef typename base::_T1_param _T1_param;
2307 typedef typename base::_T2_param _T2_param;
2308
2309 typedef typename base::_T1_reference _T1_reference;
2310 typedef typename base::_T2_reference _T2_reference;
2311
2312 typedef typename base::_T1_const_reference _T1_const_reference;
2313 typedef typename base::_T2_const_reference _T2_const_reference;
2314
2315 _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
Howard Hinnant8e251042012-01-02 17:56:022316 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
Howard Hinnantce48a112011-06-30 21:18:192317 : base(_VSTD::forward<_T1_param>(__t1)) {}
Howard Hinnant8e251042012-01-02 17:56:022318 _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192319 : base(_VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162320 _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
Howard Hinnantce48a112011-06-30 21:18:192321 : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
Howard Hinnant3e519522010-05-11 19:42:162322
Howard Hinnanta87b5e32011-12-19 17:58:442323#ifndef _LIBCPP_HAS_NO_VARIADICS
2324
2325 template <class... _Args1, class... _Args2>
2326 _LIBCPP_INLINE_VISIBILITY
2327 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2328 tuple<_Args2...> __second_args)
Howard Hinnant8e251042012-01-02 17:56:022329 : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
Howard Hinnanta87b5e32011-12-19 17:58:442330 typename __make_tuple_indices<sizeof...(_Args1)>::type(),
2331 typename __make_tuple_indices<sizeof...(_Args2) >::type())
2332 {}
2333
2334#endif // _LIBCPP_HAS_NO_VARIADICS
2335
Howard Hinnant3739fe72011-05-28 14:41:132336 _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
2337 _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
Howard Hinnant3e519522010-05-11 19:42:162338
Howard Hinnant3739fe72011-05-28 14:41:132339 _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
2340 _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
Howard Hinnant3e519522010-05-11 19:42:162341
Howard Hinnant3739fe72011-05-28 14:41:132342 _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
2343 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092344 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3739fe72011-05-28 14:41:132345 {base::swap(__x);}
Howard Hinnant3e519522010-05-11 19:42:162346};
2347
2348template <class _T1, class _T2>
2349inline _LIBCPP_INLINE_VISIBILITY
2350void
2351swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
Howard Hinnant3739fe72011-05-28 14:41:132352 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
Marshall Clowafa72ed2014-06-30 15:35:092353 __is_nothrow_swappable<_T2>::value)
Howard Hinnant3e519522010-05-11 19:42:162354 {__x.swap(__y);}
2355
Howard Hinnant8e251042012-01-02 17:56:022356// __same_or_less_cv_qualified
2357
2358template <class _Ptr1, class _Ptr2,
2359 bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
2360 typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
2361 >::value
2362 >
2363struct __same_or_less_cv_qualified_imp
2364 : is_convertible<_Ptr1, _Ptr2> {};
2365
2366template <class _Ptr1, class _Ptr2>
2367struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
2368 : false_type {};
2369
Marshall Clow85d3e7a2014-04-26 05:19:482370template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
2371 is_same<_Ptr1, _Ptr2>::value ||
2372 __has_element_type<_Ptr1>::value>
Howard Hinnant8e251042012-01-02 17:56:022373struct __same_or_less_cv_qualified
2374 : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
2375
2376template <class _Ptr1, class _Ptr2>
Marshall Clow85d3e7a2014-04-26 05:19:482377struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
Howard Hinnant8e251042012-01-02 17:56:022378 : false_type {};
2379
2380// default_delete
2381
Howard Hinnant3e519522010-05-11 19:42:162382template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:002383struct _LIBCPP_TEMPLATE_VIS default_delete
Howard Hinnant3e519522010-05-11 19:42:162384{
Eric Fiselierf9980202016-11-18 06:42:172385#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc0937e82012-07-07 20:56:042386 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2387#else
2388 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2389#endif
Howard Hinnant3e519522010-05-11 19:42:162390 template <class _Up>
2391 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
Howard Hinnant3739fe72011-05-28 14:41:132392 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
2393 _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162394 {
2395 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Howard Hinnant03ec04f2013-04-24 19:44:262396 static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
Howard Hinnant3e519522010-05-11 19:42:162397 delete __ptr;
2398 }
2399};
2400
2401template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:002402struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]>
Howard Hinnant3e519522010-05-11 19:42:162403{
Howard Hinnante4097ad2011-12-18 21:19:442404public:
Eric Fiselierf9980202016-11-18 06:42:172405#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc0937e82012-07-07 20:56:042406 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
2407#else
2408 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
2409#endif
Howard Hinnante4097ad2011-12-18 21:19:442410 template <class _Up>
2411 _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
Howard Hinnant8e251042012-01-02 17:56:022412 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
Howard Hinnante4097ad2011-12-18 21:19:442413 template <class _Up>
2414 _LIBCPP_INLINE_VISIBILITY
2415 void operator() (_Up* __ptr,
Howard Hinnant8e251042012-01-02 17:56:022416 typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162417 {
2418 static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
Marshall Clow026b8052016-02-25 16:50:512419 static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
Howard Hinnant3e519522010-05-11 19:42:162420 delete [] __ptr;
2421 }
Howard Hinnant3e519522010-05-11 19:42:162422};
2423
2424template <class _Tp, class _Dp = default_delete<_Tp> >
Eric Fiseliere2f2d1ed2017-01-04 23:56:002425class _LIBCPP_TEMPLATE_VIS unique_ptr
Howard Hinnant3e519522010-05-11 19:42:162426{
2427public:
2428 typedef _Tp element_type;
2429 typedef _Dp deleter_type;
2430 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2431private:
2432 __compressed_pair<pointer, deleter_type> __ptr_;
2433
Howard Hinnant8e251042012-01-02 17:56:022434#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162435 unique_ptr(unique_ptr&);
2436 template <class _Up, class _Ep>
2437 unique_ptr(unique_ptr<_Up, _Ep>&);
2438 unique_ptr& operator=(unique_ptr&);
2439 template <class _Up, class _Ep>
2440 unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
Howard Hinnant7609c9b2010-09-04 23:28:192441#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162442
2443 struct __nat {int __for_bool_;};
2444
2445 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2446 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2447public:
Howard Hinnantc0937e82012-07-07 20:56:042448 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162449 : __ptr_(pointer())
2450 {
2451 static_assert(!is_pointer<deleter_type>::value,
2452 "unique_ptr constructed with null function pointer deleter");
2453 }
Howard Hinnantc0937e82012-07-07 20:56:042454 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162455 : __ptr_(pointer())
2456 {
2457 static_assert(!is_pointer<deleter_type>::value,
2458 "unique_ptr constructed with null function pointer deleter");
2459 }
Howard Hinnant3739fe72011-05-28 14:41:132460 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192461 : __ptr_(_VSTD::move(__p))
Howard Hinnant3e519522010-05-11 19:42:162462 {
2463 static_assert(!is_pointer<deleter_type>::value,
2464 "unique_ptr constructed with null function pointer deleter");
2465 }
2466
Howard Hinnant7609c9b2010-09-04 23:28:192467#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162468 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
2469 is_reference<deleter_type>::value,
2470 deleter_type,
2471 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant3739fe72011-05-28 14:41:132472 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162473 : __ptr_(__p, __d) {}
2474
2475 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant3739fe72011-05-28 14:41:132476 _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192477 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnant3e519522010-05-11 19:42:162478 {
2479 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2480 }
Howard Hinnant3739fe72011-05-28 14:41:132481 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192482 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnant3e519522010-05-11 19:42:162483 template <class _Up, class _Ep>
2484 _LIBCPP_INLINE_VISIBILITY
2485 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2486 typename enable_if
2487 <
2488 !is_array<_Up>::value &&
2489 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2490 is_convertible<_Ep, deleter_type>::value &&
2491 (
2492 !is_reference<deleter_type>::value ||
2493 is_same<deleter_type, _Ep>::value
2494 ),
2495 __nat
Howard Hinnant3739fe72011-05-28 14:41:132496 >::type = __nat()) _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192497 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
Howard Hinnant3e519522010-05-11 19:42:162498
2499 template <class _Up>
2500 _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
2501 typename enable_if<
2502 is_convertible<_Up*, _Tp*>::value &&
2503 is_same<_Dp, default_delete<_Tp> >::value,
2504 __nat
Howard Hinnant3739fe72011-05-28 14:41:132505 >::type = __nat()) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162506 : __ptr_(__p.release())
2507 {
2508 }
2509
Howard Hinnant3739fe72011-05-28 14:41:132510 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162511 {
2512 reset(__u.release());
Howard Hinnantce48a112011-06-30 21:18:192513 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnant3e519522010-05-11 19:42:162514 return *this;
2515 }
2516
2517 template <class _Up, class _Ep>
2518 _LIBCPP_INLINE_VISIBILITY
2519 typename enable_if
2520 <
Howard Hinnant8e251042012-01-02 17:56:022521 !is_array<_Up>::value &&
2522 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2523 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnant3e519522010-05-11 19:42:162524 unique_ptr&
2525 >::type
Howard Hinnant3739fe72011-05-28 14:41:132526 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162527 {
2528 reset(__u.release());
Howard Hinnantce48a112011-06-30 21:18:192529 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnant3e519522010-05-11 19:42:162530 return *this;
2531 }
Howard Hinnant7609c9b2010-09-04 23:28:192532#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162533
2534 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2535 {
2536 return __rv<unique_ptr>(*this);
2537 }
2538
2539 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantce48a112011-06-30 21:18:192540 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnant3e519522010-05-11 19:42:162541
2542 template <class _Up, class _Ep>
Eric Fiselierd48306e2015-08-28 05:07:062543 _LIBCPP_INLINE_VISIBILITY
2544 typename enable_if<
2545 !is_array<_Up>::value &&
2546 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2547 is_assignable<deleter_type&, _Ep&>::value,
2548 unique_ptr&
2549 >::type
2550 operator=(unique_ptr<_Up, _Ep> __u)
Howard Hinnant3e519522010-05-11 19:42:162551 {
2552 reset(__u.release());
Eric Fiselierd48306e2015-08-28 05:07:062553 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
Howard Hinnant3e519522010-05-11 19:42:162554 return *this;
2555 }
2556
2557 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantce48a112011-06-30 21:18:192558 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
Howard Hinnant3e519522010-05-11 19:42:162559
2560 template <class _Up>
2561 _LIBCPP_INLINE_VISIBILITY
2562 typename enable_if<
2563 is_convertible<_Up*, _Tp*>::value &&
2564 is_same<_Dp, default_delete<_Tp> >::value,
2565 unique_ptr&
2566 >::type
2567 operator=(auto_ptr<_Up> __p)
2568 {reset(__p.release()); return *this;}
2569
Howard Hinnant7609c9b2010-09-04 23:28:192570#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162571 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2572
Howard Hinnant3739fe72011-05-28 14:41:132573 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162574 {
2575 reset();
2576 return *this;
2577 }
2578
2579 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
2580 {return *__ptr_.first();}
Howard Hinnant3739fe72011-05-28 14:41:132581 _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
2582 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2583 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2584 {return __ptr_.second();}
2585 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2586 {return __ptr_.second();}
Howard Hinnantf2f2d8b2012-02-21 21:46:432587 _LIBCPP_INLINE_VISIBILITY
2588 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2589 {return __ptr_.first() != nullptr;}
Howard Hinnant3e519522010-05-11 19:42:162590
Howard Hinnant3739fe72011-05-28 14:41:132591 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162592 {
2593 pointer __t = __ptr_.first();
2594 __ptr_.first() = pointer();
2595 return __t;
2596 }
2597
Howard Hinnant3739fe72011-05-28 14:41:132598 _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162599 {
2600 pointer __tmp = __ptr_.first();
2601 __ptr_.first() = __p;
2602 if (__tmp)
2603 __ptr_.second()(__tmp);
2604 }
2605
Howard Hinnant3739fe72011-05-28 14:41:132606 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
2607 {__ptr_.swap(__u.__ptr_);}
Howard Hinnant3e519522010-05-11 19:42:162608};
2609
2610template <class _Tp, class _Dp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:002611class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
Howard Hinnant3e519522010-05-11 19:42:162612{
2613public:
2614 typedef _Tp element_type;
2615 typedef _Dp deleter_type;
2616 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2617private:
2618 __compressed_pair<pointer, deleter_type> __ptr_;
2619
Howard Hinnant8e251042012-01-02 17:56:022620#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162621 unique_ptr(unique_ptr&);
2622 template <class _Up>
2623 unique_ptr(unique_ptr<_Up>&);
2624 unique_ptr& operator=(unique_ptr&);
2625 template <class _Up>
2626 unique_ptr& operator=(unique_ptr<_Up>&);
Howard Hinnant7609c9b2010-09-04 23:28:192627#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162628
2629 struct __nat {int __for_bool_;};
2630
2631 typedef typename remove_reference<deleter_type>::type& _Dp_reference;
2632 typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
2633public:
Howard Hinnantc0937e82012-07-07 20:56:042634 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162635 : __ptr_(pointer())
2636 {
2637 static_assert(!is_pointer<deleter_type>::value,
2638 "unique_ptr constructed with null function pointer deleter");
2639 }
Howard Hinnantc0937e82012-07-07 20:56:042640 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162641 : __ptr_(pointer())
2642 {
2643 static_assert(!is_pointer<deleter_type>::value,
2644 "unique_ptr constructed with null function pointer deleter");
2645 }
Howard Hinnant7609c9b2010-09-04 23:28:192646#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chien22747e62014-01-31 09:30:462647 template <class _Pp>
2648 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
2649 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162650 : __ptr_(__p)
2651 {
2652 static_assert(!is_pointer<deleter_type>::value,
2653 "unique_ptr constructed with null function pointer deleter");
2654 }
2655
Logan Chien22747e62014-01-31 09:30:462656 template <class _Pp>
Howard Hinnantc003db12011-11-29 18:15:502657 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
Howard Hinnant3e519522010-05-11 19:42:162658 is_reference<deleter_type>::value,
2659 deleter_type,
Logan Chien22747e62014-01-31 09:30:462660 typename add_lvalue_reference<const deleter_type>::type>::type __d,
2661 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant3739fe72011-05-28 14:41:132662 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162663 : __ptr_(__p, __d) {}
2664
2665 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
2666 is_reference<deleter_type>::value,
2667 deleter_type,
2668 typename add_lvalue_reference<const deleter_type>::type>::type __d)
Howard Hinnant3739fe72011-05-28 14:41:132669 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162670 : __ptr_(pointer(), __d) {}
2671
Logan Chien22747e62014-01-31 09:30:462672 template <class _Pp>
2673 _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
2674 typename remove_reference<deleter_type>::type&& __d,
2675 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
Howard Hinnant3739fe72011-05-28 14:41:132676 _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192677 : __ptr_(__p, _VSTD::move(__d))
Howard Hinnant3e519522010-05-11 19:42:162678 {
2679 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2680 }
2681
2682 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
Howard Hinnant3739fe72011-05-28 14:41:132683 _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192684 : __ptr_(pointer(), _VSTD::move(__d))
Howard Hinnant3e519522010-05-11 19:42:162685 {
2686 static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
2687 }
2688
Howard Hinnant3739fe72011-05-28 14:41:132689 _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
Howard Hinnantce48a112011-06-30 21:18:192690 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
Howard Hinnant3e519522010-05-11 19:42:162691
Howard Hinnant3739fe72011-05-28 14:41:132692 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162693 {
2694 reset(__u.release());
Howard Hinnantce48a112011-06-30 21:18:192695 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
Howard Hinnant3e519522010-05-11 19:42:162696 return *this;
2697 }
Howard Hinnante4097ad2011-12-18 21:19:442698
2699 template <class _Up, class _Ep>
2700 _LIBCPP_INLINE_VISIBILITY
2701 unique_ptr(unique_ptr<_Up, _Ep>&& __u,
2702 typename enable_if
2703 <
2704 is_array<_Up>::value &&
Howard Hinnant8e251042012-01-02 17:56:022705 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
Howard Hinnante4097ad2011-12-18 21:19:442706 && is_convertible<_Ep, deleter_type>::value &&
2707 (
2708 !is_reference<deleter_type>::value ||
2709 is_same<deleter_type, _Ep>::value
2710 ),
2711 __nat
2712 >::type = __nat()
2713 ) _NOEXCEPT
2714 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
2715
2716
2717 template <class _Up, class _Ep>
2718 _LIBCPP_INLINE_VISIBILITY
2719 typename enable_if
2720 <
2721 is_array<_Up>::value &&
Howard Hinnant8e251042012-01-02 17:56:022722 __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
2723 is_assignable<deleter_type&, _Ep&&>::value,
Howard Hinnante4097ad2011-12-18 21:19:442724 unique_ptr&
2725 >::type
2726 operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2727 {
2728 reset(__u.release());
2729 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2730 return *this;
2731 }
Howard Hinnant7609c9b2010-09-04 23:28:192732#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162733
2734 _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
2735 : __ptr_(__p)
2736 {
2737 static_assert(!is_pointer<deleter_type>::value,
2738 "unique_ptr constructed with null function pointer deleter");
2739 }
2740
2741 _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
Howard Hinnantce48a112011-06-30 21:18:192742 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnant3e519522010-05-11 19:42:162743
2744 _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
Howard Hinnantce48a112011-06-30 21:18:192745 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
Howard Hinnant3e519522010-05-11 19:42:162746
2747 _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
2748 {
2749 return __rv<unique_ptr>(*this);
2750 }
2751
2752 _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
Howard Hinnantce48a112011-06-30 21:18:192753 : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
Howard Hinnant3e519522010-05-11 19:42:162754
2755 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
2756 {
2757 reset(__u->release());
Howard Hinnantce48a112011-06-30 21:18:192758 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
Howard Hinnant3e519522010-05-11 19:42:162759 return *this;
2760 }
2761
Howard Hinnant7609c9b2010-09-04 23:28:192762#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162763 _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
2764
Howard Hinnant3739fe72011-05-28 14:41:132765 _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162766 {
2767 reset();
2768 return *this;
2769 }
2770
2771 _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
2772 {return __ptr_.first()[__i];}
Howard Hinnant3739fe72011-05-28 14:41:132773 _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
2774 _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
2775 {return __ptr_.second();}
2776 _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
2777 {return __ptr_.second();}
Howard Hinnantf2f2d8b2012-02-21 21:46:432778 _LIBCPP_INLINE_VISIBILITY
2779 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
2780 {return __ptr_.first() != nullptr;}
Howard Hinnant3e519522010-05-11 19:42:162781
Howard Hinnant3739fe72011-05-28 14:41:132782 _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162783 {
2784 pointer __t = __ptr_.first();
2785 __ptr_.first() = pointer();
2786 return __t;
2787 }
2788
Logan Chien22747e62014-01-31 09:30:462789 template <class _Pp>
2790 _LIBCPP_INLINE_VISIBILITY
2791 typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
2792 reset(_Pp __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162793 {
2794 pointer __tmp = __ptr_.first();
2795 __ptr_.first() = __p;
2796 if (__tmp)
2797 __ptr_.second()(__tmp);
2798 }
Marshall Clow026b8052016-02-25 16:50:512799 _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:162800 {
2801 pointer __tmp = __ptr_.first();
2802 __ptr_.first() = nullptr;
2803 if (__tmp)
2804 __ptr_.second()(__tmp);
2805 }
Howard Hinnant3e519522010-05-11 19:42:162806
2807 _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
2808private:
Howard Hinnantb3371f62010-08-22 00:02:432809
Howard Hinnant7609c9b2010-09-04 23:28:192810#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162811 template <class _Up>
2812 explicit unique_ptr(_Up);
2813 template <class _Up>
2814 unique_ptr(_Up __u,
2815 typename conditional<
2816 is_reference<deleter_type>::value,
2817 deleter_type,
2818 typename add_lvalue_reference<const deleter_type>::type>::type,
2819 typename enable_if
2820 <
2821 is_convertible<_Up, pointer>::value,
2822 __nat
2823 >::type = __nat());
Howard Hinnant7609c9b2010-09-04 23:28:192824#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:162825};
2826
2827template <class _Tp, class _Dp>
2828inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf07dd8d2016-04-21 23:38:592829typename enable_if<
2830 __is_swappable<_Dp>::value,
2831 void
2832>::type
Howard Hinnant3739fe72011-05-28 14:41:132833swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
Howard Hinnant3e519522010-05-11 19:42:162834
2835template <class _T1, class _D1, class _T2, class _D2>
2836inline _LIBCPP_INLINE_VISIBILITY
2837bool
2838operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2839
2840template <class _T1, class _D1, class _T2, class _D2>
2841inline _LIBCPP_INLINE_VISIBILITY
2842bool
2843operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2844
2845template <class _T1, class _D1, class _T2, class _D2>
2846inline _LIBCPP_INLINE_VISIBILITY
2847bool
Howard Hinnant67f39642012-02-21 21:02:582848operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2849{
2850 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2851 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
Eric Fiselier6fe361c2015-02-05 23:01:402852 typedef typename common_type<_P1, _P2>::type _Vp;
2853 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant67f39642012-02-21 21:02:582854}
Howard Hinnant3e519522010-05-11 19:42:162855
2856template <class _T1, class _D1, class _T2, class _D2>
2857inline _LIBCPP_INLINE_VISIBILITY
2858bool
2859operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2860
2861template <class _T1, class _D1, class _T2, class _D2>
2862inline _LIBCPP_INLINE_VISIBILITY
2863bool
2864operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2865
2866template <class _T1, class _D1, class _T2, class _D2>
2867inline _LIBCPP_INLINE_VISIBILITY
2868bool
2869operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2870
Howard Hinnant67f39642012-02-21 21:02:582871template <class _T1, class _D1>
2872inline _LIBCPP_INLINE_VISIBILITY
2873bool
Howard Hinnantc0937e82012-07-07 20:56:042874operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant67f39642012-02-21 21:02:582875{
2876 return !__x;
2877}
2878
2879template <class _T1, class _D1>
2880inline _LIBCPP_INLINE_VISIBILITY
2881bool
Howard Hinnantc0937e82012-07-07 20:56:042882operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant67f39642012-02-21 21:02:582883{
2884 return !__x;
2885}
2886
2887template <class _T1, class _D1>
2888inline _LIBCPP_INLINE_VISIBILITY
2889bool
Howard Hinnantc0937e82012-07-07 20:56:042890operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
Howard Hinnant67f39642012-02-21 21:02:582891{
2892 return static_cast<bool>(__x);
2893}
2894
2895template <class _T1, class _D1>
2896inline _LIBCPP_INLINE_VISIBILITY
2897bool
Howard Hinnantc0937e82012-07-07 20:56:042898operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
Howard Hinnant67f39642012-02-21 21:02:582899{
2900 return static_cast<bool>(__x);
2901}
2902
2903template <class _T1, class _D1>
2904inline _LIBCPP_INLINE_VISIBILITY
2905bool
2906operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2907{
2908 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2909 return less<_P1>()(__x.get(), nullptr);
2910}
2911
2912template <class _T1, class _D1>
2913inline _LIBCPP_INLINE_VISIBILITY
2914bool
2915operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2916{
2917 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2918 return less<_P1>()(nullptr, __x.get());
2919}
2920
2921template <class _T1, class _D1>
2922inline _LIBCPP_INLINE_VISIBILITY
2923bool
2924operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2925{
2926 return nullptr < __x;
2927}
2928
2929template <class _T1, class _D1>
2930inline _LIBCPP_INLINE_VISIBILITY
2931bool
2932operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2933{
2934 return __x < nullptr;
2935}
2936
2937template <class _T1, class _D1>
2938inline _LIBCPP_INLINE_VISIBILITY
2939bool
2940operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2941{
2942 return !(nullptr < __x);
2943}
2944
2945template <class _T1, class _D1>
2946inline _LIBCPP_INLINE_VISIBILITY
2947bool
2948operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2949{
2950 return !(__x < nullptr);
2951}
2952
2953template <class _T1, class _D1>
2954inline _LIBCPP_INLINE_VISIBILITY
2955bool
2956operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2957{
2958 return !(__x < nullptr);
2959}
2960
2961template <class _T1, class _D1>
2962inline _LIBCPP_INLINE_VISIBILITY
2963bool
2964operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2965{
2966 return !(nullptr < __x);
2967}
2968
Howard Hinnantbff1bfc2012-05-01 15:37:542969#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2970
2971template <class _Tp, class _Dp>
2972inline _LIBCPP_INLINE_VISIBILITY
2973unique_ptr<_Tp, _Dp>
2974move(unique_ptr<_Tp, _Dp>& __t)
2975{
2976 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
2977}
2978
2979#endif
2980
Marshall Clow28d8ba52013-07-01 18:16:032981#if _LIBCPP_STD_VER > 11
2982
2983template<class _Tp>
2984struct __unique_if
2985{
2986 typedef unique_ptr<_Tp> __unique_single;
2987};
2988
2989template<class _Tp>
2990struct __unique_if<_Tp[]>
2991{
2992 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
2993};
2994
2995template<class _Tp, size_t _Np>
2996struct __unique_if<_Tp[_Np]>
2997{
2998 typedef void __unique_array_known_bound;
2999};
3000
3001template<class _Tp, class... _Args>
Marshall Clow95ddb532013-07-02 20:06:093002inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow28d8ba52013-07-01 18:16:033003typename __unique_if<_Tp>::__unique_single
3004make_unique(_Args&&... __args)
3005{
3006 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3007}
3008
3009template<class _Tp>
Marshall Clow95ddb532013-07-02 20:06:093010inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow28d8ba52013-07-01 18:16:033011typename __unique_if<_Tp>::__unique_array_unknown_bound
3012make_unique(size_t __n)
3013{
3014 typedef typename remove_extent<_Tp>::type _Up;
3015 return unique_ptr<_Tp>(new _Up[__n]());
3016}
3017
3018template<class _Tp, class... _Args>
3019 typename __unique_if<_Tp>::__unique_array_known_bound
3020 make_unique(_Args&&...) = delete;
3021
3022#endif // _LIBCPP_STD_VER > 11
3023
Howard Hinnant84b569d2013-07-03 17:39:283024template <class _Size>
3025inline _LIBCPP_INLINE_VISIBILITY
3026_Size
3027__loadword(const void* __p)
3028{
3029 _Size __r;
3030 std::memcpy(&__r, __p, sizeof(__r));
3031 return __r;
3032}
3033
Howard Hinnant53d2fb02011-12-10 20:28:563034// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
3035// is 64 bits. This is because cityhash64 uses 64bit x 64bit
3036// multiplication, which can be very slow on 32-bit systems.
Howard Hinnantf3d14a62011-12-05 00:08:453037template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
Howard Hinnant53d2fb02011-12-10 20:28:563038struct __murmur2_or_cityhash;
Howard Hinnantf3d14a62011-12-05 00:08:453039
3040template <class _Size>
Howard Hinnant53d2fb02011-12-10 20:28:563041struct __murmur2_or_cityhash<_Size, 32>
Howard Hinnantf3d14a62011-12-05 00:08:453042{
3043 _Size operator()(const void* __key, _Size __len);
3044};
3045
Howard Hinnant53d2fb02011-12-10 20:28:563046// murmur2
Howard Hinnantf3d14a62011-12-05 00:08:453047template <class _Size>
3048_Size
Marshall Clowec880422016-01-11 19:27:103049__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantf3d14a62011-12-05 00:08:453050{
3051 const _Size __m = 0x5bd1e995;
3052 const _Size __r = 24;
3053 _Size __h = __len;
3054 const unsigned char* __data = static_cast<const unsigned char*>(__key);
3055 for (; __len >= 4; __data += 4, __len -= 4)
3056 {
Howard Hinnant84b569d2013-07-03 17:39:283057 _Size __k = __loadword<_Size>(__data);
Howard Hinnantf3d14a62011-12-05 00:08:453058 __k *= __m;
3059 __k ^= __k >> __r;
3060 __k *= __m;
3061 __h *= __m;
3062 __h ^= __k;
3063 }
3064 switch (__len)
3065 {
3066 case 3:
3067 __h ^= __data[2] << 16;
3068 case 2:
3069 __h ^= __data[1] << 8;
3070 case 1:
3071 __h ^= __data[0];
3072 __h *= __m;
3073 }
3074 __h ^= __h >> 13;
3075 __h *= __m;
3076 __h ^= __h >> 15;
3077 return __h;
3078}
3079
3080template <class _Size>
Howard Hinnant53d2fb02011-12-10 20:28:563081struct __murmur2_or_cityhash<_Size, 64>
Howard Hinnantf3d14a62011-12-05 00:08:453082{
3083 _Size operator()(const void* __key, _Size __len);
Howard Hinnant53d2fb02011-12-10 20:28:563084
3085 private:
3086 // Some primes between 2^63 and 2^64.
3087 static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
3088 static const _Size __k1 = 0xb492b66fbe98f273ULL;
3089 static const _Size __k2 = 0x9ae16a3b2f90404fULL;
3090 static const _Size __k3 = 0xc949d7c7509e6557ULL;
3091
3092 static _Size __rotate(_Size __val, int __shift) {
3093 return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
3094 }
3095
3096 static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
3097 return (__val >> __shift) | (__val << (64 - __shift));
3098 }
3099
3100 static _Size __shift_mix(_Size __val) {
3101 return __val ^ (__val >> 47);
3102 }
3103
3104 static _Size __hash_len_16(_Size __u, _Size __v) {
3105 const _Size __mul = 0x9ddfea08eb382d69ULL;
3106 _Size __a = (__u ^ __v) * __mul;
3107 __a ^= (__a >> 47);
3108 _Size __b = (__v ^ __a) * __mul;
3109 __b ^= (__b >> 47);
3110 __b *= __mul;
3111 return __b;
3112 }
3113
3114 static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
3115 if (__len > 8) {
Howard Hinnant84b569d2013-07-03 17:39:283116 const _Size __a = __loadword<_Size>(__s);
3117 const _Size __b = __loadword<_Size>(__s + __len - 8);
Howard Hinnant53d2fb02011-12-10 20:28:563118 return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
3119 }
3120 if (__len >= 4) {
Howard Hinnant84b569d2013-07-03 17:39:283121 const uint32_t __a = __loadword<uint32_t>(__s);
3122 const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
Howard Hinnant53d2fb02011-12-10 20:28:563123 return __hash_len_16(__len + (__a << 3), __b);
3124 }
3125 if (__len > 0) {
3126 const unsigned char __a = __s[0];
3127 const unsigned char __b = __s[__len >> 1];
3128 const unsigned char __c = __s[__len - 1];
3129 const uint32_t __y = static_cast<uint32_t>(__a) +
3130 (static_cast<uint32_t>(__b) << 8);
3131 const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
3132 return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
3133 }
3134 return __k2;
3135 }
3136
3137 static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
Howard Hinnant84b569d2013-07-03 17:39:283138 const _Size __a = __loadword<_Size>(__s) * __k1;
3139 const _Size __b = __loadword<_Size>(__s + 8);
3140 const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
3141 const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
Howard Hinnant53d2fb02011-12-10 20:28:563142 return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
3143 __a + __rotate(__b ^ __k3, 20) - __c + __len);
3144 }
3145
3146 // Return a 16-byte hash for 48 bytes. Quick and dirty.
3147 // Callers do best to use "random-looking" values for a and b.
3148 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3149 _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
3150 __a += __w;
3151 __b = __rotate(__b + __a + __z, 21);
3152 const _Size __c = __a;
3153 __a += __x;
3154 __a += __y;
3155 __b += __rotate(__a, 44);
3156 return pair<_Size, _Size>(__a + __z, __b + __c);
3157 }
3158
3159 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
3160 static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
3161 const char* __s, _Size __a, _Size __b) {
Howard Hinnant84b569d2013-07-03 17:39:283162 return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
3163 __loadword<_Size>(__s + 8),
3164 __loadword<_Size>(__s + 16),
3165 __loadword<_Size>(__s + 24),
Howard Hinnant53d2fb02011-12-10 20:28:563166 __a,
3167 __b);
3168 }
3169
3170 // Return an 8-byte hash for 33 to 64 bytes.
3171 static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
Howard Hinnant84b569d2013-07-03 17:39:283172 _Size __z = __loadword<_Size>(__s + 24);
3173 _Size __a = __loadword<_Size>(__s) +
3174 (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
Howard Hinnant53d2fb02011-12-10 20:28:563175 _Size __b = __rotate(__a + __z, 52);
3176 _Size __c = __rotate(__a, 37);
Howard Hinnant84b569d2013-07-03 17:39:283177 __a += __loadword<_Size>(__s + 8);
Howard Hinnant53d2fb02011-12-10 20:28:563178 __c += __rotate(__a, 7);
Howard Hinnant84b569d2013-07-03 17:39:283179 __a += __loadword<_Size>(__s + 16);
Howard Hinnant53d2fb02011-12-10 20:28:563180 _Size __vf = __a + __z;
3181 _Size __vs = __b + __rotate(__a, 31) + __c;
Howard Hinnant84b569d2013-07-03 17:39:283182 __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
3183 __z += __loadword<_Size>(__s + __len - 8);
Howard Hinnant53d2fb02011-12-10 20:28:563184 __b = __rotate(__a + __z, 52);
3185 __c = __rotate(__a, 37);
Howard Hinnant84b569d2013-07-03 17:39:283186 __a += __loadword<_Size>(__s + __len - 24);
Howard Hinnant53d2fb02011-12-10 20:28:563187 __c += __rotate(__a, 7);
Howard Hinnant84b569d2013-07-03 17:39:283188 __a += __loadword<_Size>(__s + __len - 16);
Howard Hinnant53d2fb02011-12-10 20:28:563189 _Size __wf = __a + __z;
3190 _Size __ws = __b + __rotate(__a, 31) + __c;
3191 _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
3192 return __shift_mix(__r * __k0 + __vs) * __k2;
3193 }
Howard Hinnantf3d14a62011-12-05 00:08:453194};
3195
Howard Hinnant53d2fb02011-12-10 20:28:563196// cityhash64
Howard Hinnantf3d14a62011-12-05 00:08:453197template <class _Size>
3198_Size
Marshall Clowec880422016-01-11 19:27:103199__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantf3d14a62011-12-05 00:08:453200{
Howard Hinnant53d2fb02011-12-10 20:28:563201 const char* __s = static_cast<const char*>(__key);
3202 if (__len <= 32) {
3203 if (__len <= 16) {
3204 return __hash_len_0_to_16(__s, __len);
3205 } else {
3206 return __hash_len_17_to_32(__s, __len);
Howard Hinnantf3d14a62011-12-05 00:08:453207 }
Howard Hinnant53d2fb02011-12-10 20:28:563208 } else if (__len <= 64) {
3209 return __hash_len_33_to_64(__s, __len);
3210 }
3211
3212 // For strings over 64 bytes we hash the end first, and then as we
3213 // loop we keep 56 bytes of state: v, w, x, y, and z.
Howard Hinnant84b569d2013-07-03 17:39:283214 _Size __x = __loadword<_Size>(__s + __len - 40);
3215 _Size __y = __loadword<_Size>(__s + __len - 16) +
3216 __loadword<_Size>(__s + __len - 56);
3217 _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
3218 __loadword<_Size>(__s + __len - 24));
Howard Hinnant53d2fb02011-12-10 20:28:563219 pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
3220 pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
Howard Hinnant84b569d2013-07-03 17:39:283221 __x = __x * __k1 + __loadword<_Size>(__s);
Howard Hinnant53d2fb02011-12-10 20:28:563222
3223 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
3224 __len = (__len - 1) & ~static_cast<_Size>(63);
3225 do {
Howard Hinnant84b569d2013-07-03 17:39:283226 __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
3227 __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
Howard Hinnant53d2fb02011-12-10 20:28:563228 __x ^= __w.second;
Howard Hinnant84b569d2013-07-03 17:39:283229 __y += __v.first + __loadword<_Size>(__s + 40);
Howard Hinnant53d2fb02011-12-10 20:28:563230 __z = __rotate(__z + __w.first, 33) * __k1;
3231 __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
3232 __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
Howard Hinnant84b569d2013-07-03 17:39:283233 __y + __loadword<_Size>(__s + 16));
Howard Hinnant53d2fb02011-12-10 20:28:563234 std::swap(__z, __x);
3235 __s += 64;
3236 __len -= 64;
3237 } while (__len != 0);
3238 return __hash_len_16(
3239 __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
3240 __hash_len_16(__v.second, __w.second) + __x);
Howard Hinnantf3d14a62011-12-05 00:08:453241}
3242
Howard Hinnant9b0cd142011-12-03 21:11:363243template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
3244struct __scalar_hash;
3245
3246template <class _Tp>
3247struct __scalar_hash<_Tp, 0>
3248 : public unary_function<_Tp, size_t>
Howard Hinnantd1803b62010-06-03 16:42:573249{
Howard Hinnant848a5372010-09-22 16:48:343250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9b0cd142011-12-03 21:11:363251 size_t operator()(_Tp __v) const _NOEXCEPT
Howard Hinnantd1803b62010-06-03 16:42:573252 {
Howard Hinnant9b0cd142011-12-03 21:11:363253 union
3254 {
3255 _Tp __t;
3256 size_t __a;
3257 } __u;
3258 __u.__a = 0;
3259 __u.__t = __v;
3260 return __u.__a;
Howard Hinnantd1803b62010-06-03 16:42:573261 }
3262};
3263
Howard Hinnant9b0cd142011-12-03 21:11:363264template <class _Tp>
3265struct __scalar_hash<_Tp, 1>
3266 : public unary_function<_Tp, size_t>
3267{
3268 _LIBCPP_INLINE_VISIBILITY
3269 size_t operator()(_Tp __v) const _NOEXCEPT
3270 {
3271 union
3272 {
3273 _Tp __t;
3274 size_t __a;
3275 } __u;
3276 __u.__t = __v;
3277 return __u.__a;
3278 }
3279};
3280
3281template <class _Tp>
3282struct __scalar_hash<_Tp, 2>
3283 : public unary_function<_Tp, size_t>
3284{
3285 _LIBCPP_INLINE_VISIBILITY
3286 size_t operator()(_Tp __v) const _NOEXCEPT
3287 {
3288 union
3289 {
3290 _Tp __t;
3291 struct
3292 {
3293 size_t __a;
3294 size_t __b;
Eric Fiselier87a82492015-07-18 20:40:463295 } __s;
Howard Hinnant9b0cd142011-12-03 21:11:363296 } __u;
3297 __u.__t = __v;
Howard Hinnant53d2fb02011-12-10 20:28:563298 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant9b0cd142011-12-03 21:11:363299 }
3300};
3301
3302template <class _Tp>
3303struct __scalar_hash<_Tp, 3>
3304 : public unary_function<_Tp, size_t>
3305{
3306 _LIBCPP_INLINE_VISIBILITY
3307 size_t operator()(_Tp __v) const _NOEXCEPT
3308 {
3309 union
3310 {
3311 _Tp __t;
3312 struct
3313 {
3314 size_t __a;
3315 size_t __b;
3316 size_t __c;
Eric Fiselier87a82492015-07-18 20:40:463317 } __s;
Howard Hinnant9b0cd142011-12-03 21:11:363318 } __u;
3319 __u.__t = __v;
Howard Hinnant53d2fb02011-12-10 20:28:563320 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant9b0cd142011-12-03 21:11:363321 }
3322};
3323
3324template <class _Tp>
3325struct __scalar_hash<_Tp, 4>
3326 : public unary_function<_Tp, size_t>
3327{
3328 _LIBCPP_INLINE_VISIBILITY
3329 size_t operator()(_Tp __v) const _NOEXCEPT
3330 {
3331 union
3332 {
3333 _Tp __t;
3334 struct
3335 {
3336 size_t __a;
3337 size_t __b;
3338 size_t __c;
3339 size_t __d;
Eric Fiselier87a82492015-07-18 20:40:463340 } __s;
Howard Hinnant9b0cd142011-12-03 21:11:363341 } __u;
3342 __u.__t = __v;
Howard Hinnant53d2fb02011-12-10 20:28:563343 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
Howard Hinnant9b0cd142011-12-03 21:11:363344 }
3345};
3346
Dimitry Andric082fa542017-01-09 20:29:353347struct _PairT {
3348 size_t first;
3349 size_t second;
3350};
3351
Eric Fiselier918f32f2016-12-02 23:38:313352_LIBCPP_INLINE_VISIBILITY
3353inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
Eric Fiselier918f32f2016-12-02 23:38:313354 typedef __scalar_hash<_PairT> _HashT;
Eric Fiselier58779202016-12-02 23:41:183355 const _PairT __p = {__lhs, __rhs};
Eric Fiselier918f32f2016-12-02 23:38:313356 return _HashT()(__p);
3357}
3358
Howard Hinnant9b0cd142011-12-03 21:11:363359template<class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:003360struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
Howard Hinnantd77851e2012-07-30 01:40:573361 : public unary_function<_Tp*, size_t>
Howard Hinnant9b0cd142011-12-03 21:11:363362{
Howard Hinnantd77851e2012-07-30 01:40:573363 _LIBCPP_INLINE_VISIBILITY
3364 size_t operator()(_Tp* __v) const _NOEXCEPT
3365 {
3366 union
3367 {
3368 _Tp* __t;
3369 size_t __a;
3370 } __u;
3371 __u.__t = __v;
3372 return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
3373 }
Howard Hinnant9b0cd142011-12-03 21:11:363374};
3375
Howard Hinnantd1803b62010-06-03 16:42:573376template <class _Tp, class _Dp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:003377struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
Howard Hinnantd1803b62010-06-03 16:42:573378{
3379 typedef unique_ptr<_Tp, _Dp> argument_type;
3380 typedef size_t result_type;
Howard Hinnant848a5372010-09-22 16:48:343381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133382 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnantd1803b62010-06-03 16:42:573383 {
3384 typedef typename argument_type::pointer pointer;
3385 return hash<pointer>()(__ptr.get());
3386 }
3387};
3388
Howard Hinnant3e519522010-05-11 19:42:163389struct __destruct_n
3390{
3391private:
3392 size_t size;
3393
3394 template <class _Tp>
Howard Hinnant3739fe72011-05-28 14:41:133395 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163396 {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
3397
3398 template <class _Tp>
Howard Hinnant3739fe72011-05-28 14:41:133399 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163400 {}
3401
Howard Hinnant3739fe72011-05-28 14:41:133402 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163403 {++size;}
Howard Hinnant3739fe72011-05-28 14:41:133404 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163405 {}
3406
Howard Hinnant3739fe72011-05-28 14:41:133407 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163408 {size = __s;}
Howard Hinnant3739fe72011-05-28 14:41:133409 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163410 {}
3411public:
Howard Hinnant3739fe72011-05-28 14:41:133412 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3413 : size(__s) {}
Howard Hinnant3e519522010-05-11 19:42:163414
3415 template <class _Tp>
Howard Hinnant3739fe72011-05-28 14:41:133416 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
Howard Hinnantca740482010-11-19 22:17:283417 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnant3e519522010-05-11 19:42:163418
3419 template <class _Tp>
Howard Hinnant3739fe72011-05-28 14:41:133420 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
Howard Hinnantca740482010-11-19 22:17:283421 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnant3e519522010-05-11 19:42:163422
3423 template <class _Tp>
Howard Hinnant3739fe72011-05-28 14:41:133424 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
Howard Hinnantca740482010-11-19 22:17:283425 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
Howard Hinnant3e519522010-05-11 19:42:163426};
3427
3428template <class _Alloc>
3429class __allocator_destructor
3430{
3431 typedef allocator_traits<_Alloc> __alloc_traits;
3432public:
3433 typedef typename __alloc_traits::pointer pointer;
3434 typedef typename __alloc_traits::size_type size_type;
3435private:
3436 _Alloc& __alloc_;
3437 size_type __s_;
3438public:
3439 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
Howard Hinnant3739fe72011-05-28 14:41:133440 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163441 : __alloc_(__a), __s_(__s) {}
Howard Hinnant848a5372010-09-22 16:48:343442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133443 void operator()(pointer __p) _NOEXCEPT
3444 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
Howard Hinnant3e519522010-05-11 19:42:163445};
3446
3447template <class _InputIterator, class _ForwardIterator>
3448_ForwardIterator
3449uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3450{
Howard Hinnant3e519522010-05-11 19:42:163451 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnantb34b48192011-12-29 17:45:353452#ifndef _LIBCPP_NO_EXCEPTIONS
3453 _ForwardIterator __s = __r;
3454 try
3455 {
3456#endif
Marshall Clowa00932b2015-05-19 15:01:483457 for (; __f != __l; ++__f, (void) ++__r)
3458 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnantb34b48192011-12-29 17:45:353459#ifndef _LIBCPP_NO_EXCEPTIONS
3460 }
3461 catch (...)
3462 {
3463 for (; __s != __r; ++__s)
3464 __s->~value_type();
3465 throw;
3466 }
3467#endif
Howard Hinnant3e519522010-05-11 19:42:163468 return __r;
3469}
3470
3471template <class _InputIterator, class _Size, class _ForwardIterator>
3472_ForwardIterator
3473uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3474{
Howard Hinnant3e519522010-05-11 19:42:163475 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnantb34b48192011-12-29 17:45:353476#ifndef _LIBCPP_NO_EXCEPTIONS
3477 _ForwardIterator __s = __r;
3478 try
3479 {
3480#endif
Marshall Clowa00932b2015-05-19 15:01:483481 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3482 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
Howard Hinnantb34b48192011-12-29 17:45:353483#ifndef _LIBCPP_NO_EXCEPTIONS
3484 }
3485 catch (...)
3486 {
3487 for (; __s != __r; ++__s)
3488 __s->~value_type();
3489 throw;
3490 }
3491#endif
Howard Hinnant3e519522010-05-11 19:42:163492 return __r;
3493}
3494
3495template <class _ForwardIterator, class _Tp>
3496void
3497uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3498{
Howard Hinnant3e519522010-05-11 19:42:163499 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnantb34b48192011-12-29 17:45:353500#ifndef _LIBCPP_NO_EXCEPTIONS
3501 _ForwardIterator __s = __f;
3502 try
3503 {
3504#endif
3505 for (; __f != __l; ++__f)
Marshall Clowa00932b2015-05-19 15:01:483506 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnantb34b48192011-12-29 17:45:353507#ifndef _LIBCPP_NO_EXCEPTIONS
3508 }
3509 catch (...)
3510 {
3511 for (; __s != __f; ++__s)
3512 __s->~value_type();
3513 throw;
3514 }
3515#endif
Howard Hinnant3e519522010-05-11 19:42:163516}
3517
3518template <class _ForwardIterator, class _Size, class _Tp>
Howard Hinnant48d05bd2010-11-18 16:13:033519_ForwardIterator
Howard Hinnant3e519522010-05-11 19:42:163520uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3521{
Howard Hinnant3e519522010-05-11 19:42:163522 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
Howard Hinnantb34b48192011-12-29 17:45:353523#ifndef _LIBCPP_NO_EXCEPTIONS
3524 _ForwardIterator __s = __f;
3525 try
3526 {
3527#endif
Marshall Clowa00932b2015-05-19 15:01:483528 for (; __n > 0; ++__f, (void) --__n)
3529 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
Howard Hinnantb34b48192011-12-29 17:45:353530#ifndef _LIBCPP_NO_EXCEPTIONS
3531 }
3532 catch (...)
3533 {
3534 for (; __s != __f; ++__s)
3535 __s->~value_type();
3536 throw;
3537 }
3538#endif
Howard Hinnant48d05bd2010-11-18 16:13:033539 return __f;
Howard Hinnant3e519522010-05-11 19:42:163540}
3541
Eric Fiseliere4d9c312016-07-24 03:51:393542#if _LIBCPP_STD_VER > 14
3543
Eric Fiseliere4d9c312016-07-24 03:51:393544template <class _Tp>
3545inline _LIBCPP_INLINE_VISIBILITY
3546void destroy_at(_Tp* __loc) {
3547 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3548 __loc->~_Tp();
3549}
3550
3551template <class _ForwardIterator>
3552inline _LIBCPP_INLINE_VISIBILITY
3553void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3554 for (; __first != __last; ++__first)
3555 _VSTD::destroy_at(_VSTD::addressof(*__first));
3556}
3557
3558template <class _ForwardIterator, class _Size>
3559inline _LIBCPP_INLINE_VISIBILITY
3560_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3561 for (; __n > 0; (void)++__first, --__n)
3562 _VSTD::destroy_at(_VSTD::addressof(*__first));
3563 return __first;
3564}
3565
Eric Fiseliere778d102016-10-11 21:13:443566template <class _ForwardIterator>
3567inline _LIBCPP_INLINE_VISIBILITY
3568void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3569 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3570 auto __idx = __first;
3571#ifndef _LIBCPP_NO_EXCEPTIONS
3572 try {
3573#endif
3574 for (; __idx != __last; ++__idx)
3575 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3576#ifndef _LIBCPP_NO_EXCEPTIONS
3577 } catch (...) {
3578 _VSTD::destroy(__first, __idx);
3579 throw;
3580 }
3581#endif
3582}
3583
3584template <class _ForwardIterator, class _Size>
3585inline _LIBCPP_INLINE_VISIBILITY
3586_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3587 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3588 auto __idx = __first;
3589#ifndef _LIBCPP_NO_EXCEPTIONS
3590 try {
3591#endif
3592 for (; __n > 0; (void)++__idx, --__n)
3593 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3594 return __idx;
3595#ifndef _LIBCPP_NO_EXCEPTIONS
3596 } catch (...) {
3597 _VSTD::destroy(__first, __idx);
3598 throw;
3599 }
3600#endif
3601}
3602
3603
3604template <class _ForwardIterator>
3605inline _LIBCPP_INLINE_VISIBILITY
3606void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3607 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3608 auto __idx = __first;
3609#ifndef _LIBCPP_NO_EXCEPTIONS
3610 try {
3611#endif
3612 for (; __idx != __last; ++__idx)
3613 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3614#ifndef _LIBCPP_NO_EXCEPTIONS
3615 } catch (...) {
3616 _VSTD::destroy(__first, __idx);
3617 throw;
3618 }
3619#endif
3620}
3621
3622template <class _ForwardIterator, class _Size>
3623inline _LIBCPP_INLINE_VISIBILITY
3624_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3625 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3626 auto __idx = __first;
3627#ifndef _LIBCPP_NO_EXCEPTIONS
3628 try {
3629#endif
3630 for (; __n > 0; (void)++__idx, --__n)
3631 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3632 return __idx;
3633#ifndef _LIBCPP_NO_EXCEPTIONS
3634 } catch (...) {
3635 _VSTD::destroy(__first, __idx);
3636 throw;
3637 }
3638#endif
3639}
3640
3641
3642template <class _InputIt, class _ForwardIt>
3643inline _LIBCPP_INLINE_VISIBILITY
3644_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3645 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3646 auto __idx = __first_res;
3647#ifndef _LIBCPP_NO_EXCEPTIONS
3648 try {
3649#endif
3650 for (; __first != __last; (void)++__idx, ++__first)
3651 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3652 return __idx;
3653#ifndef _LIBCPP_NO_EXCEPTIONS
3654 } catch (...) {
3655 _VSTD::destroy(__first_res, __idx);
3656 throw;
3657 }
3658#endif
3659}
3660
3661template <class _InputIt, class _Size, class _ForwardIt>
3662inline _LIBCPP_INLINE_VISIBILITY
3663pair<_InputIt, _ForwardIt>
3664uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3665 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3666 auto __idx = __first_res;
3667#ifndef _LIBCPP_NO_EXCEPTIONS
3668 try {
3669#endif
3670 for (; __n > 0; ++__idx, (void)++__first, --__n)
3671 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3672 return {__first, __idx};
3673#ifndef _LIBCPP_NO_EXCEPTIONS
3674 } catch (...) {
3675 _VSTD::destroy(__first_res, __idx);
3676 throw;
3677 }
3678#endif
3679}
3680
3681
Eric Fiseliere4d9c312016-07-24 03:51:393682#endif // _LIBCPP_STD_VER > 14
3683
Kevin Huf08de522017-01-17 02:46:333684// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3685// should be sufficient for thread safety.
3686// See https://llvm.org/bugs/show_bug.cgi?id=22803
3687#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3688 && defined(__ATOMIC_RELAXED) \
3689 && defined(__ATOMIC_ACQ_REL)
3690# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3691#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3692# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3693#endif
3694
3695template <class _Tp>
3696inline _LIBCPP_INLINE_VISIBILITY _Tp
3697__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3698{
3699#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3700 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3701#else
3702 return __t += 1;
3703#endif
3704}
3705
3706template <class _Tp>
3707inline _LIBCPP_INLINE_VISIBILITY _Tp
3708__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3709{
3710#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3711 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3712#else
3713 return __t -= 1;
3714#endif
3715}
3716
Howard Hinnant848a5372010-09-22 16:48:343717class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
Howard Hinnant3e519522010-05-11 19:42:163718 : public std::exception
3719{
3720public:
Howard Hinnant3739fe72011-05-28 14:41:133721 virtual ~bad_weak_ptr() _NOEXCEPT;
3722 virtual const char* what() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:163723};
3724
Marshall Clowd437fa52016-08-25 15:09:013725_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3726void __throw_bad_weak_ptr()
3727{
3728#ifndef _LIBCPP_NO_EXCEPTIONS
3729 throw bad_weak_ptr();
3730#else
3731 _VSTD::abort();
3732#endif
3733}
3734
Eric Fiseliere2f2d1ed2017-01-04 23:56:003735template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnant3e519522010-05-11 19:42:163736
Howard Hinnantf0544c22013-08-12 18:38:343737class _LIBCPP_TYPE_VIS __shared_count
Howard Hinnant3e519522010-05-11 19:42:163738{
3739 __shared_count(const __shared_count&);
3740 __shared_count& operator=(const __shared_count&);
3741
3742protected:
3743 long __shared_owners_;
3744 virtual ~__shared_count();
3745private:
Howard Hinnant3739fe72011-05-28 14:41:133746 virtual void __on_zero_shared() _NOEXCEPT = 0;
Howard Hinnant3e519522010-05-11 19:42:163747
3748public:
Howard Hinnant848a5372010-09-22 16:48:343749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133750 explicit __shared_count(long __refs = 0) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163751 : __shared_owners_(__refs) {}
3752
Eric Fiselier11f60452017-01-17 03:16:263753#if defined(_LIBCPP_BUILDING_MEMORY) && \
3754 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliera480c282017-01-17 03:05:313755 void __add_shared() _NOEXCEPT;
3756 bool __release_shared() _NOEXCEPT;
Kevin Huf08de522017-01-17 02:46:333757#else
3758 _LIBCPP_INLINE_VISIBILITY
3759 void __add_shared() _NOEXCEPT {
3760 __libcpp_atomic_refcount_increment(__shared_owners_);
3761 }
3762 _LIBCPP_INLINE_VISIBILITY
3763 bool __release_shared() _NOEXCEPT {
3764 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3765 __on_zero_shared();
3766 return true;
3767 }
3768 return false;
3769 }
3770#endif
Howard Hinnant848a5372010-09-22 16:48:343771 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1faf2892015-07-07 00:27:163772 long use_count() const _NOEXCEPT {
3773 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3774 }
Howard Hinnant3e519522010-05-11 19:42:163775};
3776
Howard Hinnantf0544c22013-08-12 18:38:343777class _LIBCPP_TYPE_VIS __shared_weak_count
Howard Hinnant3e519522010-05-11 19:42:163778 : private __shared_count
3779{
3780 long __shared_weak_owners_;
3781
3782public:
Howard Hinnant848a5372010-09-22 16:48:343783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133784 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163785 : __shared_count(__refs),
3786 __shared_weak_owners_(__refs) {}
3787protected:
3788 virtual ~__shared_weak_count();
3789
3790public:
Eric Fiselier11f60452017-01-17 03:16:263791#if defined(_LIBCPP_BUILDING_MEMORY) && \
3792 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
Eric Fiseliera480c282017-01-17 03:05:313793 void __add_shared() _NOEXCEPT;
3794 void __add_weak() _NOEXCEPT;
3795 void __release_shared() _NOEXCEPT;
Kevin Huf08de522017-01-17 02:46:333796#else
3797 _LIBCPP_INLINE_VISIBILITY
3798 void __add_shared() _NOEXCEPT {
3799 __shared_count::__add_shared();
3800 }
3801 _LIBCPP_INLINE_VISIBILITY
3802 void __add_weak() _NOEXCEPT {
3803 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3804 }
3805 _LIBCPP_INLINE_VISIBILITY
3806 void __release_shared() _NOEXCEPT {
3807 if (__shared_count::__release_shared())
3808 __release_weak();
3809 }
3810#endif
Howard Hinnant3739fe72011-05-28 14:41:133811 void __release_weak() _NOEXCEPT;
Howard Hinnant848a5372010-09-22 16:48:343812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133813 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3814 __shared_weak_count* lock() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:163815
Howard Hinnanta9f69802013-02-25 15:50:363816 // Define the function out only if we build static libc++ without RTTI.
3817 // Otherwise we may break clients who need to compile their projects with
3818 // -fno-rtti and yet link against a libc++.dylib compiled
3819 // without -fno-rtti.
3820#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
Howard Hinnant3739fe72011-05-28 14:41:133821 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnanta9f69802013-02-25 15:50:363822#endif
Howard Hinnant3e519522010-05-11 19:42:163823private:
Howard Hinnant3739fe72011-05-28 14:41:133824 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
Howard Hinnant3e519522010-05-11 19:42:163825};
3826
3827template <class _Tp, class _Dp, class _Alloc>
3828class __shared_ptr_pointer
3829 : public __shared_weak_count
3830{
3831 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3832public:
Howard Hinnant848a5372010-09-22 16:48:343833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163834 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
Howard Hinnantce48a112011-06-30 21:18:193835 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
Howard Hinnant3e519522010-05-11 19:42:163836
Howard Hinnant54b409f2010-08-11 17:04:313837#ifndef _LIBCPP_NO_RTTI
Howard Hinnant3739fe72011-05-28 14:41:133838 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
Howard Hinnant54b409f2010-08-11 17:04:313839#endif
Howard Hinnant3e519522010-05-11 19:42:163840
3841private:
Howard Hinnant3739fe72011-05-28 14:41:133842 virtual void __on_zero_shared() _NOEXCEPT;
3843 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:163844};
3845
Howard Hinnant54b409f2010-08-11 17:04:313846#ifndef _LIBCPP_NO_RTTI
3847
Howard Hinnant3e519522010-05-11 19:42:163848template <class _Tp, class _Dp, class _Alloc>
3849const void*
Howard Hinnant3739fe72011-05-28 14:41:133850__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163851{
Marshall Clow278ddec2014-11-17 19:05:503852 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
Howard Hinnant3e519522010-05-11 19:42:163853}
3854
Howard Hinnantb3371f62010-08-22 00:02:433855#endif // _LIBCPP_NO_RTTI
Howard Hinnant54b409f2010-08-11 17:04:313856
Howard Hinnant3e519522010-05-11 19:42:163857template <class _Tp, class _Dp, class _Alloc>
3858void
Howard Hinnant3739fe72011-05-28 14:41:133859__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163860{
3861 __data_.first().second()(__data_.first().first());
3862 __data_.first().second().~_Dp();
3863}
3864
3865template <class _Tp, class _Dp, class _Alloc>
3866void
Howard Hinnant3739fe72011-05-28 14:41:133867__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163868{
Eric Fiselier6fe361c2015-02-05 23:01:403869 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3870 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier319be722014-10-23 04:12:283871 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3872
Eric Fiselier6fe361c2015-02-05 23:01:403873 _Al __a(__data_.second());
Howard Hinnant3e519522010-05-11 19:42:163874 __data_.second().~_Alloc();
Eric Fiselier319be722014-10-23 04:12:283875 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnant3e519522010-05-11 19:42:163876}
3877
3878template <class _Tp, class _Alloc>
3879class __shared_ptr_emplace
3880 : public __shared_weak_count
3881{
3882 __compressed_pair<_Alloc, _Tp> __data_;
3883public:
3884#ifndef _LIBCPP_HAS_NO_VARIADICS
3885
Howard Hinnant848a5372010-09-22 16:48:343886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163887 __shared_ptr_emplace(_Alloc __a)
Howard Hinnantce48a112011-06-30 21:18:193888 : __data_(_VSTD::move(__a)) {}
Howard Hinnant3e519522010-05-11 19:42:163889
3890 template <class ..._Args>
Howard Hinnant848a5372010-09-22 16:48:343891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163892 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
Howard Hinnanta87b5e32011-12-19 17:58:443893 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3894 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
Howard Hinnant3e519522010-05-11 19:42:163895
3896#else // _LIBCPP_HAS_NO_VARIADICS
3897
Howard Hinnant848a5372010-09-22 16:48:343898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163899 __shared_ptr_emplace(_Alloc __a)
3900 : __data_(__a) {}
3901
3902 template <class _A0>
Howard Hinnant848a5372010-09-22 16:48:343903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163904 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3905 : __data_(__a, _Tp(__a0)) {}
3906
3907 template <class _A0, class _A1>
Howard Hinnant848a5372010-09-22 16:48:343908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163909 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3910 : __data_(__a, _Tp(__a0, __a1)) {}
3911
3912 template <class _A0, class _A1, class _A2>
Howard Hinnant848a5372010-09-22 16:48:343913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163914 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3915 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3916
3917#endif // _LIBCPP_HAS_NO_VARIADICS
3918
3919private:
Howard Hinnant3739fe72011-05-28 14:41:133920 virtual void __on_zero_shared() _NOEXCEPT;
3921 virtual void __on_zero_shared_weak() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:163922public:
Howard Hinnant848a5372010-09-22 16:48:343923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133924 _Tp* get() _NOEXCEPT {return &__data_.second();}
Howard Hinnant3e519522010-05-11 19:42:163925};
3926
3927template <class _Tp, class _Alloc>
3928void
Howard Hinnant3739fe72011-05-28 14:41:133929__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163930{
3931 __data_.second().~_Tp();
3932}
3933
3934template <class _Tp, class _Alloc>
3935void
Howard Hinnant3739fe72011-05-28 14:41:133936__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:163937{
Eric Fiselier6fe361c2015-02-05 23:01:403938 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3939 typedef allocator_traits<_Al> _ATraits;
Eric Fiselier319be722014-10-23 04:12:283940 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
Eric Fiselier6fe361c2015-02-05 23:01:403941 _Al __a(__data_.first());
Howard Hinnant3e519522010-05-11 19:42:163942 __data_.first().~_Alloc();
Eric Fiselier319be722014-10-23 04:12:283943 __a.deallocate(_PTraits::pointer_to(*this), 1);
Howard Hinnant3e519522010-05-11 19:42:163944}
3945
Eric Fiseliere2f2d1ed2017-01-04 23:56:003946template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
Howard Hinnant3e519522010-05-11 19:42:163947
3948template<class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:003949class _LIBCPP_TEMPLATE_VIS shared_ptr
Howard Hinnant3e519522010-05-11 19:42:163950{
Howard Hinnantb3371f62010-08-22 00:02:433951public:
3952 typedef _Tp element_type;
Marshall Clowdc83e772017-01-10 16:59:333953
Eric Fiselier68436a92016-06-27 01:02:433954#if _LIBCPP_STD_VER > 14
3955 typedef weak_ptr<_Tp> weak_type;
3956#endif
Howard Hinnant3e519522010-05-11 19:42:163957private:
3958 element_type* __ptr_;
3959 __shared_weak_count* __cntrl_;
3960
3961 struct __nat {int __for_bool_;};
3962public:
Evgeniy Stepanov906c8722015-11-07 01:22:133963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc0937e82012-07-07 20:56:043964 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:133965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc0937e82012-07-07 20:56:043966 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
Logan Chien22747e62014-01-31 09:30:463967 template<class _Yp>
3968 explicit shared_ptr(_Yp* __p,
3969 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3970 template<class _Yp, class _Dp>
3971 shared_ptr(_Yp* __p, _Dp __d,
3972 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3973 template<class _Yp, class _Dp, class _Alloc>
3974 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3975 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3e519522010-05-11 19:42:163976 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3977 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
Evgeniy Stepanov906c8722015-11-07 01:22:133978 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133980 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:163981 template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:133982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:163983 shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clowdc83e772017-01-10 16:59:333984 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant3739fe72011-05-28 14:41:133985 _NOEXCEPT;
Howard Hinnant7609c9b2010-09-04 23:28:193986#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov906c8722015-11-07 01:22:133987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:133988 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:133989 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clowdc83e772017-01-10 16:59:333990 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
Howard Hinnant3739fe72011-05-28 14:41:133991 _NOEXCEPT;
Howard Hinnant7609c9b2010-09-04 23:28:193992#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:163993 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clowdc83e772017-01-10 16:59:333994 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
Howard Hinnant7609c9b2010-09-04 23:28:193995#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chien22747e62014-01-31 09:30:463996 template<class _Yp>
3997 shared_ptr(auto_ptr<_Yp>&& __r,
3998 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnantb3371f62010-08-22 00:02:433999#else
Logan Chien22747e62014-01-31 09:30:464000 template<class _Yp>
4001 shared_ptr(auto_ptr<_Yp> __r,
4002 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
Howard Hinnant3e519522010-05-11 19:42:164003#endif
Howard Hinnant7609c9b2010-09-04 23:28:194004#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chien22747e62014-01-31 09:30:464005 template <class _Yp, class _Dp>
4006 shared_ptr(unique_ptr<_Yp, _Dp>&&,
4007 typename enable_if
4008 <
4009 !is_lvalue_reference<_Dp>::value &&
4010 !is_array<_Yp>::value &&
4011 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4012 __nat
4013 >::type = __nat());
4014 template <class _Yp, class _Dp>
4015 shared_ptr(unique_ptr<_Yp, _Dp>&&,
4016 typename enable_if
4017 <
4018 is_lvalue_reference<_Dp>::value &&
4019 !is_array<_Yp>::value &&
4020 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4021 __nat
4022 >::type = __nat());
Howard Hinnant7609c9b2010-09-04 23:28:194023#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chien22747e62014-01-31 09:30:464024 template <class _Yp, class _Dp>
4025 shared_ptr(unique_ptr<_Yp, _Dp>,
4026 typename enable_if
4027 <
4028 !is_lvalue_reference<_Dp>::value &&
4029 !is_array<_Yp>::value &&
4030 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4031 __nat
4032 >::type = __nat());
4033 template <class _Yp, class _Dp>
4034 shared_ptr(unique_ptr<_Yp, _Dp>,
4035 typename enable_if
4036 <
4037 is_lvalue_reference<_Dp>::value &&
4038 !is_array<_Yp>::value &&
4039 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4040 __nat
4041 >::type = __nat());
Howard Hinnant7609c9b2010-09-04 23:28:194042#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164043
4044 ~shared_ptr();
4045
Evgeniy Stepanov906c8722015-11-07 01:22:134046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134047 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
Howard Hinnant8e251042012-01-02 17:56:024048 template<class _Yp>
4049 typename enable_if
4050 <
4051 is_convertible<_Yp*, element_type*>::value,
4052 shared_ptr&
4053 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:134054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024055 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
Howard Hinnant7609c9b2010-09-04 23:28:194056#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov906c8722015-11-07 01:22:134057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134058 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
Howard Hinnant8e251042012-01-02 17:56:024059 template<class _Yp>
4060 typename enable_if
4061 <
4062 is_convertible<_Yp*, element_type*>::value,
4063 shared_ptr<_Tp>&
4064 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:134065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024066 operator=(shared_ptr<_Yp>&& __r);
4067 template<class _Yp>
Eric Fiselier89dd1dd2016-04-21 22:54:214068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024069 typename enable_if
4070 <
4071 !is_array<_Yp>::value &&
4072 is_convertible<_Yp*, element_type*>::value,
Howard Hinnant84f996f2013-09-13 23:56:004073 shared_ptr
4074 >::type&
Howard Hinnant8e251042012-01-02 17:56:024075 operator=(auto_ptr<_Yp>&& __r);
Howard Hinnant7609c9b2010-09-04 23:28:194076#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant8e251042012-01-02 17:56:024077 template<class _Yp>
Eric Fiselier89dd1dd2016-04-21 22:54:214078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024079 typename enable_if
4080 <
4081 !is_array<_Yp>::value &&
4082 is_convertible<_Yp*, element_type*>::value,
4083 shared_ptr&
4084 >::type
4085 operator=(auto_ptr<_Yp> __r);
Howard Hinnant3e519522010-05-11 19:42:164086#endif
Howard Hinnant8e251042012-01-02 17:56:024087 template <class _Yp, class _Dp>
4088 typename enable_if
4089 <
4090 !is_array<_Yp>::value &&
4091 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4092 shared_ptr&
4093 >::type
Howard Hinnant7609c9b2010-09-04 23:28:194094#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov906c8722015-11-07 01:22:134095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024096 operator=(unique_ptr<_Yp, _Dp>&& __r);
Howard Hinnant7609c9b2010-09-04 23:28:194097#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov02b8e942015-12-09 22:32:364098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024099 operator=(unique_ptr<_Yp, _Dp> __r);
Howard Hinnant3e519522010-05-11 19:42:164100#endif
4101
Evgeniy Stepanov906c8722015-11-07 01:22:134102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134103 void swap(shared_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:134104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134105 void reset() _NOEXCEPT;
Howard Hinnant8e251042012-01-02 17:56:024106 template<class _Yp>
4107 typename enable_if
4108 <
4109 is_convertible<_Yp*, element_type*>::value,
4110 void
4111 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:134112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024113 reset(_Yp* __p);
4114 template<class _Yp, class _Dp>
4115 typename enable_if
4116 <
4117 is_convertible<_Yp*, element_type*>::value,
4118 void
4119 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:134120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024121 reset(_Yp* __p, _Dp __d);
4122 template<class _Yp, class _Dp, class _Alloc>
4123 typename enable_if
4124 <
4125 is_convertible<_Yp*, element_type*>::value,
4126 void
4127 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:134128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024129 reset(_Yp* __p, _Dp __d, _Alloc __a);
Howard Hinnant3e519522010-05-11 19:42:164130
Howard Hinnant848a5372010-09-22 16:48:344131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134132 element_type* get() const _NOEXCEPT {return __ptr_;}
Howard Hinnant848a5372010-09-22 16:48:344133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134134 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
4135 {return *__ptr_;}
Howard Hinnant848a5372010-09-22 16:48:344136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134137 element_type* operator->() const _NOEXCEPT {return __ptr_;}
Howard Hinnant848a5372010-09-22 16:48:344138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134139 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant848a5372010-09-22 16:48:344140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134141 bool unique() const _NOEXCEPT {return use_count() == 1;}
Howard Hinnant848a5372010-09-22 16:48:344142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf2f2d8b2012-02-21 21:46:434143 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
Howard Hinnantc003db12011-11-29 18:15:504144 template <class _Up>
Howard Hinnant848a5372010-09-22 16:48:344145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:504146 bool owner_before(shared_ptr<_Up> const& __p) const
Howard Hinnant3e519522010-05-11 19:42:164147 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantc003db12011-11-29 18:15:504148 template <class _Up>
Howard Hinnant848a5372010-09-22 16:48:344149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc003db12011-11-29 18:15:504150 bool owner_before(weak_ptr<_Up> const& __p) const
Howard Hinnant3e519522010-05-11 19:42:164151 {return __cntrl_ < __p.__cntrl_;}
Howard Hinnantd77851e2012-07-30 01:40:574152 _LIBCPP_INLINE_VISIBILITY
4153 bool
4154 __owner_equivalent(const shared_ptr& __p) const
4155 {return __cntrl_ == __p.__cntrl_;}
Howard Hinnant3e519522010-05-11 19:42:164156
Howard Hinnant54b409f2010-08-11 17:04:314157#ifndef _LIBCPP_NO_RTTI
Howard Hinnant3e519522010-05-11 19:42:164158 template <class _Dp>
Howard Hinnant848a5372010-09-22 16:48:344159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:134160 _Dp* __get_deleter() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164161 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
Howard Hinnantb3371f62010-08-22 00:02:434162#endif // _LIBCPP_NO_RTTI
Howard Hinnant3e519522010-05-11 19:42:164163
4164#ifndef _LIBCPP_HAS_NO_VARIADICS
4165
4166 template<class ..._Args>
4167 static
4168 shared_ptr<_Tp>
4169 make_shared(_Args&& ...__args);
4170
4171 template<class _Alloc, class ..._Args>
4172 static
4173 shared_ptr<_Tp>
4174 allocate_shared(const _Alloc& __a, _Args&& ...__args);
4175
4176#else // _LIBCPP_HAS_NO_VARIADICS
4177
4178 static shared_ptr<_Tp> make_shared();
4179
4180 template<class _A0>
4181 static shared_ptr<_Tp> make_shared(_A0&);
4182
4183 template<class _A0, class _A1>
4184 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
4185
4186 template<class _A0, class _A1, class _A2>
4187 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
4188
4189 template<class _Alloc>
4190 static shared_ptr<_Tp>
4191 allocate_shared(const _Alloc& __a);
4192
4193 template<class _Alloc, class _A0>
4194 static shared_ptr<_Tp>
4195 allocate_shared(const _Alloc& __a, _A0& __a0);
4196
4197 template<class _Alloc, class _A0, class _A1>
4198 static shared_ptr<_Tp>
4199 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
4200
4201 template<class _Alloc, class _A0, class _A1, class _A2>
4202 static shared_ptr<_Tp>
4203 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
4204
4205#endif // _LIBCPP_HAS_NO_VARIADICS
4206
4207private:
4208
Eric Fiselier39005d32016-06-26 23:56:324209 template <class _Yp, class _OrigPtr>
Howard Hinnant848a5372010-09-22 16:48:344210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:164211 void
Eric Fiselier39005d32016-06-26 23:56:324212 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4213 _OrigPtr* __ptr) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164214 {
Eric Fiselier39005d32016-06-26 23:56:324215 typedef typename remove_cv<_Yp>::type _RawYp;
Eric Fiselier88f5bfd2016-06-02 00:15:354216 if (__e && __e->__weak_this_.expired())
Marshall Clow55112de2015-06-19 15:54:134217 {
Eric Fiselier39005d32016-06-26 23:56:324218 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4219 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
Marshall Clow55112de2015-06-19 15:54:134220 }
Howard Hinnant3e519522010-05-11 19:42:164221 }
4222
Howard Hinnant848a5372010-09-22 16:48:344223 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier39005d32016-06-26 23:56:324224 void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {}
Howard Hinnant3e519522010-05-11 19:42:164225
Eric Fiseliere2f2d1ed2017-01-04 23:56:004226 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4227 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
Howard Hinnant3e519522010-05-11 19:42:164228};
4229
4230template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134231inline
Howard Hinnantc0937e82012-07-07 20:56:044232_LIBCPP_CONSTEXPR
Howard Hinnant3739fe72011-05-28 14:41:134233shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164234 : __ptr_(0),
4235 __cntrl_(0)
4236{
4237}
4238
4239template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134240inline
Howard Hinnantc0937e82012-07-07 20:56:044241_LIBCPP_CONSTEXPR
Howard Hinnant3739fe72011-05-28 14:41:134242shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164243 : __ptr_(0),
4244 __cntrl_(0)
4245{
4246}
4247
4248template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464249template<class _Yp>
4250shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4251 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3e519522010-05-11 19:42:164252 : __ptr_(__p)
4253{
4254 unique_ptr<_Yp> __hold(__p);
4255 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4256 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
4257 __hold.release();
Eric Fiselier39005d32016-06-26 23:56:324258 __enable_weak_this(__p, __p);
Howard Hinnant3e519522010-05-11 19:42:164259}
4260
4261template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464262template<class _Yp, class _Dp>
4263shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4264 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3e519522010-05-11 19:42:164265 : __ptr_(__p)
4266{
4267#ifndef _LIBCPP_NO_EXCEPTIONS
4268 try
4269 {
Howard Hinnantb3371f62010-08-22 00:02:434270#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164271 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4272 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
Eric Fiselier39005d32016-06-26 23:56:324273 __enable_weak_this(__p, __p);
Howard Hinnant3e519522010-05-11 19:42:164274#ifndef _LIBCPP_NO_EXCEPTIONS
4275 }
4276 catch (...)
4277 {
4278 __d(__p);
4279 throw;
4280 }
Howard Hinnantb3371f62010-08-22 00:02:434281#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164282}
4283
4284template<class _Tp>
4285template<class _Dp>
4286shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4287 : __ptr_(0)
4288{
4289#ifndef _LIBCPP_NO_EXCEPTIONS
4290 try
4291 {
Howard Hinnantb3371f62010-08-22 00:02:434292#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164293 typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
4294 __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
4295#ifndef _LIBCPP_NO_EXCEPTIONS
4296 }
4297 catch (...)
4298 {
4299 __d(__p);
4300 throw;
4301 }
Howard Hinnantb3371f62010-08-22 00:02:434302#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164303}
4304
4305template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464306template<class _Yp, class _Dp, class _Alloc>
4307shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4308 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3e519522010-05-11 19:42:164309 : __ptr_(__p)
4310{
4311#ifndef _LIBCPP_NO_EXCEPTIONS
4312 try
4313 {
Howard Hinnantb3371f62010-08-22 00:02:434314#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164315 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284316 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnant3e519522010-05-11 19:42:164317 typedef __allocator_destructor<_A2> _D2;
4318 _A2 __a2(__a);
4319 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier319be722014-10-23 04:12:284320 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4321 _CntrlBlk(__p, __d, __a);
4322 __cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324323 __enable_weak_this(__p, __p);
Howard Hinnant3e519522010-05-11 19:42:164324#ifndef _LIBCPP_NO_EXCEPTIONS
4325 }
4326 catch (...)
4327 {
4328 __d(__p);
4329 throw;
4330 }
Howard Hinnantb3371f62010-08-22 00:02:434331#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164332}
4333
4334template<class _Tp>
4335template<class _Dp, class _Alloc>
4336shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4337 : __ptr_(0)
4338{
4339#ifndef _LIBCPP_NO_EXCEPTIONS
4340 try
4341 {
Howard Hinnantb3371f62010-08-22 00:02:434342#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164343 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284344 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnant3e519522010-05-11 19:42:164345 typedef __allocator_destructor<_A2> _D2;
4346 _A2 __a2(__a);
4347 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier319be722014-10-23 04:12:284348 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4349 _CntrlBlk(__p, __d, __a);
4350 __cntrl_ = _VSTD::addressof(*__hold2.release());
Howard Hinnant3e519522010-05-11 19:42:164351#ifndef _LIBCPP_NO_EXCEPTIONS
4352 }
4353 catch (...)
4354 {
4355 __d(__p);
4356 throw;
4357 }
Howard Hinnantb3371f62010-08-22 00:02:434358#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:164359}
4360
4361template<class _Tp>
4362template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134363inline
Howard Hinnant3739fe72011-05-28 14:41:134364shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164365 : __ptr_(__p),
4366 __cntrl_(__r.__cntrl_)
4367{
4368 if (__cntrl_)
4369 __cntrl_->__add_shared();
4370}
4371
4372template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134373inline
Howard Hinnant3739fe72011-05-28 14:41:134374shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164375 : __ptr_(__r.__ptr_),
4376 __cntrl_(__r.__cntrl_)
4377{
4378 if (__cntrl_)
4379 __cntrl_->__add_shared();
4380}
4381
4382template<class _Tp>
4383template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134384inline
Howard Hinnant3e519522010-05-11 19:42:164385shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
Marshall Clowdc83e772017-01-10 16:59:334386 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3739fe72011-05-28 14:41:134387 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164388 : __ptr_(__r.__ptr_),
4389 __cntrl_(__r.__cntrl_)
4390{
4391 if (__cntrl_)
4392 __cntrl_->__add_shared();
4393}
4394
Howard Hinnant7609c9b2010-09-04 23:28:194395#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164396
4397template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134398inline
Howard Hinnant3739fe72011-05-28 14:41:134399shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164400 : __ptr_(__r.__ptr_),
4401 __cntrl_(__r.__cntrl_)
4402{
4403 __r.__ptr_ = 0;
4404 __r.__cntrl_ = 0;
4405}
4406
4407template<class _Tp>
4408template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134409inline
Howard Hinnant3e519522010-05-11 19:42:164410shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
Marshall Clowdc83e772017-01-10 16:59:334411 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3739fe72011-05-28 14:41:134412 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164413 : __ptr_(__r.__ptr_),
4414 __cntrl_(__r.__cntrl_)
4415{
4416 __r.__ptr_ = 0;
4417 __r.__cntrl_ = 0;
4418}
4419
Howard Hinnant7609c9b2010-09-04 23:28:194420#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164421
4422template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464423template<class _Yp>
Howard Hinnant7609c9b2010-09-04 23:28:194424#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Logan Chien22747e62014-01-31 09:30:464425shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
Howard Hinnant3e519522010-05-11 19:42:164426#else
Logan Chien22747e62014-01-31 09:30:464427shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
Howard Hinnant3e519522010-05-11 19:42:164428#endif
Logan Chien22747e62014-01-31 09:30:464429 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3e519522010-05-11 19:42:164430 : __ptr_(__r.get())
4431{
4432 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4433 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
Eric Fiselier39005d32016-06-26 23:56:324434 __enable_weak_this(__r.get(), __r.get());
Howard Hinnant3e519522010-05-11 19:42:164435 __r.release();
4436}
4437
4438template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464439template <class _Yp, class _Dp>
Howard Hinnant7609c9b2010-09-04 23:28:194440#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164441shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4442#else
4443shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4444#endif
Logan Chien22747e62014-01-31 09:30:464445 typename enable_if
4446 <
4447 !is_lvalue_reference<_Dp>::value &&
4448 !is_array<_Yp>::value &&
4449 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4450 __nat
4451 >::type)
Howard Hinnant3e519522010-05-11 19:42:164452 : __ptr_(__r.get())
4453{
Marshall Clowc34f8472015-05-10 13:59:454454#if _LIBCPP_STD_VER > 11
4455 if (__ptr_ == nullptr)
4456 __cntrl_ = nullptr;
4457 else
4458#endif
4459 {
4460 typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
4461 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
Eric Fiselier39005d32016-06-26 23:56:324462 __enable_weak_this(__r.get(), __r.get());
Marshall Clowc34f8472015-05-10 13:59:454463 }
Howard Hinnant3e519522010-05-11 19:42:164464 __r.release();
4465}
4466
4467template<class _Tp>
Logan Chien22747e62014-01-31 09:30:464468template <class _Yp, class _Dp>
Howard Hinnant7609c9b2010-09-04 23:28:194469#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164470shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4471#else
4472shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4473#endif
Logan Chien22747e62014-01-31 09:30:464474 typename enable_if
4475 <
4476 is_lvalue_reference<_Dp>::value &&
4477 !is_array<_Yp>::value &&
4478 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4479 __nat
4480 >::type)
Howard Hinnant3e519522010-05-11 19:42:164481 : __ptr_(__r.get())
4482{
Marshall Clowc34f8472015-05-10 13:59:454483#if _LIBCPP_STD_VER > 11
4484 if (__ptr_ == nullptr)
4485 __cntrl_ = nullptr;
4486 else
4487#endif
4488 {
4489 typedef __shared_ptr_pointer<_Yp*,
4490 reference_wrapper<typename remove_reference<_Dp>::type>,
4491 allocator<_Yp> > _CntrlBlk;
4492 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
Eric Fiselier39005d32016-06-26 23:56:324493 __enable_weak_this(__r.get(), __r.get());
Marshall Clowc34f8472015-05-10 13:59:454494 }
Howard Hinnant3e519522010-05-11 19:42:164495 __r.release();
4496}
4497
4498#ifndef _LIBCPP_HAS_NO_VARIADICS
4499
4500template<class _Tp>
4501template<class ..._Args>
4502shared_ptr<_Tp>
4503shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4504{
4505 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4506 typedef allocator<_CntrlBlk> _A2;
4507 typedef __allocator_destructor<_A2> _D2;
4508 _A2 __a2;
4509 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Howard Hinnantce48a112011-06-30 21:18:194510 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:164511 shared_ptr<_Tp> __r;
4512 __r.__ptr_ = __hold2.get()->get();
4513 __r.__cntrl_ = __hold2.release();
Eric Fiselier39005d32016-06-26 23:56:324514 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164515 return __r;
4516}
4517
4518template<class _Tp>
4519template<class _Alloc, class ..._Args>
4520shared_ptr<_Tp>
4521shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4522{
4523 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284524 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
Howard Hinnant3e519522010-05-11 19:42:164525 typedef __allocator_destructor<_A2> _D2;
4526 _A2 __a2(__a);
4527 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
Eric Fiselier319be722014-10-23 04:12:284528 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4529 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:164530 shared_ptr<_Tp> __r;
4531 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier319be722014-10-23 04:12:284532 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324533 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164534 return __r;
4535}
4536
4537#else // _LIBCPP_HAS_NO_VARIADICS
4538
4539template<class _Tp>
4540shared_ptr<_Tp>
4541shared_ptr<_Tp>::make_shared()
4542{
4543 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4544 typedef allocator<_CntrlBlk> _Alloc2;
4545 typedef __allocator_destructor<_Alloc2> _D2;
4546 _Alloc2 __alloc2;
4547 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4548 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4549 shared_ptr<_Tp> __r;
4550 __r.__ptr_ = __hold2.get()->get();
4551 __r.__cntrl_ = __hold2.release();
Eric Fiselier39005d32016-06-26 23:56:324552 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164553 return __r;
4554}
4555
4556template<class _Tp>
4557template<class _A0>
4558shared_ptr<_Tp>
4559shared_ptr<_Tp>::make_shared(_A0& __a0)
4560{
4561 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4562 typedef allocator<_CntrlBlk> _Alloc2;
4563 typedef __allocator_destructor<_Alloc2> _D2;
4564 _Alloc2 __alloc2;
4565 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4566 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4567 shared_ptr<_Tp> __r;
4568 __r.__ptr_ = __hold2.get()->get();
4569 __r.__cntrl_ = __hold2.release();
Eric Fiselier39005d32016-06-26 23:56:324570 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164571 return __r;
4572}
4573
4574template<class _Tp>
4575template<class _A0, class _A1>
4576shared_ptr<_Tp>
4577shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4578{
4579 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4580 typedef allocator<_CntrlBlk> _Alloc2;
4581 typedef __allocator_destructor<_Alloc2> _D2;
4582 _Alloc2 __alloc2;
4583 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4584 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4585 shared_ptr<_Tp> __r;
4586 __r.__ptr_ = __hold2.get()->get();
4587 __r.__cntrl_ = __hold2.release();
Eric Fiselier39005d32016-06-26 23:56:324588 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164589 return __r;
4590}
4591
4592template<class _Tp>
4593template<class _A0, class _A1, class _A2>
4594shared_ptr<_Tp>
4595shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4596{
4597 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4598 typedef allocator<_CntrlBlk> _Alloc2;
4599 typedef __allocator_destructor<_Alloc2> _D2;
4600 _Alloc2 __alloc2;
4601 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4602 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4603 shared_ptr<_Tp> __r;
4604 __r.__ptr_ = __hold2.get()->get();
4605 __r.__cntrl_ = __hold2.release();
Eric Fiselier39005d32016-06-26 23:56:324606 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164607 return __r;
4608}
4609
4610template<class _Tp>
4611template<class _Alloc>
4612shared_ptr<_Tp>
4613shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4614{
4615 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284616 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnant3e519522010-05-11 19:42:164617 typedef __allocator_destructor<_Alloc2> _D2;
4618 _Alloc2 __alloc2(__a);
4619 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier319be722014-10-23 04:12:284620 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4621 _CntrlBlk(__a);
Howard Hinnant3e519522010-05-11 19:42:164622 shared_ptr<_Tp> __r;
4623 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier319be722014-10-23 04:12:284624 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324625 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164626 return __r;
4627}
4628
4629template<class _Tp>
4630template<class _Alloc, class _A0>
4631shared_ptr<_Tp>
4632shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4633{
4634 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284635 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnant3e519522010-05-11 19:42:164636 typedef __allocator_destructor<_Alloc2> _D2;
4637 _Alloc2 __alloc2(__a);
4638 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier319be722014-10-23 04:12:284639 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4640 _CntrlBlk(__a, __a0);
Howard Hinnant3e519522010-05-11 19:42:164641 shared_ptr<_Tp> __r;
4642 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier319be722014-10-23 04:12:284643 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324644 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164645 return __r;
4646}
4647
4648template<class _Tp>
4649template<class _Alloc, class _A0, class _A1>
4650shared_ptr<_Tp>
4651shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4652{
4653 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284654 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnant3e519522010-05-11 19:42:164655 typedef __allocator_destructor<_Alloc2> _D2;
4656 _Alloc2 __alloc2(__a);
4657 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier319be722014-10-23 04:12:284658 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4659 _CntrlBlk(__a, __a0, __a1);
Howard Hinnant3e519522010-05-11 19:42:164660 shared_ptr<_Tp> __r;
4661 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier319be722014-10-23 04:12:284662 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324663 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164664 return __r;
4665}
4666
4667template<class _Tp>
4668template<class _Alloc, class _A0, class _A1, class _A2>
4669shared_ptr<_Tp>
4670shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4671{
4672 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
Eric Fiselier319be722014-10-23 04:12:284673 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
Howard Hinnant3e519522010-05-11 19:42:164674 typedef __allocator_destructor<_Alloc2> _D2;
4675 _Alloc2 __alloc2(__a);
4676 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
Eric Fiselier319be722014-10-23 04:12:284677 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4678 _CntrlBlk(__a, __a0, __a1, __a2);
Howard Hinnant3e519522010-05-11 19:42:164679 shared_ptr<_Tp> __r;
4680 __r.__ptr_ = __hold2.get()->get();
Eric Fiselier319be722014-10-23 04:12:284681 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
Eric Fiselier39005d32016-06-26 23:56:324682 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:164683 return __r;
4684}
4685
4686#endif // _LIBCPP_HAS_NO_VARIADICS
4687
4688template<class _Tp>
4689shared_ptr<_Tp>::~shared_ptr()
4690{
4691 if (__cntrl_)
4692 __cntrl_->__release_shared();
4693}
4694
4695template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134696inline
Howard Hinnant3e519522010-05-11 19:42:164697shared_ptr<_Tp>&
Howard Hinnant3739fe72011-05-28 14:41:134698shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164699{
4700 shared_ptr(__r).swap(*this);
4701 return *this;
4702}
4703
4704template<class _Tp>
4705template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134706inline
Howard Hinnant8e251042012-01-02 17:56:024707typename enable_if
4708<
Marshall Clowdc83e772017-01-10 16:59:334709 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024710 shared_ptr<_Tp>&
4711>::type
Howard Hinnant3739fe72011-05-28 14:41:134712shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164713{
4714 shared_ptr(__r).swap(*this);
4715 return *this;
4716}
4717
Howard Hinnant7609c9b2010-09-04 23:28:194718#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164719
4720template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134721inline
Howard Hinnant3e519522010-05-11 19:42:164722shared_ptr<_Tp>&
Howard Hinnant3739fe72011-05-28 14:41:134723shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164724{
Howard Hinnantce48a112011-06-30 21:18:194725 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnant3e519522010-05-11 19:42:164726 return *this;
4727}
4728
4729template<class _Tp>
4730template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134731inline
Howard Hinnant8e251042012-01-02 17:56:024732typename enable_if
4733<
Marshall Clowdc83e772017-01-10 16:59:334734 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024735 shared_ptr<_Tp>&
4736>::type
Howard Hinnant3e519522010-05-11 19:42:164737shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4738{
Howard Hinnantce48a112011-06-30 21:18:194739 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnant3e519522010-05-11 19:42:164740 return *this;
4741}
4742
4743template<class _Tp>
4744template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134745inline
Howard Hinnant8e251042012-01-02 17:56:024746typename enable_if
4747<
4748 !is_array<_Yp>::value &&
Marshall Clowdc83e772017-01-10 16:59:334749 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant84f996f2013-09-13 23:56:004750 shared_ptr<_Tp>
4751>::type&
Howard Hinnant3e519522010-05-11 19:42:164752shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4753{
Howard Hinnantce48a112011-06-30 21:18:194754 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnant3e519522010-05-11 19:42:164755 return *this;
4756}
4757
4758template<class _Tp>
4759template <class _Yp, class _Dp>
Evgeniy Stepanov906c8722015-11-07 01:22:134760inline
Howard Hinnant8e251042012-01-02 17:56:024761typename enable_if
4762<
4763 !is_array<_Yp>::value &&
Marshall Clowdc83e772017-01-10 16:59:334764 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4765 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024766 shared_ptr<_Tp>&
4767>::type
Howard Hinnant3e519522010-05-11 19:42:164768shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4769{
Howard Hinnantce48a112011-06-30 21:18:194770 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnant3e519522010-05-11 19:42:164771 return *this;
4772}
4773
Howard Hinnant7609c9b2010-09-04 23:28:194774#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164775
4776template<class _Tp>
4777template<class _Yp>
4778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024779typename enable_if
4780<
4781 !is_array<_Yp>::value &&
Marshall Clow3a6474e2017-01-10 18:40:014782 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024783 shared_ptr<_Tp>&
4784>::type
Howard Hinnantb3371f62010-08-22 00:02:434785shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
Howard Hinnant3e519522010-05-11 19:42:164786{
4787 shared_ptr(__r).swap(*this);
4788 return *this;
4789}
4790
4791template<class _Tp>
4792template <class _Yp, class _Dp>
4793inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024794typename enable_if
4795<
4796 !is_array<_Yp>::value &&
Marshall Clow3a6474e2017-01-10 18:40:014797 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4798 typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024799 shared_ptr<_Tp>&
4800>::type
Howard Hinnant3e519522010-05-11 19:42:164801shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4802{
Howard Hinnantce48a112011-06-30 21:18:194803 shared_ptr(_VSTD::move(__r)).swap(*this);
Howard Hinnant3e519522010-05-11 19:42:164804 return *this;
4805}
4806
Howard Hinnant7609c9b2010-09-04 23:28:194807#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:164808
4809template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134810inline
Howard Hinnant3e519522010-05-11 19:42:164811void
Howard Hinnant3739fe72011-05-28 14:41:134812shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164813{
Howard Hinnantce48a112011-06-30 21:18:194814 _VSTD::swap(__ptr_, __r.__ptr_);
4815 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnant3e519522010-05-11 19:42:164816}
4817
4818template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:134819inline
Howard Hinnant3e519522010-05-11 19:42:164820void
Howard Hinnant3739fe72011-05-28 14:41:134821shared_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164822{
4823 shared_ptr().swap(*this);
4824}
4825
4826template<class _Tp>
4827template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:134828inline
Howard Hinnant8e251042012-01-02 17:56:024829typename enable_if
4830<
Marshall Clowdc83e772017-01-10 16:59:334831 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024832 void
4833>::type
Howard Hinnant3e519522010-05-11 19:42:164834shared_ptr<_Tp>::reset(_Yp* __p)
4835{
4836 shared_ptr(__p).swap(*this);
4837}
4838
4839template<class _Tp>
4840template<class _Yp, class _Dp>
Evgeniy Stepanov906c8722015-11-07 01:22:134841inline
Howard Hinnant8e251042012-01-02 17:56:024842typename enable_if
4843<
Marshall Clowdc83e772017-01-10 16:59:334844 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024845 void
4846>::type
Howard Hinnant3e519522010-05-11 19:42:164847shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4848{
4849 shared_ptr(__p, __d).swap(*this);
4850}
4851
4852template<class _Tp>
4853template<class _Yp, class _Dp, class _Alloc>
Evgeniy Stepanov906c8722015-11-07 01:22:134854inline
Howard Hinnant8e251042012-01-02 17:56:024855typename enable_if
4856<
Marshall Clowdc83e772017-01-10 16:59:334857 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
Howard Hinnant8e251042012-01-02 17:56:024858 void
4859>::type
Howard Hinnant3e519522010-05-11 19:42:164860shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4861{
4862 shared_ptr(__p, __d, __a).swap(*this);
4863}
4864
4865#ifndef _LIBCPP_HAS_NO_VARIADICS
4866
Howard Hinnantb3371f62010-08-22 00:02:434867template<class _Tp, class ..._Args>
Howard Hinnant3e519522010-05-11 19:42:164868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024869typename enable_if
4870<
4871 !is_array<_Tp>::value,
4872 shared_ptr<_Tp>
4873>::type
Howard Hinnant3e519522010-05-11 19:42:164874make_shared(_Args&& ...__args)
4875{
Howard Hinnantce48a112011-06-30 21:18:194876 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:164877}
4878
Howard Hinnantb3371f62010-08-22 00:02:434879template<class _Tp, class _Alloc, class ..._Args>
Howard Hinnant3e519522010-05-11 19:42:164880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:024881typename enable_if
4882<
4883 !is_array<_Tp>::value,
4884 shared_ptr<_Tp>
4885>::type
Howard Hinnant3e519522010-05-11 19:42:164886allocate_shared(const _Alloc& __a, _Args&& ...__args)
4887{
Howard Hinnantce48a112011-06-30 21:18:194888 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
Howard Hinnant3e519522010-05-11 19:42:164889}
4890
4891#else // _LIBCPP_HAS_NO_VARIADICS
4892
4893template<class _Tp>
4894inline _LIBCPP_INLINE_VISIBILITY
4895shared_ptr<_Tp>
4896make_shared()
4897{
4898 return shared_ptr<_Tp>::make_shared();
4899}
4900
4901template<class _Tp, class _A0>
4902inline _LIBCPP_INLINE_VISIBILITY
4903shared_ptr<_Tp>
4904make_shared(_A0& __a0)
4905{
4906 return shared_ptr<_Tp>::make_shared(__a0);
4907}
4908
4909template<class _Tp, class _A0, class _A1>
4910inline _LIBCPP_INLINE_VISIBILITY
4911shared_ptr<_Tp>
4912make_shared(_A0& __a0, _A1& __a1)
4913{
4914 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4915}
4916
Howard Hinnantb3371f62010-08-22 00:02:434917template<class _Tp, class _A0, class _A1, class _A2>
Howard Hinnant3e519522010-05-11 19:42:164918inline _LIBCPP_INLINE_VISIBILITY
4919shared_ptr<_Tp>
4920make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4921{
4922 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4923}
4924
4925template<class _Tp, class _Alloc>
4926inline _LIBCPP_INLINE_VISIBILITY
4927shared_ptr<_Tp>
4928allocate_shared(const _Alloc& __a)
4929{
4930 return shared_ptr<_Tp>::allocate_shared(__a);
4931}
4932
4933template<class _Tp, class _Alloc, class _A0>
4934inline _LIBCPP_INLINE_VISIBILITY
4935shared_ptr<_Tp>
4936allocate_shared(const _Alloc& __a, _A0& __a0)
4937{
4938 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4939}
4940
4941template<class _Tp, class _Alloc, class _A0, class _A1>
4942inline _LIBCPP_INLINE_VISIBILITY
4943shared_ptr<_Tp>
4944allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4945{
4946 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4947}
4948
4949template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4950inline _LIBCPP_INLINE_VISIBILITY
4951shared_ptr<_Tp>
4952allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4953{
4954 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4955}
4956
4957#endif // _LIBCPP_HAS_NO_VARIADICS
4958
4959template<class _Tp, class _Up>
4960inline _LIBCPP_INLINE_VISIBILITY
4961bool
Howard Hinnant3739fe72011-05-28 14:41:134962operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164963{
4964 return __x.get() == __y.get();
4965}
4966
4967template<class _Tp, class _Up>
4968inline _LIBCPP_INLINE_VISIBILITY
4969bool
Howard Hinnant3739fe72011-05-28 14:41:134970operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164971{
4972 return !(__x == __y);
4973}
4974
4975template<class _Tp, class _Up>
4976inline _LIBCPP_INLINE_VISIBILITY
4977bool
Howard Hinnant3739fe72011-05-28 14:41:134978operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:164979{
Eric Fiselier6fe361c2015-02-05 23:01:404980 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4981 return less<_Vp>()(__x.get(), __y.get());
Howard Hinnant67f39642012-02-21 21:02:584982}
4983
4984template<class _Tp, class _Up>
4985inline _LIBCPP_INLINE_VISIBILITY
4986bool
4987operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4988{
4989 return __y < __x;
4990}
4991
4992template<class _Tp, class _Up>
4993inline _LIBCPP_INLINE_VISIBILITY
4994bool
4995operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4996{
4997 return !(__y < __x);
4998}
4999
5000template<class _Tp, class _Up>
5001inline _LIBCPP_INLINE_VISIBILITY
5002bool
5003operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
5004{
5005 return !(__x < __y);
5006}
5007
5008template<class _Tp>
5009inline _LIBCPP_INLINE_VISIBILITY
5010bool
5011operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5012{
5013 return !__x;
5014}
5015
5016template<class _Tp>
5017inline _LIBCPP_INLINE_VISIBILITY
5018bool
5019operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5020{
5021 return !__x;
5022}
5023
5024template<class _Tp>
5025inline _LIBCPP_INLINE_VISIBILITY
5026bool
5027operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5028{
5029 return static_cast<bool>(__x);
5030}
5031
5032template<class _Tp>
5033inline _LIBCPP_INLINE_VISIBILITY
5034bool
5035operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5036{
5037 return static_cast<bool>(__x);
5038}
5039
5040template<class _Tp>
5041inline _LIBCPP_INLINE_VISIBILITY
5042bool
5043operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5044{
5045 return less<_Tp*>()(__x.get(), nullptr);
5046}
5047
5048template<class _Tp>
5049inline _LIBCPP_INLINE_VISIBILITY
5050bool
5051operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5052{
5053 return less<_Tp*>()(nullptr, __x.get());
5054}
5055
5056template<class _Tp>
5057inline _LIBCPP_INLINE_VISIBILITY
5058bool
5059operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5060{
5061 return nullptr < __x;
5062}
5063
5064template<class _Tp>
5065inline _LIBCPP_INLINE_VISIBILITY
5066bool
5067operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5068{
5069 return __x < nullptr;
5070}
5071
5072template<class _Tp>
5073inline _LIBCPP_INLINE_VISIBILITY
5074bool
5075operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5076{
5077 return !(nullptr < __x);
5078}
5079
5080template<class _Tp>
5081inline _LIBCPP_INLINE_VISIBILITY
5082bool
5083operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5084{
5085 return !(__x < nullptr);
5086}
5087
5088template<class _Tp>
5089inline _LIBCPP_INLINE_VISIBILITY
5090bool
5091operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
5092{
5093 return !(__x < nullptr);
5094}
5095
5096template<class _Tp>
5097inline _LIBCPP_INLINE_VISIBILITY
5098bool
5099operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
5100{
5101 return !(nullptr < __x);
Howard Hinnant3e519522010-05-11 19:42:165102}
5103
5104template<class _Tp>
5105inline _LIBCPP_INLINE_VISIBILITY
5106void
Howard Hinnant3739fe72011-05-28 14:41:135107swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165108{
5109 __x.swap(__y);
5110}
5111
5112template<class _Tp, class _Up>
5113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025114typename enable_if
5115<
5116 !is_array<_Tp>::value && !is_array<_Up>::value,
5117 shared_ptr<_Tp>
5118>::type
Howard Hinnant3739fe72011-05-28 14:41:135119static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165120{
5121 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
5122}
5123
5124template<class _Tp, class _Up>
5125inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025126typename enable_if
5127<
5128 !is_array<_Tp>::value && !is_array<_Up>::value,
5129 shared_ptr<_Tp>
5130>::type
Howard Hinnant3739fe72011-05-28 14:41:135131dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165132{
5133 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
5134 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
5135}
5136
5137template<class _Tp, class _Up>
Howard Hinnant8e251042012-01-02 17:56:025138typename enable_if
5139<
5140 is_array<_Tp>::value == is_array<_Up>::value,
5141 shared_ptr<_Tp>
5142>::type
Howard Hinnant3739fe72011-05-28 14:41:135143const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165144{
Howard Hinnant8e251042012-01-02 17:56:025145 typedef typename remove_extent<_Tp>::type _RTp;
5146 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
Howard Hinnant3e519522010-05-11 19:42:165147}
5148
Howard Hinnant54b409f2010-08-11 17:04:315149#ifndef _LIBCPP_NO_RTTI
5150
Howard Hinnant3e519522010-05-11 19:42:165151template<class _Dp, class _Tp>
5152inline _LIBCPP_INLINE_VISIBILITY
5153_Dp*
Howard Hinnant3739fe72011-05-28 14:41:135154get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165155{
5156 return __p.template __get_deleter<_Dp>();
5157}
5158
Howard Hinnantb3371f62010-08-22 00:02:435159#endif // _LIBCPP_NO_RTTI
Howard Hinnant54b409f2010-08-11 17:04:315160
Howard Hinnant3e519522010-05-11 19:42:165161template<class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005162class _LIBCPP_TEMPLATE_VIS weak_ptr
Howard Hinnant3e519522010-05-11 19:42:165163{
Howard Hinnantb3371f62010-08-22 00:02:435164public:
5165 typedef _Tp element_type;
Howard Hinnant3e519522010-05-11 19:42:165166private:
5167 element_type* __ptr_;
5168 __shared_weak_count* __cntrl_;
5169
Howard Hinnantb3371f62010-08-22 00:02:435170public:
Evgeniy Stepanov906c8722015-11-07 01:22:135171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc0937e82012-07-07 20:56:045172 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:135173 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant3739fe72011-05-28 14:41:135174 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5175 _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:135176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135177 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:135178 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant3739fe72011-05-28 14:41:135179 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5180 _NOEXCEPT;
Howard Hinnantb3371f62010-08-22 00:02:435181
Howard Hinnant8e251042012-01-02 17:56:025182#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov906c8722015-11-07 01:22:135183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025184 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:135185 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
Howard Hinnant8e251042012-01-02 17:56:025186 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5187 _NOEXCEPT;
5188#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantb3371f62010-08-22 00:02:435189 ~weak_ptr();
5190
Evgeniy Stepanov906c8722015-11-07 01:22:135191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135192 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
Howard Hinnant8e251042012-01-02 17:56:025193 template<class _Yp>
5194 typename enable_if
5195 <
5196 is_convertible<_Yp*, element_type*>::value,
5197 weak_ptr&
5198 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:135199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025200 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5201
5202#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5203
Evgeniy Stepanov906c8722015-11-07 01:22:135204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025205 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5206 template<class _Yp>
5207 typename enable_if
5208 <
5209 is_convertible<_Yp*, element_type*>::value,
5210 weak_ptr&
5211 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:135212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025213 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5214
5215#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5216
5217 template<class _Yp>
5218 typename enable_if
5219 <
5220 is_convertible<_Yp*, element_type*>::value,
5221 weak_ptr&
5222 >::type
Evgeniy Stepanov906c8722015-11-07 01:22:135223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8e251042012-01-02 17:56:025224 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
Howard Hinnantb3371f62010-08-22 00:02:435225
Evgeniy Stepanov906c8722015-11-07 01:22:135226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135227 void swap(weak_ptr& __r) _NOEXCEPT;
Evgeniy Stepanov906c8722015-11-07 01:22:135228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135229 void reset() _NOEXCEPT;
Howard Hinnantb3371f62010-08-22 00:02:435230
Howard Hinnant848a5372010-09-22 16:48:345231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135232 long use_count() const _NOEXCEPT
5233 {return __cntrl_ ? __cntrl_->use_count() : 0;}
Howard Hinnant848a5372010-09-22 16:48:345234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135235 bool expired() const _NOEXCEPT
5236 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5237 shared_ptr<_Tp> lock() const _NOEXCEPT;
Howard Hinnant848a5372010-09-22 16:48:345238 template<class _Up>
5239 _LIBCPP_INLINE_VISIBILITY
5240 bool owner_before(const shared_ptr<_Up>& __r) const
Howard Hinnant3e519522010-05-11 19:42:165241 {return __cntrl_ < __r.__cntrl_;}
Howard Hinnant848a5372010-09-22 16:48:345242 template<class _Up>
5243 _LIBCPP_INLINE_VISIBILITY
5244 bool owner_before(const weak_ptr<_Up>& __r) const
Howard Hinnant3e519522010-05-11 19:42:165245 {return __cntrl_ < __r.__cntrl_;}
5246
Eric Fiseliere2f2d1ed2017-01-04 23:56:005247 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5248 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
Howard Hinnant3e519522010-05-11 19:42:165249};
5250
5251template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135252inline
Howard Hinnantc0937e82012-07-07 20:56:045253_LIBCPP_CONSTEXPR
Howard Hinnant3739fe72011-05-28 14:41:135254weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165255 : __ptr_(0),
5256 __cntrl_(0)
5257{
5258}
5259
5260template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135261inline
Howard Hinnant3739fe72011-05-28 14:41:135262weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165263 : __ptr_(__r.__ptr_),
5264 __cntrl_(__r.__cntrl_)
5265{
5266 if (__cntrl_)
5267 __cntrl_->__add_weak();
5268}
5269
5270template<class _Tp>
5271template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135272inline
Howard Hinnant3e519522010-05-11 19:42:165273weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
Howard Hinnant5eb6bdf2011-05-22 00:09:025274 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant3739fe72011-05-28 14:41:135275 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165276 : __ptr_(__r.__ptr_),
5277 __cntrl_(__r.__cntrl_)
5278{
5279 if (__cntrl_)
5280 __cntrl_->__add_weak();
5281}
5282
5283template<class _Tp>
5284template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135285inline
Howard Hinnant3e519522010-05-11 19:42:165286weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
Howard Hinnant5eb6bdf2011-05-22 00:09:025287 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
Howard Hinnant3739fe72011-05-28 14:41:135288 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165289 : __ptr_(__r.__ptr_),
5290 __cntrl_(__r.__cntrl_)
5291{
5292 if (__cntrl_)
5293 __cntrl_->__add_weak();
5294}
5295
Howard Hinnant8e251042012-01-02 17:56:025296#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5297
5298template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135299inline
Howard Hinnant8e251042012-01-02 17:56:025300weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5301 : __ptr_(__r.__ptr_),
5302 __cntrl_(__r.__cntrl_)
5303{
5304 __r.__ptr_ = 0;
5305 __r.__cntrl_ = 0;
5306}
5307
5308template<class _Tp>
5309template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135310inline
Howard Hinnant8e251042012-01-02 17:56:025311weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5312 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5313 _NOEXCEPT
5314 : __ptr_(__r.__ptr_),
5315 __cntrl_(__r.__cntrl_)
5316{
5317 __r.__ptr_ = 0;
5318 __r.__cntrl_ = 0;
5319}
5320
5321#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5322
Howard Hinnant3e519522010-05-11 19:42:165323template<class _Tp>
5324weak_ptr<_Tp>::~weak_ptr()
5325{
5326 if (__cntrl_)
5327 __cntrl_->__release_weak();
5328}
5329
5330template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135331inline
Howard Hinnant3e519522010-05-11 19:42:165332weak_ptr<_Tp>&
Howard Hinnant3739fe72011-05-28 14:41:135333weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165334{
5335 weak_ptr(__r).swap(*this);
5336 return *this;
5337}
5338
5339template<class _Tp>
Howard Hinnantb3371f62010-08-22 00:02:435340template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135341inline
Howard Hinnant8e251042012-01-02 17:56:025342typename enable_if
5343<
5344 is_convertible<_Yp*, _Tp*>::value,
5345 weak_ptr<_Tp>&
5346>::type
Howard Hinnant3739fe72011-05-28 14:41:135347weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165348{
5349 weak_ptr(__r).swap(*this);
5350 return *this;
5351}
5352
Howard Hinnant8e251042012-01-02 17:56:025353#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5354
5355template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135356inline
Howard Hinnant8e251042012-01-02 17:56:025357weak_ptr<_Tp>&
5358weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5359{
5360 weak_ptr(_VSTD::move(__r)).swap(*this);
5361 return *this;
5362}
5363
Howard Hinnant3e519522010-05-11 19:42:165364template<class _Tp>
Howard Hinnantb3371f62010-08-22 00:02:435365template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135366inline
Howard Hinnant8e251042012-01-02 17:56:025367typename enable_if
5368<
5369 is_convertible<_Yp*, _Tp*>::value,
5370 weak_ptr<_Tp>&
5371>::type
5372weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5373{
5374 weak_ptr(_VSTD::move(__r)).swap(*this);
5375 return *this;
5376}
5377
5378#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5379
5380template<class _Tp>
5381template<class _Yp>
Evgeniy Stepanov906c8722015-11-07 01:22:135382inline
Howard Hinnant8e251042012-01-02 17:56:025383typename enable_if
5384<
5385 is_convertible<_Yp*, _Tp*>::value,
5386 weak_ptr<_Tp>&
5387>::type
Howard Hinnant3739fe72011-05-28 14:41:135388weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165389{
5390 weak_ptr(__r).swap(*this);
5391 return *this;
5392}
5393
5394template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135395inline
Howard Hinnant3e519522010-05-11 19:42:165396void
Howard Hinnant3739fe72011-05-28 14:41:135397weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165398{
Howard Hinnantce48a112011-06-30 21:18:195399 _VSTD::swap(__ptr_, __r.__ptr_);
5400 _VSTD::swap(__cntrl_, __r.__cntrl_);
Howard Hinnant3e519522010-05-11 19:42:165401}
5402
5403template<class _Tp>
5404inline _LIBCPP_INLINE_VISIBILITY
5405void
Howard Hinnant3739fe72011-05-28 14:41:135406swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165407{
5408 __x.swap(__y);
5409}
5410
5411template<class _Tp>
Evgeniy Stepanov906c8722015-11-07 01:22:135412inline
Howard Hinnant3e519522010-05-11 19:42:165413void
Howard Hinnant3739fe72011-05-28 14:41:135414weak_ptr<_Tp>::reset() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165415{
5416 weak_ptr().swap(*this);
5417}
5418
5419template<class _Tp>
5420template<class _Yp>
5421shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
Marshall Clowdc83e772017-01-10 16:59:335422 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
Howard Hinnant3e519522010-05-11 19:42:165423 : __ptr_(__r.__ptr_),
5424 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5425{
5426 if (__cntrl_ == 0)
Marshall Clowd437fa52016-08-25 15:09:015427 __throw_bad_weak_ptr();
Howard Hinnant3e519522010-05-11 19:42:165428}
5429
5430template<class _Tp>
5431shared_ptr<_Tp>
Howard Hinnant3739fe72011-05-28 14:41:135432weak_ptr<_Tp>::lock() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:165433{
5434 shared_ptr<_Tp> __r;
5435 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5436 if (__r.__cntrl_)
5437 __r.__ptr_ = __ptr_;
5438 return __r;
5439}
5440
Marshall Clow183c0102015-11-12 15:56:445441#if _LIBCPP_STD_VER > 14
5442template <class _Tp = void> struct owner_less;
5443#else
Howard Hinnantb3371f62010-08-22 00:02:435444template <class _Tp> struct owner_less;
Marshall Clow183c0102015-11-12 15:56:445445#endif
Howard Hinnant3e519522010-05-11 19:42:165446
5447template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005448struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
Howard Hinnant3e519522010-05-11 19:42:165449 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
Howard Hinnantb3371f62010-08-22 00:02:435450{
5451 typedef bool result_type;
Howard Hinnant848a5372010-09-22 16:48:345452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165453 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5454 {return __x.owner_before(__y);}
Howard Hinnant848a5372010-09-22 16:48:345455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165456 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5457 {return __x.owner_before(__y);}
Howard Hinnant848a5372010-09-22 16:48:345458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165459 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5460 {return __x.owner_before(__y);}
Howard Hinnantb3371f62010-08-22 00:02:435461};
Howard Hinnant3e519522010-05-11 19:42:165462
5463template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005464struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
Howard Hinnant3e519522010-05-11 19:42:165465 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5466{
Howard Hinnantb3371f62010-08-22 00:02:435467 typedef bool result_type;
Howard Hinnant848a5372010-09-22 16:48:345468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165469 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5470 {return __x.owner_before(__y);}
Howard Hinnant848a5372010-09-22 16:48:345471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165472 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
5473 {return __x.owner_before(__y);}
Howard Hinnant848a5372010-09-22 16:48:345474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165475 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
5476 {return __x.owner_before(__y);}
5477};
5478
Marshall Clow183c0102015-11-12 15:56:445479#if _LIBCPP_STD_VER > 14
5480template <>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005481struct _LIBCPP_TEMPLATE_VIS owner_less<void>
Marshall Clow183c0102015-11-12 15:56:445482{
5483 template <class _Tp, class _Up>
5484 _LIBCPP_INLINE_VISIBILITY
5485 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5486 {return __x.owner_before(__y);}
5487 template <class _Tp, class _Up>
5488 _LIBCPP_INLINE_VISIBILITY
5489 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5490 {return __x.owner_before(__y);}
5491 template <class _Tp, class _Up>
5492 _LIBCPP_INLINE_VISIBILITY
5493 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
5494 {return __x.owner_before(__y);}
5495 template <class _Tp, class _Up>
5496 _LIBCPP_INLINE_VISIBILITY
5497 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
5498 {return __x.owner_before(__y);}
5499 typedef void is_transparent;
5500};
5501#endif
5502
Howard Hinnant3e519522010-05-11 19:42:165503template<class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005504class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
Howard Hinnant3e519522010-05-11 19:42:165505{
5506 mutable weak_ptr<_Tp> __weak_this_;
Howard Hinnantb3371f62010-08-22 00:02:435507protected:
Howard Hinnantc0937e82012-07-07 20:56:045508 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Howard Hinnant3739fe72011-05-28 14:41:135509 enable_shared_from_this() _NOEXCEPT {}
Howard Hinnant848a5372010-09-22 16:48:345510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135511 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
Howard Hinnant848a5372010-09-22 16:48:345512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135513 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5514 {return *this;}
Howard Hinnant848a5372010-09-22 16:48:345515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165516 ~enable_shared_from_this() {}
Howard Hinnantb3371f62010-08-22 00:02:435517public:
Howard Hinnant848a5372010-09-22 16:48:345518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135519 shared_ptr<_Tp> shared_from_this()
5520 {return shared_ptr<_Tp>(__weak_this_);}
Howard Hinnant848a5372010-09-22 16:48:345521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135522 shared_ptr<_Tp const> shared_from_this() const
5523 {return shared_ptr<const _Tp>(__weak_this_);}
Howard Hinnant3e519522010-05-11 19:42:165524
Eric Fiselier88f5bfd2016-06-02 00:15:355525#if _LIBCPP_STD_VER > 14
5526 _LIBCPP_INLINE_VISIBILITY
5527 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5528 { return __weak_this_; }
5529
5530 _LIBCPP_INLINE_VISIBILITY
5531 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5532 { return __weak_this_; }
5533#endif // _LIBCPP_STD_VER > 14
5534
Howard Hinnant3e519522010-05-11 19:42:165535 template <class _Up> friend class shared_ptr;
5536};
5537
Howard Hinnantd1803b62010-06-03 16:42:575538template <class _Tp>
Eric Fiseliere2f2d1ed2017-01-04 23:56:005539struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
Howard Hinnantd1803b62010-06-03 16:42:575540{
5541 typedef shared_ptr<_Tp> argument_type;
5542 typedef size_t result_type;
Howard Hinnant848a5372010-09-22 16:48:345543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3739fe72011-05-28 14:41:135544 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
Howard Hinnantd1803b62010-06-03 16:42:575545 {
5546 return hash<_Tp*>()(__ptr.get());
5547 }
5548};
5549
Howard Hinnantc003db12011-11-29 18:15:505550template<class _CharT, class _Traits, class _Yp>
Howard Hinnante3163f52011-07-18 15:51:595551inline _LIBCPP_INLINE_VISIBILITY
5552basic_ostream<_CharT, _Traits>&
Howard Hinnantc003db12011-11-29 18:15:505553operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
Howard Hinnante3163f52011-07-18 15:51:595554
Eric Fiselierdf93bad2016-06-18 02:12:535555
5556#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnantd77851e2012-07-30 01:40:575557
Howard Hinnantf0544c22013-08-12 18:38:345558class _LIBCPP_TYPE_VIS __sp_mut
Howard Hinnantd77851e2012-07-30 01:40:575559{
Howard Hinnant54d333a2012-10-30 19:06:595560 void* __lx;
Howard Hinnantd77851e2012-07-30 01:40:575561public:
5562 void lock() _NOEXCEPT;
5563 void unlock() _NOEXCEPT;
5564
5565private:
5566 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5567 __sp_mut(const __sp_mut&);
5568 __sp_mut& operator=(const __sp_mut&);
5569
Howard Hinnant6e412562013-03-06 23:30:195570 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnantd77851e2012-07-30 01:40:575571};
5572
Howard Hinnant6e412562013-03-06 23:30:195573_LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
Howard Hinnantd77851e2012-07-30 01:40:575574
5575template <class _Tp>
5576inline _LIBCPP_INLINE_VISIBILITY
5577bool
5578atomic_is_lock_free(const shared_ptr<_Tp>*)
5579{
5580 return false;
5581}
5582
5583template <class _Tp>
5584shared_ptr<_Tp>
5585atomic_load(const shared_ptr<_Tp>* __p)
5586{
5587 __sp_mut& __m = __get_sp_mut(__p);
5588 __m.lock();
5589 shared_ptr<_Tp> __q = *__p;
5590 __m.unlock();
5591 return __q;
5592}
5593
5594template <class _Tp>
5595inline _LIBCPP_INLINE_VISIBILITY
5596shared_ptr<_Tp>
5597atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5598{
5599 return atomic_load(__p);
5600}
5601
5602template <class _Tp>
5603void
5604atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5605{
5606 __sp_mut& __m = __get_sp_mut(__p);
5607 __m.lock();
5608 __p->swap(__r);
5609 __m.unlock();
5610}
5611
5612template <class _Tp>
5613inline _LIBCPP_INLINE_VISIBILITY
5614void
5615atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5616{
5617 atomic_store(__p, __r);
5618}
5619
5620template <class _Tp>
5621shared_ptr<_Tp>
5622atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5623{
5624 __sp_mut& __m = __get_sp_mut(__p);
5625 __m.lock();
5626 __p->swap(__r);
5627 __m.unlock();
5628 return __r;
5629}
5630
5631template <class _Tp>
5632inline _LIBCPP_INLINE_VISIBILITY
5633shared_ptr<_Tp>
5634atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5635{
5636 return atomic_exchange(__p, __r);
5637}
5638
5639template <class _Tp>
5640bool
5641atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5642{
Marshall Clow3379bae2016-05-18 17:50:135643 shared_ptr<_Tp> __temp;
Howard Hinnantd77851e2012-07-30 01:40:575644 __sp_mut& __m = __get_sp_mut(__p);
5645 __m.lock();
5646 if (__p->__owner_equivalent(*__v))
5647 {
Marshall Clow3379bae2016-05-18 17:50:135648 _VSTD::swap(__temp, *__p);
Howard Hinnantd77851e2012-07-30 01:40:575649 *__p = __w;
5650 __m.unlock();
5651 return true;
5652 }
Marshall Clow3379bae2016-05-18 17:50:135653 _VSTD::swap(__temp, *__v);
Howard Hinnantd77851e2012-07-30 01:40:575654 *__v = *__p;
5655 __m.unlock();
5656 return false;
5657}
5658
5659template <class _Tp>
5660inline _LIBCPP_INLINE_VISIBILITY
5661bool
5662atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5663{
5664 return atomic_compare_exchange_strong(__p, __v, __w);
5665}
5666
5667template <class _Tp>
5668inline _LIBCPP_INLINE_VISIBILITY
5669bool
5670atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5671 shared_ptr<_Tp> __w, memory_order, memory_order)
5672{
5673 return atomic_compare_exchange_strong(__p, __v, __w);
5674}
5675
5676template <class _Tp>
5677inline _LIBCPP_INLINE_VISIBILITY
5678bool
5679atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5680 shared_ptr<_Tp> __w, memory_order, memory_order)
5681{
5682 return atomic_compare_exchange_weak(__p, __v, __w);
5683}
5684
Eric Fiselierdf93bad2016-06-18 02:12:535685#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
Howard Hinnantd77851e2012-07-30 01:40:575686
Howard Hinnantb3371f62010-08-22 00:02:435687//enum class
Eric Fiselier528600c2017-01-05 01:15:425688#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5689# ifndef _LIBCPP_CXX03_LANG
5690enum class pointer_safety : unsigned char {
5691 relaxed,
5692 preferred,
5693 strict
5694};
5695# endif
5696#else
Howard Hinnant6e412562013-03-06 23:30:195697struct _LIBCPP_TYPE_VIS pointer_safety
Howard Hinnant3e519522010-05-11 19:42:165698{
Howard Hinnant54d333a2012-10-30 19:06:595699 enum __lx
Howard Hinnant3e519522010-05-11 19:42:165700 {
5701 relaxed,
5702 preferred,
5703 strict
5704 };
5705
Howard Hinnant54d333a2012-10-30 19:06:595706 __lx __v_;
Howard Hinnant3e519522010-05-11 19:42:165707
Howard Hinnant848a5372010-09-22 16:48:345708 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier76a01ea2017-01-05 01:28:405709 pointer_safety() : __v_() {}
5710
5711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant54d333a2012-10-30 19:06:595712 pointer_safety(__lx __v) : __v_(__v) {}
Howard Hinnant848a5372010-09-22 16:48:345713 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:165714 operator int() const {return __v_;}
5715};
Eric Fiselier528600c2017-01-05 01:15:425716#endif
5717
5718#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5719 defined(_LIBCPP_BUILDING_MEMORY)
5720_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5721#else
5722// This function is only offered in C++03 under ABI v1.
5723# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5724inline _LIBCPP_INLINE_VISIBILITY
5725pointer_safety get_pointer_safety() _NOEXCEPT {
5726 return pointer_safety::relaxed;
5727}
5728# endif
5729#endif
5730
Howard Hinnant3e519522010-05-11 19:42:165731
Howard Hinnantf0544c22013-08-12 18:38:345732_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5733_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5734_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
Howard Hinnantf0544c22013-08-12 18:38:345735_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
Howard Hinnant3e519522010-05-11 19:42:165736
5737template <class _Tp>
5738inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb3371f62010-08-22 00:02:435739_Tp*
Howard Hinnant3e519522010-05-11 19:42:165740undeclare_reachable(_Tp* __p)
5741{
5742 return static_cast<_Tp*>(__undeclare_reachable(__p));
5743}
5744
Howard Hinnantf0544c22013-08-12 18:38:345745_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
Howard Hinnant3e519522010-05-11 19:42:165746
Marshall Clowe3fbe142015-07-13 20:04:565747// --- Helper for container swap --
5748template <typename _Alloc>
Eric Fiselier89dd1dd2016-04-21 22:54:215749inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe3fbe142015-07-13 20:04:565750void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5751#if _LIBCPP_STD_VER >= 14
5752 _NOEXCEPT
5753#else
5754 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5755#endif
5756{
5757 __swap_allocator(__a1, __a2,
5758 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5759}
5760
5761template <typename _Alloc>
5762_LIBCPP_INLINE_VISIBILITY
5763void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5764#if _LIBCPP_STD_VER >= 14
5765 _NOEXCEPT
5766#else
5767 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5768#endif
5769{
5770 using _VSTD::swap;
5771 swap(__a1, __a2);
5772}
5773
5774template <typename _Alloc>
Eric Fiselier89dd1dd2016-04-21 22:54:215775inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowe3fbe142015-07-13 20:04:565776void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5777
Marshall Clow29f11b32015-08-18 19:51:375778template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
Marshall Clow1378a5a2015-08-18 18:57:005779struct __noexcept_move_assign_container : public integral_constant<bool,
5780 _Traits::propagate_on_container_move_assignment::value
5781#if _LIBCPP_STD_VER > 14
5782 || _Traits::is_always_equal::value
5783#else
5784 && is_nothrow_move_assignable<_Alloc>::value
5785#endif
5786 > {};
Marshall Clowe3fbe142015-07-13 20:04:565787
Marshall Clowdc3eb832016-07-11 21:38:085788
5789#ifndef _LIBCPP_HAS_NO_VARIADICS
5790template <class _Tp, class _Alloc>
5791struct __temp_value {
5792 typedef allocator_traits<_Alloc> _Traits;
5793
5794 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5795 _Alloc &__a;
5796
5797 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5798 _Tp & get() { return *__addr(); }
5799
5800 template<class... _Args>
5801 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5802 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5803
5804 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5805 };
5806#endif
5807
Howard Hinnant3e519522010-05-11 19:42:165808_LIBCPP_END_NAMESPACE_STD
5809
5810#endif // _LIBCPP_MEMORY