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 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 allocator() noexcept;
130 allocator(const allocator&) noexcept;
131 template <class U> allocator(const allocator<U>&) noexcept;
133 pointer address(reference x) const noexcept;
134 const_pointer address(const_reference x) const noexcept;
135 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
136 void deallocate(pointer p, size_type n) noexcept;
137 size_type max_size() const noexcept;
138 template<class U, class... Args>
139 void construct(U* p, Args&&... args);
144 template <class T, class U>
145 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
147 template <class T, class U>
148 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
150 template <class OutputIterator, class T>
151 class raw_storage_iterator
152 : public iterator<output_iterator_tag,
153 T, // purposefully not C++03
154 ptrdiff_t, // purposefully not C++03
155 T*, // purposefully not C++03
156 raw_storage_iterator&> // purposefully not C++03
159 explicit raw_storage_iterator(OutputIterator x);
160 raw_storage_iterator& operator*();
161 raw_storage_iterator& operator=(const T& element);
162 raw_storage_iterator& operator++();
163 raw_storage_iterator operator++(int);
166 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
167 template <class T> void return_temporary_buffer(T* p) noexcept;
169 template <class T> T* addressof(T& r) noexcept;
170 template <class T> T* addressof(const T&& r) noexcept = delete;
172 template <class InputIterator, class ForwardIterator>
174 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
176 template <class InputIterator, class Size, class ForwardIterator>
178 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
180 template <class ForwardIterator, class T>
181 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
183 template <class ForwardIterator, class Size, class T>
185 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
188 void destroy_at(T* location);
190 template <class ForwardIterator>
191 void destroy(ForwardIterator first, ForwardIterator last);
193 template <class ForwardIterator, class Size>
194 ForwardIterator destroy_n(ForwardIterator first, Size n);
196 template <class InputIterator, class ForwardIterator>
197 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
199 template <class InputIterator, class Size, class ForwardIterator>
200 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
202 template <class ForwardIterator>
203 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
205 template <class ForwardIterator, class Size>
206 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
208 template <class ForwardIterator>
209 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
211 template <class ForwardIterator, class Size>
212 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
214 template <class Y> struct auto_ptr_ref {}; // removed in C++17
217 class auto_ptr // removed in C++17
220 typedef X element_type;
222 explicit auto_ptr(X* p =0) throw();
223 auto_ptr(auto_ptr&) throw();
224 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
225 auto_ptr& operator=(auto_ptr&) throw();
226 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
227 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
230 typename add_lvalue_reference<X>::type operator*() const throw();
231 X* operator->() const throw();
232 X* get() const throw();
233 X* release() throw();
234 void reset(X* p =0) throw();
236 auto_ptr(auto_ptr_ref<X>) throw();
237 template<class Y> operator auto_ptr_ref<Y>() throw();
238 template<class Y> operator auto_ptr<Y>() throw();
242 struct default_delete
244 constexpr default_delete() noexcept = default;
245 template <class U> default_delete(const default_delete<U>&) noexcept;
247 void operator()(T*) const noexcept;
251 struct default_delete<T[]>
253 constexpr default_delete() noexcept = default;
254 void operator()(T*) const noexcept;
255 template <class U> void operator()(U*) const = delete;
258 template <class T, class D = default_delete<T>>
262 typedef see below pointer;
263 typedef T element_type;
264 typedef D deleter_type;
267 constexpr unique_ptr() noexcept;
268 explicit unique_ptr(pointer p) noexcept;
269 unique_ptr(pointer p, see below d1) noexcept;
270 unique_ptr(pointer p, see below d2) noexcept;
271 unique_ptr(unique_ptr&& u) noexcept;
272 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
273 template <class U, class E>
274 unique_ptr(unique_ptr<U, E>&& u) noexcept;
276 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
282 unique_ptr& operator=(unique_ptr&& u) noexcept;
283 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
284 unique_ptr& operator=(nullptr_t) noexcept;
287 typename add_lvalue_reference<T>::type operator*() const;
288 pointer operator->() const noexcept;
289 pointer get() const noexcept;
290 deleter_type& get_deleter() noexcept;
291 const deleter_type& get_deleter() const noexcept;
292 explicit operator bool() const noexcept;
295 pointer release() noexcept;
296 void reset(pointer p = pointer()) noexcept;
297 void swap(unique_ptr& u) noexcept;
300 template <class T, class D>
301 class unique_ptr<T[], D>
304 typedef implementation-defined pointer;
305 typedef T element_type;
306 typedef D deleter_type;
309 constexpr unique_ptr() noexcept;
310 explicit unique_ptr(pointer p) noexcept;
311 unique_ptr(pointer p, see below d) noexcept;
312 unique_ptr(pointer p, see below d) noexcept;
313 unique_ptr(unique_ptr&& u) noexcept;
314 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
320 unique_ptr& operator=(unique_ptr&& u) noexcept;
321 unique_ptr& operator=(nullptr_t) noexcept;
324 T& operator[](size_t i) const;
325 pointer get() const noexcept;
326 deleter_type& get_deleter() noexcept;
327 const deleter_type& get_deleter() const noexcept;
328 explicit operator bool() const noexcept;
331 pointer release() noexcept;
332 void reset(pointer p = pointer()) noexcept;
333 void reset(nullptr_t) noexcept;
334 template <class U> void reset(U) = delete;
335 void swap(unique_ptr& u) noexcept;
338 template <class T, class D>
339 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
341 template <class T1, class D1, class T2, class D2>
342 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
343 template <class T1, class D1, class T2, class D2>
344 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
345 template <class T1, class D1, class T2, class D2>
346 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
347 template <class T1, class D1, class T2, class D2>
348 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
349 template <class T1, class D1, class T2, class D2>
350 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
351 template <class T1, class D1, class T2, class D2>
352 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
354 template <class T, class D>
355 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
356 template <class T, class D>
357 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
358 template <class T, class D>
359 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
360 template <class T, class D>
361 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
363 template <class T, class D>
364 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
365 template <class T, class D>
366 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
367 template <class T, class D>
368 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
369 template <class T, class D>
370 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
371 template <class T, class D>
372 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
373 template <class T, class D>
374 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
375 template <class T, class D>
376 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
377 template <class T, class D>
378 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
381 : public std::exception
383 bad_weak_ptr() noexcept;
386 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
387 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
388 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
390 template<class E, class T, class Y, class D>
391 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
397 typedef T element_type;
398 typedef weak_ptr<T> weak_type; // C++17
401 constexpr shared_ptr() noexcept;
402 template<class Y> explicit shared_ptr(Y* p);
403 template<class Y, class D> shared_ptr(Y* p, D d);
404 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
405 template <class D> shared_ptr(nullptr_t p, D d);
406 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
407 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
408 shared_ptr(const shared_ptr& r) noexcept;
409 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
410 shared_ptr(shared_ptr&& r) noexcept;
411 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
412 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
413 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
414 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
415 shared_ptr(nullptr_t) : shared_ptr() { }
421 shared_ptr& operator=(const shared_ptr& r) noexcept;
422 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
423 shared_ptr& operator=(shared_ptr&& r) noexcept;
424 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
425 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
426 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
429 void swap(shared_ptr& r) noexcept;
430 void reset() noexcept;
431 template<class Y> void reset(Y* p);
432 template<class Y, class D> void reset(Y* p, D d);
433 template<class Y, class D, class A> void reset(Y* p, D d, A a);
436 T* get() const noexcept;
437 T& operator*() const noexcept;
438 T* operator->() const noexcept;
439 long use_count() const noexcept;
440 bool unique() const noexcept;
441 explicit operator bool() const noexcept;
442 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
443 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
446 // shared_ptr comparisons:
447 template<class T, class U>
448 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
449 template<class T, class U>
450 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
451 template<class T, class U>
452 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
453 template<class T, class U>
454 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
455 template<class T, class U>
456 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
457 template<class T, class U>
458 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
461 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
463 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
465 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
467 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
469 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
471 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
473 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
475 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
477 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
479 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
481 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
483 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
485 // shared_ptr specialized algorithms:
486 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
489 template<class T, class U>
490 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
491 template<class T, class U>
492 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
493 template<class T, class U>
494 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
497 template<class E, class T, class Y>
498 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
500 // shared_ptr get_deleter:
501 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
503 template<class T, class... Args>
504 shared_ptr<T> make_shared(Args&&... args);
505 template<class T, class A, class... Args>
506 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
512 typedef T element_type;
515 constexpr weak_ptr() noexcept;
516 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
517 weak_ptr(weak_ptr const& r) noexcept;
518 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
519 weak_ptr(weak_ptr&& r) noexcept; // C++14
520 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
526 weak_ptr& operator=(weak_ptr const& r) noexcept;
527 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
528 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
529 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
530 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
533 void swap(weak_ptr& r) noexcept;
534 void reset() noexcept;
537 long use_count() const noexcept;
538 bool expired() const noexcept;
539 shared_ptr<T> lock() const noexcept;
540 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
541 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
544 // weak_ptr specialized algorithms:
545 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
548 template<class T> struct owner_less;
551 struct owner_less<shared_ptr<T>>
552 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
554 typedef bool result_type;
555 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
556 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
557 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
561 struct owner_less<weak_ptr<T>>
562 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
564 typedef bool result_type;
565 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
566 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
567 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
570 template <> // Added in C++14
571 struct owner_less<void>
573 template <class _Tp, class _Up>
574 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
575 template <class _Tp, class _Up>
576 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
577 template <class _Tp, class _Up>
578 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
579 template <class _Tp, class _Up>
580 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
582 typedef void is_transparent;
586 class enable_shared_from_this
589 constexpr enable_shared_from_this() noexcept;
590 enable_shared_from_this(enable_shared_from_this const&) noexcept;
591 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
592 ~enable_shared_from_this();
594 shared_ptr<T> shared_from_this();
595 shared_ptr<T const> shared_from_this() const;
599 bool atomic_is_lock_free(const shared_ptr<T>* p);
601 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
603 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
605 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
607 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
609 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
612 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
615 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
618 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
621 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
622 shared_ptr<T> w, memory_order success,
623 memory_order failure);
626 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
627 shared_ptr<T> w, memory_order success,
628 memory_order failure);
630 template <class T> struct hash;
631 template <class T, class D> struct hash<unique_ptr<T, D> >;
632 template <class T> struct hash<shared_ptr<T> >;
635 enum class pointer_safety { relaxed, preferred, strict };
636 void declare_reachable(void *p);
637 template <class T> T *undeclare_reachable(T *p);
638 void declare_no_pointers(char *p, size_t n);
639 void undeclare_no_pointers(char *p, size_t n);
640 pointer_safety get_pointer_safety() noexcept;
642 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
649 #include <type_traits>
657 #include <__functional_base>
663 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
667 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
668 #pragma GCC system_header
672 #include <__undef_macros>
675 _LIBCPP_BEGIN_NAMESPACE_STD
677 template <class _ValueType>
678 inline _LIBCPP_ALWAYS_INLINE
679 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
680 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
681 defined(__ATOMIC_RELAXED) && \
682 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
683 return __atomic_load_n(__value, __ATOMIC_RELAXED);
689 template <class _ValueType>
690 inline _LIBCPP_ALWAYS_INLINE
691 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
692 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
693 defined(__ATOMIC_ACQUIRE) && \
694 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
695 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
701 // addressof moved to <type_traits>
703 template <class _Tp> class allocator;
706 class _LIBCPP_TEMPLATE_VIS allocator<void>
709 typedef void* pointer;
710 typedef const void* const_pointer;
711 typedef void value_type;
713 template <class _Up> struct rebind {typedef allocator<_Up> other;};
717 class _LIBCPP_TEMPLATE_VIS allocator<const void>
720 typedef const void* pointer;
721 typedef const void* const_pointer;
722 typedef const void value_type;
724 template <class _Up> struct rebind {typedef allocator<_Up> other;};
729 template <class _Tp, class = void>
730 struct __has_element_type : false_type {};
733 struct __has_element_type<_Tp,
734 typename __void_t<typename _Tp::element_type>::type> : true_type {};
736 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
737 struct __pointer_traits_element_type;
739 template <class _Ptr>
740 struct __pointer_traits_element_type<_Ptr, true>
742 typedef typename _Ptr::element_type type;
745 #ifndef _LIBCPP_HAS_NO_VARIADICS
747 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
748 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
750 typedef typename _Sp<_Tp, _Args...>::element_type type;
753 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
754 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
759 #else // _LIBCPP_HAS_NO_VARIADICS
761 template <template <class> class _Sp, class _Tp>
762 struct __pointer_traits_element_type<_Sp<_Tp>, true>
764 typedef typename _Sp<_Tp>::element_type type;
767 template <template <class> class _Sp, class _Tp>
768 struct __pointer_traits_element_type<_Sp<_Tp>, false>
773 template <template <class, class> class _Sp, class _Tp, class _A0>
774 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
776 typedef typename _Sp<_Tp, _A0>::element_type type;
779 template <template <class, class> class _Sp, class _Tp, class _A0>
780 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
785 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
786 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
788 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
791 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
792 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
797 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
798 class _A1, class _A2>
799 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
801 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
804 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
805 class _A1, class _A2>
806 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
811 #endif // _LIBCPP_HAS_NO_VARIADICS
813 template <class _Tp, class = void>
814 struct __has_difference_type : false_type {};
817 struct __has_difference_type<_Tp,
818 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
820 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
821 struct __pointer_traits_difference_type
823 typedef ptrdiff_t type;
826 template <class _Ptr>
827 struct __pointer_traits_difference_type<_Ptr, true>
829 typedef typename _Ptr::difference_type type;
832 template <class _Tp, class _Up>
836 struct __two {char __lx; char __lxx;};
837 template <class _Xp> static __two __test(...);
838 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
840 static const bool value = sizeof(__test<_Tp>(0)) == 1;
843 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
844 struct __pointer_traits_rebind
846 #ifndef _LIBCPP_CXX03_LANG
847 typedef typename _Tp::template rebind<_Up> type;
849 typedef typename _Tp::template rebind<_Up>::other type;
853 #ifndef _LIBCPP_HAS_NO_VARIADICS
855 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
856 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
858 #ifndef _LIBCPP_CXX03_LANG
859 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
861 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
865 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
866 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
868 typedef _Sp<_Up, _Args...> type;
871 #else // _LIBCPP_HAS_NO_VARIADICS
873 template <template <class> class _Sp, class _Tp, class _Up>
874 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
876 #ifndef _LIBCPP_CXX03_LANG
877 typedef typename _Sp<_Tp>::template rebind<_Up> type;
879 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
883 template <template <class> class _Sp, class _Tp, class _Up>
884 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
886 typedef _Sp<_Up> type;
889 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
890 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
892 #ifndef _LIBCPP_CXX03_LANG
893 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
895 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
899 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
900 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
902 typedef _Sp<_Up, _A0> type;
905 template <template <class, class, class> class _Sp, class _Tp, class _A0,
906 class _A1, class _Up>
907 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
909 #ifndef _LIBCPP_CXX03_LANG
910 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
912 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
916 template <template <class, class, class> class _Sp, class _Tp, class _A0,
917 class _A1, class _Up>
918 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
920 typedef _Sp<_Up, _A0, _A1> type;
923 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
924 class _A1, class _A2, class _Up>
925 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
927 #ifndef _LIBCPP_CXX03_LANG
928 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
930 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
934 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
935 class _A1, class _A2, class _Up>
936 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
938 typedef _Sp<_Up, _A0, _A1, _A2> type;
941 #endif // _LIBCPP_HAS_NO_VARIADICS
943 template <class _Ptr>
944 struct _LIBCPP_TEMPLATE_VIS pointer_traits
946 typedef _Ptr pointer;
947 typedef typename __pointer_traits_element_type<pointer>::type element_type;
948 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
950 #ifndef _LIBCPP_CXX03_LANG
951 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
953 template <class _Up> struct rebind
954 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
955 #endif // _LIBCPP_CXX03_LANG
960 _LIBCPP_INLINE_VISIBILITY
961 static pointer pointer_to(typename conditional<is_void<element_type>::value,
962 __nat, element_type>::type& __r)
963 {return pointer::pointer_to(__r);}
967 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
969 typedef _Tp* pointer;
970 typedef _Tp element_type;
971 typedef ptrdiff_t difference_type;
973 #ifndef _LIBCPP_CXX03_LANG
974 template <class _Up> using rebind = _Up*;
976 template <class _Up> struct rebind {typedef _Up* other;};
982 _LIBCPP_INLINE_VISIBILITY
983 static pointer pointer_to(typename conditional<is_void<element_type>::value,
984 __nat, element_type>::type& __r) _NOEXCEPT
985 {return _VSTD::addressof(__r);}
988 template <class _From, class _To>
989 struct __rebind_pointer {
990 #ifndef _LIBCPP_CXX03_LANG
991 typedef typename pointer_traits<_From>::template rebind<_To> type;
993 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
999 template <class _Tp, class = void>
1000 struct __has_pointer_type : false_type {};
1002 template <class _Tp>
1003 struct __has_pointer_type<_Tp,
1004 typename __void_t<typename _Tp::pointer>::type> : true_type {};
1006 namespace __pointer_type_imp
1009 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1010 struct __pointer_type
1012 typedef typename _Dp::pointer type;
1015 template <class _Tp, class _Dp>
1016 struct __pointer_type<_Tp, _Dp, false>
1021 } // __pointer_type_imp
1023 template <class _Tp, class _Dp>
1024 struct __pointer_type
1026 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1029 template <class _Tp, class = void>
1030 struct __has_const_pointer : false_type {};
1032 template <class _Tp>
1033 struct __has_const_pointer<_Tp,
1034 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1036 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1037 struct __const_pointer
1039 typedef typename _Alloc::const_pointer type;
1042 template <class _Tp, class _Ptr, class _Alloc>
1043 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1045 #ifndef _LIBCPP_CXX03_LANG
1046 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1048 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1052 template <class _Tp, class = void>
1053 struct __has_void_pointer : false_type {};
1055 template <class _Tp>
1056 struct __has_void_pointer<_Tp,
1057 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1059 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1060 struct __void_pointer
1062 typedef typename _Alloc::void_pointer type;
1065 template <class _Ptr, class _Alloc>
1066 struct __void_pointer<_Ptr, _Alloc, false>
1068 #ifndef _LIBCPP_CXX03_LANG
1069 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1071 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1075 template <class _Tp, class = void>
1076 struct __has_const_void_pointer : false_type {};
1078 template <class _Tp>
1079 struct __has_const_void_pointer<_Tp,
1080 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1082 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1083 struct __const_void_pointer
1085 typedef typename _Alloc::const_void_pointer type;
1088 template <class _Ptr, class _Alloc>
1089 struct __const_void_pointer<_Ptr, _Alloc, false>
1091 #ifndef _LIBCPP_CXX03_LANG
1092 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1094 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1098 template <class _Tp>
1099 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1101 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1106 #if _LIBCPP_STD_VER <= 17
1107 template <class _Pointer>
1108 inline _LIBCPP_INLINE_VISIBILITY
1109 typename pointer_traits<_Pointer>::element_type*
1110 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1112 return _VSTD::__to_raw_pointer(__p.operator->());
1115 template <class _Pointer>
1116 inline _LIBCPP_INLINE_VISIBILITY
1118 __to_raw_pointer(const _Pointer& __p) _NOEXCEPT
1119 -> decltype(pointer_traits<_Pointer>::to_address(__p))
1121 return pointer_traits<_Pointer>::to_address(__p);
1124 template <class _Pointer, class... _None>
1125 inline _LIBCPP_INLINE_VISIBILITY
1127 __to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
1129 return _VSTD::__to_raw_pointer(__p.operator->());
1132 template <class _Tp>
1133 inline _LIBCPP_INLINE_VISIBILITY constexpr
1135 to_address(_Tp* __p) _NOEXCEPT
1137 static_assert(!is_function_v<_Tp>, "_Tp is a function type");
1141 template <class _Pointer>
1142 inline _LIBCPP_INLINE_VISIBILITY
1144 to_address(const _Pointer& __p) _NOEXCEPT
1146 return _VSTD::__to_raw_pointer(__p);
1150 template <class _Tp, class = void>
1151 struct __has_size_type : false_type {};
1153 template <class _Tp>
1154 struct __has_size_type<_Tp,
1155 typename __void_t<typename _Tp::size_type>::type> : true_type {};
1157 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1160 typedef typename make_unsigned<_DiffType>::type type;
1163 template <class _Alloc, class _DiffType>
1164 struct __size_type<_Alloc, _DiffType, true>
1166 typedef typename _Alloc::size_type type;
1169 template <class _Tp, class = void>
1170 struct __has_propagate_on_container_copy_assignment : false_type {};
1172 template <class _Tp>
1173 struct __has_propagate_on_container_copy_assignment<_Tp,
1174 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1177 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1178 struct __propagate_on_container_copy_assignment
1180 typedef false_type type;
1183 template <class _Alloc>
1184 struct __propagate_on_container_copy_assignment<_Alloc, true>
1186 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1189 template <class _Tp, class = void>
1190 struct __has_propagate_on_container_move_assignment : false_type {};
1192 template <class _Tp>
1193 struct __has_propagate_on_container_move_assignment<_Tp,
1194 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1197 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1198 struct __propagate_on_container_move_assignment
1200 typedef false_type type;
1203 template <class _Alloc>
1204 struct __propagate_on_container_move_assignment<_Alloc, true>
1206 typedef typename _Alloc::propagate_on_container_move_assignment type;
1209 template <class _Tp, class = void>
1210 struct __has_propagate_on_container_swap : false_type {};
1212 template <class _Tp>
1213 struct __has_propagate_on_container_swap<_Tp,
1214 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1217 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1218 struct __propagate_on_container_swap
1220 typedef false_type type;
1223 template <class _Alloc>
1224 struct __propagate_on_container_swap<_Alloc, true>
1226 typedef typename _Alloc::propagate_on_container_swap type;
1229 template <class _Tp, class = void>
1230 struct __has_is_always_equal : false_type {};
1232 template <class _Tp>
1233 struct __has_is_always_equal<_Tp,
1234 typename __void_t<typename _Tp::is_always_equal>::type>
1237 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1238 struct __is_always_equal
1240 typedef typename _VSTD::is_empty<_Alloc>::type type;
1243 template <class _Alloc>
1244 struct __is_always_equal<_Alloc, true>
1246 typedef typename _Alloc::is_always_equal type;
1249 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1250 struct __has_rebind_other
1253 struct __two {char __lx; char __lxx;};
1254 template <class _Xp> static __two __test(...);
1255 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1257 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1260 template <class _Tp, class _Up>
1261 struct __has_rebind_other<_Tp, _Up, false>
1263 static const bool value = false;
1266 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1267 struct __allocator_traits_rebind
1269 typedef typename _Tp::template rebind<_Up>::other type;
1272 #ifndef _LIBCPP_HAS_NO_VARIADICS
1274 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1275 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1277 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1280 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1281 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1283 typedef _Alloc<_Up, _Args...> type;
1286 #else // _LIBCPP_HAS_NO_VARIADICS
1288 template <template <class> class _Alloc, class _Tp, class _Up>
1289 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1291 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1294 template <template <class> class _Alloc, class _Tp, class _Up>
1295 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1297 typedef _Alloc<_Up> type;
1300 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1301 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1303 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1306 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1307 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1309 typedef _Alloc<_Up, _A0> type;
1312 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1313 class _A1, class _Up>
1314 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1316 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1319 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1320 class _A1, class _Up>
1321 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1323 typedef _Alloc<_Up, _A0, _A1> type;
1326 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1327 class _A1, class _A2, class _Up>
1328 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1330 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1333 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1334 class _A1, class _A2, class _Up>
1335 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1337 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1340 #endif // _LIBCPP_HAS_NO_VARIADICS
1342 #ifndef _LIBCPP_CXX03_LANG
1344 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1346 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1347 -> decltype((void)__a.allocate(__sz, __p), true_type());
1349 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1351 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1354 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1355 struct __has_allocate_hint
1356 : integral_constant<bool,
1358 decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
1359 declval<_SizeType>(),
1360 declval<_ConstVoidPtr>())),
1365 #else // _LIBCPP_CXX03_LANG
1367 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1368 struct __has_allocate_hint
1373 #endif // _LIBCPP_CXX03_LANG
1375 #if !defined(_LIBCPP_CXX03_LANG)
1377 template <class _Alloc, class _Tp, class ..._Args>
1378 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1379 _VSTD::declval<_Args>()...),
1381 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1383 template <class _Alloc, class _Pointer, class ..._Args>
1385 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1387 template <class _Alloc, class _Pointer, class ..._Args>
1388 struct __has_construct
1389 : integral_constant<bool,
1391 decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
1392 declval<_Pointer>(),
1393 declval<_Args>()...)),
1398 template <class _Alloc, class _Pointer>
1400 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1401 -> decltype(__a.destroy(__p), true_type());
1403 template <class _Alloc, class _Pointer>
1405 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1408 template <class _Alloc, class _Pointer>
1409 struct __has_destroy
1410 : integral_constant<bool,
1412 decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
1413 declval<_Pointer>())),
1418 template <class _Alloc>
1420 __has_max_size_test(_Alloc&& __a)
1421 -> decltype(__a.max_size(), true_type());
1423 template <class _Alloc>
1425 __has_max_size_test(const volatile _Alloc& __a)
1428 template <class _Alloc>
1429 struct __has_max_size
1430 : integral_constant<bool,
1432 decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
1437 template <class _Alloc>
1439 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1440 -> decltype(__a.select_on_container_copy_construction(), true_type());
1442 template <class _Alloc>
1444 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1447 template <class _Alloc>
1448 struct __has_select_on_container_copy_construction
1449 : integral_constant<bool,
1451 decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1456 #else // _LIBCPP_CXX03_LANG
1458 #ifndef _LIBCPP_HAS_NO_VARIADICS
1460 template <class _Alloc, class _Pointer, class ..._Args>
1461 struct __has_construct
1466 #else // _LIBCPP_HAS_NO_VARIADICS
1468 template <class _Alloc, class _Pointer, class _Args>
1469 struct __has_construct
1474 #endif // _LIBCPP_HAS_NO_VARIADICS
1476 template <class _Alloc, class _Pointer>
1477 struct __has_destroy
1482 template <class _Alloc>
1483 struct __has_max_size
1488 template <class _Alloc>
1489 struct __has_select_on_container_copy_construction
1494 #endif // _LIBCPP_CXX03_LANG
1496 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1497 struct __alloc_traits_difference_type
1499 typedef typename pointer_traits<_Ptr>::difference_type type;
1502 template <class _Alloc, class _Ptr>
1503 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1505 typedef typename _Alloc::difference_type type;
1508 template <class _Alloc>
1509 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1511 typedef _Alloc allocator_type;
1512 typedef typename allocator_type::value_type value_type;
1514 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1515 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1516 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1517 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1519 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1520 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1522 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1523 propagate_on_container_copy_assignment;
1524 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1525 propagate_on_container_move_assignment;
1526 typedef typename __propagate_on_container_swap<allocator_type>::type
1527 propagate_on_container_swap;
1528 typedef typename __is_always_equal<allocator_type>::type
1531 #ifndef _LIBCPP_CXX03_LANG
1532 template <class _Tp> using rebind_alloc =
1533 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1534 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1535 #else // _LIBCPP_CXX03_LANG
1536 template <class _Tp> struct rebind_alloc
1537 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1538 template <class _Tp> struct rebind_traits
1539 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1540 #endif // _LIBCPP_CXX03_LANG
1542 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1543 static pointer allocate(allocator_type& __a, size_type __n)
1544 {return __a.allocate(__n);}
1545 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1546 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1547 {return __allocate(__a, __n, __hint,
1548 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1550 _LIBCPP_INLINE_VISIBILITY
1551 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1552 {__a.deallocate(__p, __n);}
1554 #ifndef _LIBCPP_HAS_NO_VARIADICS
1555 template <class _Tp, class... _Args>
1556 _LIBCPP_INLINE_VISIBILITY
1557 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1558 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1559 __a, __p, _VSTD::forward<_Args>(__args)...);}
1560 #else // _LIBCPP_HAS_NO_VARIADICS
1561 template <class _Tp>
1562 _LIBCPP_INLINE_VISIBILITY
1563 static void construct(allocator_type&, _Tp* __p)
1565 ::new ((void*)__p) _Tp();
1567 template <class _Tp, class _A0>
1568 _LIBCPP_INLINE_VISIBILITY
1569 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
1571 ::new ((void*)__p) _Tp(__a0);
1573 template <class _Tp, class _A0, class _A1>
1574 _LIBCPP_INLINE_VISIBILITY
1575 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1578 ::new ((void*)__p) _Tp(__a0, __a1);
1580 template <class _Tp, class _A0, class _A1, class _A2>
1581 _LIBCPP_INLINE_VISIBILITY
1582 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1583 const _A1& __a1, const _A2& __a2)
1585 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1587 #endif // _LIBCPP_HAS_NO_VARIADICS
1589 template <class _Tp>
1590 _LIBCPP_INLINE_VISIBILITY
1591 static void destroy(allocator_type& __a, _Tp* __p)
1592 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1594 _LIBCPP_INLINE_VISIBILITY
1595 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1596 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1598 _LIBCPP_INLINE_VISIBILITY
1599 static allocator_type
1600 select_on_container_copy_construction(const allocator_type& __a)
1601 {return __select_on_container_copy_construction(
1602 __has_select_on_container_copy_construction<const allocator_type>(),
1605 template <class _Ptr>
1606 _LIBCPP_INLINE_VISIBILITY
1609 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1611 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1612 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1615 template <class _Tp>
1616 _LIBCPP_INLINE_VISIBILITY
1620 (is_same<allocator_type, allocator<_Tp> >::value
1621 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1622 is_trivially_move_constructible<_Tp>::value,
1625 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1627 ptrdiff_t _Np = __end1 - __begin1;
1630 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1635 template <class _Iter, class _Ptr>
1636 _LIBCPP_INLINE_VISIBILITY
1639 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1641 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1642 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1645 template <class _Tp>
1646 _LIBCPP_INLINE_VISIBILITY
1650 (is_same<allocator_type, allocator<_Tp> >::value
1651 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1652 is_trivially_move_constructible<_Tp>::value,
1655 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1657 typedef typename remove_const<_Tp>::type _Vp;
1658 ptrdiff_t _Np = __end1 - __begin1;
1661 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1666 template <class _Ptr>
1667 _LIBCPP_INLINE_VISIBILITY
1670 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1672 while (__end1 != __begin1)
1674 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1679 template <class _Tp>
1680 _LIBCPP_INLINE_VISIBILITY
1684 (is_same<allocator_type, allocator<_Tp> >::value
1685 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1686 is_trivially_move_constructible<_Tp>::value,
1689 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1691 ptrdiff_t _Np = __end1 - __begin1;
1694 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1699 _LIBCPP_INLINE_VISIBILITY
1700 static pointer __allocate(allocator_type& __a, size_type __n,
1701 const_void_pointer __hint, true_type)
1702 {return __a.allocate(__n, __hint);}
1703 _LIBCPP_INLINE_VISIBILITY
1704 static pointer __allocate(allocator_type& __a, size_type __n,
1705 const_void_pointer, false_type)
1706 {return __a.allocate(__n);}
1708 #ifndef _LIBCPP_HAS_NO_VARIADICS
1709 template <class _Tp, class... _Args>
1710 _LIBCPP_INLINE_VISIBILITY
1711 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1712 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1713 template <class _Tp, class... _Args>
1714 _LIBCPP_INLINE_VISIBILITY
1715 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1717 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1719 #endif // _LIBCPP_HAS_NO_VARIADICS
1721 template <class _Tp>
1722 _LIBCPP_INLINE_VISIBILITY
1723 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1725 template <class _Tp>
1726 _LIBCPP_INLINE_VISIBILITY
1727 static void __destroy(false_type, allocator_type&, _Tp* __p)
1732 _LIBCPP_INLINE_VISIBILITY
1733 static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
1734 {return __a.max_size();}
1735 _LIBCPP_INLINE_VISIBILITY
1736 static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
1737 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1739 _LIBCPP_INLINE_VISIBILITY
1740 static allocator_type
1741 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1742 {return __a.select_on_container_copy_construction();}
1743 _LIBCPP_INLINE_VISIBILITY
1744 static allocator_type
1745 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1749 template <class _Traits, class _Tp>
1750 struct __rebind_alloc_helper
1752 #ifndef _LIBCPP_CXX03_LANG
1753 typedef typename _Traits::template rebind_alloc<_Tp> type;
1755 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1761 template <class _Tp>
1762 class _LIBCPP_TEMPLATE_VIS allocator
1765 typedef size_t size_type;
1766 typedef ptrdiff_t difference_type;
1767 typedef _Tp* pointer;
1768 typedef const _Tp* const_pointer;
1769 typedef _Tp& reference;
1770 typedef const _Tp& const_reference;
1771 typedef _Tp value_type;
1773 typedef true_type propagate_on_container_move_assignment;
1774 typedef true_type is_always_equal;
1776 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1778 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1779 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1780 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1781 {return _VSTD::addressof(__x);}
1782 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1783 {return _VSTD::addressof(__x);}
1784 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1785 pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1787 if (__n > max_size())
1788 __throw_length_error("allocator<T>::allocate(size_t n)"
1789 " 'n' exceeds maximum supported size");
1790 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1792 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1793 {_VSTD::__libcpp_deallocate((void*)__p);}
1794 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1795 {return size_type(~0) / sizeof(_Tp);}
1796 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1797 template <class _Up, class... _Args>
1798 _LIBCPP_INLINE_VISIBILITY
1800 construct(_Up* __p, _Args&&... __args)
1802 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1804 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1805 _LIBCPP_INLINE_VISIBILITY
1807 construct(pointer __p)
1809 ::new((void*)__p) _Tp();
1811 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1813 template <class _A0>
1814 _LIBCPP_INLINE_VISIBILITY
1816 construct(pointer __p, _A0& __a0)
1818 ::new((void*)__p) _Tp(__a0);
1820 template <class _A0>
1821 _LIBCPP_INLINE_VISIBILITY
1823 construct(pointer __p, const _A0& __a0)
1825 ::new((void*)__p) _Tp(__a0);
1827 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1828 template <class _A0, class _A1>
1829 _LIBCPP_INLINE_VISIBILITY
1831 construct(pointer __p, _A0& __a0, _A1& __a1)
1833 ::new((void*)__p) _Tp(__a0, __a1);
1835 template <class _A0, class _A1>
1836 _LIBCPP_INLINE_VISIBILITY
1838 construct(pointer __p, const _A0& __a0, _A1& __a1)
1840 ::new((void*)__p) _Tp(__a0, __a1);
1842 template <class _A0, class _A1>
1843 _LIBCPP_INLINE_VISIBILITY
1845 construct(pointer __p, _A0& __a0, const _A1& __a1)
1847 ::new((void*)__p) _Tp(__a0, __a1);
1849 template <class _A0, class _A1>
1850 _LIBCPP_INLINE_VISIBILITY
1852 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1854 ::new((void*)__p) _Tp(__a0, __a1);
1856 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1857 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1860 template <class _Tp>
1861 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1864 typedef size_t size_type;
1865 typedef ptrdiff_t difference_type;
1866 typedef const _Tp* pointer;
1867 typedef const _Tp* const_pointer;
1868 typedef const _Tp& reference;
1869 typedef const _Tp& const_reference;
1870 typedef const _Tp value_type;
1872 typedef true_type propagate_on_container_move_assignment;
1873 typedef true_type is_always_equal;
1875 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1877 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1878 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1879 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1880 {return _VSTD::addressof(__x);}
1881 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1883 if (__n > max_size())
1884 __throw_length_error("allocator<const T>::allocate(size_t n)"
1885 " 'n' exceeds maximum supported size");
1886 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1888 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1889 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
1890 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1891 {return size_type(~0) / sizeof(_Tp);}
1892 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1893 template <class _Up, class... _Args>
1894 _LIBCPP_INLINE_VISIBILITY
1896 construct(_Up* __p, _Args&&... __args)
1898 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1900 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1901 _LIBCPP_INLINE_VISIBILITY
1903 construct(pointer __p)
1905 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1907 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1909 template <class _A0>
1910 _LIBCPP_INLINE_VISIBILITY
1912 construct(pointer __p, _A0& __a0)
1914 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1916 template <class _A0>
1917 _LIBCPP_INLINE_VISIBILITY
1919 construct(pointer __p, const _A0& __a0)
1921 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1923 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1924 template <class _A0, class _A1>
1925 _LIBCPP_INLINE_VISIBILITY
1927 construct(pointer __p, _A0& __a0, _A1& __a1)
1929 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1931 template <class _A0, class _A1>
1932 _LIBCPP_INLINE_VISIBILITY
1934 construct(pointer __p, const _A0& __a0, _A1& __a1)
1936 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1938 template <class _A0, class _A1>
1939 _LIBCPP_INLINE_VISIBILITY
1941 construct(pointer __p, _A0& __a0, const _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, const _A1& __a1)
1950 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1952 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1953 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1956 template <class _Tp, class _Up>
1957 inline _LIBCPP_INLINE_VISIBILITY
1958 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1960 template <class _Tp, class _Up>
1961 inline _LIBCPP_INLINE_VISIBILITY
1962 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1964 template <class _OutputIterator, class _Tp>
1965 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1966 : public iterator<output_iterator_tag,
1967 _Tp, // purposefully not C++03
1968 ptrdiff_t, // purposefully not C++03
1969 _Tp*, // purposefully not C++03
1970 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1973 _OutputIterator __x_;
1975 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1976 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1977 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1978 {::new(&*__x_) _Tp(__element); return *this;}
1979 #if _LIBCPP_STD_VER >= 14
1980 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1981 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1983 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1984 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1985 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1986 #if _LIBCPP_STD_VER >= 14
1987 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1991 template <class _Tp>
1992 pair<_Tp*, ptrdiff_t>
1993 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1995 pair<_Tp*, ptrdiff_t> __r(0, 0);
1996 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1997 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2003 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2014 template <class _Tp>
2015 inline _LIBCPP_INLINE_VISIBILITY
2016 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
2018 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2019 template <class _Tp>
2026 class _LIBCPP_TEMPLATE_VIS auto_ptr
2031 typedef _Tp element_type;
2033 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2034 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2035 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2036 : __ptr_(__p.release()) {}
2037 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2038 {reset(__p.release()); return *this;}
2039 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2040 {reset(__p.release()); return *this;}
2041 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2042 {reset(__p.__ptr_); return *this;}
2043 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2045 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2047 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2048 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2049 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2055 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2062 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2063 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2064 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2065 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2066 {return auto_ptr<_Up>(release());}
2070 class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
2073 typedef void element_type;
2077 template <class _Tp, int _Idx,
2078 bool _CanBeEmptyBase =
2079 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2080 struct __compressed_pair_elem {
2081 typedef _Tp _ParamT;
2082 typedef _Tp& reference;
2083 typedef const _Tp& const_reference;
2085 #ifndef _LIBCPP_CXX03_LANG
2086 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
2088 template <class _Up, class = typename enable_if<
2089 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2091 _LIBCPP_INLINE_VISIBILITY
2093 __compressed_pair_elem(_Up&& __u)
2094 : __value_(_VSTD::forward<_Up>(__u)){};
2096 template <class... _Args, size_t... _Indexes>
2097 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2098 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2099 __tuple_indices<_Indexes...>)
2100 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2102 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
2103 _LIBCPP_INLINE_VISIBILITY
2104 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2107 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
2108 _LIBCPP_INLINE_VISIBILITY
2109 const_reference __get() const _NOEXCEPT { return __value_; }
2115 template <class _Tp, int _Idx>
2116 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2117 typedef _Tp _ParamT;
2118 typedef _Tp& reference;
2119 typedef const _Tp& const_reference;
2120 typedef _Tp __value_type;
2122 #ifndef _LIBCPP_CXX03_LANG
2123 _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
2125 template <class _Up, class = typename enable_if<
2126 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2128 _LIBCPP_INLINE_VISIBILITY
2130 __compressed_pair_elem(_Up&& __u)
2131 : __value_type(_VSTD::forward<_Up>(__u)){};
2133 template <class... _Args, size_t... _Indexes>
2134 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2135 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2136 __tuple_indices<_Indexes...>)
2137 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2139 _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
2140 _LIBCPP_INLINE_VISIBILITY
2141 __compressed_pair_elem(_ParamT __p)
2142 : __value_type(std::forward<_ParamT>(__p)) {}
2145 _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
2146 _LIBCPP_INLINE_VISIBILITY
2147 const_reference __get() const _NOEXCEPT { return *this; }
2150 // Tag used to construct the second element of the compressed pair.
2151 struct __second_tag {};
2153 template <class _T1, class _T2>
2154 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2155 private __compressed_pair_elem<_T2, 1> {
2156 typedef __compressed_pair_elem<_T1, 0> _Base1;
2157 typedef __compressed_pair_elem<_T2, 1> _Base2;
2159 // NOTE: This static assert should never fire because __compressed_pair
2160 // is *almost never* used in a scenario where it's possible for T1 == T2.
2161 // (The exception is std::function where it is possible that the function
2162 // object and the allocator have the same type).
2163 static_assert((!is_same<_T1, _T2>::value),
2164 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2165 "The current implementation is NOT ABI-compatible with the previous "
2166 "implementation for this configuration");
2169 #ifndef _LIBCPP_CXX03_LANG
2170 template <bool _Dummy = true,
2171 class = typename enable_if<
2172 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2173 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2176 _LIBCPP_INLINE_VISIBILITY
2177 constexpr __compressed_pair() {}
2179 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2180 __compressed_pair>::value,
2182 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2183 __compressed_pair(_Tp&& __t)
2184 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2186 template <class _Tp>
2187 _LIBCPP_INLINE_VISIBILITY constexpr
2188 __compressed_pair(__second_tag, _Tp&& __t)
2189 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2191 template <class _U1, class _U2>
2192 _LIBCPP_INLINE_VISIBILITY constexpr
2193 __compressed_pair(_U1&& __t1, _U2&& __t2)
2194 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2196 template <class... _Args1, class... _Args2>
2197 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2198 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2199 tuple<_Args2...> __second_args)
2200 : _Base1(__pc, _VSTD::move(__first_args),
2201 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2202 _Base2(__pc, _VSTD::move(__second_args),
2203 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2206 _LIBCPP_INLINE_VISIBILITY
2207 __compressed_pair() {}
2209 _LIBCPP_INLINE_VISIBILITY explicit
2210 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2212 _LIBCPP_INLINE_VISIBILITY
2213 __compressed_pair(__second_tag, _T2 __t2)
2214 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2216 _LIBCPP_INLINE_VISIBILITY
2217 __compressed_pair(_T1 __t1, _T2 __t2)
2218 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2221 _LIBCPP_INLINE_VISIBILITY
2222 typename _Base1::reference first() _NOEXCEPT {
2223 return static_cast<_Base1&>(*this).__get();
2226 _LIBCPP_INLINE_VISIBILITY
2227 typename _Base1::const_reference first() const _NOEXCEPT {
2228 return static_cast<_Base1 const&>(*this).__get();
2231 _LIBCPP_INLINE_VISIBILITY
2232 typename _Base2::reference second() _NOEXCEPT {
2233 return static_cast<_Base2&>(*this).__get();
2236 _LIBCPP_INLINE_VISIBILITY
2237 typename _Base2::const_reference second() const _NOEXCEPT {
2238 return static_cast<_Base2 const&>(*this).__get();
2241 _LIBCPP_INLINE_VISIBILITY
2242 void swap(__compressed_pair& __x)
2243 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2244 __is_nothrow_swappable<_T2>::value)
2247 swap(first(), __x.first());
2248 swap(second(), __x.second());
2252 template <class _T1, class _T2>
2253 inline _LIBCPP_INLINE_VISIBILITY
2254 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2255 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2256 __is_nothrow_swappable<_T2>::value) {
2262 template <class _Tp>
2263 struct _LIBCPP_TEMPLATE_VIS default_delete {
2264 static_assert(!is_function<_Tp>::value,
2265 "default_delete cannot be instantiated for function types");
2266 #ifndef _LIBCPP_CXX03_LANG
2267 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2269 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2271 template <class _Up>
2272 _LIBCPP_INLINE_VISIBILITY
2273 default_delete(const default_delete<_Up>&,
2274 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2277 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2278 static_assert(sizeof(_Tp) > 0,
2279 "default_delete can not delete incomplete type");
2280 static_assert(!is_void<_Tp>::value,
2281 "default_delete can not delete incomplete type");
2286 template <class _Tp>
2287 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2289 template <class _Up>
2290 struct _EnableIfConvertible
2291 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2294 #ifndef _LIBCPP_CXX03_LANG
2295 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2297 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2300 template <class _Up>
2301 _LIBCPP_INLINE_VISIBILITY
2302 default_delete(const default_delete<_Up[]>&,
2303 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2305 template <class _Up>
2306 _LIBCPP_INLINE_VISIBILITY
2307 typename _EnableIfConvertible<_Up>::type
2308 operator()(_Up* __ptr) const _NOEXCEPT {
2309 static_assert(sizeof(_Tp) > 0,
2310 "default_delete can not delete incomplete type");
2311 static_assert(!is_void<_Tp>::value,
2312 "default_delete can not delete void type");
2319 #ifndef _LIBCPP_CXX03_LANG
2320 template <class _Deleter>
2321 struct __unique_ptr_deleter_sfinae {
2322 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2323 typedef const _Deleter& __lval_ref_type;
2324 typedef _Deleter&& __good_rval_ref_type;
2325 typedef true_type __enable_rval_overload;
2328 template <class _Deleter>
2329 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2330 typedef const _Deleter& __lval_ref_type;
2331 typedef const _Deleter&& __bad_rval_ref_type;
2332 typedef false_type __enable_rval_overload;
2335 template <class _Deleter>
2336 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2337 typedef _Deleter& __lval_ref_type;
2338 typedef _Deleter&& __bad_rval_ref_type;
2339 typedef false_type __enable_rval_overload;
2341 #endif // !defined(_LIBCPP_CXX03_LANG)
2343 template <class _Tp, class _Dp = default_delete<_Tp> >
2344 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2346 typedef _Tp element_type;
2347 typedef _Dp deleter_type;
2348 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2350 static_assert(!is_rvalue_reference<deleter_type>::value,
2351 "the specified deleter type cannot be an rvalue reference");
2354 __compressed_pair<pointer, deleter_type> __ptr_;
2356 struct __nat { int __for_bool_; };
2358 #ifndef _LIBCPP_CXX03_LANG
2359 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2361 template <bool _Dummy>
2362 using _LValRefType =
2363 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2365 template <bool _Dummy>
2366 using _GoodRValRefType =
2367 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2369 template <bool _Dummy>
2370 using _BadRValRefType =
2371 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2373 template <bool _Dummy, class _Deleter = typename __dependent_type<
2374 __identity<deleter_type>, _Dummy>::type>
2375 using _EnableIfDeleterDefaultConstructible =
2376 typename enable_if<is_default_constructible<_Deleter>::value &&
2377 !is_pointer<_Deleter>::value>::type;
2379 template <class _ArgType>
2380 using _EnableIfDeleterConstructible =
2381 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2383 template <class _UPtr, class _Up>
2384 using _EnableIfMoveConvertible = typename enable_if<
2385 is_convertible<typename _UPtr::pointer, pointer>::value &&
2386 !is_array<_Up>::value
2389 template <class _UDel>
2390 using _EnableIfDeleterConvertible = typename enable_if<
2391 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2392 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2395 template <class _UDel>
2396 using _EnableIfDeleterAssignable = typename enable_if<
2397 is_assignable<_Dp&, _UDel&&>::value
2401 template <bool _Dummy = true,
2402 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2403 _LIBCPP_INLINE_VISIBILITY
2404 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2406 template <bool _Dummy = true,
2407 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2408 _LIBCPP_INLINE_VISIBILITY
2409 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2411 template <bool _Dummy = true,
2412 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2413 _LIBCPP_INLINE_VISIBILITY
2414 explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2416 template <bool _Dummy = true,
2417 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2418 _LIBCPP_INLINE_VISIBILITY
2419 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2420 : __ptr_(__p, __d) {}
2422 template <bool _Dummy = true,
2423 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2424 _LIBCPP_INLINE_VISIBILITY
2425 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2426 : __ptr_(__p, _VSTD::move(__d)) {
2427 static_assert(!is_reference<deleter_type>::value,
2428 "rvalue deleter bound to reference");
2431 template <bool _Dummy = true,
2432 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2433 _LIBCPP_INLINE_VISIBILITY
2434 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2436 _LIBCPP_INLINE_VISIBILITY
2437 unique_ptr(unique_ptr&& __u) noexcept
2438 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2441 template <class _Up, class _Ep,
2442 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2443 class = _EnableIfDeleterConvertible<_Ep>
2445 _LIBCPP_INLINE_VISIBILITY
2446 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2447 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2449 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2450 template <class _Up>
2451 _LIBCPP_INLINE_VISIBILITY
2452 unique_ptr(auto_ptr<_Up>&& __p,
2453 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2454 is_same<_Dp, default_delete<_Tp>>::value,
2455 __nat>::type = __nat()) _NOEXCEPT
2456 : __ptr_(__p.release()) {}
2459 _LIBCPP_INLINE_VISIBILITY
2460 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2461 reset(__u.release());
2462 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2466 template <class _Up, class _Ep,
2467 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2468 class = _EnableIfDeleterAssignable<_Ep>
2470 _LIBCPP_INLINE_VISIBILITY
2471 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2472 reset(__u.release());
2473 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2477 #else // _LIBCPP_CXX03_LANG
2479 unique_ptr(unique_ptr&);
2480 template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2482 unique_ptr& operator=(unique_ptr&);
2483 template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2486 _LIBCPP_INLINE_VISIBILITY
2487 unique_ptr() : __ptr_(pointer())
2489 static_assert(!is_pointer<deleter_type>::value,
2490 "unique_ptr constructed with null function pointer deleter");
2491 static_assert(is_default_constructible<deleter_type>::value,
2492 "unique_ptr::deleter_type is not default constructible");
2494 _LIBCPP_INLINE_VISIBILITY
2495 unique_ptr(nullptr_t) : __ptr_(pointer())
2497 static_assert(!is_pointer<deleter_type>::value,
2498 "unique_ptr constructed with null function pointer deleter");
2500 _LIBCPP_INLINE_VISIBILITY
2501 explicit unique_ptr(pointer __p)
2502 : __ptr_(_VSTD::move(__p)) {
2503 static_assert(!is_pointer<deleter_type>::value,
2504 "unique_ptr constructed with null function pointer deleter");
2507 _LIBCPP_INLINE_VISIBILITY
2508 operator __rv<unique_ptr>() {
2509 return __rv<unique_ptr>(*this);
2512 _LIBCPP_INLINE_VISIBILITY
2513 unique_ptr(__rv<unique_ptr> __u)
2514 : __ptr_(__u->release(),
2515 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2517 template <class _Up, class _Ep>
2518 _LIBCPP_INLINE_VISIBILITY
2520 !is_array<_Up>::value &&
2521 is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2523 is_assignable<deleter_type&, _Ep&>::value,
2525 operator=(unique_ptr<_Up, _Ep> __u) {
2526 reset(__u.release());
2527 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2531 _LIBCPP_INLINE_VISIBILITY
2532 unique_ptr(pointer __p, deleter_type __d)
2533 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2534 #endif // _LIBCPP_CXX03_LANG
2536 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2537 template <class _Up>
2538 _LIBCPP_INLINE_VISIBILITY
2539 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2540 is_same<_Dp, default_delete<_Tp> >::value,
2542 operator=(auto_ptr<_Up> __p) {
2543 reset(__p.release());
2548 _LIBCPP_INLINE_VISIBILITY
2549 ~unique_ptr() { reset(); }
2551 _LIBCPP_INLINE_VISIBILITY
2552 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2557 _LIBCPP_INLINE_VISIBILITY
2558 typename add_lvalue_reference<_Tp>::type
2560 return *__ptr_.first();
2562 _LIBCPP_INLINE_VISIBILITY
2563 pointer operator->() const _NOEXCEPT {
2564 return __ptr_.first();
2566 _LIBCPP_INLINE_VISIBILITY
2567 pointer get() const _NOEXCEPT {
2568 return __ptr_.first();
2570 _LIBCPP_INLINE_VISIBILITY
2571 deleter_type& get_deleter() _NOEXCEPT {
2572 return __ptr_.second();
2574 _LIBCPP_INLINE_VISIBILITY
2575 const deleter_type& get_deleter() const _NOEXCEPT {
2576 return __ptr_.second();
2578 _LIBCPP_INLINE_VISIBILITY
2579 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2580 return __ptr_.first() != nullptr;
2583 _LIBCPP_INLINE_VISIBILITY
2584 pointer release() _NOEXCEPT {
2585 pointer __t = __ptr_.first();
2586 __ptr_.first() = pointer();
2590 _LIBCPP_INLINE_VISIBILITY
2591 void reset(pointer __p = pointer()) _NOEXCEPT {
2592 pointer __tmp = __ptr_.first();
2593 __ptr_.first() = __p;
2595 __ptr_.second()(__tmp);
2598 _LIBCPP_INLINE_VISIBILITY
2599 void swap(unique_ptr& __u) _NOEXCEPT {
2600 __ptr_.swap(__u.__ptr_);
2605 template <class _Tp, class _Dp>
2606 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2608 typedef _Tp element_type;
2609 typedef _Dp deleter_type;
2610 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2613 __compressed_pair<pointer, deleter_type> __ptr_;
2615 template <class _From>
2616 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2618 template <class _FromElem>
2619 struct _CheckArrayPointerConversion<_FromElem*>
2620 : integral_constant<bool,
2621 is_same<_FromElem*, pointer>::value ||
2622 (is_same<pointer, element_type*>::value &&
2623 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2627 #ifndef _LIBCPP_CXX03_LANG
2628 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2630 template <bool _Dummy>
2631 using _LValRefType =
2632 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2634 template <bool _Dummy>
2635 using _GoodRValRefType =
2636 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2638 template <bool _Dummy>
2639 using _BadRValRefType =
2640 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2642 template <bool _Dummy, class _Deleter = typename __dependent_type<
2643 __identity<deleter_type>, _Dummy>::type>
2644 using _EnableIfDeleterDefaultConstructible =
2645 typename enable_if<is_default_constructible<_Deleter>::value &&
2646 !is_pointer<_Deleter>::value>::type;
2648 template <class _ArgType>
2649 using _EnableIfDeleterConstructible =
2650 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2652 template <class _Pp>
2653 using _EnableIfPointerConvertible = typename enable_if<
2654 _CheckArrayPointerConversion<_Pp>::value
2657 template <class _UPtr, class _Up,
2658 class _ElemT = typename _UPtr::element_type>
2659 using _EnableIfMoveConvertible = typename enable_if<
2660 is_array<_Up>::value &&
2661 is_same<pointer, element_type*>::value &&
2662 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2663 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2666 template <class _UDel>
2667 using _EnableIfDeleterConvertible = typename enable_if<
2668 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2669 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2672 template <class _UDel>
2673 using _EnableIfDeleterAssignable = typename enable_if<
2674 is_assignable<_Dp&, _UDel&&>::value
2678 template <bool _Dummy = true,
2679 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2680 _LIBCPP_INLINE_VISIBILITY
2681 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2683 template <bool _Dummy = true,
2684 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2685 _LIBCPP_INLINE_VISIBILITY
2686 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2688 template <class _Pp, bool _Dummy = true,
2689 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2690 class = _EnableIfPointerConvertible<_Pp>>
2691 _LIBCPP_INLINE_VISIBILITY
2692 explicit unique_ptr(_Pp __p) noexcept
2695 template <class _Pp, bool _Dummy = true,
2696 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2697 class = _EnableIfPointerConvertible<_Pp>>
2698 _LIBCPP_INLINE_VISIBILITY
2699 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2700 : __ptr_(__p, __d) {}
2702 template <bool _Dummy = true,
2703 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2704 _LIBCPP_INLINE_VISIBILITY
2705 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2706 : __ptr_(nullptr, __d) {}
2708 template <class _Pp, bool _Dummy = true,
2709 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2710 class = _EnableIfPointerConvertible<_Pp>>
2711 _LIBCPP_INLINE_VISIBILITY
2712 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2713 : __ptr_(__p, _VSTD::move(__d)) {
2714 static_assert(!is_reference<deleter_type>::value,
2715 "rvalue deleter bound to reference");
2718 template <bool _Dummy = true,
2719 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2720 _LIBCPP_INLINE_VISIBILITY
2721 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2722 : __ptr_(nullptr, _VSTD::move(__d)) {
2723 static_assert(!is_reference<deleter_type>::value,
2724 "rvalue deleter bound to reference");
2727 template <class _Pp, bool _Dummy = true,
2728 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2729 class = _EnableIfPointerConvertible<_Pp>>
2730 _LIBCPP_INLINE_VISIBILITY
2731 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2733 _LIBCPP_INLINE_VISIBILITY
2734 unique_ptr(unique_ptr&& __u) noexcept
2735 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2738 _LIBCPP_INLINE_VISIBILITY
2739 unique_ptr& operator=(unique_ptr&& __u) noexcept {
2740 reset(__u.release());
2741 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2745 template <class _Up, class _Ep,
2746 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2747 class = _EnableIfDeleterConvertible<_Ep>
2749 _LIBCPP_INLINE_VISIBILITY
2750 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
2751 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2754 template <class _Up, class _Ep,
2755 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2756 class = _EnableIfDeleterAssignable<_Ep>
2758 _LIBCPP_INLINE_VISIBILITY
2760 operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2761 reset(__u.release());
2762 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2766 #else // _LIBCPP_CXX03_LANG
2768 template <class _Up> explicit unique_ptr(_Up);
2770 unique_ptr(unique_ptr&);
2771 template <class _Up> unique_ptr(unique_ptr<_Up>&);
2773 unique_ptr& operator=(unique_ptr&);
2774 template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2776 template <class _Up>
2778 typename conditional<
2779 is_reference<deleter_type>::value, deleter_type,
2780 typename add_lvalue_reference<const deleter_type>::type>::type,
2781 typename enable_if<is_convertible<_Up, pointer>::value,
2782 __nat>::type = __nat());
2784 _LIBCPP_INLINE_VISIBILITY
2785 unique_ptr() : __ptr_(pointer()) {
2786 static_assert(!is_pointer<deleter_type>::value,
2787 "unique_ptr constructed with null function pointer deleter");
2789 _LIBCPP_INLINE_VISIBILITY
2790 unique_ptr(nullptr_t) : __ptr_(pointer()) {
2791 static_assert(!is_pointer<deleter_type>::value,
2792 "unique_ptr constructed with null function pointer deleter");
2795 _LIBCPP_INLINE_VISIBILITY
2796 explicit unique_ptr(pointer __p) : __ptr_(__p) {
2797 static_assert(!is_pointer<deleter_type>::value,
2798 "unique_ptr constructed with null function pointer deleter");
2801 _LIBCPP_INLINE_VISIBILITY
2802 unique_ptr(pointer __p, deleter_type __d)
2803 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2805 _LIBCPP_INLINE_VISIBILITY
2806 unique_ptr(nullptr_t, deleter_type __d)
2807 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2809 _LIBCPP_INLINE_VISIBILITY
2810 operator __rv<unique_ptr>() {
2811 return __rv<unique_ptr>(*this);
2814 _LIBCPP_INLINE_VISIBILITY
2815 unique_ptr(__rv<unique_ptr> __u)
2816 : __ptr_(__u->release(),
2817 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2819 _LIBCPP_INLINE_VISIBILITY
2820 unique_ptr& operator=(__rv<unique_ptr> __u) {
2821 reset(__u->release());
2822 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2826 #endif // _LIBCPP_CXX03_LANG
2829 _LIBCPP_INLINE_VISIBILITY
2830 ~unique_ptr() { reset(); }
2832 _LIBCPP_INLINE_VISIBILITY
2833 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2838 _LIBCPP_INLINE_VISIBILITY
2839 typename add_lvalue_reference<_Tp>::type
2840 operator[](size_t __i) const {
2841 return __ptr_.first()[__i];
2843 _LIBCPP_INLINE_VISIBILITY
2844 pointer get() const _NOEXCEPT {
2845 return __ptr_.first();
2848 _LIBCPP_INLINE_VISIBILITY
2849 deleter_type& get_deleter() _NOEXCEPT {
2850 return __ptr_.second();
2853 _LIBCPP_INLINE_VISIBILITY
2854 const deleter_type& get_deleter() const _NOEXCEPT {
2855 return __ptr_.second();
2857 _LIBCPP_INLINE_VISIBILITY
2858 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2859 return __ptr_.first() != nullptr;
2862 _LIBCPP_INLINE_VISIBILITY
2863 pointer release() _NOEXCEPT {
2864 pointer __t = __ptr_.first();
2865 __ptr_.first() = pointer();
2869 template <class _Pp>
2870 _LIBCPP_INLINE_VISIBILITY
2872 _CheckArrayPointerConversion<_Pp>::value
2874 reset(_Pp __p) _NOEXCEPT {
2875 pointer __tmp = __ptr_.first();
2876 __ptr_.first() = __p;
2878 __ptr_.second()(__tmp);
2881 _LIBCPP_INLINE_VISIBILITY
2882 void reset(nullptr_t = nullptr) _NOEXCEPT {
2883 pointer __tmp = __ptr_.first();
2884 __ptr_.first() = nullptr;
2886 __ptr_.second()(__tmp);
2889 _LIBCPP_INLINE_VISIBILITY
2890 void swap(unique_ptr& __u) _NOEXCEPT {
2891 __ptr_.swap(__u.__ptr_);
2896 template <class _Tp, class _Dp>
2897 inline _LIBCPP_INLINE_VISIBILITY
2899 __is_swappable<_Dp>::value,
2902 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2904 template <class _T1, class _D1, class _T2, class _D2>
2905 inline _LIBCPP_INLINE_VISIBILITY
2907 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2909 template <class _T1, class _D1, class _T2, class _D2>
2910 inline _LIBCPP_INLINE_VISIBILITY
2912 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2914 template <class _T1, class _D1, class _T2, class _D2>
2915 inline _LIBCPP_INLINE_VISIBILITY
2917 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2919 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2920 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2921 typedef typename common_type<_P1, _P2>::type _Vp;
2922 return less<_Vp>()(__x.get(), __y.get());
2925 template <class _T1, class _D1, class _T2, class _D2>
2926 inline _LIBCPP_INLINE_VISIBILITY
2928 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2930 template <class _T1, class _D1, class _T2, class _D2>
2931 inline _LIBCPP_INLINE_VISIBILITY
2933 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2935 template <class _T1, class _D1, class _T2, class _D2>
2936 inline _LIBCPP_INLINE_VISIBILITY
2938 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2940 template <class _T1, class _D1>
2941 inline _LIBCPP_INLINE_VISIBILITY
2943 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2948 template <class _T1, class _D1>
2949 inline _LIBCPP_INLINE_VISIBILITY
2951 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2956 template <class _T1, class _D1>
2957 inline _LIBCPP_INLINE_VISIBILITY
2959 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2961 return static_cast<bool>(__x);
2964 template <class _T1, class _D1>
2965 inline _LIBCPP_INLINE_VISIBILITY
2967 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2969 return static_cast<bool>(__x);
2972 template <class _T1, class _D1>
2973 inline _LIBCPP_INLINE_VISIBILITY
2975 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2977 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2978 return less<_P1>()(__x.get(), nullptr);
2981 template <class _T1, class _D1>
2982 inline _LIBCPP_INLINE_VISIBILITY
2984 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2986 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2987 return less<_P1>()(nullptr, __x.get());
2990 template <class _T1, class _D1>
2991 inline _LIBCPP_INLINE_VISIBILITY
2993 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2995 return nullptr < __x;
2998 template <class _T1, class _D1>
2999 inline _LIBCPP_INLINE_VISIBILITY
3001 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3003 return __x < nullptr;
3006 template <class _T1, class _D1>
3007 inline _LIBCPP_INLINE_VISIBILITY
3009 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3011 return !(nullptr < __x);
3014 template <class _T1, class _D1>
3015 inline _LIBCPP_INLINE_VISIBILITY
3017 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3019 return !(__x < nullptr);
3022 template <class _T1, class _D1>
3023 inline _LIBCPP_INLINE_VISIBILITY
3025 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3027 return !(__x < nullptr);
3030 template <class _T1, class _D1>
3031 inline _LIBCPP_INLINE_VISIBILITY
3033 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3035 return !(nullptr < __x);
3038 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3040 template <class _Tp, class _Dp>
3041 inline _LIBCPP_INLINE_VISIBILITY
3042 unique_ptr<_Tp, _Dp>
3043 move(unique_ptr<_Tp, _Dp>& __t)
3045 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3050 #if _LIBCPP_STD_VER > 11
3055 typedef unique_ptr<_Tp> __unique_single;
3059 struct __unique_if<_Tp[]>
3061 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3064 template<class _Tp, size_t _Np>
3065 struct __unique_if<_Tp[_Np]>
3067 typedef void __unique_array_known_bound;
3070 template<class _Tp, class... _Args>
3071 inline _LIBCPP_INLINE_VISIBILITY
3072 typename __unique_if<_Tp>::__unique_single
3073 make_unique(_Args&&... __args)
3075 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3079 inline _LIBCPP_INLINE_VISIBILITY
3080 typename __unique_if<_Tp>::__unique_array_unknown_bound
3081 make_unique(size_t __n)
3083 typedef typename remove_extent<_Tp>::type _Up;
3084 return unique_ptr<_Tp>(new _Up[__n]());
3087 template<class _Tp, class... _Args>
3088 typename __unique_if<_Tp>::__unique_array_known_bound
3089 make_unique(_Args&&...) = delete;
3091 #endif // _LIBCPP_STD_VER > 11
3093 template <class _Tp, class _Dp>
3094 #ifdef _LIBCPP_CXX03_LANG
3095 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3097 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3098 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3101 typedef unique_ptr<_Tp, _Dp> argument_type;
3102 typedef size_t result_type;
3103 _LIBCPP_INLINE_VISIBILITY
3104 result_type operator()(const argument_type& __ptr) const
3106 typedef typename argument_type::pointer pointer;
3107 return hash<pointer>()(__ptr.get());
3116 template <class _Tp>
3117 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3118 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3120 template <class _Tp>
3121 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3124 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3126 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3129 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3131 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3134 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3137 template <class _Tp>
3138 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3139 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3141 template <class _Tp>
3142 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3143 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3145 template <class _Tp>
3146 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3147 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3150 template <class _Alloc>
3151 class __allocator_destructor
3153 typedef allocator_traits<_Alloc> __alloc_traits;
3155 typedef typename __alloc_traits::pointer pointer;
3156 typedef typename __alloc_traits::size_type size_type;
3161 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3163 : __alloc_(__a), __s_(__s) {}
3164 _LIBCPP_INLINE_VISIBILITY
3165 void operator()(pointer __p) _NOEXCEPT
3166 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3169 template <class _InputIterator, class _ForwardIterator>
3171 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3173 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3174 #ifndef _LIBCPP_NO_EXCEPTIONS
3175 _ForwardIterator __s = __r;
3179 for (; __f != __l; ++__f, (void) ++__r)
3180 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3181 #ifndef _LIBCPP_NO_EXCEPTIONS
3185 for (; __s != __r; ++__s)
3193 template <class _InputIterator, class _Size, class _ForwardIterator>
3195 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3197 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3198 #ifndef _LIBCPP_NO_EXCEPTIONS
3199 _ForwardIterator __s = __r;
3203 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3204 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3205 #ifndef _LIBCPP_NO_EXCEPTIONS
3209 for (; __s != __r; ++__s)
3217 template <class _ForwardIterator, class _Tp>
3219 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3221 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3222 #ifndef _LIBCPP_NO_EXCEPTIONS
3223 _ForwardIterator __s = __f;
3227 for (; __f != __l; ++__f)
3228 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3229 #ifndef _LIBCPP_NO_EXCEPTIONS
3233 for (; __s != __f; ++__s)
3240 template <class _ForwardIterator, class _Size, class _Tp>
3242 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3244 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3245 #ifndef _LIBCPP_NO_EXCEPTIONS
3246 _ForwardIterator __s = __f;
3250 for (; __n > 0; ++__f, (void) --__n)
3251 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3252 #ifndef _LIBCPP_NO_EXCEPTIONS
3256 for (; __s != __f; ++__s)
3264 #if _LIBCPP_STD_VER > 14
3266 template <class _Tp>
3267 inline _LIBCPP_INLINE_VISIBILITY
3268 void destroy_at(_Tp* __loc) {
3269 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3273 template <class _ForwardIterator>
3274 inline _LIBCPP_INLINE_VISIBILITY
3275 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3276 for (; __first != __last; ++__first)
3277 _VSTD::destroy_at(_VSTD::addressof(*__first));
3280 template <class _ForwardIterator, class _Size>
3281 inline _LIBCPP_INLINE_VISIBILITY
3282 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3283 for (; __n > 0; (void)++__first, --__n)
3284 _VSTD::destroy_at(_VSTD::addressof(*__first));
3288 template <class _ForwardIterator>
3289 inline _LIBCPP_INLINE_VISIBILITY
3290 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3291 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3292 auto __idx = __first;
3293 #ifndef _LIBCPP_NO_EXCEPTIONS
3296 for (; __idx != __last; ++__idx)
3297 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3298 #ifndef _LIBCPP_NO_EXCEPTIONS
3300 _VSTD::destroy(__first, __idx);
3306 template <class _ForwardIterator, class _Size>
3307 inline _LIBCPP_INLINE_VISIBILITY
3308 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3309 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3310 auto __idx = __first;
3311 #ifndef _LIBCPP_NO_EXCEPTIONS
3314 for (; __n > 0; (void)++__idx, --__n)
3315 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3317 #ifndef _LIBCPP_NO_EXCEPTIONS
3319 _VSTD::destroy(__first, __idx);
3326 template <class _ForwardIterator>
3327 inline _LIBCPP_INLINE_VISIBILITY
3328 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3329 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3330 auto __idx = __first;
3331 #ifndef _LIBCPP_NO_EXCEPTIONS
3334 for (; __idx != __last; ++__idx)
3335 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3336 #ifndef _LIBCPP_NO_EXCEPTIONS
3338 _VSTD::destroy(__first, __idx);
3344 template <class _ForwardIterator, class _Size>
3345 inline _LIBCPP_INLINE_VISIBILITY
3346 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3347 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3348 auto __idx = __first;
3349 #ifndef _LIBCPP_NO_EXCEPTIONS
3352 for (; __n > 0; (void)++__idx, --__n)
3353 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3355 #ifndef _LIBCPP_NO_EXCEPTIONS
3357 _VSTD::destroy(__first, __idx);
3364 template <class _InputIt, class _ForwardIt>
3365 inline _LIBCPP_INLINE_VISIBILITY
3366 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3367 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3368 auto __idx = __first_res;
3369 #ifndef _LIBCPP_NO_EXCEPTIONS
3372 for (; __first != __last; (void)++__idx, ++__first)
3373 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3375 #ifndef _LIBCPP_NO_EXCEPTIONS
3377 _VSTD::destroy(__first_res, __idx);
3383 template <class _InputIt, class _Size, class _ForwardIt>
3384 inline _LIBCPP_INLINE_VISIBILITY
3385 pair<_InputIt, _ForwardIt>
3386 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3387 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3388 auto __idx = __first_res;
3389 #ifndef _LIBCPP_NO_EXCEPTIONS
3392 for (; __n > 0; ++__idx, (void)++__first, --__n)
3393 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3394 return {__first, __idx};
3395 #ifndef _LIBCPP_NO_EXCEPTIONS
3397 _VSTD::destroy(__first_res, __idx);
3404 #endif // _LIBCPP_STD_VER > 14
3406 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3407 // should be sufficient for thread safety.
3408 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3409 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3410 && defined(__ATOMIC_RELAXED) \
3411 && defined(__ATOMIC_ACQ_REL)
3412 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3413 #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3414 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3417 template <class _Tp>
3418 inline _LIBCPP_INLINE_VISIBILITY _Tp
3419 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3421 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3422 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3428 template <class _Tp>
3429 inline _LIBCPP_INLINE_VISIBILITY _Tp
3430 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3432 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3433 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3439 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3440 : public std::exception
3443 virtual ~bad_weak_ptr() _NOEXCEPT;
3444 virtual const char* what() const _NOEXCEPT;
3447 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3448 void __throw_bad_weak_ptr()
3450 #ifndef _LIBCPP_NO_EXCEPTIONS
3451 throw bad_weak_ptr();
3457 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3459 class _LIBCPP_TYPE_VIS __shared_count
3461 __shared_count(const __shared_count&);
3462 __shared_count& operator=(const __shared_count&);
3465 long __shared_owners_;
3466 virtual ~__shared_count();
3468 virtual void __on_zero_shared() _NOEXCEPT = 0;
3471 _LIBCPP_INLINE_VISIBILITY
3472 explicit __shared_count(long __refs = 0) _NOEXCEPT
3473 : __shared_owners_(__refs) {}
3475 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3476 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3477 void __add_shared() _NOEXCEPT;
3478 bool __release_shared() _NOEXCEPT;
3480 _LIBCPP_INLINE_VISIBILITY
3481 void __add_shared() _NOEXCEPT {
3482 __libcpp_atomic_refcount_increment(__shared_owners_);
3484 _LIBCPP_INLINE_VISIBILITY
3485 bool __release_shared() _NOEXCEPT {
3486 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3493 _LIBCPP_INLINE_VISIBILITY
3494 long use_count() const _NOEXCEPT {
3495 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3499 class _LIBCPP_TYPE_VIS __shared_weak_count
3500 : private __shared_count
3502 long __shared_weak_owners_;
3505 _LIBCPP_INLINE_VISIBILITY
3506 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3507 : __shared_count(__refs),
3508 __shared_weak_owners_(__refs) {}
3510 virtual ~__shared_weak_count();
3513 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3514 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3515 void __add_shared() _NOEXCEPT;
3516 void __add_weak() _NOEXCEPT;
3517 void __release_shared() _NOEXCEPT;
3519 _LIBCPP_INLINE_VISIBILITY
3520 void __add_shared() _NOEXCEPT {
3521 __shared_count::__add_shared();
3523 _LIBCPP_INLINE_VISIBILITY
3524 void __add_weak() _NOEXCEPT {
3525 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3527 _LIBCPP_INLINE_VISIBILITY
3528 void __release_shared() _NOEXCEPT {
3529 if (__shared_count::__release_shared())
3533 void __release_weak() _NOEXCEPT;
3534 _LIBCPP_INLINE_VISIBILITY
3535 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3536 __shared_weak_count* lock() _NOEXCEPT;
3538 // Define the function out only if we build static libc++ without RTTI.
3539 // Otherwise we may break clients who need to compile their projects with
3540 // -fno-rtti and yet link against a libc++.dylib compiled
3541 // without -fno-rtti.
3542 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3543 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3546 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3549 template <class _Tp, class _Dp, class _Alloc>
3550 class __shared_ptr_pointer
3551 : public __shared_weak_count
3553 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3555 _LIBCPP_INLINE_VISIBILITY
3556 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3557 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3559 #ifndef _LIBCPP_NO_RTTI
3560 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3564 virtual void __on_zero_shared() _NOEXCEPT;
3565 virtual void __on_zero_shared_weak() _NOEXCEPT;
3568 #ifndef _LIBCPP_NO_RTTI
3570 template <class _Tp, class _Dp, class _Alloc>
3572 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3574 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3577 #endif // _LIBCPP_NO_RTTI
3579 template <class _Tp, class _Dp, class _Alloc>
3581 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3583 __data_.first().second()(__data_.first().first());
3584 __data_.first().second().~_Dp();
3587 template <class _Tp, class _Dp, class _Alloc>
3589 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3591 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3592 typedef allocator_traits<_Al> _ATraits;
3593 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3595 _Al __a(__data_.second());
3596 __data_.second().~_Alloc();
3597 __a.deallocate(_PTraits::pointer_to(*this), 1);
3600 template <class _Tp, class _Alloc>
3601 class __shared_ptr_emplace
3602 : public __shared_weak_count
3604 __compressed_pair<_Alloc, _Tp> __data_;
3606 #ifndef _LIBCPP_HAS_NO_VARIADICS
3608 _LIBCPP_INLINE_VISIBILITY
3609 __shared_ptr_emplace(_Alloc __a)
3610 : __data_(_VSTD::move(__a)) {}
3612 template <class ..._Args>
3613 _LIBCPP_INLINE_VISIBILITY
3614 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3615 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3616 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3618 #else // _LIBCPP_HAS_NO_VARIADICS
3620 _LIBCPP_INLINE_VISIBILITY
3621 __shared_ptr_emplace(_Alloc __a)
3624 template <class _A0>
3625 _LIBCPP_INLINE_VISIBILITY
3626 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3627 : __data_(__a, _Tp(__a0)) {}
3629 template <class _A0, class _A1>
3630 _LIBCPP_INLINE_VISIBILITY
3631 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3632 : __data_(__a, _Tp(__a0, __a1)) {}
3634 template <class _A0, class _A1, class _A2>
3635 _LIBCPP_INLINE_VISIBILITY
3636 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3637 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3639 #endif // _LIBCPP_HAS_NO_VARIADICS
3642 virtual void __on_zero_shared() _NOEXCEPT;
3643 virtual void __on_zero_shared_weak() _NOEXCEPT;
3645 _LIBCPP_INLINE_VISIBILITY
3646 _Tp* get() _NOEXCEPT {return &__data_.second();}
3649 template <class _Tp, class _Alloc>
3651 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3653 __data_.second().~_Tp();
3656 template <class _Tp, class _Alloc>
3658 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3660 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3661 typedef allocator_traits<_Al> _ATraits;
3662 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3663 _Al __a(__data_.first());
3664 __data_.first().~_Alloc();
3665 __a.deallocate(_PTraits::pointer_to(*this), 1);
3668 struct __shared_ptr_dummy_rebind_allocator_type;
3670 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3673 template <class _Other>
3676 typedef allocator<_Other> other;
3680 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3683 class _LIBCPP_TEMPLATE_VIS shared_ptr
3686 typedef _Tp element_type;
3688 #if _LIBCPP_STD_VER > 14
3689 typedef weak_ptr<_Tp> weak_type;
3692 element_type* __ptr_;
3693 __shared_weak_count* __cntrl_;
3695 struct __nat {int __for_bool_;};
3697 _LIBCPP_INLINE_VISIBILITY
3698 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3699 _LIBCPP_INLINE_VISIBILITY
3700 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3702 explicit shared_ptr(_Yp* __p,
3703 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3704 template<class _Yp, class _Dp>
3705 shared_ptr(_Yp* __p, _Dp __d,
3706 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3707 template<class _Yp, class _Dp, class _Alloc>
3708 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3709 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3710 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3711 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3712 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3713 _LIBCPP_INLINE_VISIBILITY
3714 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3716 _LIBCPP_INLINE_VISIBILITY
3717 shared_ptr(const shared_ptr<_Yp>& __r,
3718 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3720 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3721 _LIBCPP_INLINE_VISIBILITY
3722 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3723 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3724 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3726 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3727 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3728 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3729 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3730 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3732 shared_ptr(auto_ptr<_Yp>&& __r,
3733 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3736 shared_ptr(auto_ptr<_Yp> __r,
3737 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3740 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3741 template <class _Yp, class _Dp>
3742 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3745 !is_lvalue_reference<_Dp>::value &&
3746 !is_array<_Yp>::value &&
3747 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3750 template <class _Yp, class _Dp>
3751 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3754 is_lvalue_reference<_Dp>::value &&
3755 !is_array<_Yp>::value &&
3756 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3759 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3760 template <class _Yp, class _Dp>
3761 shared_ptr(unique_ptr<_Yp, _Dp>,
3764 !is_lvalue_reference<_Dp>::value &&
3765 !is_array<_Yp>::value &&
3766 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3769 template <class _Yp, class _Dp>
3770 shared_ptr(unique_ptr<_Yp, _Dp>,
3773 is_lvalue_reference<_Dp>::value &&
3774 !is_array<_Yp>::value &&
3775 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3778 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3782 _LIBCPP_INLINE_VISIBILITY
3783 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3787 is_convertible<_Yp*, element_type*>::value,
3790 _LIBCPP_INLINE_VISIBILITY
3791 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3792 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3793 _LIBCPP_INLINE_VISIBILITY
3794 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3798 is_convertible<_Yp*, element_type*>::value,
3801 _LIBCPP_INLINE_VISIBILITY
3802 operator=(shared_ptr<_Yp>&& __r);
3803 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3805 _LIBCPP_INLINE_VISIBILITY
3808 !is_array<_Yp>::value &&
3809 is_convertible<_Yp*, element_type*>::value,
3812 operator=(auto_ptr<_Yp>&& __r);
3814 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3815 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3817 _LIBCPP_INLINE_VISIBILITY
3820 !is_array<_Yp>::value &&
3821 is_convertible<_Yp*, element_type*>::value,
3824 operator=(auto_ptr<_Yp> __r);
3827 template <class _Yp, class _Dp>
3830 !is_array<_Yp>::value &&
3831 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3834 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3835 _LIBCPP_INLINE_VISIBILITY
3836 operator=(unique_ptr<_Yp, _Dp>&& __r);
3837 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3838 _LIBCPP_INLINE_VISIBILITY
3839 operator=(unique_ptr<_Yp, _Dp> __r);
3842 _LIBCPP_INLINE_VISIBILITY
3843 void swap(shared_ptr& __r) _NOEXCEPT;
3844 _LIBCPP_INLINE_VISIBILITY
3845 void reset() _NOEXCEPT;
3849 is_convertible<_Yp*, element_type*>::value,
3852 _LIBCPP_INLINE_VISIBILITY
3854 template<class _Yp, class _Dp>
3857 is_convertible<_Yp*, element_type*>::value,
3860 _LIBCPP_INLINE_VISIBILITY
3861 reset(_Yp* __p, _Dp __d);
3862 template<class _Yp, class _Dp, class _Alloc>
3865 is_convertible<_Yp*, element_type*>::value,
3868 _LIBCPP_INLINE_VISIBILITY
3869 reset(_Yp* __p, _Dp __d, _Alloc __a);
3871 _LIBCPP_INLINE_VISIBILITY
3872 element_type* get() const _NOEXCEPT {return __ptr_;}
3873 _LIBCPP_INLINE_VISIBILITY
3874 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3876 _LIBCPP_INLINE_VISIBILITY
3877 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3878 _LIBCPP_INLINE_VISIBILITY
3879 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3880 _LIBCPP_INLINE_VISIBILITY
3881 bool unique() const _NOEXCEPT {return use_count() == 1;}
3882 _LIBCPP_INLINE_VISIBILITY
3883 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3884 template <class _Up>
3885 _LIBCPP_INLINE_VISIBILITY
3886 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3887 {return __cntrl_ < __p.__cntrl_;}
3888 template <class _Up>
3889 _LIBCPP_INLINE_VISIBILITY
3890 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3891 {return __cntrl_ < __p.__cntrl_;}
3892 _LIBCPP_INLINE_VISIBILITY
3894 __owner_equivalent(const shared_ptr& __p) const
3895 {return __cntrl_ == __p.__cntrl_;}
3897 #ifndef _LIBCPP_NO_RTTI
3898 template <class _Dp>
3899 _LIBCPP_INLINE_VISIBILITY
3900 _Dp* __get_deleter() const _NOEXCEPT
3901 {return static_cast<_Dp*>(__cntrl_
3902 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3904 #endif // _LIBCPP_NO_RTTI
3906 #ifndef _LIBCPP_HAS_NO_VARIADICS
3908 template<class ..._Args>
3911 make_shared(_Args&& ...__args);
3913 template<class _Alloc, class ..._Args>
3916 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3918 #else // _LIBCPP_HAS_NO_VARIADICS
3920 static shared_ptr<_Tp> make_shared();
3923 static shared_ptr<_Tp> make_shared(_A0&);
3925 template<class _A0, class _A1>
3926 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3928 template<class _A0, class _A1, class _A2>
3929 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3931 template<class _Alloc>
3932 static shared_ptr<_Tp>
3933 allocate_shared(const _Alloc& __a);
3935 template<class _Alloc, class _A0>
3936 static shared_ptr<_Tp>
3937 allocate_shared(const _Alloc& __a, _A0& __a0);
3939 template<class _Alloc, class _A0, class _A1>
3940 static shared_ptr<_Tp>
3941 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3943 template<class _Alloc, class _A0, class _A1, class _A2>
3944 static shared_ptr<_Tp>
3945 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3947 #endif // _LIBCPP_HAS_NO_VARIADICS
3950 template <class _Yp, bool = is_function<_Yp>::value>
3951 struct __shared_ptr_default_allocator
3953 typedef allocator<_Yp> type;
3956 template <class _Yp>
3957 struct __shared_ptr_default_allocator<_Yp, true>
3959 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3962 template <class _Yp, class _OrigPtr>
3963 _LIBCPP_INLINE_VISIBILITY
3964 typename enable_if<is_convertible<_OrigPtr*,
3965 const enable_shared_from_this<_Yp>*
3968 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3969 _OrigPtr* __ptr) _NOEXCEPT
3971 typedef typename remove_cv<_Yp>::type _RawYp;
3972 if (__e && __e->__weak_this_.expired())
3974 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3975 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
3979 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
3981 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3982 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
3989 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3998 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
4006 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
4007 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4010 unique_ptr<_Yp> __hold(__p);
4011 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4012 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
4013 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
4015 __enable_weak_this(__p, __p);
4019 template<class _Yp, class _Dp>
4020 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4021 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4024 #ifndef _LIBCPP_NO_EXCEPTIONS
4027 #endif // _LIBCPP_NO_EXCEPTIONS
4028 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4029 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4030 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4031 __enable_weak_this(__p, __p);
4032 #ifndef _LIBCPP_NO_EXCEPTIONS
4039 #endif // _LIBCPP_NO_EXCEPTIONS
4044 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4047 #ifndef _LIBCPP_NO_EXCEPTIONS
4050 #endif // _LIBCPP_NO_EXCEPTIONS
4051 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4052 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4053 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4054 #ifndef _LIBCPP_NO_EXCEPTIONS
4061 #endif // _LIBCPP_NO_EXCEPTIONS
4065 template<class _Yp, class _Dp, class _Alloc>
4066 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4067 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4070 #ifndef _LIBCPP_NO_EXCEPTIONS
4073 #endif // _LIBCPP_NO_EXCEPTIONS
4074 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4075 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4076 typedef __allocator_destructor<_A2> _D2;
4078 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4079 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4080 _CntrlBlk(__p, __d, __a);
4081 __cntrl_ = _VSTD::addressof(*__hold2.release());
4082 __enable_weak_this(__p, __p);
4083 #ifndef _LIBCPP_NO_EXCEPTIONS
4090 #endif // _LIBCPP_NO_EXCEPTIONS
4094 template<class _Dp, class _Alloc>
4095 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4098 #ifndef _LIBCPP_NO_EXCEPTIONS
4101 #endif // _LIBCPP_NO_EXCEPTIONS
4102 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4103 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4104 typedef __allocator_destructor<_A2> _D2;
4106 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4107 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4108 _CntrlBlk(__p, __d, __a);
4109 __cntrl_ = _VSTD::addressof(*__hold2.release());
4110 #ifndef _LIBCPP_NO_EXCEPTIONS
4117 #endif // _LIBCPP_NO_EXCEPTIONS
4123 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4125 __cntrl_(__r.__cntrl_)
4128 __cntrl_->__add_shared();
4133 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4134 : __ptr_(__r.__ptr_),
4135 __cntrl_(__r.__cntrl_)
4138 __cntrl_->__add_shared();
4144 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4145 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4147 : __ptr_(__r.__ptr_),
4148 __cntrl_(__r.__cntrl_)
4151 __cntrl_->__add_shared();
4154 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4158 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4159 : __ptr_(__r.__ptr_),
4160 __cntrl_(__r.__cntrl_)
4169 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4170 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4172 : __ptr_(__r.__ptr_),
4173 __cntrl_(__r.__cntrl_)
4179 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4181 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4184 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4185 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4187 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4189 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4192 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4193 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4194 __enable_weak_this(__r.get(), __r.get());
4200 template <class _Yp, class _Dp>
4201 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4202 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4204 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4208 !is_lvalue_reference<_Dp>::value &&
4209 !is_array<_Yp>::value &&
4210 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4215 #if _LIBCPP_STD_VER > 11
4216 if (__ptr_ == nullptr)
4221 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4222 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4223 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4224 __enable_weak_this(__r.get(), __r.get());
4230 template <class _Yp, class _Dp>
4231 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4232 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4234 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4238 is_lvalue_reference<_Dp>::value &&
4239 !is_array<_Yp>::value &&
4240 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4245 #if _LIBCPP_STD_VER > 11
4246 if (__ptr_ == nullptr)
4251 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4252 typedef __shared_ptr_pointer<_Yp*,
4253 reference_wrapper<typename remove_reference<_Dp>::type>,
4254 _AllocT > _CntrlBlk;
4255 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4256 __enable_weak_this(__r.get(), __r.get());
4261 #ifndef _LIBCPP_HAS_NO_VARIADICS
4264 template<class ..._Args>
4266 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4268 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" );
4269 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4270 typedef allocator<_CntrlBlk> _A2;
4271 typedef __allocator_destructor<_A2> _D2;
4273 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4274 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4275 shared_ptr<_Tp> __r;
4276 __r.__ptr_ = __hold2.get()->get();
4277 __r.__cntrl_ = __hold2.release();
4278 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4283 template<class _Alloc, class ..._Args>
4285 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4287 static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
4288 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4289 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4290 typedef __allocator_destructor<_A2> _D2;
4292 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4293 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4294 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4295 shared_ptr<_Tp> __r;
4296 __r.__ptr_ = __hold2.get()->get();
4297 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4298 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4302 #else // _LIBCPP_HAS_NO_VARIADICS
4306 shared_ptr<_Tp>::make_shared()
4308 static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
4309 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4310 typedef allocator<_CntrlBlk> _Alloc2;
4311 typedef __allocator_destructor<_Alloc2> _D2;
4313 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4314 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4315 shared_ptr<_Tp> __r;
4316 __r.__ptr_ = __hold2.get()->get();
4317 __r.__cntrl_ = __hold2.release();
4318 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4325 shared_ptr<_Tp>::make_shared(_A0& __a0)
4327 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
4328 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4329 typedef allocator<_CntrlBlk> _Alloc2;
4330 typedef __allocator_destructor<_Alloc2> _D2;
4332 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4333 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4334 shared_ptr<_Tp> __r;
4335 __r.__ptr_ = __hold2.get()->get();
4336 __r.__cntrl_ = __hold2.release();
4337 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4342 template<class _A0, class _A1>
4344 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4346 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
4347 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4348 typedef allocator<_CntrlBlk> _Alloc2;
4349 typedef __allocator_destructor<_Alloc2> _D2;
4351 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4352 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4353 shared_ptr<_Tp> __r;
4354 __r.__ptr_ = __hold2.get()->get();
4355 __r.__cntrl_ = __hold2.release();
4356 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4361 template<class _A0, class _A1, class _A2>
4363 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4365 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
4366 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4367 typedef allocator<_CntrlBlk> _Alloc2;
4368 typedef __allocator_destructor<_Alloc2> _D2;
4370 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4371 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4372 shared_ptr<_Tp> __r;
4373 __r.__ptr_ = __hold2.get()->get();
4374 __r.__cntrl_ = __hold2.release();
4375 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4380 template<class _Alloc>
4382 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4384 static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
4385 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4386 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4387 typedef __allocator_destructor<_Alloc2> _D2;
4388 _Alloc2 __alloc2(__a);
4389 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4390 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4392 shared_ptr<_Tp> __r;
4393 __r.__ptr_ = __hold2.get()->get();
4394 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4395 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4400 template<class _Alloc, class _A0>
4402 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4404 static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
4405 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4406 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4407 typedef __allocator_destructor<_Alloc2> _D2;
4408 _Alloc2 __alloc2(__a);
4409 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4410 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4411 _CntrlBlk(__a, __a0);
4412 shared_ptr<_Tp> __r;
4413 __r.__ptr_ = __hold2.get()->get();
4414 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4415 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4420 template<class _Alloc, class _A0, class _A1>
4422 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4424 static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
4425 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4426 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4427 typedef __allocator_destructor<_Alloc2> _D2;
4428 _Alloc2 __alloc2(__a);
4429 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4430 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4431 _CntrlBlk(__a, __a0, __a1);
4432 shared_ptr<_Tp> __r;
4433 __r.__ptr_ = __hold2.get()->get();
4434 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4435 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4440 template<class _Alloc, class _A0, class _A1, class _A2>
4442 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4444 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
4445 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4446 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4447 typedef __allocator_destructor<_Alloc2> _D2;
4448 _Alloc2 __alloc2(__a);
4449 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4450 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4451 _CntrlBlk(__a, __a0, __a1, __a2);
4452 shared_ptr<_Tp> __r;
4453 __r.__ptr_ = __hold2.get()->get();
4454 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4455 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4459 #endif // _LIBCPP_HAS_NO_VARIADICS
4462 shared_ptr<_Tp>::~shared_ptr()
4465 __cntrl_->__release_shared();
4471 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4473 shared_ptr(__r).swap(*this);
4482 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4485 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4487 shared_ptr(__r).swap(*this);
4491 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4496 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4498 shared_ptr(_VSTD::move(__r)).swap(*this);
4507 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4510 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4512 shared_ptr(_VSTD::move(__r)).swap(*this);
4516 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4522 !is_array<_Yp>::value &&
4523 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4526 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4528 shared_ptr(_VSTD::move(__r)).swap(*this);
4534 template <class _Yp, class _Dp>
4538 !is_array<_Yp>::value &&
4539 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4540 typename shared_ptr<_Tp>::element_type*>::value,
4543 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4545 shared_ptr(_VSTD::move(__r)).swap(*this);
4549 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4551 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4554 inline _LIBCPP_INLINE_VISIBILITY
4557 !is_array<_Yp>::value &&
4558 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4561 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4563 shared_ptr(__r).swap(*this);
4569 template <class _Yp, class _Dp>
4570 inline _LIBCPP_INLINE_VISIBILITY
4573 !is_array<_Yp>::value &&
4574 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4575 typename shared_ptr<_Tp>::element_type*>::value,
4578 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4580 shared_ptr(_VSTD::move(__r)).swap(*this);
4584 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4589 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4591 _VSTD::swap(__ptr_, __r.__ptr_);
4592 _VSTD::swap(__cntrl_, __r.__cntrl_);
4598 shared_ptr<_Tp>::reset() _NOEXCEPT
4600 shared_ptr().swap(*this);
4608 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4611 shared_ptr<_Tp>::reset(_Yp* __p)
4613 shared_ptr(__p).swap(*this);
4617 template<class _Yp, class _Dp>
4621 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4624 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4626 shared_ptr(__p, __d).swap(*this);
4630 template<class _Yp, class _Dp, class _Alloc>
4634 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4637 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4639 shared_ptr(__p, __d, __a).swap(*this);
4642 #ifndef _LIBCPP_HAS_NO_VARIADICS
4644 template<class _Tp, class ..._Args>
4645 inline _LIBCPP_INLINE_VISIBILITY
4648 !is_array<_Tp>::value,
4651 make_shared(_Args&& ...__args)
4653 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4656 template<class _Tp, class _Alloc, class ..._Args>
4657 inline _LIBCPP_INLINE_VISIBILITY
4660 !is_array<_Tp>::value,
4663 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4665 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4668 #else // _LIBCPP_HAS_NO_VARIADICS
4671 inline _LIBCPP_INLINE_VISIBILITY
4675 return shared_ptr<_Tp>::make_shared();
4678 template<class _Tp, class _A0>
4679 inline _LIBCPP_INLINE_VISIBILITY
4681 make_shared(_A0& __a0)
4683 return shared_ptr<_Tp>::make_shared(__a0);
4686 template<class _Tp, class _A0, class _A1>
4687 inline _LIBCPP_INLINE_VISIBILITY
4689 make_shared(_A0& __a0, _A1& __a1)
4691 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4694 template<class _Tp, class _A0, class _A1, class _A2>
4695 inline _LIBCPP_INLINE_VISIBILITY
4697 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4699 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4702 template<class _Tp, class _Alloc>
4703 inline _LIBCPP_INLINE_VISIBILITY
4705 allocate_shared(const _Alloc& __a)
4707 return shared_ptr<_Tp>::allocate_shared(__a);
4710 template<class _Tp, class _Alloc, class _A0>
4711 inline _LIBCPP_INLINE_VISIBILITY
4713 allocate_shared(const _Alloc& __a, _A0& __a0)
4715 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4718 template<class _Tp, class _Alloc, class _A0, class _A1>
4719 inline _LIBCPP_INLINE_VISIBILITY
4721 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4723 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4726 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4727 inline _LIBCPP_INLINE_VISIBILITY
4729 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4731 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4734 #endif // _LIBCPP_HAS_NO_VARIADICS
4736 template<class _Tp, class _Up>
4737 inline _LIBCPP_INLINE_VISIBILITY
4739 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4741 return __x.get() == __y.get();
4744 template<class _Tp, class _Up>
4745 inline _LIBCPP_INLINE_VISIBILITY
4747 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4749 return !(__x == __y);
4752 template<class _Tp, class _Up>
4753 inline _LIBCPP_INLINE_VISIBILITY
4755 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4757 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4758 return less<_Vp>()(__x.get(), __y.get());
4761 template<class _Tp, class _Up>
4762 inline _LIBCPP_INLINE_VISIBILITY
4764 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4769 template<class _Tp, class _Up>
4770 inline _LIBCPP_INLINE_VISIBILITY
4772 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4774 return !(__y < __x);
4777 template<class _Tp, class _Up>
4778 inline _LIBCPP_INLINE_VISIBILITY
4780 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4782 return !(__x < __y);
4786 inline _LIBCPP_INLINE_VISIBILITY
4788 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4794 inline _LIBCPP_INLINE_VISIBILITY
4796 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4802 inline _LIBCPP_INLINE_VISIBILITY
4804 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4806 return static_cast<bool>(__x);
4810 inline _LIBCPP_INLINE_VISIBILITY
4812 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4814 return static_cast<bool>(__x);
4818 inline _LIBCPP_INLINE_VISIBILITY
4820 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4822 return less<_Tp*>()(__x.get(), nullptr);
4826 inline _LIBCPP_INLINE_VISIBILITY
4828 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4830 return less<_Tp*>()(nullptr, __x.get());
4834 inline _LIBCPP_INLINE_VISIBILITY
4836 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4838 return nullptr < __x;
4842 inline _LIBCPP_INLINE_VISIBILITY
4844 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4846 return __x < nullptr;
4850 inline _LIBCPP_INLINE_VISIBILITY
4852 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4854 return !(nullptr < __x);
4858 inline _LIBCPP_INLINE_VISIBILITY
4860 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4862 return !(__x < nullptr);
4866 inline _LIBCPP_INLINE_VISIBILITY
4868 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4870 return !(__x < nullptr);
4874 inline _LIBCPP_INLINE_VISIBILITY
4876 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4878 return !(nullptr < __x);
4882 inline _LIBCPP_INLINE_VISIBILITY
4884 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4889 template<class _Tp, class _Up>
4890 inline _LIBCPP_INLINE_VISIBILITY
4893 !is_array<_Tp>::value && !is_array<_Up>::value,
4896 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4898 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4901 template<class _Tp, class _Up>
4902 inline _LIBCPP_INLINE_VISIBILITY
4905 !is_array<_Tp>::value && !is_array<_Up>::value,
4908 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4910 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4911 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4914 template<class _Tp, class _Up>
4917 is_array<_Tp>::value == is_array<_Up>::value,
4920 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4922 typedef typename remove_extent<_Tp>::type _RTp;
4923 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4926 #ifndef _LIBCPP_NO_RTTI
4928 template<class _Dp, class _Tp>
4929 inline _LIBCPP_INLINE_VISIBILITY
4931 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4933 return __p.template __get_deleter<_Dp>();
4936 #endif // _LIBCPP_NO_RTTI
4939 class _LIBCPP_TEMPLATE_VIS weak_ptr
4942 typedef _Tp element_type;
4944 element_type* __ptr_;
4945 __shared_weak_count* __cntrl_;
4948 _LIBCPP_INLINE_VISIBILITY
4949 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4950 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4951 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4953 _LIBCPP_INLINE_VISIBILITY
4954 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4955 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
4956 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4959 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4960 _LIBCPP_INLINE_VISIBILITY
4961 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4962 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
4963 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4965 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4968 _LIBCPP_INLINE_VISIBILITY
4969 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4973 is_convertible<_Yp*, element_type*>::value,
4976 _LIBCPP_INLINE_VISIBILITY
4977 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4979 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4981 _LIBCPP_INLINE_VISIBILITY
4982 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4986 is_convertible<_Yp*, element_type*>::value,
4989 _LIBCPP_INLINE_VISIBILITY
4990 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4992 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4997 is_convertible<_Yp*, element_type*>::value,
5000 _LIBCPP_INLINE_VISIBILITY
5001 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
5003 _LIBCPP_INLINE_VISIBILITY
5004 void swap(weak_ptr& __r) _NOEXCEPT;
5005 _LIBCPP_INLINE_VISIBILITY
5006 void reset() _NOEXCEPT;
5008 _LIBCPP_INLINE_VISIBILITY
5009 long use_count() const _NOEXCEPT
5010 {return __cntrl_ ? __cntrl_->use_count() : 0;}
5011 _LIBCPP_INLINE_VISIBILITY
5012 bool expired() const _NOEXCEPT
5013 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
5014 shared_ptr<_Tp> lock() const _NOEXCEPT;
5016 _LIBCPP_INLINE_VISIBILITY
5017 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
5018 {return __cntrl_ < __r.__cntrl_;}
5020 _LIBCPP_INLINE_VISIBILITY
5021 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
5022 {return __cntrl_ < __r.__cntrl_;}
5024 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5025 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
5031 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5039 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5040 : __ptr_(__r.__ptr_),
5041 __cntrl_(__r.__cntrl_)
5044 __cntrl_->__add_weak();
5050 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5051 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5053 : __ptr_(__r.__ptr_),
5054 __cntrl_(__r.__cntrl_)
5057 __cntrl_->__add_weak();
5063 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5064 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5066 : __ptr_(__r.__ptr_),
5067 __cntrl_(__r.__cntrl_)
5070 __cntrl_->__add_weak();
5073 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5077 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5078 : __ptr_(__r.__ptr_),
5079 __cntrl_(__r.__cntrl_)
5088 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5089 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5091 : __ptr_(__r.__ptr_),
5092 __cntrl_(__r.__cntrl_)
5098 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5101 weak_ptr<_Tp>::~weak_ptr()
5104 __cntrl_->__release_weak();
5110 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5112 weak_ptr(__r).swap(*this);
5121 is_convertible<_Yp*, _Tp*>::value,
5124 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5126 weak_ptr(__r).swap(*this);
5130 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5135 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5137 weak_ptr(_VSTD::move(__r)).swap(*this);
5146 is_convertible<_Yp*, _Tp*>::value,
5149 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5151 weak_ptr(_VSTD::move(__r)).swap(*this);
5155 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5162 is_convertible<_Yp*, _Tp*>::value,
5165 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5167 weak_ptr(__r).swap(*this);
5174 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5176 _VSTD::swap(__ptr_, __r.__ptr_);
5177 _VSTD::swap(__cntrl_, __r.__cntrl_);
5181 inline _LIBCPP_INLINE_VISIBILITY
5183 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5191 weak_ptr<_Tp>::reset() _NOEXCEPT
5193 weak_ptr().swap(*this);
5198 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5199 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5200 : __ptr_(__r.__ptr_),
5201 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5204 __throw_bad_weak_ptr();
5209 weak_ptr<_Tp>::lock() const _NOEXCEPT
5211 shared_ptr<_Tp> __r;
5212 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5214 __r.__ptr_ = __ptr_;
5218 #if _LIBCPP_STD_VER > 14
5219 template <class _Tp = void> struct owner_less;
5221 template <class _Tp> struct owner_less;
5224 template <class _Tp>
5225 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5226 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5228 typedef bool result_type;
5229 _LIBCPP_INLINE_VISIBILITY
5230 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5231 {return __x.owner_before(__y);}
5232 _LIBCPP_INLINE_VISIBILITY
5233 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5234 {return __x.owner_before(__y);}
5235 _LIBCPP_INLINE_VISIBILITY
5236 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5237 {return __x.owner_before(__y);}
5240 template <class _Tp>
5241 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5242 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5244 typedef bool result_type;
5245 _LIBCPP_INLINE_VISIBILITY
5246 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5247 {return __x.owner_before(__y);}
5248 _LIBCPP_INLINE_VISIBILITY
5249 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5250 {return __x.owner_before(__y);}
5251 _LIBCPP_INLINE_VISIBILITY
5252 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5253 {return __x.owner_before(__y);}
5256 #if _LIBCPP_STD_VER > 14
5258 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5260 template <class _Tp, class _Up>
5261 _LIBCPP_INLINE_VISIBILITY
5262 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5263 {return __x.owner_before(__y);}
5264 template <class _Tp, class _Up>
5265 _LIBCPP_INLINE_VISIBILITY
5266 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5267 {return __x.owner_before(__y);}
5268 template <class _Tp, class _Up>
5269 _LIBCPP_INLINE_VISIBILITY
5270 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5271 {return __x.owner_before(__y);}
5272 template <class _Tp, class _Up>
5273 _LIBCPP_INLINE_VISIBILITY
5274 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5275 {return __x.owner_before(__y);}
5276 typedef void is_transparent;
5281 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5283 mutable weak_ptr<_Tp> __weak_this_;
5285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5286 enable_shared_from_this() _NOEXCEPT {}
5287 _LIBCPP_INLINE_VISIBILITY
5288 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5289 _LIBCPP_INLINE_VISIBILITY
5290 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5292 _LIBCPP_INLINE_VISIBILITY
5293 ~enable_shared_from_this() {}
5295 _LIBCPP_INLINE_VISIBILITY
5296 shared_ptr<_Tp> shared_from_this()
5297 {return shared_ptr<_Tp>(__weak_this_);}
5298 _LIBCPP_INLINE_VISIBILITY
5299 shared_ptr<_Tp const> shared_from_this() const
5300 {return shared_ptr<const _Tp>(__weak_this_);}
5302 #if _LIBCPP_STD_VER > 14
5303 _LIBCPP_INLINE_VISIBILITY
5304 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5305 { return __weak_this_; }
5307 _LIBCPP_INLINE_VISIBILITY
5308 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5309 { return __weak_this_; }
5310 #endif // _LIBCPP_STD_VER > 14
5312 template <class _Up> friend class shared_ptr;
5315 template <class _Tp>
5316 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5318 typedef shared_ptr<_Tp> argument_type;
5319 typedef size_t result_type;
5321 _LIBCPP_INLINE_VISIBILITY
5322 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5324 return hash<_Tp*>()(__ptr.get());
5328 template<class _CharT, class _Traits, class _Yp>
5329 inline _LIBCPP_INLINE_VISIBILITY
5330 basic_ostream<_CharT, _Traits>&
5331 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5334 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5336 class _LIBCPP_TYPE_VIS __sp_mut
5340 void lock() _NOEXCEPT;
5341 void unlock() _NOEXCEPT;
5344 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5345 __sp_mut(const __sp_mut&);
5346 __sp_mut& operator=(const __sp_mut&);
5348 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5351 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5352 __sp_mut& __get_sp_mut(const void*);
5354 template <class _Tp>
5355 inline _LIBCPP_INLINE_VISIBILITY
5357 atomic_is_lock_free(const shared_ptr<_Tp>*)
5362 template <class _Tp>
5363 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5365 atomic_load(const shared_ptr<_Tp>* __p)
5367 __sp_mut& __m = __get_sp_mut(__p);
5369 shared_ptr<_Tp> __q = *__p;
5374 template <class _Tp>
5375 inline _LIBCPP_INLINE_VISIBILITY
5376 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5378 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5380 return atomic_load(__p);
5383 template <class _Tp>
5384 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5386 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5388 __sp_mut& __m = __get_sp_mut(__p);
5394 template <class _Tp>
5395 inline _LIBCPP_INLINE_VISIBILITY
5396 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5398 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5400 atomic_store(__p, __r);
5403 template <class _Tp>
5404 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5406 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5408 __sp_mut& __m = __get_sp_mut(__p);
5415 template <class _Tp>
5416 inline _LIBCPP_INLINE_VISIBILITY
5417 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5419 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5421 return atomic_exchange(__p, __r);
5424 template <class _Tp>
5425 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5427 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5429 shared_ptr<_Tp> __temp;
5430 __sp_mut& __m = __get_sp_mut(__p);
5432 if (__p->__owner_equivalent(*__v))
5434 _VSTD::swap(__temp, *__p);
5439 _VSTD::swap(__temp, *__v);
5445 template <class _Tp>
5446 inline _LIBCPP_INLINE_VISIBILITY
5447 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5449 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5451 return atomic_compare_exchange_strong(__p, __v, __w);
5454 template <class _Tp>
5455 inline _LIBCPP_INLINE_VISIBILITY
5456 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5458 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5459 shared_ptr<_Tp> __w, memory_order, memory_order)
5461 return atomic_compare_exchange_strong(__p, __v, __w);
5464 template <class _Tp>
5465 inline _LIBCPP_INLINE_VISIBILITY
5466 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5468 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5469 shared_ptr<_Tp> __w, memory_order, memory_order)
5471 return atomic_compare_exchange_weak(__p, __v, __w);
5474 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5477 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5478 # ifndef _LIBCPP_CXX03_LANG
5479 enum class pointer_safety : unsigned char {
5486 struct _LIBCPP_TYPE_VIS pointer_safety
5497 _LIBCPP_INLINE_VISIBILITY
5498 pointer_safety() : __v_() {}
5500 _LIBCPP_INLINE_VISIBILITY
5501 pointer_safety(__lx __v) : __v_(__v) {}
5502 _LIBCPP_INLINE_VISIBILITY
5503 operator int() const {return __v_;}
5507 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5508 defined(_LIBCPP_BUILDING_MEMORY)
5509 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5511 // This function is only offered in C++03 under ABI v1.
5512 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5513 inline _LIBCPP_INLINE_VISIBILITY
5514 pointer_safety get_pointer_safety() _NOEXCEPT {
5515 return pointer_safety::relaxed;
5521 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5522 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5523 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5524 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5526 template <class _Tp>
5527 inline _LIBCPP_INLINE_VISIBILITY
5529 undeclare_reachable(_Tp* __p)
5531 return static_cast<_Tp*>(__undeclare_reachable(__p));
5534 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5536 // --- Helper for container swap --
5537 template <typename _Alloc>
5538 inline _LIBCPP_INLINE_VISIBILITY
5539 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5540 #if _LIBCPP_STD_VER >= 14
5543 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5546 __swap_allocator(__a1, __a2,
5547 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5550 template <typename _Alloc>
5551 _LIBCPP_INLINE_VISIBILITY
5552 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5553 #if _LIBCPP_STD_VER >= 14
5556 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5563 template <typename _Alloc>
5564 inline _LIBCPP_INLINE_VISIBILITY
5565 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5567 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5568 struct __noexcept_move_assign_container : public integral_constant<bool,
5569 _Traits::propagate_on_container_move_assignment::value
5570 #if _LIBCPP_STD_VER > 14
5571 || _Traits::is_always_equal::value
5573 && is_nothrow_move_assignable<_Alloc>::value
5578 #ifndef _LIBCPP_HAS_NO_VARIADICS
5579 template <class _Tp, class _Alloc>
5580 struct __temp_value {
5581 typedef allocator_traits<_Alloc> _Traits;
5583 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5586 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5587 _Tp & get() { return *__addr(); }
5589 template<class... _Args>
5590 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5591 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5593 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5597 _LIBCPP_END_NAMESPACE_STD
5601 #endif // _LIBCPP_MEMORY