2 //===-------------------------- memory ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_MEMORY
12 #define _LIBCPP_MEMORY
20 struct allocator_arg_t { };
21 inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
23 template <class T, class Alloc> struct uses_allocator;
29 typedef <details> element_type;
30 typedef <details> difference_type;
32 template <class U> using rebind = <details>;
34 static pointer pointer_to(<details>);
38 struct pointer_traits<T*>
41 typedef T element_type;
42 typedef ptrdiff_t difference_type;
44 template <class U> using rebind = U*;
46 static pointer pointer_to(<details>) noexcept;
49 template <class T> constexpr T* to_address(T* p) noexcept; // C++20
50 template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
52 template <class Alloc>
53 struct allocator_traits
55 typedef Alloc allocator_type;
56 typedef typename allocator_type::value_type
59 typedef Alloc::pointer | value_type* pointer;
60 typedef Alloc::const_pointer
61 | pointer_traits<pointer>::rebind<const value_type>
63 typedef Alloc::void_pointer
64 | pointer_traits<pointer>::rebind<void>
66 typedef Alloc::const_void_pointer
67 | pointer_traits<pointer>::rebind<const void>
69 typedef Alloc::difference_type
70 | pointer_traits<pointer>::difference_type
72 typedef Alloc::size_type
73 | make_unsigned<difference_type>::type
75 typedef Alloc::propagate_on_container_copy_assignment
76 | false_type propagate_on_container_copy_assignment;
77 typedef Alloc::propagate_on_container_move_assignment
78 | false_type propagate_on_container_move_assignment;
79 typedef Alloc::propagate_on_container_swap
80 | false_type propagate_on_container_swap;
81 typedef Alloc::is_always_equal
82 | is_empty is_always_equal;
84 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
85 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
87 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
88 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
90 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
92 template <class T, class... Args>
93 static void construct(allocator_type& a, T* p, Args&&... args);
96 static void destroy(allocator_type& a, T* p);
98 static size_type max_size(const allocator_type& a); // noexcept in C++14
100 static allocator_type
101 select_on_container_copy_construction(const allocator_type& a);
105 class allocator<void>
108 typedef void* pointer;
109 typedef const void* const_pointer;
110 typedef void value_type;
112 template <class _Up> struct rebind {typedef allocator<_Up> other;};
119 typedef size_t size_type;
120 typedef ptrdiff_t difference_type;
122 typedef const T* const_pointer;
123 typedef typename add_lvalue_reference<T>::type reference;
124 typedef typename add_lvalue_reference<const T>::type const_reference;
125 typedef T value_type;
127 template <class U> struct rebind {typedef allocator<U> other;};
129 constexpr allocator() noexcept; // constexpr in C++20
130 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
132 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
134 pointer address(reference x) const noexcept;
135 const_pointer address(const_reference x) const noexcept;
136 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
137 void deallocate(pointer p, size_type n) noexcept;
138 size_type max_size() const noexcept;
139 template<class U, class... Args>
140 void construct(U* p, Args&&... args);
145 template <class T, class U>
146 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
148 template <class T, class U>
149 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
151 template <class OutputIterator, class T>
152 class raw_storage_iterator
153 : public iterator<output_iterator_tag,
154 T, // purposefully not C++03
155 ptrdiff_t, // purposefully not C++03
156 T*, // purposefully not C++03
157 raw_storage_iterator&> // purposefully not C++03
160 explicit raw_storage_iterator(OutputIterator x);
161 raw_storage_iterator& operator*();
162 raw_storage_iterator& operator=(const T& element);
163 raw_storage_iterator& operator++();
164 raw_storage_iterator operator++(int);
167 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
168 template <class T> void return_temporary_buffer(T* p) noexcept;
170 template <class T> T* addressof(T& r) noexcept;
171 template <class T> T* addressof(const T&& r) noexcept = delete;
173 template <class InputIterator, class ForwardIterator>
175 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
177 template <class InputIterator, class Size, class ForwardIterator>
179 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
181 template <class ForwardIterator, class T>
182 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
184 template <class ForwardIterator, class Size, class T>
186 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
189 void destroy_at(T* location);
191 template <class ForwardIterator>
192 void destroy(ForwardIterator first, ForwardIterator last);
194 template <class ForwardIterator, class Size>
195 ForwardIterator destroy_n(ForwardIterator first, Size n);
197 template <class InputIterator, class ForwardIterator>
198 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
200 template <class InputIterator, class Size, class ForwardIterator>
201 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
203 template <class ForwardIterator>
204 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
206 template <class ForwardIterator, class Size>
207 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
209 template <class ForwardIterator>
210 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
212 template <class ForwardIterator, class Size>
213 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
215 template <class Y> struct auto_ptr_ref {}; // removed in C++17
218 class auto_ptr // removed in C++17
221 typedef X element_type;
223 explicit auto_ptr(X* p =0) throw();
224 auto_ptr(auto_ptr&) throw();
225 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
226 auto_ptr& operator=(auto_ptr&) throw();
227 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
228 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
231 typename add_lvalue_reference<X>::type operator*() const throw();
232 X* operator->() const throw();
233 X* get() const throw();
234 X* release() throw();
235 void reset(X* p =0) throw();
237 auto_ptr(auto_ptr_ref<X>) throw();
238 template<class Y> operator auto_ptr_ref<Y>() throw();
239 template<class Y> operator auto_ptr<Y>() throw();
243 struct default_delete
245 constexpr default_delete() noexcept = default;
246 template <class U> default_delete(const default_delete<U>&) noexcept;
248 void operator()(T*) const noexcept;
252 struct default_delete<T[]>
254 constexpr default_delete() noexcept = default;
255 void operator()(T*) const noexcept;
256 template <class U> void operator()(U*) const = delete;
259 template <class T, class D = default_delete<T>>
263 typedef see below pointer;
264 typedef T element_type;
265 typedef D deleter_type;
268 constexpr unique_ptr() noexcept;
269 explicit unique_ptr(pointer p) noexcept;
270 unique_ptr(pointer p, see below d1) noexcept;
271 unique_ptr(pointer p, see below d2) noexcept;
272 unique_ptr(unique_ptr&& u) noexcept;
273 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
274 template <class U, class E>
275 unique_ptr(unique_ptr<U, E>&& u) noexcept;
277 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
283 unique_ptr& operator=(unique_ptr&& u) noexcept;
284 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
285 unique_ptr& operator=(nullptr_t) noexcept;
288 typename add_lvalue_reference<T>::type operator*() const;
289 pointer operator->() const noexcept;
290 pointer get() const noexcept;
291 deleter_type& get_deleter() noexcept;
292 const deleter_type& get_deleter() const noexcept;
293 explicit operator bool() const noexcept;
296 pointer release() noexcept;
297 void reset(pointer p = pointer()) noexcept;
298 void swap(unique_ptr& u) noexcept;
301 template <class T, class D>
302 class unique_ptr<T[], D>
305 typedef implementation-defined pointer;
306 typedef T element_type;
307 typedef D deleter_type;
310 constexpr unique_ptr() noexcept;
311 explicit unique_ptr(pointer p) noexcept;
312 unique_ptr(pointer p, see below d) noexcept;
313 unique_ptr(pointer p, see below d) noexcept;
314 unique_ptr(unique_ptr&& u) noexcept;
315 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
321 unique_ptr& operator=(unique_ptr&& u) noexcept;
322 unique_ptr& operator=(nullptr_t) noexcept;
325 T& operator[](size_t i) const;
326 pointer get() const noexcept;
327 deleter_type& get_deleter() noexcept;
328 const deleter_type& get_deleter() const noexcept;
329 explicit operator bool() const noexcept;
332 pointer release() noexcept;
333 void reset(pointer p = pointer()) noexcept;
334 void reset(nullptr_t) noexcept;
335 template <class U> void reset(U) = delete;
336 void swap(unique_ptr& u) noexcept;
339 template <class T, class D>
340 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
342 template <class T1, class D1, class T2, class D2>
343 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
344 template <class T1, class D1, class T2, class D2>
345 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
346 template <class T1, class D1, class T2, class D2>
347 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
348 template <class T1, class D1, class T2, class D2>
349 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
350 template <class T1, class D1, class T2, class D2>
351 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
352 template <class T1, class D1, class T2, class D2>
353 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
355 template <class T, class D>
356 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
357 template <class T, class D>
358 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
359 template <class T, class D>
360 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
361 template <class T, class D>
362 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
364 template <class T, class D>
365 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
366 template <class T, class D>
367 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
368 template <class T, class D>
369 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
370 template <class T, class D>
371 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
372 template <class T, class D>
373 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
374 template <class T, class D>
375 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
376 template <class T, class D>
377 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
378 template <class T, class D>
379 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
382 : public std::exception
384 bad_weak_ptr() noexcept;
387 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
388 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
389 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
391 template<class E, class T, class Y, class D>
392 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
398 typedef T element_type;
399 typedef weak_ptr<T> weak_type; // C++17
402 constexpr shared_ptr() noexcept;
403 template<class Y> explicit shared_ptr(Y* p);
404 template<class Y, class D> shared_ptr(Y* p, D d);
405 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
406 template <class D> shared_ptr(nullptr_t p, D d);
407 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
408 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
409 shared_ptr(const shared_ptr& r) noexcept;
410 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
411 shared_ptr(shared_ptr&& r) noexcept;
412 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
413 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
414 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
415 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
416 shared_ptr(nullptr_t) : shared_ptr() { }
422 shared_ptr& operator=(const shared_ptr& r) noexcept;
423 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
424 shared_ptr& operator=(shared_ptr&& r) noexcept;
425 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
426 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
427 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
430 void swap(shared_ptr& r) noexcept;
431 void reset() noexcept;
432 template<class Y> void reset(Y* p);
433 template<class Y, class D> void reset(Y* p, D d);
434 template<class Y, class D, class A> void reset(Y* p, D d, A a);
437 T* get() const noexcept;
438 T& operator*() const noexcept;
439 T* operator->() const noexcept;
440 long use_count() const noexcept;
441 bool unique() const noexcept;
442 explicit operator bool() const noexcept;
443 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
444 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
447 // shared_ptr comparisons:
448 template<class T, class U>
449 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
450 template<class T, class U>
451 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
452 template<class T, class U>
453 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
454 template<class T, class U>
455 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
456 template<class T, class U>
457 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
458 template<class T, class U>
459 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
462 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
464 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
466 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
468 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
470 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
472 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
474 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
476 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
478 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
480 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
482 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
484 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
486 // shared_ptr specialized algorithms:
487 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
490 template<class T, class U>
491 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
492 template<class T, class U>
493 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
494 template<class T, class U>
495 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
498 template<class E, class T, class Y>
499 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
501 // shared_ptr get_deleter:
502 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
504 template<class T, class... Args>
505 shared_ptr<T> make_shared(Args&&... args);
506 template<class T, class A, class... Args>
507 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
513 typedef T element_type;
516 constexpr weak_ptr() noexcept;
517 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
518 weak_ptr(weak_ptr const& r) noexcept;
519 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
520 weak_ptr(weak_ptr&& r) noexcept; // C++14
521 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
527 weak_ptr& operator=(weak_ptr const& r) noexcept;
528 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
529 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
530 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
531 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
534 void swap(weak_ptr& r) noexcept;
535 void reset() noexcept;
538 long use_count() const noexcept;
539 bool expired() const noexcept;
540 shared_ptr<T> lock() const noexcept;
541 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
542 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
545 // weak_ptr specialized algorithms:
546 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
549 template<class T> struct owner_less;
552 struct owner_less<shared_ptr<T>>
553 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
555 typedef bool result_type;
556 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
557 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
558 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
562 struct owner_less<weak_ptr<T>>
563 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
565 typedef bool result_type;
566 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
568 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
571 template <> // Added in C++14
572 struct owner_less<void>
574 template <class _Tp, class _Up>
575 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
576 template <class _Tp, class _Up>
577 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
578 template <class _Tp, class _Up>
579 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
580 template <class _Tp, class _Up>
581 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
583 typedef void is_transparent;
587 class enable_shared_from_this
590 constexpr enable_shared_from_this() noexcept;
591 enable_shared_from_this(enable_shared_from_this const&) noexcept;
592 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
593 ~enable_shared_from_this();
595 shared_ptr<T> shared_from_this();
596 shared_ptr<T const> shared_from_this() const;
600 bool atomic_is_lock_free(const shared_ptr<T>* p);
602 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
604 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
606 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
608 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
610 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
613 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
616 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
619 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
622 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
623 shared_ptr<T> w, memory_order success,
624 memory_order failure);
627 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
628 shared_ptr<T> w, memory_order success,
629 memory_order failure);
631 template <class T> struct hash;
632 template <class T, class D> struct hash<unique_ptr<T, D> >;
633 template <class T> struct hash<shared_ptr<T> >;
635 template <class T, class Alloc>
636 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
639 enum class pointer_safety { relaxed, preferred, strict };
640 void declare_reachable(void *p);
641 template <class T> T *undeclare_reachable(T *p);
642 void declare_no_pointers(char *p, size_t n);
643 void undeclare_no_pointers(char *p, size_t n);
644 pointer_safety get_pointer_safety() noexcept;
646 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
653 #include <type_traits>
661 #include <__functional_base>
667 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
671 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
672 #pragma GCC system_header
676 #include <__undef_macros>
679 _LIBCPP_BEGIN_NAMESPACE_STD
681 template <class _ValueType>
682 inline _LIBCPP_INLINE_VISIBILITY
683 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
684 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
685 defined(__ATOMIC_RELAXED) && \
686 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
687 return __atomic_load_n(__value, __ATOMIC_RELAXED);
693 template <class _ValueType>
694 inline _LIBCPP_INLINE_VISIBILITY
695 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
696 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
697 defined(__ATOMIC_ACQUIRE) && \
698 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
699 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
705 // addressof moved to <type_traits>
707 template <class _Tp> class allocator;
710 class _LIBCPP_TEMPLATE_VIS allocator<void>
713 typedef void* pointer;
714 typedef const void* const_pointer;
715 typedef void value_type;
717 template <class _Up> struct rebind {typedef allocator<_Up> other;};
721 class _LIBCPP_TEMPLATE_VIS allocator<const void>
724 typedef const void* pointer;
725 typedef const void* const_pointer;
726 typedef const void value_type;
728 template <class _Up> struct rebind {typedef allocator<_Up> other;};
733 template <class _Tp, class = void>
734 struct __has_element_type : false_type {};
737 struct __has_element_type<_Tp,
738 typename __void_t<typename _Tp::element_type>::type> : true_type {};
740 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
741 struct __pointer_traits_element_type;
743 template <class _Ptr>
744 struct __pointer_traits_element_type<_Ptr, true>
746 typedef typename _Ptr::element_type type;
749 #ifndef _LIBCPP_HAS_NO_VARIADICS
751 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
752 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
754 typedef typename _Sp<_Tp, _Args...>::element_type type;
757 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
758 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
763 #else // _LIBCPP_HAS_NO_VARIADICS
765 template <template <class> class _Sp, class _Tp>
766 struct __pointer_traits_element_type<_Sp<_Tp>, true>
768 typedef typename _Sp<_Tp>::element_type type;
771 template <template <class> class _Sp, class _Tp>
772 struct __pointer_traits_element_type<_Sp<_Tp>, false>
777 template <template <class, class> class _Sp, class _Tp, class _A0>
778 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
780 typedef typename _Sp<_Tp, _A0>::element_type type;
783 template <template <class, class> class _Sp, class _Tp, class _A0>
784 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
789 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
790 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
792 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
795 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
796 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
801 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
802 class _A1, class _A2>
803 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
805 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
808 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
809 class _A1, class _A2>
810 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
815 #endif // _LIBCPP_HAS_NO_VARIADICS
817 template <class _Tp, class = void>
818 struct __has_difference_type : false_type {};
821 struct __has_difference_type<_Tp,
822 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
824 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
825 struct __pointer_traits_difference_type
827 typedef ptrdiff_t type;
830 template <class _Ptr>
831 struct __pointer_traits_difference_type<_Ptr, true>
833 typedef typename _Ptr::difference_type type;
836 template <class _Tp, class _Up>
840 struct __two {char __lx; char __lxx;};
841 template <class _Xp> static __two __test(...);
842 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
844 static const bool value = sizeof(__test<_Tp>(0)) == 1;
847 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
848 struct __pointer_traits_rebind
850 #ifndef _LIBCPP_CXX03_LANG
851 typedef typename _Tp::template rebind<_Up> type;
853 typedef typename _Tp::template rebind<_Up>::other type;
857 #ifndef _LIBCPP_HAS_NO_VARIADICS
859 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
860 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
862 #ifndef _LIBCPP_CXX03_LANG
863 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
865 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
869 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
870 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
872 typedef _Sp<_Up, _Args...> type;
875 #else // _LIBCPP_HAS_NO_VARIADICS
877 template <template <class> class _Sp, class _Tp, class _Up>
878 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
880 #ifndef _LIBCPP_CXX03_LANG
881 typedef typename _Sp<_Tp>::template rebind<_Up> type;
883 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
887 template <template <class> class _Sp, class _Tp, class _Up>
888 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
890 typedef _Sp<_Up> type;
893 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
894 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
896 #ifndef _LIBCPP_CXX03_LANG
897 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
899 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
903 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
904 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
906 typedef _Sp<_Up, _A0> type;
909 template <template <class, class, class> class _Sp, class _Tp, class _A0,
910 class _A1, class _Up>
911 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
913 #ifndef _LIBCPP_CXX03_LANG
914 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
916 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
920 template <template <class, class, class> class _Sp, class _Tp, class _A0,
921 class _A1, class _Up>
922 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
924 typedef _Sp<_Up, _A0, _A1> type;
927 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
928 class _A1, class _A2, class _Up>
929 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
931 #ifndef _LIBCPP_CXX03_LANG
932 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
934 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
938 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
939 class _A1, class _A2, class _Up>
940 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
942 typedef _Sp<_Up, _A0, _A1, _A2> type;
945 #endif // _LIBCPP_HAS_NO_VARIADICS
947 template <class _Ptr>
948 struct _LIBCPP_TEMPLATE_VIS pointer_traits
950 typedef _Ptr pointer;
951 typedef typename __pointer_traits_element_type<pointer>::type element_type;
952 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
954 #ifndef _LIBCPP_CXX03_LANG
955 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
957 template <class _Up> struct rebind
958 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
959 #endif // _LIBCPP_CXX03_LANG
964 _LIBCPP_INLINE_VISIBILITY
965 static pointer pointer_to(typename conditional<is_void<element_type>::value,
966 __nat, element_type>::type& __r)
967 {return pointer::pointer_to(__r);}
971 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
973 typedef _Tp* pointer;
974 typedef _Tp element_type;
975 typedef ptrdiff_t difference_type;
977 #ifndef _LIBCPP_CXX03_LANG
978 template <class _Up> using rebind = _Up*;
980 template <class _Up> struct rebind {typedef _Up* other;};
986 _LIBCPP_INLINE_VISIBILITY
987 static pointer pointer_to(typename conditional<is_void<element_type>::value,
988 __nat, element_type>::type& __r) _NOEXCEPT
989 {return _VSTD::addressof(__r);}
992 template <class _From, class _To>
993 struct __rebind_pointer {
994 #ifndef _LIBCPP_CXX03_LANG
995 typedef typename pointer_traits<_From>::template rebind<_To> type;
997 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
1003 template <class _Tp, class = void>
1004 struct __has_pointer_type : false_type {};
1006 template <class _Tp>
1007 struct __has_pointer_type<_Tp,
1008 typename __void_t<typename _Tp::pointer>::type> : true_type {};
1010 namespace __pointer_type_imp
1013 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1014 struct __pointer_type
1016 typedef typename _Dp::pointer type;
1019 template <class _Tp, class _Dp>
1020 struct __pointer_type<_Tp, _Dp, false>
1025 } // __pointer_type_imp
1027 template <class _Tp, class _Dp>
1028 struct __pointer_type
1030 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1033 template <class _Tp, class = void>
1034 struct __has_const_pointer : false_type {};
1036 template <class _Tp>
1037 struct __has_const_pointer<_Tp,
1038 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1040 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1041 struct __const_pointer
1043 typedef typename _Alloc::const_pointer type;
1046 template <class _Tp, class _Ptr, class _Alloc>
1047 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1049 #ifndef _LIBCPP_CXX03_LANG
1050 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1052 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1056 template <class _Tp, class = void>
1057 struct __has_void_pointer : false_type {};
1059 template <class _Tp>
1060 struct __has_void_pointer<_Tp,
1061 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1063 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1064 struct __void_pointer
1066 typedef typename _Alloc::void_pointer type;
1069 template <class _Ptr, class _Alloc>
1070 struct __void_pointer<_Ptr, _Alloc, false>
1072 #ifndef _LIBCPP_CXX03_LANG
1073 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1075 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1079 template <class _Tp, class = void>
1080 struct __has_const_void_pointer : false_type {};
1082 template <class _Tp>
1083 struct __has_const_void_pointer<_Tp,
1084 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1086 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1087 struct __const_void_pointer
1089 typedef typename _Alloc::const_void_pointer type;
1092 template <class _Ptr, class _Alloc>
1093 struct __const_void_pointer<_Ptr, _Alloc, false>
1095 #ifndef _LIBCPP_CXX03_LANG
1096 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1098 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1102 template <class _Tp>
1103 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1105 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1110 #if _LIBCPP_STD_VER <= 17
1111 template <class _Pointer>
1112 inline _LIBCPP_INLINE_VISIBILITY
1113 typename pointer_traits<_Pointer>::element_type*
1114 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1116 return _VSTD::__to_raw_pointer(__p.operator->());
1119 template <class _Pointer>
1120 inline _LIBCPP_INLINE_VISIBILITY
1122 __to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1123 -> decltype(pointer_traits<_Pointer>::to_address(__p))
1125 return pointer_traits<_Pointer>::to_address(__p);
1128 template <class _Pointer, class... _None>
1129 inline _LIBCPP_INLINE_VISIBILITY
1131 __to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1133 return _VSTD::__to_raw_pointer(__p.operator->());
1136 template <class _Tp>
1137 inline _LIBCPP_INLINE_VISIBILITY constexpr
1139 to_address(_Tp* __p) _NOEXCEPT
1141 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1145 template <class _Pointer>
1146 inline _LIBCPP_INLINE_VISIBILITY
1148 to_address(const _Pointer& __p) _NOEXCEPT
1150 return _VSTD::__to_raw_pointer(__p);
1154 template <class _Tp, class = void>
1155 struct __has_size_type : false_type {};
1157 template <class _Tp>
1158 struct __has_size_type<_Tp,
1159 typename __void_t<typename _Tp::size_type>::type> : true_type {};
1161 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1164 typedef typename make_unsigned<_DiffType>::type type;
1167 template <class _Alloc, class _DiffType>
1168 struct __size_type<_Alloc, _DiffType, true>
1170 typedef typename _Alloc::size_type type;
1173 template <class _Tp, class = void>
1174 struct __has_propagate_on_container_copy_assignment : false_type {};
1176 template <class _Tp>
1177 struct __has_propagate_on_container_copy_assignment<_Tp,
1178 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1181 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1182 struct __propagate_on_container_copy_assignment
1184 typedef false_type type;
1187 template <class _Alloc>
1188 struct __propagate_on_container_copy_assignment<_Alloc, true>
1190 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1193 template <class _Tp, class = void>
1194 struct __has_propagate_on_container_move_assignment : false_type {};
1196 template <class _Tp>
1197 struct __has_propagate_on_container_move_assignment<_Tp,
1198 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1201 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1202 struct __propagate_on_container_move_assignment
1204 typedef false_type type;
1207 template <class _Alloc>
1208 struct __propagate_on_container_move_assignment<_Alloc, true>
1210 typedef typename _Alloc::propagate_on_container_move_assignment type;
1213 template <class _Tp, class = void>
1214 struct __has_propagate_on_container_swap : false_type {};
1216 template <class _Tp>
1217 struct __has_propagate_on_container_swap<_Tp,
1218 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1221 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1222 struct __propagate_on_container_swap
1224 typedef false_type type;
1227 template <class _Alloc>
1228 struct __propagate_on_container_swap<_Alloc, true>
1230 typedef typename _Alloc::propagate_on_container_swap type;
1233 template <class _Tp, class = void>
1234 struct __has_is_always_equal : false_type {};
1236 template <class _Tp>
1237 struct __has_is_always_equal<_Tp,
1238 typename __void_t<typename _Tp::is_always_equal>::type>
1241 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1242 struct __is_always_equal
1244 typedef typename _VSTD::is_empty<_Alloc>::type type;
1247 template <class _Alloc>
1248 struct __is_always_equal<_Alloc, true>
1250 typedef typename _Alloc::is_always_equal type;
1253 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1254 struct __has_rebind_other
1257 struct __two {char __lx; char __lxx;};
1258 template <class _Xp> static __two __test(...);
1259 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1261 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1264 template <class _Tp, class _Up>
1265 struct __has_rebind_other<_Tp, _Up, false>
1267 static const bool value = false;
1270 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1271 struct __allocator_traits_rebind
1273 typedef typename _Tp::template rebind<_Up>::other type;
1276 #ifndef _LIBCPP_HAS_NO_VARIADICS
1278 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1279 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1281 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1284 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1285 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1287 typedef _Alloc<_Up, _Args...> type;
1290 #else // _LIBCPP_HAS_NO_VARIADICS
1292 template <template <class> class _Alloc, class _Tp, class _Up>
1293 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1295 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1298 template <template <class> class _Alloc, class _Tp, class _Up>
1299 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1301 typedef _Alloc<_Up> type;
1304 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1305 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1307 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1310 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1311 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1313 typedef _Alloc<_Up, _A0> type;
1316 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1317 class _A1, class _Up>
1318 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1320 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1323 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1324 class _A1, class _Up>
1325 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1327 typedef _Alloc<_Up, _A0, _A1> type;
1330 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1331 class _A1, class _A2, class _Up>
1332 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1334 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1337 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1338 class _A1, class _A2, class _Up>
1339 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1341 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1344 #endif // _LIBCPP_HAS_NO_VARIADICS
1346 #ifndef _LIBCPP_CXX03_LANG
1348 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1351 -> decltype((void)__a.allocate(__sz, __p), true_type());
1353 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1355 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1358 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1359 struct __has_allocate_hint
1360 : integral_constant<bool,
1362 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1363 declval<_SizeType>(),
1364 declval<_ConstVoidPtr>())),
1369 #else // _LIBCPP_CXX03_LANG
1371 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1372 struct __has_allocate_hint
1377 #endif // _LIBCPP_CXX03_LANG
1379 #if !defined(_LIBCPP_CXX03_LANG)
1381 template <class _Alloc, class _Tp, class ..._Args>
1382 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1383 _VSTD::declval<_Args>()...),
1385 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1387 template <class _Alloc, class _Pointer, class ..._Args>
1389 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1391 template <class _Alloc, class _Pointer, class ..._Args>
1392 struct __has_construct
1393 : integral_constant<bool,
1395 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1396 declval<_Pointer>(),
1397 declval<_Args>()...)),
1402 template <class _Alloc, class _Pointer>
1404 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1405 -> decltype(__a.destroy(__p), true_type());
1407 template <class _Alloc, class _Pointer>
1409 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1412 template <class _Alloc, class _Pointer>
1413 struct __has_destroy
1414 : integral_constant<bool,
1416 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1417 declval<_Pointer>())),
1422 template <class _Alloc>
1424 __has_max_size_test(_Alloc&& __a)
1425 -> decltype(__a.max_size(), true_type());
1427 template <class _Alloc>
1429 __has_max_size_test(const volatile _Alloc& __a)
1432 template <class _Alloc>
1433 struct __has_max_size
1434 : integral_constant<bool,
1436 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1441 template <class _Alloc>
1443 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1444 -> decltype(__a.select_on_container_copy_construction(), true_type());
1446 template <class _Alloc>
1448 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1451 template <class _Alloc>
1452 struct __has_select_on_container_copy_construction
1453 : integral_constant<bool,
1455 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1460 #else // _LIBCPP_CXX03_LANG
1462 #ifndef _LIBCPP_HAS_NO_VARIADICS
1464 template <class _Alloc, class _Pointer, class ..._Args>
1465 struct __has_construct
1470 #else // _LIBCPP_HAS_NO_VARIADICS
1472 template <class _Alloc, class _Pointer, class _Args>
1473 struct __has_construct
1478 #endif // _LIBCPP_HAS_NO_VARIADICS
1480 template <class _Alloc, class _Pointer>
1481 struct __has_destroy
1486 template <class _Alloc>
1487 struct __has_max_size
1492 template <class _Alloc>
1493 struct __has_select_on_container_copy_construction
1498 #endif // _LIBCPP_CXX03_LANG
1500 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1501 struct __alloc_traits_difference_type
1503 typedef typename pointer_traits<_Ptr>::difference_type type;
1506 template <class _Alloc, class _Ptr>
1507 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1509 typedef typename _Alloc::difference_type type;
1512 template <class _Alloc>
1513 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1515 typedef _Alloc allocator_type;
1516 typedef typename allocator_type::value_type value_type;
1518 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1519 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1520 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1521 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1523 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1524 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1526 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1527 propagate_on_container_copy_assignment;
1528 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1529 propagate_on_container_move_assignment;
1530 typedef typename __propagate_on_container_swap<allocator_type>::type
1531 propagate_on_container_swap;
1532 typedef typename __is_always_equal<allocator_type>::type
1535 #ifndef _LIBCPP_CXX03_LANG
1536 template <class _Tp> using rebind_alloc =
1537 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1538 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1539 #else // _LIBCPP_CXX03_LANG
1540 template <class _Tp> struct rebind_alloc
1541 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1542 template <class _Tp> struct rebind_traits
1543 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1544 #endif // _LIBCPP_CXX03_LANG
1546 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1547 static pointer allocate(allocator_type& __a, size_type __n)
1548 {return __a.allocate(__n);}
1549 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1550 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1551 {return __allocate(__a, __n, __hint,
1552 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1554 _LIBCPP_INLINE_VISIBILITY
1555 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1556 {__a.deallocate(__p, __n);}
1558 #ifndef _LIBCPP_HAS_NO_VARIADICS
1559 template <class _Tp, class... _Args>
1560 _LIBCPP_INLINE_VISIBILITY
1561 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1562 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1563 __a, __p, _VSTD::forward<_Args>(__args)...);}
1564 #else // _LIBCPP_HAS_NO_VARIADICS
1565 template <class _Tp>
1566 _LIBCPP_INLINE_VISIBILITY
1567 static void construct(allocator_type&, _Tp* __p)
1569 ::new ((void*)__p) _Tp();
1571 template <class _Tp, class _A0>
1572 _LIBCPP_INLINE_VISIBILITY
1573 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
1575 ::new ((void*)__p) _Tp(__a0);
1577 template <class _Tp, class _A0, class _A1>
1578 _LIBCPP_INLINE_VISIBILITY
1579 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1582 ::new ((void*)__p) _Tp(__a0, __a1);
1584 template <class _Tp, class _A0, class _A1, class _A2>
1585 _LIBCPP_INLINE_VISIBILITY
1586 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1587 const _A1& __a1, const _A2& __a2)
1589 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1591 #endif // _LIBCPP_HAS_NO_VARIADICS
1593 template <class _Tp>
1594 _LIBCPP_INLINE_VISIBILITY
1595 static void destroy(allocator_type& __a, _Tp* __p)
1596 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1598 _LIBCPP_INLINE_VISIBILITY
1599 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1600 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1602 _LIBCPP_INLINE_VISIBILITY
1603 static allocator_type
1604 select_on_container_copy_construction(const allocator_type& __a)
1605 {return __select_on_container_copy_construction(
1606 __has_select_on_container_copy_construction<const allocator_type>(),
1609 template <class _Ptr>
1610 _LIBCPP_INLINE_VISIBILITY
1613 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1615 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1616 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1619 template <class _Tp>
1620 _LIBCPP_INLINE_VISIBILITY
1624 (is_same<allocator_type, allocator<_Tp> >::value
1625 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1626 is_trivially_move_constructible<_Tp>::value,
1629 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1631 ptrdiff_t _Np = __end1 - __begin1;
1634 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1639 template <class _Iter, class _Ptr>
1640 _LIBCPP_INLINE_VISIBILITY
1643 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1645 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1646 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1649 template <class _Tp>
1650 _LIBCPP_INLINE_VISIBILITY
1654 (is_same<allocator_type, allocator<_Tp> >::value
1655 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1656 is_trivially_move_constructible<_Tp>::value,
1659 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1661 typedef typename remove_const<_Tp>::type _Vp;
1662 ptrdiff_t _Np = __end1 - __begin1;
1665 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1670 template <class _Ptr>
1671 _LIBCPP_INLINE_VISIBILITY
1674 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1676 while (__end1 != __begin1)
1678 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1683 template <class _Tp>
1684 _LIBCPP_INLINE_VISIBILITY
1688 (is_same<allocator_type, allocator<_Tp> >::value
1689 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1690 is_trivially_move_constructible<_Tp>::value,
1693 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1695 ptrdiff_t _Np = __end1 - __begin1;
1698 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1703 _LIBCPP_INLINE_VISIBILITY
1704 static pointer __allocate(allocator_type& __a, size_type __n,
1705 const_void_pointer __hint, true_type)
1706 {return __a.allocate(__n, __hint);}
1707 _LIBCPP_INLINE_VISIBILITY
1708 static pointer __allocate(allocator_type& __a, size_type __n,
1709 const_void_pointer, false_type)
1710 {return __a.allocate(__n);}
1712 #ifndef _LIBCPP_HAS_NO_VARIADICS
1713 template <class _Tp, class... _Args>
1714 _LIBCPP_INLINE_VISIBILITY
1715 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1716 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1717 template <class _Tp, class... _Args>
1718 _LIBCPP_INLINE_VISIBILITY
1719 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1721 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1723 #endif // _LIBCPP_HAS_NO_VARIADICS
1725 template <class _Tp>
1726 _LIBCPP_INLINE_VISIBILITY
1727 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1729 template <class _Tp>
1730 _LIBCPP_INLINE_VISIBILITY
1731 static void __destroy(false_type, allocator_type&, _Tp* __p)
1736 _LIBCPP_INLINE_VISIBILITY
1737 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1738 {return __a.max_size();}
1739 _LIBCPP_INLINE_VISIBILITY
1740 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
1741 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1743 _LIBCPP_INLINE_VISIBILITY
1744 static allocator_type
1745 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1746 {return __a.select_on_container_copy_construction();}
1747 _LIBCPP_INLINE_VISIBILITY
1748 static allocator_type
1749 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1753 template <class _Traits, class _Tp>
1754 struct __rebind_alloc_helper
1756 #ifndef _LIBCPP_CXX03_LANG
1757 typedef typename _Traits::template rebind_alloc<_Tp> type;
1759 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1765 template <class _Tp>
1766 class _LIBCPP_TEMPLATE_VIS allocator
1769 typedef size_t size_type;
1770 typedef ptrdiff_t difference_type;
1771 typedef _Tp* pointer;
1772 typedef const _Tp* const_pointer;
1773 typedef _Tp& reference;
1774 typedef const _Tp& const_reference;
1775 typedef _Tp value_type;
1777 typedef true_type propagate_on_container_move_assignment;
1778 typedef true_type is_always_equal;
1780 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1782 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1783 allocator() _NOEXCEPT {}
1785 template <class _Up>
1786 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1787 allocator(const allocator<_Up>&) _NOEXCEPT {}
1789 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1790 {return _VSTD::addressof(__x);}
1791 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1792 {return _VSTD::addressof(__x);}
1793 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1794 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1796 if (__n > max_size())
1797 __throw_length_error("allocator<T>::allocate(size_t n)"
1798 " 'n' exceeds maximum supported size");
1799 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp)));
1801 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1802 {_VSTD::__libcpp_deallocate((void*)__p, __alignof(_Tp));}
1803 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1804 {return size_type(~0) / sizeof(_Tp);}
1805 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1806 template <class _Up, class... _Args>
1807 _LIBCPP_INLINE_VISIBILITY
1809 construct(_Up* __p, _Args&&... __args)
1811 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1813 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1814 _LIBCPP_INLINE_VISIBILITY
1816 construct(pointer __p)
1818 ::new((void*)__p) _Tp();
1820 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1822 template <class _A0>
1823 _LIBCPP_INLINE_VISIBILITY
1825 construct(pointer __p, _A0& __a0)
1827 ::new((void*)__p) _Tp(__a0);
1829 template <class _A0>
1830 _LIBCPP_INLINE_VISIBILITY
1832 construct(pointer __p, const _A0& __a0)
1834 ::new((void*)__p) _Tp(__a0);
1836 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1837 template <class _A0, class _A1>
1838 _LIBCPP_INLINE_VISIBILITY
1840 construct(pointer __p, _A0& __a0, _A1& __a1)
1842 ::new((void*)__p) _Tp(__a0, __a1);
1844 template <class _A0, class _A1>
1845 _LIBCPP_INLINE_VISIBILITY
1847 construct(pointer __p, const _A0& __a0, _A1& __a1)
1849 ::new((void*)__p) _Tp(__a0, __a1);
1851 template <class _A0, class _A1>
1852 _LIBCPP_INLINE_VISIBILITY
1854 construct(pointer __p, _A0& __a0, const _A1& __a1)
1856 ::new((void*)__p) _Tp(__a0, __a1);
1858 template <class _A0, class _A1>
1859 _LIBCPP_INLINE_VISIBILITY
1861 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1863 ::new((void*)__p) _Tp(__a0, __a1);
1865 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1866 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1869 template <class _Tp>
1870 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1873 typedef size_t size_type;
1874 typedef ptrdiff_t difference_type;
1875 typedef const _Tp* pointer;
1876 typedef const _Tp* const_pointer;
1877 typedef const _Tp& reference;
1878 typedef const _Tp& const_reference;
1879 typedef const _Tp value_type;
1881 typedef true_type propagate_on_container_move_assignment;
1882 typedef true_type is_always_equal;
1884 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1886 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1887 allocator() _NOEXCEPT {}
1889 template <class _Up>
1890 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1891 allocator(const allocator<_Up>&) _NOEXCEPT {}
1893 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1894 {return _VSTD::addressof(__x);}
1895 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1897 if (__n > max_size())
1898 __throw_length_error("allocator<const T>::allocate(size_t n)"
1899 " 'n' exceeds maximum supported size");
1900 return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), __alignof(_Tp)));
1902 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1903 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __alignof(_Tp));}
1904 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1905 {return size_type(~0) / sizeof(_Tp);}
1906 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1907 template <class _Up, class... _Args>
1908 _LIBCPP_INLINE_VISIBILITY
1910 construct(_Up* __p, _Args&&... __args)
1912 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1914 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1915 _LIBCPP_INLINE_VISIBILITY
1917 construct(pointer __p)
1919 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1921 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1923 template <class _A0>
1924 _LIBCPP_INLINE_VISIBILITY
1926 construct(pointer __p, _A0& __a0)
1928 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1930 template <class _A0>
1931 _LIBCPP_INLINE_VISIBILITY
1933 construct(pointer __p, const _A0& __a0)
1935 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1937 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1938 template <class _A0, class _A1>
1939 _LIBCPP_INLINE_VISIBILITY
1941 construct(pointer __p, _A0& __a0, _A1& __a1)
1943 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1945 template <class _A0, class _A1>
1946 _LIBCPP_INLINE_VISIBILITY
1948 construct(pointer __p, const _A0& __a0, _A1& __a1)
1950 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1952 template <class _A0, class _A1>
1953 _LIBCPP_INLINE_VISIBILITY
1955 construct(pointer __p, _A0& __a0, const _A1& __a1)
1957 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1959 template <class _A0, class _A1>
1960 _LIBCPP_INLINE_VISIBILITY
1962 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1964 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1966 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1967 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1970 template <class _Tp, class _Up>
1971 inline _LIBCPP_INLINE_VISIBILITY
1972 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1974 template <class _Tp, class _Up>
1975 inline _LIBCPP_INLINE_VISIBILITY
1976 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1978 template <class _OutputIterator, class _Tp>
1979 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1980 : public iterator<output_iterator_tag,
1981 _Tp, // purposefully not C++03
1982 ptrdiff_t, // purposefully not C++03
1983 _Tp*, // purposefully not C++03
1984 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1987 _OutputIterator __x_;
1989 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1990 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1991 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1992 {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
1993 #if _LIBCPP_STD_VER >= 14
1994 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1995 {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
1997 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1998 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1999 {raw_storage_iterator __t(*this); ++__x_; return __t;}
2000 #if _LIBCPP_STD_VER >= 14
2001 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
2005 template <class _Tp>
2007 pair<_Tp*, ptrdiff_t>
2008 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
2010 pair<_Tp*, ptrdiff_t> __r(0, 0);
2011 const ptrdiff_t __m = (~ptrdiff_t(0) ^
2012 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2018 #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
2019 if (__is_overaligned_for_new(__alignof(_Tp)))
2021 std::align_val_t __al =
2022 std::align_val_t(std::alignment_of<_Tp>::value);
2023 __r.first = static_cast<_Tp*>(::operator new(
2024 __n * sizeof(_Tp), __al, nothrow));
2026 __r.first = static_cast<_Tp*>(::operator new(
2027 __n * sizeof(_Tp), nothrow));
2030 if (__is_overaligned_for_new(__alignof(_Tp)))
2032 // Since aligned operator new is unavailable, return an empty
2033 // buffer rather than one with invalid alignment.
2037 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2050 template <class _Tp>
2051 inline _LIBCPP_INLINE_VISIBILITY
2052 void return_temporary_buffer(_Tp* __p) _NOEXCEPT
2054 _VSTD::__libcpp_deallocate((void*)__p, __alignof(_Tp));
2057 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2058 template <class _Tp>
2065 class _LIBCPP_TEMPLATE_VIS auto_ptr
2070 typedef _Tp element_type;
2072 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2073 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2074 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2075 : __ptr_(__p.release()) {}
2076 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2077 {reset(__p.release()); return *this;}
2078 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2079 {reset(__p.release()); return *this;}
2080 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2081 {reset(__p.__ptr_); return *this;}
2082 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2084 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2086 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2087 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2088 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2094 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2101 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2102 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2103 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2104 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2105 {return auto_ptr<_Up>(release());}
2109 class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
2112 typedef void element_type;
2116 template <class _Tp, int _Idx,
2117 bool _CanBeEmptyBase =
2118 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2119 struct __compressed_pair_elem {
2120 typedef _Tp _ParamT;
2121 typedef _Tp& reference;
2122 typedef const _Tp& const_reference;
2124 #ifndef _LIBCPP_CXX03_LANG
2125 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
2127 template <class _Up, class = typename enable_if<
2128 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2130 _LIBCPP_INLINE_VISIBILITY
2132 __compressed_pair_elem(_Up&& __u)
2133 : __value_(_VSTD::forward<_Up>(__u)){};
2135 template <class... _Args, size_t... _Indexes>
2136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2137 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2138 __tuple_indices<_Indexes...>)
2139 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2141 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2142 _LIBCPP_INLINE_VISIBILITY
2143 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2146 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2147 _LIBCPP_INLINE_VISIBILITY
2148 const_reference __get() const _NOEXCEPT { return __value_; }
2154 template <class _Tp, int _Idx>
2155 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2156 typedef _Tp _ParamT;
2157 typedef _Tp& reference;
2158 typedef const _Tp& const_reference;
2159 typedef _Tp __value_type;
2161 #ifndef _LIBCPP_CXX03_LANG
2162 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
2164 template <class _Up, class = typename enable_if<
2165 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2167 _LIBCPP_INLINE_VISIBILITY
2169 __compressed_pair_elem(_Up&& __u)
2170 : __value_type(_VSTD::forward<_Up>(__u)){};
2172 template <class... _Args, size_t... _Indexes>
2173 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2174 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2175 __tuple_indices<_Indexes...>)
2176 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2178 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2179 _LIBCPP_INLINE_VISIBILITY
2180 __compressed_pair_elem(_ParamT __p)
2181 : __value_type(std::forward<_ParamT>(__p)) {}
2184 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2185 _LIBCPP_INLINE_VISIBILITY
2186 const_reference __get() const _NOEXCEPT { return *this; }
2189 // Tag used to construct the second element of the compressed pair.
2190 struct __second_tag {};
2192 template <class _T1, class _T2>
2193 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2194 private __compressed_pair_elem<_T2, 1> {
2195 typedef __compressed_pair_elem<_T1, 0> _Base1;
2196 typedef __compressed_pair_elem<_T2, 1> _Base2;
2198 // NOTE: This static assert should never fire because __compressed_pair
2199 // is *almost never* used in a scenario where it's possible for T1 == T2.
2200 // (The exception is std::function where it is possible that the function
2201 // object and the allocator have the same type).
2202 static_assert((!is_same<_T1, _T2>::value),
2203 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2204 "The current implementation is NOT ABI-compatible with the previous "
2205 "implementation for this configuration");
2208 #ifndef _LIBCPP_CXX03_LANG
2209 template <bool _Dummy = true,
2210 class = typename enable_if<
2211 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2212 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2215 _LIBCPP_INLINE_VISIBILITY
2216 constexpr __compressed_pair() {}
2218 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2219 __compressed_pair>::value,
2221 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2222 __compressed_pair(_Tp&& __t)
2223 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2225 template <class _Tp>
2226 _LIBCPP_INLINE_VISIBILITY constexpr
2227 __compressed_pair(__second_tag, _Tp&& __t)
2228 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2230 template <class _U1, class _U2>
2231 _LIBCPP_INLINE_VISIBILITY constexpr
2232 __compressed_pair(_U1&& __t1, _U2&& __t2)
2233 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2235 template <class... _Args1, class... _Args2>
2236 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2237 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2238 tuple<_Args2...> __second_args)
2239 : _Base1(__pc, _VSTD::move(__first_args),
2240 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2241 _Base2(__pc, _VSTD::move(__second_args),
2242 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2245 _LIBCPP_INLINE_VISIBILITY
2246 __compressed_pair() {}
2248 _LIBCPP_INLINE_VISIBILITY explicit
2249 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2251 _LIBCPP_INLINE_VISIBILITY
2252 __compressed_pair(__second_tag, _T2 __t2)
2253 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2255 _LIBCPP_INLINE_VISIBILITY
2256 __compressed_pair(_T1 __t1, _T2 __t2)
2257 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2260 _LIBCPP_INLINE_VISIBILITY
2261 typename _Base1::reference first() _NOEXCEPT {
2262 return static_cast<_Base1&>(*this).__get();
2265 _LIBCPP_INLINE_VISIBILITY
2266 typename _Base1::const_reference first() const _NOEXCEPT {
2267 return static_cast<_Base1 const&>(*this).__get();
2270 _LIBCPP_INLINE_VISIBILITY
2271 typename _Base2::reference second() _NOEXCEPT {
2272 return static_cast<_Base2&>(*this).__get();
2275 _LIBCPP_INLINE_VISIBILITY
2276 typename _Base2::const_reference second() const _NOEXCEPT {
2277 return static_cast<_Base2 const&>(*this).__get();
2280 _LIBCPP_INLINE_VISIBILITY
2281 void swap(__compressed_pair& __x)
2282 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2283 __is_nothrow_swappable<_T2>::value)
2286 swap(first(), __x.first());
2287 swap(second(), __x.second());
2291 template <class _T1, class _T2>
2292 inline _LIBCPP_INLINE_VISIBILITY
2293 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2294 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2295 __is_nothrow_swappable<_T2>::value) {
2301 template <class _Tp>
2302 struct _LIBCPP_TEMPLATE_VIS default_delete {
2303 static_assert(!is_function<_Tp>::value,
2304 "default_delete cannot be instantiated for function types");
2305 #ifndef _LIBCPP_CXX03_LANG
2306 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2308 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2310 template <class _Up>
2311 _LIBCPP_INLINE_VISIBILITY
2312 default_delete(const default_delete<_Up>&,
2313 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2316 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2317 static_assert(sizeof(_Tp) > 0,
2318 "default_delete can not delete incomplete type");
2319 static_assert(!is_void<_Tp>::value,
2320 "default_delete can not delete incomplete type");
2325 template <class _Tp>
2326 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2328 template <class _Up>
2329 struct _EnableIfConvertible
2330 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2333 #ifndef _LIBCPP_CXX03_LANG
2334 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2336 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2339 template <class _Up>
2340 _LIBCPP_INLINE_VISIBILITY
2341 default_delete(const default_delete<_Up[]>&,
2342 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2344 template <class _Up>
2345 _LIBCPP_INLINE_VISIBILITY
2346 typename _EnableIfConvertible<_Up>::type
2347 operator()(_Up* __ptr) const _NOEXCEPT {
2348 static_assert(sizeof(_Tp) > 0,
2349 "default_delete can not delete incomplete type");
2350 static_assert(!is_void<_Tp>::value,
2351 "default_delete can not delete void type");
2358 #ifndef _LIBCPP_CXX03_LANG
2359 template <class _Deleter>
2360 struct __unique_ptr_deleter_sfinae {
2361 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2362 typedef const _Deleter& __lval_ref_type;
2363 typedef _Deleter&& __good_rval_ref_type;
2364 typedef true_type __enable_rval_overload;
2367 template <class _Deleter>
2368 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2369 typedef const _Deleter& __lval_ref_type;
2370 typedef const _Deleter&& __bad_rval_ref_type;
2371 typedef false_type __enable_rval_overload;
2374 template <class _Deleter>
2375 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2376 typedef _Deleter& __lval_ref_type;
2377 typedef _Deleter&& __bad_rval_ref_type;
2378 typedef false_type __enable_rval_overload;
2380 #endif // !defined(_LIBCPP_CXX03_LANG)
2382 template <class _Tp, class _Dp = default_delete<_Tp> >
2383 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2385 typedef _Tp element_type;
2386 typedef _Dp deleter_type;
2387 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2389 static_assert(!is_rvalue_reference<deleter_type>::value,
2390 "the specified deleter type cannot be an rvalue reference");
2393 __compressed_pair<pointer, deleter_type> __ptr_;
2395 struct __nat { int __for_bool_; };
2397 #ifndef _LIBCPP_CXX03_LANG
2398 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2400 template <bool _Dummy>
2401 using _LValRefType =
2402 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2404 template <bool _Dummy>
2405 using _GoodRValRefType =
2406 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2408 template <bool _Dummy>
2409 using _BadRValRefType =
2410 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2412 template <bool _Dummy, class _Deleter = typename __dependent_type<
2413 __identity<deleter_type>, _Dummy>::type>
2414 using _EnableIfDeleterDefaultConstructible =
2415 typename enable_if<is_default_constructible<_Deleter>::value &&
2416 !is_pointer<_Deleter>::value>::type;
2418 template <class _ArgType>
2419 using _EnableIfDeleterConstructible =
2420 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2422 template <class _UPtr, class _Up>
2423 using _EnableIfMoveConvertible = typename enable_if<
2424 is_convertible<typename _UPtr::pointer, pointer>::value &&
2425 !is_array<_Up>::value
2428 template <class _UDel>
2429 using _EnableIfDeleterConvertible = typename enable_if<
2430 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2431 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2434 template <class _UDel>
2435 using _EnableIfDeleterAssignable = typename enable_if<
2436 is_assignable<_Dp&, _UDel&&>::value
2440 template <bool _Dummy = true,
2441 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2442 _LIBCPP_INLINE_VISIBILITY
2443 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2445 template <bool _Dummy = true,
2446 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2447 _LIBCPP_INLINE_VISIBILITY
2448 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2450 template <bool _Dummy = true,
2451 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2452 _LIBCPP_INLINE_VISIBILITY
2453 explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2455 template <bool _Dummy = true,
2456 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2457 _LIBCPP_INLINE_VISIBILITY
2458 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2459 : __ptr_(__p, __d) {}
2461 template <bool _Dummy = true,
2462 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2463 _LIBCPP_INLINE_VISIBILITY
2464 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2465 : __ptr_(__p, _VSTD::move(__d)) {
2466 static_assert(!is_reference<deleter_type>::value,
2467 "rvalue deleter bound to reference");
2470 template <bool _Dummy = true,
2471 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2472 _LIBCPP_INLINE_VISIBILITY
2473 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2475 _LIBCPP_INLINE_VISIBILITY
2476 unique_ptr(unique_ptr&& __u) noexcept
2477 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2480 template <class _Up, class _Ep,
2481 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2482 class = _EnableIfDeleterConvertible<_Ep>
2484 _LIBCPP_INLINE_VISIBILITY
2485 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2486 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2488 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2489 template <class _Up>
2490 _LIBCPP_INLINE_VISIBILITY
2491 unique_ptr(auto_ptr<_Up>&& __p,
2492 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2493 is_same<_Dp, default_delete<_Tp>>::value,
2494 __nat>::type = __nat()) _NOEXCEPT
2495 : __ptr_(__p.release()) {}
2498 _LIBCPP_INLINE_VISIBILITY
2499 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2500 reset(__u.release());
2501 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2505 template <class _Up, class _Ep,
2506 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2507 class = _EnableIfDeleterAssignable<_Ep>
2509 _LIBCPP_INLINE_VISIBILITY
2510 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2511 reset(__u.release());
2512 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2516 #else // _LIBCPP_CXX03_LANG
2518 unique_ptr(unique_ptr&);
2519 template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2521 unique_ptr& operator=(unique_ptr&);
2522 template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2525 _LIBCPP_INLINE_VISIBILITY
2526 unique_ptr() : __ptr_(pointer())
2528 static_assert(!is_pointer<deleter_type>::value,
2529 "unique_ptr constructed with null function pointer deleter");
2530 static_assert(is_default_constructible<deleter_type>::value,
2531 "unique_ptr::deleter_type is not default constructible");
2533 _LIBCPP_INLINE_VISIBILITY
2534 unique_ptr(nullptr_t) : __ptr_(pointer())
2536 static_assert(!is_pointer<deleter_type>::value,
2537 "unique_ptr constructed with null function pointer deleter");
2539 _LIBCPP_INLINE_VISIBILITY
2540 explicit unique_ptr(pointer __p)
2541 : __ptr_(_VSTD::move(__p)) {
2542 static_assert(!is_pointer<deleter_type>::value,
2543 "unique_ptr constructed with null function pointer deleter");
2546 _LIBCPP_INLINE_VISIBILITY
2547 operator __rv<unique_ptr>() {
2548 return __rv<unique_ptr>(*this);
2551 _LIBCPP_INLINE_VISIBILITY
2552 unique_ptr(__rv<unique_ptr> __u)
2553 : __ptr_(__u->release(),
2554 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2556 template <class _Up, class _Ep>
2557 _LIBCPP_INLINE_VISIBILITY
2559 !is_array<_Up>::value &&
2560 is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2562 is_assignable<deleter_type&, _Ep&>::value,
2564 operator=(unique_ptr<_Up, _Ep> __u) {
2565 reset(__u.release());
2566 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2570 _LIBCPP_INLINE_VISIBILITY
2571 unique_ptr(pointer __p, deleter_type __d)
2572 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2573 #endif // _LIBCPP_CXX03_LANG
2575 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2576 template <class _Up>
2577 _LIBCPP_INLINE_VISIBILITY
2578 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2579 is_same<_Dp, default_delete<_Tp> >::value,
2581 operator=(auto_ptr<_Up> __p) {
2582 reset(__p.release());
2587 _LIBCPP_INLINE_VISIBILITY
2588 ~unique_ptr() { reset(); }
2590 _LIBCPP_INLINE_VISIBILITY
2591 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2596 _LIBCPP_INLINE_VISIBILITY
2597 typename add_lvalue_reference<_Tp>::type
2599 return *__ptr_.first();
2601 _LIBCPP_INLINE_VISIBILITY
2602 pointer operator->() const _NOEXCEPT {
2603 return __ptr_.first();
2605 _LIBCPP_INLINE_VISIBILITY
2606 pointer get() const _NOEXCEPT {
2607 return __ptr_.first();
2609 _LIBCPP_INLINE_VISIBILITY
2610 deleter_type& get_deleter() _NOEXCEPT {
2611 return __ptr_.second();
2613 _LIBCPP_INLINE_VISIBILITY
2614 const deleter_type& get_deleter() const _NOEXCEPT {
2615 return __ptr_.second();
2617 _LIBCPP_INLINE_VISIBILITY
2618 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2619 return __ptr_.first() != nullptr;
2622 _LIBCPP_INLINE_VISIBILITY
2623 pointer release() _NOEXCEPT {
2624 pointer __t = __ptr_.first();
2625 __ptr_.first() = pointer();
2629 _LIBCPP_INLINE_VISIBILITY
2630 void reset(pointer __p = pointer()) _NOEXCEPT {
2631 pointer __tmp = __ptr_.first();
2632 __ptr_.first() = __p;
2634 __ptr_.second()(__tmp);
2637 _LIBCPP_INLINE_VISIBILITY
2638 void swap(unique_ptr& __u) _NOEXCEPT {
2639 __ptr_.swap(__u.__ptr_);
2644 template <class _Tp, class _Dp>
2645 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2647 typedef _Tp element_type;
2648 typedef _Dp deleter_type;
2649 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2652 __compressed_pair<pointer, deleter_type> __ptr_;
2654 template <class _From>
2655 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2657 template <class _FromElem>
2658 struct _CheckArrayPointerConversion<_FromElem*>
2659 : integral_constant<bool,
2660 is_same<_FromElem*, pointer>::value ||
2661 (is_same<pointer, element_type*>::value &&
2662 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2666 #ifndef _LIBCPP_CXX03_LANG
2667 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2669 template <bool _Dummy>
2670 using _LValRefType =
2671 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2673 template <bool _Dummy>
2674 using _GoodRValRefType =
2675 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2677 template <bool _Dummy>
2678 using _BadRValRefType =
2679 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2681 template <bool _Dummy, class _Deleter = typename __dependent_type<
2682 __identity<deleter_type>, _Dummy>::type>
2683 using _EnableIfDeleterDefaultConstructible =
2684 typename enable_if<is_default_constructible<_Deleter>::value &&
2685 !is_pointer<_Deleter>::value>::type;
2687 template <class _ArgType>
2688 using _EnableIfDeleterConstructible =
2689 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2691 template <class _Pp>
2692 using _EnableIfPointerConvertible = typename enable_if<
2693 _CheckArrayPointerConversion<_Pp>::value
2696 template <class _UPtr, class _Up,
2697 class _ElemT = typename _UPtr::element_type>
2698 using _EnableIfMoveConvertible = typename enable_if<
2699 is_array<_Up>::value &&
2700 is_same<pointer, element_type*>::value &&
2701 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2702 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2705 template <class _UDel>
2706 using _EnableIfDeleterConvertible = typename enable_if<
2707 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2708 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2711 template <class _UDel>
2712 using _EnableIfDeleterAssignable = typename enable_if<
2713 is_assignable<_Dp&, _UDel&&>::value
2717 template <bool _Dummy = true,
2718 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2719 _LIBCPP_INLINE_VISIBILITY
2720 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2722 template <bool _Dummy = true,
2723 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2724 _LIBCPP_INLINE_VISIBILITY
2725 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2727 template <class _Pp, bool _Dummy = true,
2728 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2729 class = _EnableIfPointerConvertible<_Pp>>
2730 _LIBCPP_INLINE_VISIBILITY
2731 explicit unique_ptr(_Pp __p) noexcept
2734 template <class _Pp, bool _Dummy = true,
2735 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2736 class = _EnableIfPointerConvertible<_Pp>>
2737 _LIBCPP_INLINE_VISIBILITY
2738 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2739 : __ptr_(__p, __d) {}
2741 template <bool _Dummy = true,
2742 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2743 _LIBCPP_INLINE_VISIBILITY
2744 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2745 : __ptr_(nullptr, __d) {}
2747 template <class _Pp, bool _Dummy = true,
2748 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2749 class = _EnableIfPointerConvertible<_Pp>>
2750 _LIBCPP_INLINE_VISIBILITY
2751 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2752 : __ptr_(__p, _VSTD::move(__d)) {
2753 static_assert(!is_reference<deleter_type>::value,
2754 "rvalue deleter bound to reference");
2757 template <bool _Dummy = true,
2758 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2759 _LIBCPP_INLINE_VISIBILITY
2760 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2761 : __ptr_(nullptr, _VSTD::move(__d)) {
2762 static_assert(!is_reference<deleter_type>::value,
2763 "rvalue deleter bound to reference");
2766 template <class _Pp, bool _Dummy = true,
2767 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2768 class = _EnableIfPointerConvertible<_Pp>>
2769 _LIBCPP_INLINE_VISIBILITY
2770 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2772 _LIBCPP_INLINE_VISIBILITY
2773 unique_ptr(unique_ptr&& __u) noexcept
2774 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2777 _LIBCPP_INLINE_VISIBILITY
2778 unique_ptr& operator=(unique_ptr&& __u) noexcept {
2779 reset(__u.release());
2780 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2784 template <class _Up, class _Ep,
2785 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2786 class = _EnableIfDeleterConvertible<_Ep>
2788 _LIBCPP_INLINE_VISIBILITY
2789 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
2790 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2793 template <class _Up, class _Ep,
2794 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2795 class = _EnableIfDeleterAssignable<_Ep>
2797 _LIBCPP_INLINE_VISIBILITY
2799 operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2800 reset(__u.release());
2801 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2805 #else // _LIBCPP_CXX03_LANG
2807 template <class _Up> explicit unique_ptr(_Up);
2809 unique_ptr(unique_ptr&);
2810 template <class _Up> unique_ptr(unique_ptr<_Up>&);
2812 unique_ptr& operator=(unique_ptr&);
2813 template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2815 template <class _Up>
2817 typename conditional<
2818 is_reference<deleter_type>::value, deleter_type,
2819 typename add_lvalue_reference<const deleter_type>::type>::type,
2820 typename enable_if<is_convertible<_Up, pointer>::value,
2821 __nat>::type = __nat());
2823 _LIBCPP_INLINE_VISIBILITY
2824 unique_ptr() : __ptr_(pointer()) {
2825 static_assert(!is_pointer<deleter_type>::value,
2826 "unique_ptr constructed with null function pointer deleter");
2828 _LIBCPP_INLINE_VISIBILITY
2829 unique_ptr(nullptr_t) : __ptr_(pointer()) {
2830 static_assert(!is_pointer<deleter_type>::value,
2831 "unique_ptr constructed with null function pointer deleter");
2834 _LIBCPP_INLINE_VISIBILITY
2835 explicit unique_ptr(pointer __p) : __ptr_(__p) {
2836 static_assert(!is_pointer<deleter_type>::value,
2837 "unique_ptr constructed with null function pointer deleter");
2840 _LIBCPP_INLINE_VISIBILITY
2841 unique_ptr(pointer __p, deleter_type __d)
2842 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2844 _LIBCPP_INLINE_VISIBILITY
2845 unique_ptr(nullptr_t, deleter_type __d)
2846 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2848 _LIBCPP_INLINE_VISIBILITY
2849 operator __rv<unique_ptr>() {
2850 return __rv<unique_ptr>(*this);
2853 _LIBCPP_INLINE_VISIBILITY
2854 unique_ptr(__rv<unique_ptr> __u)
2855 : __ptr_(__u->release(),
2856 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2858 _LIBCPP_INLINE_VISIBILITY
2859 unique_ptr& operator=(__rv<unique_ptr> __u) {
2860 reset(__u->release());
2861 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2865 #endif // _LIBCPP_CXX03_LANG
2868 _LIBCPP_INLINE_VISIBILITY
2869 ~unique_ptr() { reset(); }
2871 _LIBCPP_INLINE_VISIBILITY
2872 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2877 _LIBCPP_INLINE_VISIBILITY
2878 typename add_lvalue_reference<_Tp>::type
2879 operator[](size_t __i) const {
2880 return __ptr_.first()[__i];
2882 _LIBCPP_INLINE_VISIBILITY
2883 pointer get() const _NOEXCEPT {
2884 return __ptr_.first();
2887 _LIBCPP_INLINE_VISIBILITY
2888 deleter_type& get_deleter() _NOEXCEPT {
2889 return __ptr_.second();
2892 _LIBCPP_INLINE_VISIBILITY
2893 const deleter_type& get_deleter() const _NOEXCEPT {
2894 return __ptr_.second();
2896 _LIBCPP_INLINE_VISIBILITY
2897 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2898 return __ptr_.first() != nullptr;
2901 _LIBCPP_INLINE_VISIBILITY
2902 pointer release() _NOEXCEPT {
2903 pointer __t = __ptr_.first();
2904 __ptr_.first() = pointer();
2908 template <class _Pp>
2909 _LIBCPP_INLINE_VISIBILITY
2911 _CheckArrayPointerConversion<_Pp>::value
2913 reset(_Pp __p) _NOEXCEPT {
2914 pointer __tmp = __ptr_.first();
2915 __ptr_.first() = __p;
2917 __ptr_.second()(__tmp);
2920 _LIBCPP_INLINE_VISIBILITY
2921 void reset(nullptr_t = nullptr) _NOEXCEPT {
2922 pointer __tmp = __ptr_.first();
2923 __ptr_.first() = nullptr;
2925 __ptr_.second()(__tmp);
2928 _LIBCPP_INLINE_VISIBILITY
2929 void swap(unique_ptr& __u) _NOEXCEPT {
2930 __ptr_.swap(__u.__ptr_);
2935 template <class _Tp, class _Dp>
2936 inline _LIBCPP_INLINE_VISIBILITY
2938 __is_swappable<_Dp>::value,
2941 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2943 template <class _T1, class _D1, class _T2, class _D2>
2944 inline _LIBCPP_INLINE_VISIBILITY
2946 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2948 template <class _T1, class _D1, class _T2, class _D2>
2949 inline _LIBCPP_INLINE_VISIBILITY
2951 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2953 template <class _T1, class _D1, class _T2, class _D2>
2954 inline _LIBCPP_INLINE_VISIBILITY
2956 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2958 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2959 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2960 typedef typename common_type<_P1, _P2>::type _Vp;
2961 return less<_Vp>()(__x.get(), __y.get());
2964 template <class _T1, class _D1, class _T2, class _D2>
2965 inline _LIBCPP_INLINE_VISIBILITY
2967 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2969 template <class _T1, class _D1, class _T2, class _D2>
2970 inline _LIBCPP_INLINE_VISIBILITY
2972 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2974 template <class _T1, class _D1, class _T2, class _D2>
2975 inline _LIBCPP_INLINE_VISIBILITY
2977 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2979 template <class _T1, class _D1>
2980 inline _LIBCPP_INLINE_VISIBILITY
2982 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2987 template <class _T1, class _D1>
2988 inline _LIBCPP_INLINE_VISIBILITY
2990 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2995 template <class _T1, class _D1>
2996 inline _LIBCPP_INLINE_VISIBILITY
2998 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
3000 return static_cast<bool>(__x);
3003 template <class _T1, class _D1>
3004 inline _LIBCPP_INLINE_VISIBILITY
3006 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
3008 return static_cast<bool>(__x);
3011 template <class _T1, class _D1>
3012 inline _LIBCPP_INLINE_VISIBILITY
3014 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3016 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3017 return less<_P1>()(__x.get(), nullptr);
3020 template <class _T1, class _D1>
3021 inline _LIBCPP_INLINE_VISIBILITY
3023 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3025 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
3026 return less<_P1>()(nullptr, __x.get());
3029 template <class _T1, class _D1>
3030 inline _LIBCPP_INLINE_VISIBILITY
3032 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3034 return nullptr < __x;
3037 template <class _T1, class _D1>
3038 inline _LIBCPP_INLINE_VISIBILITY
3040 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3042 return __x < nullptr;
3045 template <class _T1, class _D1>
3046 inline _LIBCPP_INLINE_VISIBILITY
3048 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3050 return !(nullptr < __x);
3053 template <class _T1, class _D1>
3054 inline _LIBCPP_INLINE_VISIBILITY
3056 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3058 return !(__x < nullptr);
3061 template <class _T1, class _D1>
3062 inline _LIBCPP_INLINE_VISIBILITY
3064 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3066 return !(__x < nullptr);
3069 template <class _T1, class _D1>
3070 inline _LIBCPP_INLINE_VISIBILITY
3072 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3074 return !(nullptr < __x);
3077 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3079 template <class _Tp, class _Dp>
3080 inline _LIBCPP_INLINE_VISIBILITY
3081 unique_ptr<_Tp, _Dp>
3082 move(unique_ptr<_Tp, _Dp>& __t)
3084 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3089 #if _LIBCPP_STD_VER > 11
3094 typedef unique_ptr<_Tp> __unique_single;
3098 struct __unique_if<_Tp[]>
3100 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3103 template<class _Tp, size_t _Np>
3104 struct __unique_if<_Tp[_Np]>
3106 typedef void __unique_array_known_bound;
3109 template<class _Tp, class... _Args>
3110 inline _LIBCPP_INLINE_VISIBILITY
3111 typename __unique_if<_Tp>::__unique_single
3112 make_unique(_Args&&... __args)
3114 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3118 inline _LIBCPP_INLINE_VISIBILITY
3119 typename __unique_if<_Tp>::__unique_array_unknown_bound
3120 make_unique(size_t __n)
3122 typedef typename remove_extent<_Tp>::type _Up;
3123 return unique_ptr<_Tp>(new _Up[__n]());
3126 template<class _Tp, class... _Args>
3127 typename __unique_if<_Tp>::__unique_array_known_bound
3128 make_unique(_Args&&...) = delete;
3130 #endif // _LIBCPP_STD_VER > 11
3132 template <class _Tp, class _Dp>
3133 #ifdef _LIBCPP_CXX03_LANG
3134 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3136 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3137 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3140 typedef unique_ptr<_Tp, _Dp> argument_type;
3141 typedef size_t result_type;
3142 _LIBCPP_INLINE_VISIBILITY
3143 result_type operator()(const argument_type& __ptr) const
3145 typedef typename argument_type::pointer pointer;
3146 return hash<pointer>()(__ptr.get());
3155 template <class _Tp>
3156 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3157 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3159 template <class _Tp>
3160 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3163 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3165 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3168 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3170 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3173 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3176 template <class _Tp>
3177 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3178 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3180 template <class _Tp>
3181 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3182 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3184 template <class _Tp>
3185 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3186 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3189 template <class _Alloc>
3190 class __allocator_destructor
3192 typedef allocator_traits<_Alloc> __alloc_traits;
3194 typedef typename __alloc_traits::pointer pointer;
3195 typedef typename __alloc_traits::size_type size_type;
3200 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3202 : __alloc_(__a), __s_(__s) {}
3203 _LIBCPP_INLINE_VISIBILITY
3204 void operator()(pointer __p) _NOEXCEPT
3205 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3208 template <class _InputIterator, class _ForwardIterator>
3210 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3212 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3213 #ifndef _LIBCPP_NO_EXCEPTIONS
3214 _ForwardIterator __s = __r;
3218 for (; __f != __l; ++__f, (void) ++__r)
3219 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3220 #ifndef _LIBCPP_NO_EXCEPTIONS
3224 for (; __s != __r; ++__s)
3232 template <class _InputIterator, class _Size, class _ForwardIterator>
3234 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3236 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3237 #ifndef _LIBCPP_NO_EXCEPTIONS
3238 _ForwardIterator __s = __r;
3242 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3243 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3244 #ifndef _LIBCPP_NO_EXCEPTIONS
3248 for (; __s != __r; ++__s)
3256 template <class _ForwardIterator, class _Tp>
3258 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3260 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3261 #ifndef _LIBCPP_NO_EXCEPTIONS
3262 _ForwardIterator __s = __f;
3266 for (; __f != __l; ++__f)
3267 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3268 #ifndef _LIBCPP_NO_EXCEPTIONS
3272 for (; __s != __f; ++__s)
3279 template <class _ForwardIterator, class _Size, class _Tp>
3281 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3283 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3284 #ifndef _LIBCPP_NO_EXCEPTIONS
3285 _ForwardIterator __s = __f;
3289 for (; __n > 0; ++__f, (void) --__n)
3290 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3291 #ifndef _LIBCPP_NO_EXCEPTIONS
3295 for (; __s != __f; ++__s)
3303 #if _LIBCPP_STD_VER > 14
3305 template <class _Tp>
3306 inline _LIBCPP_INLINE_VISIBILITY
3307 void destroy_at(_Tp* __loc) {
3308 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3312 template <class _ForwardIterator>
3313 inline _LIBCPP_INLINE_VISIBILITY
3314 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3315 for (; __first != __last; ++__first)
3316 _VSTD::destroy_at(_VSTD::addressof(*__first));
3319 template <class _ForwardIterator, class _Size>
3320 inline _LIBCPP_INLINE_VISIBILITY
3321 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3322 for (; __n > 0; (void)++__first, --__n)
3323 _VSTD::destroy_at(_VSTD::addressof(*__first));
3327 template <class _ForwardIterator>
3328 inline _LIBCPP_INLINE_VISIBILITY
3329 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3330 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3331 auto __idx = __first;
3332 #ifndef _LIBCPP_NO_EXCEPTIONS
3335 for (; __idx != __last; ++__idx)
3336 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3337 #ifndef _LIBCPP_NO_EXCEPTIONS
3339 _VSTD::destroy(__first, __idx);
3345 template <class _ForwardIterator, class _Size>
3346 inline _LIBCPP_INLINE_VISIBILITY
3347 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3348 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3349 auto __idx = __first;
3350 #ifndef _LIBCPP_NO_EXCEPTIONS
3353 for (; __n > 0; (void)++__idx, --__n)
3354 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3356 #ifndef _LIBCPP_NO_EXCEPTIONS
3358 _VSTD::destroy(__first, __idx);
3365 template <class _ForwardIterator>
3366 inline _LIBCPP_INLINE_VISIBILITY
3367 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3368 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3369 auto __idx = __first;
3370 #ifndef _LIBCPP_NO_EXCEPTIONS
3373 for (; __idx != __last; ++__idx)
3374 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3375 #ifndef _LIBCPP_NO_EXCEPTIONS
3377 _VSTD::destroy(__first, __idx);
3383 template <class _ForwardIterator, class _Size>
3384 inline _LIBCPP_INLINE_VISIBILITY
3385 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3386 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3387 auto __idx = __first;
3388 #ifndef _LIBCPP_NO_EXCEPTIONS
3391 for (; __n > 0; (void)++__idx, --__n)
3392 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3394 #ifndef _LIBCPP_NO_EXCEPTIONS
3396 _VSTD::destroy(__first, __idx);
3403 template <class _InputIt, class _ForwardIt>
3404 inline _LIBCPP_INLINE_VISIBILITY
3405 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3406 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3407 auto __idx = __first_res;
3408 #ifndef _LIBCPP_NO_EXCEPTIONS
3411 for (; __first != __last; (void)++__idx, ++__first)
3412 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3414 #ifndef _LIBCPP_NO_EXCEPTIONS
3416 _VSTD::destroy(__first_res, __idx);
3422 template <class _InputIt, class _Size, class _ForwardIt>
3423 inline _LIBCPP_INLINE_VISIBILITY
3424 pair<_InputIt, _ForwardIt>
3425 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3426 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3427 auto __idx = __first_res;
3428 #ifndef _LIBCPP_NO_EXCEPTIONS
3431 for (; __n > 0; ++__idx, (void)++__first, --__n)
3432 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3433 return {__first, __idx};
3434 #ifndef _LIBCPP_NO_EXCEPTIONS
3436 _VSTD::destroy(__first_res, __idx);
3443 #endif // _LIBCPP_STD_VER > 14
3445 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3446 // should be sufficient for thread safety.
3447 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3448 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3449 && defined(__ATOMIC_RELAXED) \
3450 && defined(__ATOMIC_ACQ_REL)
3451 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3452 #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3453 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3456 template <class _Tp>
3457 inline _LIBCPP_INLINE_VISIBILITY _Tp
3458 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3460 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3461 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3467 template <class _Tp>
3468 inline _LIBCPP_INLINE_VISIBILITY _Tp
3469 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3471 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3472 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3478 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3479 : public std::exception
3482 virtual ~bad_weak_ptr() _NOEXCEPT;
3483 virtual const char* what() const _NOEXCEPT;
3486 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
3487 void __throw_bad_weak_ptr()
3489 #ifndef _LIBCPP_NO_EXCEPTIONS
3490 throw bad_weak_ptr();
3496 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3498 class _LIBCPP_TYPE_VIS __shared_count
3500 __shared_count(const __shared_count&);
3501 __shared_count& operator=(const __shared_count&);
3504 long __shared_owners_;
3505 virtual ~__shared_count();
3507 virtual void __on_zero_shared() _NOEXCEPT = 0;
3510 _LIBCPP_INLINE_VISIBILITY
3511 explicit __shared_count(long __refs = 0) _NOEXCEPT
3512 : __shared_owners_(__refs) {}
3514 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3515 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3516 void __add_shared() _NOEXCEPT;
3517 bool __release_shared() _NOEXCEPT;
3519 _LIBCPP_INLINE_VISIBILITY
3520 void __add_shared() _NOEXCEPT {
3521 __libcpp_atomic_refcount_increment(__shared_owners_);
3523 _LIBCPP_INLINE_VISIBILITY
3524 bool __release_shared() _NOEXCEPT {
3525 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3532 _LIBCPP_INLINE_VISIBILITY
3533 long use_count() const _NOEXCEPT {
3534 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3538 class _LIBCPP_TYPE_VIS __shared_weak_count
3539 : private __shared_count
3541 long __shared_weak_owners_;
3544 _LIBCPP_INLINE_VISIBILITY
3545 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3546 : __shared_count(__refs),
3547 __shared_weak_owners_(__refs) {}
3549 virtual ~__shared_weak_count();
3552 #if defined(_LIBCPP_BUILDING_LIBRARY) && \
3553 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3554 void __add_shared() _NOEXCEPT;
3555 void __add_weak() _NOEXCEPT;
3556 void __release_shared() _NOEXCEPT;
3558 _LIBCPP_INLINE_VISIBILITY
3559 void __add_shared() _NOEXCEPT {
3560 __shared_count::__add_shared();
3562 _LIBCPP_INLINE_VISIBILITY
3563 void __add_weak() _NOEXCEPT {
3564 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3566 _LIBCPP_INLINE_VISIBILITY
3567 void __release_shared() _NOEXCEPT {
3568 if (__shared_count::__release_shared())
3572 void __release_weak() _NOEXCEPT;
3573 _LIBCPP_INLINE_VISIBILITY
3574 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3575 __shared_weak_count* lock() _NOEXCEPT;
3577 // Define the function out only if we build static libc++ without RTTI.
3578 // Otherwise we may break clients who need to compile their projects with
3579 // -fno-rtti and yet link against a libc++.dylib compiled
3580 // without -fno-rtti.
3581 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3582 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3585 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3588 template <class _Tp, class _Dp, class _Alloc>
3589 class __shared_ptr_pointer
3590 : public __shared_weak_count
3592 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3594 _LIBCPP_INLINE_VISIBILITY
3595 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3596 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3598 #ifndef _LIBCPP_NO_RTTI
3599 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3603 virtual void __on_zero_shared() _NOEXCEPT;
3604 virtual void __on_zero_shared_weak() _NOEXCEPT;
3607 #ifndef _LIBCPP_NO_RTTI
3609 template <class _Tp, class _Dp, class _Alloc>
3611 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3613 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3616 #endif // _LIBCPP_NO_RTTI
3618 template <class _Tp, class _Dp, class _Alloc>
3620 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3622 __data_.first().second()(__data_.first().first());
3623 __data_.first().second().~_Dp();
3626 template <class _Tp, class _Dp, class _Alloc>
3628 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3630 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3631 typedef allocator_traits<_Al> _ATraits;
3632 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3634 _Al __a(__data_.second());
3635 __data_.second().~_Alloc();
3636 __a.deallocate(_PTraits::pointer_to(*this), 1);
3639 template <class _Tp, class _Alloc>
3640 class __shared_ptr_emplace
3641 : public __shared_weak_count
3643 __compressed_pair<_Alloc, _Tp> __data_;
3645 #ifndef _LIBCPP_HAS_NO_VARIADICS
3647 _LIBCPP_INLINE_VISIBILITY
3648 __shared_ptr_emplace(_Alloc __a)
3649 : __data_(_VSTD::move(__a)) {}
3651 template <class ..._Args>
3652 _LIBCPP_INLINE_VISIBILITY
3653 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3654 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3655 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3657 #else // _LIBCPP_HAS_NO_VARIADICS
3659 _LIBCPP_INLINE_VISIBILITY
3660 __shared_ptr_emplace(_Alloc __a)
3663 template <class _A0>
3664 _LIBCPP_INLINE_VISIBILITY
3665 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3666 : __data_(__a, _Tp(__a0)) {}
3668 template <class _A0, class _A1>
3669 _LIBCPP_INLINE_VISIBILITY
3670 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3671 : __data_(__a, _Tp(__a0, __a1)) {}
3673 template <class _A0, class _A1, class _A2>
3674 _LIBCPP_INLINE_VISIBILITY
3675 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3676 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3678 #endif // _LIBCPP_HAS_NO_VARIADICS
3681 virtual void __on_zero_shared() _NOEXCEPT;
3682 virtual void __on_zero_shared_weak() _NOEXCEPT;
3684 _LIBCPP_INLINE_VISIBILITY
3685 _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
3688 template <class _Tp, class _Alloc>
3690 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3692 __data_.second().~_Tp();
3695 template <class _Tp, class _Alloc>
3697 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3699 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3700 typedef allocator_traits<_Al> _ATraits;
3701 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3702 _Al __a(__data_.first());
3703 __data_.first().~_Alloc();
3704 __a.deallocate(_PTraits::pointer_to(*this), 1);
3707 struct __shared_ptr_dummy_rebind_allocator_type;
3709 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3712 template <class _Other>
3715 typedef allocator<_Other> other;
3719 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3722 class _LIBCPP_TEMPLATE_VIS shared_ptr
3725 typedef _Tp element_type;
3727 #if _LIBCPP_STD_VER > 14
3728 typedef weak_ptr<_Tp> weak_type;
3731 element_type* __ptr_;
3732 __shared_weak_count* __cntrl_;
3734 struct __nat {int __for_bool_;};
3736 _LIBCPP_INLINE_VISIBILITY
3737 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3738 _LIBCPP_INLINE_VISIBILITY
3739 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3741 explicit shared_ptr(_Yp* __p,
3742 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3743 template<class _Yp, class _Dp>
3744 shared_ptr(_Yp* __p, _Dp __d,
3745 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3746 template<class _Yp, class _Dp, class _Alloc>
3747 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3748 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3749 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3750 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3751 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3752 _LIBCPP_INLINE_VISIBILITY
3753 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3755 _LIBCPP_INLINE_VISIBILITY
3756 shared_ptr(const shared_ptr<_Yp>& __r,
3757 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3759 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3760 _LIBCPP_INLINE_VISIBILITY
3761 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3762 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3763 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3765 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3766 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3767 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3768 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3769 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3771 shared_ptr(auto_ptr<_Yp>&& __r,
3772 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3775 shared_ptr(auto_ptr<_Yp> __r,
3776 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3779 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3780 template <class _Yp, class _Dp>
3781 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3784 !is_lvalue_reference<_Dp>::value &&
3785 !is_array<_Yp>::value &&
3786 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3789 template <class _Yp, class _Dp>
3790 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3793 is_lvalue_reference<_Dp>::value &&
3794 !is_array<_Yp>::value &&
3795 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3798 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3799 template <class _Yp, class _Dp>
3800 shared_ptr(unique_ptr<_Yp, _Dp>,
3803 !is_lvalue_reference<_Dp>::value &&
3804 !is_array<_Yp>::value &&
3805 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3808 template <class _Yp, class _Dp>
3809 shared_ptr(unique_ptr<_Yp, _Dp>,
3812 is_lvalue_reference<_Dp>::value &&
3813 !is_array<_Yp>::value &&
3814 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3817 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3821 _LIBCPP_INLINE_VISIBILITY
3822 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3826 is_convertible<_Yp*, element_type*>::value,
3829 _LIBCPP_INLINE_VISIBILITY
3830 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3831 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3832 _LIBCPP_INLINE_VISIBILITY
3833 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3837 is_convertible<_Yp*, element_type*>::value,
3840 _LIBCPP_INLINE_VISIBILITY
3841 operator=(shared_ptr<_Yp>&& __r);
3842 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3844 _LIBCPP_INLINE_VISIBILITY
3847 !is_array<_Yp>::value &&
3848 is_convertible<_Yp*, element_type*>::value,
3851 operator=(auto_ptr<_Yp>&& __r);
3853 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3854 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3856 _LIBCPP_INLINE_VISIBILITY
3859 !is_array<_Yp>::value &&
3860 is_convertible<_Yp*, element_type*>::value,
3863 operator=(auto_ptr<_Yp> __r);
3866 template <class _Yp, class _Dp>
3869 !is_array<_Yp>::value &&
3870 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3873 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3874 _LIBCPP_INLINE_VISIBILITY
3875 operator=(unique_ptr<_Yp, _Dp>&& __r);
3876 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3877 _LIBCPP_INLINE_VISIBILITY
3878 operator=(unique_ptr<_Yp, _Dp> __r);
3881 _LIBCPP_INLINE_VISIBILITY
3882 void swap(shared_ptr& __r) _NOEXCEPT;
3883 _LIBCPP_INLINE_VISIBILITY
3884 void reset() _NOEXCEPT;
3888 is_convertible<_Yp*, element_type*>::value,
3891 _LIBCPP_INLINE_VISIBILITY
3893 template<class _Yp, class _Dp>
3896 is_convertible<_Yp*, element_type*>::value,
3899 _LIBCPP_INLINE_VISIBILITY
3900 reset(_Yp* __p, _Dp __d);
3901 template<class _Yp, class _Dp, class _Alloc>
3904 is_convertible<_Yp*, element_type*>::value,
3907 _LIBCPP_INLINE_VISIBILITY
3908 reset(_Yp* __p, _Dp __d, _Alloc __a);
3910 _LIBCPP_INLINE_VISIBILITY
3911 element_type* get() const _NOEXCEPT {return __ptr_;}
3912 _LIBCPP_INLINE_VISIBILITY
3913 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3915 _LIBCPP_INLINE_VISIBILITY
3916 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3917 _LIBCPP_INLINE_VISIBILITY
3918 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3919 _LIBCPP_INLINE_VISIBILITY
3920 bool unique() const _NOEXCEPT {return use_count() == 1;}
3921 _LIBCPP_INLINE_VISIBILITY
3922 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3923 template <class _Up>
3924 _LIBCPP_INLINE_VISIBILITY
3925 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3926 {return __cntrl_ < __p.__cntrl_;}
3927 template <class _Up>
3928 _LIBCPP_INLINE_VISIBILITY
3929 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3930 {return __cntrl_ < __p.__cntrl_;}
3931 _LIBCPP_INLINE_VISIBILITY
3933 __owner_equivalent(const shared_ptr& __p) const
3934 {return __cntrl_ == __p.__cntrl_;}
3936 #ifndef _LIBCPP_NO_RTTI
3937 template <class _Dp>
3938 _LIBCPP_INLINE_VISIBILITY
3939 _Dp* __get_deleter() const _NOEXCEPT
3940 {return static_cast<_Dp*>(__cntrl_
3941 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3943 #endif // _LIBCPP_NO_RTTI
3945 #ifndef _LIBCPP_HAS_NO_VARIADICS
3947 template<class ..._Args>
3950 make_shared(_Args&& ...__args);
3952 template<class _Alloc, class ..._Args>
3955 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3957 #else // _LIBCPP_HAS_NO_VARIADICS
3959 static shared_ptr<_Tp> make_shared();
3962 static shared_ptr<_Tp> make_shared(_A0&);
3964 template<class _A0, class _A1>
3965 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3967 template<class _A0, class _A1, class _A2>
3968 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3970 template<class _Alloc>
3971 static shared_ptr<_Tp>
3972 allocate_shared(const _Alloc& __a);
3974 template<class _Alloc, class _A0>
3975 static shared_ptr<_Tp>
3976 allocate_shared(const _Alloc& __a, _A0& __a0);
3978 template<class _Alloc, class _A0, class _A1>
3979 static shared_ptr<_Tp>
3980 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3982 template<class _Alloc, class _A0, class _A1, class _A2>
3983 static shared_ptr<_Tp>
3984 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3986 #endif // _LIBCPP_HAS_NO_VARIADICS
3989 template <class _Yp, bool = is_function<_Yp>::value>
3990 struct __shared_ptr_default_allocator
3992 typedef allocator<_Yp> type;
3995 template <class _Yp>
3996 struct __shared_ptr_default_allocator<_Yp, true>
3998 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
4001 template <class _Yp, class _OrigPtr>
4002 _LIBCPP_INLINE_VISIBILITY
4003 typename enable_if<is_convertible<_OrigPtr*,
4004 const enable_shared_from_this<_Yp>*
4007 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
4008 _OrigPtr* __ptr) _NOEXCEPT
4010 typedef typename remove_cv<_Yp>::type _RawYp;
4011 if (__e && __e->__weak_this_.expired())
4013 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
4014 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
4018 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
4020 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4021 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4028 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
4037 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4045 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4046 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4049 unique_ptr<_Yp> __hold(__p);
4050 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4051 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
4052 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
4054 __enable_weak_this(__p, __p);
4058 template<class _Yp, class _Dp>
4059 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4060 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4063 #ifndef _LIBCPP_NO_EXCEPTIONS
4066 #endif // _LIBCPP_NO_EXCEPTIONS
4067 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4068 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4069 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4070 __enable_weak_this(__p, __p);
4071 #ifndef _LIBCPP_NO_EXCEPTIONS
4078 #endif // _LIBCPP_NO_EXCEPTIONS
4083 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4086 #ifndef _LIBCPP_NO_EXCEPTIONS
4089 #endif // _LIBCPP_NO_EXCEPTIONS
4090 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4091 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4092 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4093 #ifndef _LIBCPP_NO_EXCEPTIONS
4100 #endif // _LIBCPP_NO_EXCEPTIONS
4104 template<class _Yp, class _Dp, class _Alloc>
4105 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4106 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4109 #ifndef _LIBCPP_NO_EXCEPTIONS
4112 #endif // _LIBCPP_NO_EXCEPTIONS
4113 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4114 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4115 typedef __allocator_destructor<_A2> _D2;
4117 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4118 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4119 _CntrlBlk(__p, __d, __a);
4120 __cntrl_ = _VSTD::addressof(*__hold2.release());
4121 __enable_weak_this(__p, __p);
4122 #ifndef _LIBCPP_NO_EXCEPTIONS
4129 #endif // _LIBCPP_NO_EXCEPTIONS
4133 template<class _Dp, class _Alloc>
4134 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4137 #ifndef _LIBCPP_NO_EXCEPTIONS
4140 #endif // _LIBCPP_NO_EXCEPTIONS
4141 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4142 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4143 typedef __allocator_destructor<_A2> _D2;
4145 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4146 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4147 _CntrlBlk(__p, __d, __a);
4148 __cntrl_ = _VSTD::addressof(*__hold2.release());
4149 #ifndef _LIBCPP_NO_EXCEPTIONS
4156 #endif // _LIBCPP_NO_EXCEPTIONS
4162 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4164 __cntrl_(__r.__cntrl_)
4167 __cntrl_->__add_shared();
4172 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4173 : __ptr_(__r.__ptr_),
4174 __cntrl_(__r.__cntrl_)
4177 __cntrl_->__add_shared();
4183 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4184 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4186 : __ptr_(__r.__ptr_),
4187 __cntrl_(__r.__cntrl_)
4190 __cntrl_->__add_shared();
4193 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4197 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4198 : __ptr_(__r.__ptr_),
4199 __cntrl_(__r.__cntrl_)
4208 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4209 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4211 : __ptr_(__r.__ptr_),
4212 __cntrl_(__r.__cntrl_)
4218 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4220 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4223 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4224 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4226 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4228 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4231 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4232 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4233 __enable_weak_this(__r.get(), __r.get());
4239 template <class _Yp, class _Dp>
4240 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4241 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4243 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4247 !is_lvalue_reference<_Dp>::value &&
4248 !is_array<_Yp>::value &&
4249 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4254 #if _LIBCPP_STD_VER > 11
4255 if (__ptr_ == nullptr)
4260 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4261 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4262 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4263 __enable_weak_this(__r.get(), __r.get());
4269 template <class _Yp, class _Dp>
4270 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4271 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4273 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4277 is_lvalue_reference<_Dp>::value &&
4278 !is_array<_Yp>::value &&
4279 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4284 #if _LIBCPP_STD_VER > 11
4285 if (__ptr_ == nullptr)
4290 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4291 typedef __shared_ptr_pointer<_Yp*,
4292 reference_wrapper<typename remove_reference<_Dp>::type>,
4293 _AllocT > _CntrlBlk;
4294 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4295 __enable_weak_this(__r.get(), __r.get());
4300 #ifndef _LIBCPP_HAS_NO_VARIADICS
4303 template<class ..._Args>
4305 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4307 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
4308 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4309 typedef allocator<_CntrlBlk> _A2;
4310 typedef __allocator_destructor<_A2> _D2;
4312 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4313 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4314 shared_ptr<_Tp> __r;
4315 __r.__ptr_ = __hold2.get()->get();
4316 __r.__cntrl_ = __hold2.release();
4317 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4322 template<class _Alloc, class ..._Args>
4324 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4326 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4327 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4328 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4329 typedef __allocator_destructor<_A2> _D2;
4331 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4332 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4333 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4334 shared_ptr<_Tp> __r;
4335 __r.__ptr_ = __hold2.get()->get();
4336 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4337 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4341 #else // _LIBCPP_HAS_NO_VARIADICS
4345 shared_ptr<_Tp>::make_shared()
4347 static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
4348 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4349 typedef allocator<_CntrlBlk> _Alloc2;
4350 typedef __allocator_destructor<_Alloc2> _D2;
4352 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4353 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4354 shared_ptr<_Tp> __r;
4355 __r.__ptr_ = __hold2.get()->get();
4356 __r.__cntrl_ = __hold2.release();
4357 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4364 shared_ptr<_Tp>::make_shared(_A0& __a0)
4366 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
4367 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4368 typedef allocator<_CntrlBlk> _Alloc2;
4369 typedef __allocator_destructor<_Alloc2> _D2;
4371 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4372 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4373 shared_ptr<_Tp> __r;
4374 __r.__ptr_ = __hold2.get()->get();
4375 __r.__cntrl_ = __hold2.release();
4376 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4381 template<class _A0, class _A1>
4383 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4385 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
4386 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4387 typedef allocator<_CntrlBlk> _Alloc2;
4388 typedef __allocator_destructor<_Alloc2> _D2;
4390 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4391 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4392 shared_ptr<_Tp> __r;
4393 __r.__ptr_ = __hold2.get()->get();
4394 __r.__cntrl_ = __hold2.release();
4395 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4400 template<class _A0, class _A1, class _A2>
4402 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4404 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
4405 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4406 typedef allocator<_CntrlBlk> _Alloc2;
4407 typedef __allocator_destructor<_Alloc2> _D2;
4409 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4410 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4411 shared_ptr<_Tp> __r;
4412 __r.__ptr_ = __hold2.get()->get();
4413 __r.__cntrl_ = __hold2.release();
4414 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4419 template<class _Alloc>
4421 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4423 static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
4424 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4425 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4426 typedef __allocator_destructor<_Alloc2> _D2;
4427 _Alloc2 __alloc2(__a);
4428 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4429 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4431 shared_ptr<_Tp> __r;
4432 __r.__ptr_ = __hold2.get()->get();
4433 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4434 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4439 template<class _Alloc, class _A0>
4441 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4443 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
4444 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4445 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4446 typedef __allocator_destructor<_Alloc2> _D2;
4447 _Alloc2 __alloc2(__a);
4448 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4449 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4450 _CntrlBlk(__a, __a0);
4451 shared_ptr<_Tp> __r;
4452 __r.__ptr_ = __hold2.get()->get();
4453 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4454 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4459 template<class _Alloc, class _A0, class _A1>
4461 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4463 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
4464 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4465 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4466 typedef __allocator_destructor<_Alloc2> _D2;
4467 _Alloc2 __alloc2(__a);
4468 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4469 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4470 _CntrlBlk(__a, __a0, __a1);
4471 shared_ptr<_Tp> __r;
4472 __r.__ptr_ = __hold2.get()->get();
4473 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4474 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4479 template<class _Alloc, class _A0, class _A1, class _A2>
4481 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4483 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
4484 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4485 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4486 typedef __allocator_destructor<_Alloc2> _D2;
4487 _Alloc2 __alloc2(__a);
4488 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4489 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4490 _CntrlBlk(__a, __a0, __a1, __a2);
4491 shared_ptr<_Tp> __r;
4492 __r.__ptr_ = __hold2.get()->get();
4493 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4494 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4498 #endif // _LIBCPP_HAS_NO_VARIADICS
4501 shared_ptr<_Tp>::~shared_ptr()
4504 __cntrl_->__release_shared();
4510 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4512 shared_ptr(__r).swap(*this);
4521 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4524 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4526 shared_ptr(__r).swap(*this);
4530 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4535 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4537 shared_ptr(_VSTD::move(__r)).swap(*this);
4546 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4549 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4551 shared_ptr(_VSTD::move(__r)).swap(*this);
4555 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4561 !is_array<_Yp>::value &&
4562 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4565 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4567 shared_ptr(_VSTD::move(__r)).swap(*this);
4573 template <class _Yp, class _Dp>
4577 !is_array<_Yp>::value &&
4578 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4579 typename shared_ptr<_Tp>::element_type*>::value,
4582 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4584 shared_ptr(_VSTD::move(__r)).swap(*this);
4588 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4590 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4593 inline _LIBCPP_INLINE_VISIBILITY
4596 !is_array<_Yp>::value &&
4597 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4600 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4602 shared_ptr(__r).swap(*this);
4608 template <class _Yp, class _Dp>
4609 inline _LIBCPP_INLINE_VISIBILITY
4612 !is_array<_Yp>::value &&
4613 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4614 typename shared_ptr<_Tp>::element_type*>::value,
4617 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4619 shared_ptr(_VSTD::move(__r)).swap(*this);
4623 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4628 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4630 _VSTD::swap(__ptr_, __r.__ptr_);
4631 _VSTD::swap(__cntrl_, __r.__cntrl_);
4637 shared_ptr<_Tp>::reset() _NOEXCEPT
4639 shared_ptr().swap(*this);
4647 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4650 shared_ptr<_Tp>::reset(_Yp* __p)
4652 shared_ptr(__p).swap(*this);
4656 template<class _Yp, class _Dp>
4660 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4663 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4665 shared_ptr(__p, __d).swap(*this);
4669 template<class _Yp, class _Dp, class _Alloc>
4673 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4676 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4678 shared_ptr(__p, __d, __a).swap(*this);
4681 #ifndef _LIBCPP_HAS_NO_VARIADICS
4683 template<class _Tp, class ..._Args>
4684 inline _LIBCPP_INLINE_VISIBILITY
4687 !is_array<_Tp>::value,
4690 make_shared(_Args&& ...__args)
4692 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4695 template<class _Tp, class _Alloc, class ..._Args>
4696 inline _LIBCPP_INLINE_VISIBILITY
4699 !is_array<_Tp>::value,
4702 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4704 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4707 #else // _LIBCPP_HAS_NO_VARIADICS
4710 inline _LIBCPP_INLINE_VISIBILITY
4714 return shared_ptr<_Tp>::make_shared();
4717 template<class _Tp, class _A0>
4718 inline _LIBCPP_INLINE_VISIBILITY
4720 make_shared(_A0& __a0)
4722 return shared_ptr<_Tp>::make_shared(__a0);
4725 template<class _Tp, class _A0, class _A1>
4726 inline _LIBCPP_INLINE_VISIBILITY
4728 make_shared(_A0& __a0, _A1& __a1)
4730 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4733 template<class _Tp, class _A0, class _A1, class _A2>
4734 inline _LIBCPP_INLINE_VISIBILITY
4736 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4738 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4741 template<class _Tp, class _Alloc>
4742 inline _LIBCPP_INLINE_VISIBILITY
4744 allocate_shared(const _Alloc& __a)
4746 return shared_ptr<_Tp>::allocate_shared(__a);
4749 template<class _Tp, class _Alloc, class _A0>
4750 inline _LIBCPP_INLINE_VISIBILITY
4752 allocate_shared(const _Alloc& __a, _A0& __a0)
4754 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4757 template<class _Tp, class _Alloc, class _A0, class _A1>
4758 inline _LIBCPP_INLINE_VISIBILITY
4760 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4762 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4765 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4766 inline _LIBCPP_INLINE_VISIBILITY
4768 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4770 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4773 #endif // _LIBCPP_HAS_NO_VARIADICS
4775 template<class _Tp, class _Up>
4776 inline _LIBCPP_INLINE_VISIBILITY
4778 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4780 return __x.get() == __y.get();
4783 template<class _Tp, class _Up>
4784 inline _LIBCPP_INLINE_VISIBILITY
4786 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4788 return !(__x == __y);
4791 template<class _Tp, class _Up>
4792 inline _LIBCPP_INLINE_VISIBILITY
4794 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4796 #if _LIBCPP_STD_VER <= 11
4797 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4798 return less<_Vp>()(__x.get(), __y.get());
4800 return less<>()(__x.get(), __y.get());
4805 template<class _Tp, class _Up>
4806 inline _LIBCPP_INLINE_VISIBILITY
4808 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4813 template<class _Tp, class _Up>
4814 inline _LIBCPP_INLINE_VISIBILITY
4816 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4818 return !(__y < __x);
4821 template<class _Tp, class _Up>
4822 inline _LIBCPP_INLINE_VISIBILITY
4824 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4826 return !(__x < __y);
4830 inline _LIBCPP_INLINE_VISIBILITY
4832 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4838 inline _LIBCPP_INLINE_VISIBILITY
4840 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4846 inline _LIBCPP_INLINE_VISIBILITY
4848 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4850 return static_cast<bool>(__x);
4854 inline _LIBCPP_INLINE_VISIBILITY
4856 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4858 return static_cast<bool>(__x);
4862 inline _LIBCPP_INLINE_VISIBILITY
4864 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4866 return less<_Tp*>()(__x.get(), nullptr);
4870 inline _LIBCPP_INLINE_VISIBILITY
4872 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4874 return less<_Tp*>()(nullptr, __x.get());
4878 inline _LIBCPP_INLINE_VISIBILITY
4880 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4882 return nullptr < __x;
4886 inline _LIBCPP_INLINE_VISIBILITY
4888 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4890 return __x < nullptr;
4894 inline _LIBCPP_INLINE_VISIBILITY
4896 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4898 return !(nullptr < __x);
4902 inline _LIBCPP_INLINE_VISIBILITY
4904 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4906 return !(__x < nullptr);
4910 inline _LIBCPP_INLINE_VISIBILITY
4912 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4914 return !(__x < nullptr);
4918 inline _LIBCPP_INLINE_VISIBILITY
4920 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4922 return !(nullptr < __x);
4926 inline _LIBCPP_INLINE_VISIBILITY
4928 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4933 template<class _Tp, class _Up>
4934 inline _LIBCPP_INLINE_VISIBILITY
4937 !is_array<_Tp>::value && !is_array<_Up>::value,
4940 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4942 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4945 template<class _Tp, class _Up>
4946 inline _LIBCPP_INLINE_VISIBILITY
4949 !is_array<_Tp>::value && !is_array<_Up>::value,
4952 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4954 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4955 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4958 template<class _Tp, class _Up>
4961 is_array<_Tp>::value == is_array<_Up>::value,
4964 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4966 typedef typename remove_extent<_Tp>::type _RTp;
4967 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4970 #ifndef _LIBCPP_NO_RTTI
4972 template<class _Dp, class _Tp>
4973 inline _LIBCPP_INLINE_VISIBILITY
4975 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4977 return __p.template __get_deleter<_Dp>();
4980 #endif // _LIBCPP_NO_RTTI
4983 class _LIBCPP_TEMPLATE_VIS weak_ptr
4986 typedef _Tp element_type;
4988 element_type* __ptr_;
4989 __shared_weak_count* __cntrl_;
4992 _LIBCPP_INLINE_VISIBILITY
4993 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4994 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4995 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4997 _LIBCPP_INLINE_VISIBILITY
4998 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4999 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
5000 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5003 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5004 _LIBCPP_INLINE_VISIBILITY
5005 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
5006 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
5007 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
5009 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5012 _LIBCPP_INLINE_VISIBILITY
5013 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
5017 is_convertible<_Yp*, element_type*>::value,
5020 _LIBCPP_INLINE_VISIBILITY
5021 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
5023 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5025 _LIBCPP_INLINE_VISIBILITY
5026 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
5030 is_convertible<_Yp*, element_type*>::value,
5033 _LIBCPP_INLINE_VISIBILITY
5034 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
5036 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5041 is_convertible<_Yp*, element_type*>::value,
5044 _LIBCPP_INLINE_VISIBILITY
5045 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5047 _LIBCPP_INLINE_VISIBILITY
5048 void swap(weak_ptr& __r) _NOEXCEPT;
5049 _LIBCPP_INLINE_VISIBILITY
5050 void reset() _NOEXCEPT;
5052 _LIBCPP_INLINE_VISIBILITY
5053 long use_count() const _NOEXCEPT
5054 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5055 _LIBCPP_INLINE_VISIBILITY
5056 bool expired() const _NOEXCEPT
5057 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5058 shared_ptr<_Tp> lock() const _NOEXCEPT;
5060 _LIBCPP_INLINE_VISIBILITY
5061 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
5062 {return __cntrl_ < __r.__cntrl_;}
5064 _LIBCPP_INLINE_VISIBILITY
5065 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
5066 {return __cntrl_ < __r.__cntrl_;}
5068 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5069 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
5075 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5083 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5084 : __ptr_(__r.__ptr_),
5085 __cntrl_(__r.__cntrl_)
5088 __cntrl_->__add_weak();
5094 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5095 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5097 : __ptr_(__r.__ptr_),
5098 __cntrl_(__r.__cntrl_)
5101 __cntrl_->__add_weak();
5107 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5108 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5110 : __ptr_(__r.__ptr_),
5111 __cntrl_(__r.__cntrl_)
5114 __cntrl_->__add_weak();
5117 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5121 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5122 : __ptr_(__r.__ptr_),
5123 __cntrl_(__r.__cntrl_)
5132 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5133 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5135 : __ptr_(__r.__ptr_),
5136 __cntrl_(__r.__cntrl_)
5142 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5145 weak_ptr<_Tp>::~weak_ptr()
5148 __cntrl_->__release_weak();
5154 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5156 weak_ptr(__r).swap(*this);
5165 is_convertible<_Yp*, _Tp*>::value,
5168 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5170 weak_ptr(__r).swap(*this);
5174 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5179 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5181 weak_ptr(_VSTD::move(__r)).swap(*this);
5190 is_convertible<_Yp*, _Tp*>::value,
5193 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5195 weak_ptr(_VSTD::move(__r)).swap(*this);
5199 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5206 is_convertible<_Yp*, _Tp*>::value,
5209 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5211 weak_ptr(__r).swap(*this);
5218 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5220 _VSTD::swap(__ptr_, __r.__ptr_);
5221 _VSTD::swap(__cntrl_, __r.__cntrl_);
5225 inline _LIBCPP_INLINE_VISIBILITY
5227 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5235 weak_ptr<_Tp>::reset() _NOEXCEPT
5237 weak_ptr().swap(*this);
5242 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5243 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5244 : __ptr_(__r.__ptr_),
5245 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5248 __throw_bad_weak_ptr();
5253 weak_ptr<_Tp>::lock() const _NOEXCEPT
5255 shared_ptr<_Tp> __r;
5256 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5258 __r.__ptr_ = __ptr_;
5262 #if _LIBCPP_STD_VER > 14
5263 template <class _Tp = void> struct owner_less;
5265 template <class _Tp> struct owner_less;
5268 template <class _Tp>
5269 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5270 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5272 typedef bool result_type;
5273 _LIBCPP_INLINE_VISIBILITY
5274 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5275 {return __x.owner_before(__y);}
5276 _LIBCPP_INLINE_VISIBILITY
5277 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5278 {return __x.owner_before(__y);}
5279 _LIBCPP_INLINE_VISIBILITY
5280 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5281 {return __x.owner_before(__y);}
5284 template <class _Tp>
5285 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5286 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5288 typedef bool result_type;
5289 _LIBCPP_INLINE_VISIBILITY
5290 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5291 {return __x.owner_before(__y);}
5292 _LIBCPP_INLINE_VISIBILITY
5293 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5294 {return __x.owner_before(__y);}
5295 _LIBCPP_INLINE_VISIBILITY
5296 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5297 {return __x.owner_before(__y);}
5300 #if _LIBCPP_STD_VER > 14
5302 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5304 template <class _Tp, class _Up>
5305 _LIBCPP_INLINE_VISIBILITY
5306 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5307 {return __x.owner_before(__y);}
5308 template <class _Tp, class _Up>
5309 _LIBCPP_INLINE_VISIBILITY
5310 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5311 {return __x.owner_before(__y);}
5312 template <class _Tp, class _Up>
5313 _LIBCPP_INLINE_VISIBILITY
5314 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5315 {return __x.owner_before(__y);}
5316 template <class _Tp, class _Up>
5317 _LIBCPP_INLINE_VISIBILITY
5318 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5319 {return __x.owner_before(__y);}
5320 typedef void is_transparent;
5325 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5327 mutable weak_ptr<_Tp> __weak_this_;
5329 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5330 enable_shared_from_this() _NOEXCEPT {}
5331 _LIBCPP_INLINE_VISIBILITY
5332 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5333 _LIBCPP_INLINE_VISIBILITY
5334 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5336 _LIBCPP_INLINE_VISIBILITY
5337 ~enable_shared_from_this() {}
5339 _LIBCPP_INLINE_VISIBILITY
5340 shared_ptr<_Tp> shared_from_this()
5341 {return shared_ptr<_Tp>(__weak_this_);}
5342 _LIBCPP_INLINE_VISIBILITY
5343 shared_ptr<_Tp const> shared_from_this() const
5344 {return shared_ptr<const _Tp>(__weak_this_);}
5346 #if _LIBCPP_STD_VER > 14
5347 _LIBCPP_INLINE_VISIBILITY
5348 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5349 { return __weak_this_; }
5351 _LIBCPP_INLINE_VISIBILITY
5352 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5353 { return __weak_this_; }
5354 #endif // _LIBCPP_STD_VER > 14
5356 template <class _Up> friend class shared_ptr;
5359 template <class _Tp>
5360 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5362 typedef shared_ptr<_Tp> argument_type;
5363 typedef size_t result_type;
5365 _LIBCPP_INLINE_VISIBILITY
5366 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5368 return hash<_Tp*>()(__ptr.get());
5372 template<class _CharT, class _Traits, class _Yp>
5373 inline _LIBCPP_INLINE_VISIBILITY
5374 basic_ostream<_CharT, _Traits>&
5375 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5378 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5380 class _LIBCPP_TYPE_VIS __sp_mut
5384 void lock() _NOEXCEPT;
5385 void unlock() _NOEXCEPT;
5388 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5389 __sp_mut(const __sp_mut&);
5390 __sp_mut& operator=(const __sp_mut&);
5392 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5395 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5396 __sp_mut& __get_sp_mut(const void*);
5398 template <class _Tp>
5399 inline _LIBCPP_INLINE_VISIBILITY
5401 atomic_is_lock_free(const shared_ptr<_Tp>*)
5406 template <class _Tp>
5407 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5409 atomic_load(const shared_ptr<_Tp>* __p)
5411 __sp_mut& __m = __get_sp_mut(__p);
5413 shared_ptr<_Tp> __q = *__p;
5418 template <class _Tp>
5419 inline _LIBCPP_INLINE_VISIBILITY
5420 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5422 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5424 return atomic_load(__p);
5427 template <class _Tp>
5428 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5430 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5432 __sp_mut& __m = __get_sp_mut(__p);
5438 template <class _Tp>
5439 inline _LIBCPP_INLINE_VISIBILITY
5440 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5442 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5444 atomic_store(__p, __r);
5447 template <class _Tp>
5448 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5450 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5452 __sp_mut& __m = __get_sp_mut(__p);
5459 template <class _Tp>
5460 inline _LIBCPP_INLINE_VISIBILITY
5461 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5463 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5465 return atomic_exchange(__p, __r);
5468 template <class _Tp>
5469 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5471 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5473 shared_ptr<_Tp> __temp;
5474 __sp_mut& __m = __get_sp_mut(__p);
5476 if (__p->__owner_equivalent(*__v))
5478 _VSTD::swap(__temp, *__p);
5483 _VSTD::swap(__temp, *__v);
5489 template <class _Tp>
5490 inline _LIBCPP_INLINE_VISIBILITY
5491 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5493 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5495 return atomic_compare_exchange_strong(__p, __v, __w);
5498 template <class _Tp>
5499 inline _LIBCPP_INLINE_VISIBILITY
5500 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5502 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5503 shared_ptr<_Tp> __w, memory_order, memory_order)
5505 return atomic_compare_exchange_strong(__p, __v, __w);
5508 template <class _Tp>
5509 inline _LIBCPP_INLINE_VISIBILITY
5510 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5512 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5513 shared_ptr<_Tp> __w, memory_order, memory_order)
5515 return atomic_compare_exchange_weak(__p, __v, __w);
5518 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5521 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5522 # ifndef _LIBCPP_CXX03_LANG
5523 enum class pointer_safety : unsigned char {
5530 struct _LIBCPP_TYPE_VIS pointer_safety
5541 _LIBCPP_INLINE_VISIBILITY
5542 pointer_safety() : __v_() {}
5544 _LIBCPP_INLINE_VISIBILITY
5545 pointer_safety(__lx __v) : __v_(__v) {}
5546 _LIBCPP_INLINE_VISIBILITY
5547 operator int() const {return __v_;}
5551 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5552 defined(_LIBCPP_BUILDING_LIBRARY)
5553 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5555 // This function is only offered in C++03 under ABI v1.
5556 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5557 inline _LIBCPP_INLINE_VISIBILITY
5558 pointer_safety get_pointer_safety() _NOEXCEPT {
5559 return pointer_safety::relaxed;
5565 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5566 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5567 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5568 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5570 template <class _Tp>
5571 inline _LIBCPP_INLINE_VISIBILITY
5573 undeclare_reachable(_Tp* __p)
5575 return static_cast<_Tp*>(__undeclare_reachable(__p));
5578 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5580 // --- Helper for container swap --
5581 template <typename _Alloc>
5582 inline _LIBCPP_INLINE_VISIBILITY
5583 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5584 #if _LIBCPP_STD_VER >= 14
5587 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5590 __swap_allocator(__a1, __a2,
5591 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5594 template <typename _Alloc>
5595 _LIBCPP_INLINE_VISIBILITY
5596 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5597 #if _LIBCPP_STD_VER >= 14
5600 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5607 template <typename _Alloc>
5608 inline _LIBCPP_INLINE_VISIBILITY
5609 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5611 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5612 struct __noexcept_move_assign_container : public integral_constant<bool,
5613 _Traits::propagate_on_container_move_assignment::value
5614 #if _LIBCPP_STD_VER > 14
5615 || _Traits::is_always_equal::value
5617 && is_nothrow_move_assignable<_Alloc>::value
5622 #ifndef _LIBCPP_HAS_NO_VARIADICS
5623 template <class _Tp, class _Alloc>
5624 struct __temp_value {
5625 typedef allocator_traits<_Alloc> _Traits;
5627 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5630 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5631 _Tp & get() { return *__addr(); }
5633 template<class... _Args>
5634 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5635 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5637 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5641 template<typename _Alloc, typename = void, typename = void>
5642 struct __is_allocator : false_type {};
5644 template<typename _Alloc>
5645 struct __is_allocator<_Alloc,
5646 typename __void_t<typename _Alloc::value_type>::type,
5647 typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
5651 _LIBCPP_END_NAMESPACE_STD
5655 #endif // _LIBCPP_MEMORY