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 Alloc>
50 struct allocator_traits
52 typedef Alloc allocator_type;
53 typedef typename allocator_type::value_type
56 typedef Alloc::pointer | value_type* pointer;
57 typedef Alloc::const_pointer
58 | pointer_traits<pointer>::rebind<const value_type>
60 typedef Alloc::void_pointer
61 | pointer_traits<pointer>::rebind<void>
63 typedef Alloc::const_void_pointer
64 | pointer_traits<pointer>::rebind<const void>
66 typedef Alloc::difference_type
67 | pointer_traits<pointer>::difference_type
69 typedef Alloc::size_type
70 | make_unsigned<difference_type>::type
72 typedef Alloc::propagate_on_container_copy_assignment
73 | false_type propagate_on_container_copy_assignment;
74 typedef Alloc::propagate_on_container_move_assignment
75 | false_type propagate_on_container_move_assignment;
76 typedef Alloc::propagate_on_container_swap
77 | false_type propagate_on_container_swap;
78 typedef Alloc::is_always_equal
79 | is_empty is_always_equal;
81 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
82 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
84 static pointer allocate(allocator_type& a, size_type n);
85 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
87 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
89 template <class T, class... Args>
90 static void construct(allocator_type& a, T* p, Args&&... args);
93 static void destroy(allocator_type& a, T* p);
95 static size_type max_size(const allocator_type& a); // noexcept in C++14
98 select_on_container_copy_construction(const allocator_type& a);
102 class allocator<void>
105 typedef void* pointer;
106 typedef const void* const_pointer;
107 typedef void value_type;
109 template <class _Up> struct rebind {typedef allocator<_Up> other;};
116 typedef size_t size_type;
117 typedef ptrdiff_t difference_type;
119 typedef const T* const_pointer;
120 typedef typename add_lvalue_reference<T>::type reference;
121 typedef typename add_lvalue_reference<const T>::type const_reference;
122 typedef T value_type;
124 template <class U> struct rebind {typedef allocator<U> other;};
126 allocator() noexcept;
127 allocator(const allocator&) noexcept;
128 template <class U> allocator(const allocator<U>&) noexcept;
130 pointer address(reference x) const noexcept;
131 const_pointer address(const_reference x) const noexcept;
132 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
133 void deallocate(pointer p, size_type n) noexcept;
134 size_type max_size() const noexcept;
135 template<class U, class... Args>
136 void construct(U* p, Args&&... args);
141 template <class T, class U>
142 bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
144 template <class T, class U>
145 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
147 template <class OutputIterator, class T>
148 class raw_storage_iterator
149 : public iterator<output_iterator_tag,
150 T, // purposefully not C++03
151 ptrdiff_t, // purposefully not C++03
152 T*, // purposefully not C++03
153 raw_storage_iterator&> // purposefully not C++03
156 explicit raw_storage_iterator(OutputIterator x);
157 raw_storage_iterator& operator*();
158 raw_storage_iterator& operator=(const T& element);
159 raw_storage_iterator& operator++();
160 raw_storage_iterator operator++(int);
163 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
164 template <class T> void return_temporary_buffer(T* p) noexcept;
166 template <class T> T* addressof(T& r) noexcept;
167 template <class T> T* addressof(const T&& r) noexcept = delete;
169 template <class InputIterator, class ForwardIterator>
171 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
173 template <class InputIterator, class Size, class ForwardIterator>
175 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
177 template <class ForwardIterator, class T>
178 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
180 template <class ForwardIterator, class Size, class T>
182 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
185 void destroy_at(T* location);
187 template <class ForwardIterator>
188 void destroy(ForwardIterator first, ForwardIterator last);
190 template <class ForwardIterator, class Size>
191 ForwardIterator destroy_n(ForwardIterator first, Size n);
193 template <class InputIterator, class ForwardIterator>
194 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
196 template <class InputIterator, class Size, class ForwardIterator>
197 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
199 template <class ForwardIterator>
200 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
202 template <class ForwardIterator, class Size>
203 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
205 template <class ForwardIterator>
206 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
208 template <class ForwardIterator, class Size>
209 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
211 template <class Y> struct auto_ptr_ref {}; // removed in C++17
214 class auto_ptr // removed in C++17
217 typedef X element_type;
219 explicit auto_ptr(X* p =0) throw();
220 auto_ptr(auto_ptr&) throw();
221 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
222 auto_ptr& operator=(auto_ptr&) throw();
223 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
224 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
227 typename add_lvalue_reference<X>::type operator*() const throw();
228 X* operator->() const throw();
229 X* get() const throw();
230 X* release() throw();
231 void reset(X* p =0) throw();
233 auto_ptr(auto_ptr_ref<X>) throw();
234 template<class Y> operator auto_ptr_ref<Y>() throw();
235 template<class Y> operator auto_ptr<Y>() throw();
239 struct default_delete
241 constexpr default_delete() noexcept = default;
242 template <class U> default_delete(const default_delete<U>&) noexcept;
244 void operator()(T*) const noexcept;
248 struct default_delete<T[]>
250 constexpr default_delete() noexcept = default;
251 void operator()(T*) const noexcept;
252 template <class U> void operator()(U*) const = delete;
255 template <class T, class D = default_delete<T>>
259 typedef see below pointer;
260 typedef T element_type;
261 typedef D deleter_type;
264 constexpr unique_ptr() noexcept;
265 explicit unique_ptr(pointer p) noexcept;
266 unique_ptr(pointer p, see below d1) noexcept;
267 unique_ptr(pointer p, see below d2) noexcept;
268 unique_ptr(unique_ptr&& u) noexcept;
269 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
270 template <class U, class E>
271 unique_ptr(unique_ptr<U, E>&& u) noexcept;
273 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
279 unique_ptr& operator=(unique_ptr&& u) noexcept;
280 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
281 unique_ptr& operator=(nullptr_t) noexcept;
284 typename add_lvalue_reference<T>::type operator*() const;
285 pointer operator->() const noexcept;
286 pointer get() const noexcept;
287 deleter_type& get_deleter() noexcept;
288 const deleter_type& get_deleter() const noexcept;
289 explicit operator bool() const noexcept;
292 pointer release() noexcept;
293 void reset(pointer p = pointer()) noexcept;
294 void swap(unique_ptr& u) noexcept;
297 template <class T, class D>
298 class unique_ptr<T[], D>
301 typedef implementation-defined pointer;
302 typedef T element_type;
303 typedef D deleter_type;
306 constexpr unique_ptr() noexcept;
307 explicit unique_ptr(pointer p) noexcept;
308 unique_ptr(pointer p, see below d) noexcept;
309 unique_ptr(pointer p, see below d) noexcept;
310 unique_ptr(unique_ptr&& u) noexcept;
311 unique_ptr(nullptr_t) noexcept : unique_ptr() { }
317 unique_ptr& operator=(unique_ptr&& u) noexcept;
318 unique_ptr& operator=(nullptr_t) noexcept;
321 T& operator[](size_t i) const;
322 pointer get() const noexcept;
323 deleter_type& get_deleter() noexcept;
324 const deleter_type& get_deleter() const noexcept;
325 explicit operator bool() const noexcept;
328 pointer release() noexcept;
329 void reset(pointer p = pointer()) noexcept;
330 void reset(nullptr_t) noexcept;
331 template <class U> void reset(U) = delete;
332 void swap(unique_ptr& u) noexcept;
335 template <class T, class D>
336 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
338 template <class T1, class D1, class T2, class D2>
339 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
340 template <class T1, class D1, class T2, class D2>
341 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
342 template <class T1, class D1, class T2, class D2>
343 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
344 template <class T1, class D1, class T2, class D2>
345 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
346 template <class T1, class D1, class T2, class D2>
347 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
348 template <class T1, class D1, class T2, class D2>
349 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
351 template <class T, class D>
352 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
353 template <class T, class D>
354 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
355 template <class T, class D>
356 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
357 template <class T, class D>
358 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
360 template <class T, class D>
361 bool operator<(const unique_ptr<T, D>& x, nullptr_t);
362 template <class T, class D>
363 bool operator<(nullptr_t, const unique_ptr<T, D>& y);
364 template <class T, class D>
365 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
366 template <class T, class D>
367 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
368 template <class T, class D>
369 bool operator>(const unique_ptr<T, D>& x, nullptr_t);
370 template <class T, class D>
371 bool operator>(nullptr_t, const unique_ptr<T, D>& y);
372 template <class T, class D>
373 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
374 template <class T, class D>
375 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
378 : public std::exception
380 bad_weak_ptr() noexcept;
383 template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
384 template<class T> unique_ptr<T> make_unique(size_t n); // C++14
385 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
391 typedef T element_type;
392 typedef weak_ptr<T> weak_type; // C++17
395 constexpr shared_ptr() noexcept;
396 template<class Y> explicit shared_ptr(Y* p);
397 template<class Y, class D> shared_ptr(Y* p, D d);
398 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
399 template <class D> shared_ptr(nullptr_t p, D d);
400 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
401 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
402 shared_ptr(const shared_ptr& r) noexcept;
403 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
404 shared_ptr(shared_ptr&& r) noexcept;
405 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
406 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
407 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
408 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
409 shared_ptr(nullptr_t) : shared_ptr() { }
415 shared_ptr& operator=(const shared_ptr& r) noexcept;
416 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
417 shared_ptr& operator=(shared_ptr&& r) noexcept;
418 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
419 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
420 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
423 void swap(shared_ptr& r) noexcept;
424 void reset() noexcept;
425 template<class Y> void reset(Y* p);
426 template<class Y, class D> void reset(Y* p, D d);
427 template<class Y, class D, class A> void reset(Y* p, D d, A a);
430 T* get() const noexcept;
431 T& operator*() const noexcept;
432 T* operator->() const noexcept;
433 long use_count() const noexcept;
434 bool unique() const noexcept;
435 explicit operator bool() const noexcept;
436 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
437 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
440 // shared_ptr comparisons:
441 template<class T, class U>
442 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
443 template<class T, class U>
444 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
445 template<class T, class U>
446 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
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;
455 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
457 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
459 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
461 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
463 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
465 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
467 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
469 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
471 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
473 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
475 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
477 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
479 // shared_ptr specialized algorithms:
480 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
483 template<class T, class U>
484 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
485 template<class T, class U>
486 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
487 template<class T, class U>
488 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
491 template<class E, class T, class Y>
492 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
494 // shared_ptr get_deleter:
495 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
497 template<class T, class... Args>
498 shared_ptr<T> make_shared(Args&&... args);
499 template<class T, class A, class... Args>
500 shared_ptr<T> allocate_shared(const A& a, Args&&... args);
506 typedef T element_type;
509 constexpr weak_ptr() noexcept;
510 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
511 weak_ptr(weak_ptr const& r) noexcept;
512 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
513 weak_ptr(weak_ptr&& r) noexcept; // C++14
514 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
520 weak_ptr& operator=(weak_ptr const& r) noexcept;
521 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
522 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
523 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
524 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
527 void swap(weak_ptr& r) noexcept;
528 void reset() noexcept;
531 long use_count() const noexcept;
532 bool expired() const noexcept;
533 shared_ptr<T> lock() const noexcept;
534 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
535 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
538 // weak_ptr specialized algorithms:
539 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
542 template<class T> struct owner_less;
545 struct owner_less<shared_ptr<T>>
546 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
548 typedef bool result_type;
549 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
550 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
551 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
555 struct owner_less<weak_ptr<T>>
556 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
558 typedef bool result_type;
559 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
560 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
561 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
564 template <> // Added in C++14
565 struct owner_less<void>
567 template <class _Tp, class _Up>
568 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
569 template <class _Tp, class _Up>
570 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
571 template <class _Tp, class _Up>
572 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
573 template <class _Tp, class _Up>
574 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
576 typedef void is_transparent;
580 class enable_shared_from_this
583 constexpr enable_shared_from_this() noexcept;
584 enable_shared_from_this(enable_shared_from_this const&) noexcept;
585 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
586 ~enable_shared_from_this();
588 shared_ptr<T> shared_from_this();
589 shared_ptr<T const> shared_from_this() const;
593 bool atomic_is_lock_free(const shared_ptr<T>* p);
595 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
597 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
599 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
601 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
603 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
606 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
609 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
612 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
615 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
616 shared_ptr<T> w, memory_order success,
617 memory_order failure);
620 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
621 shared_ptr<T> w, memory_order success,
622 memory_order failure);
624 template <class T> struct hash;
625 template <class T, class D> struct hash<unique_ptr<T, D> >;
626 template <class T> struct hash<shared_ptr<T> >;
629 enum class pointer_safety { relaxed, preferred, strict };
630 void declare_reachable(void *p);
631 template <class T> T *undeclare_reachable(T *p);
632 void declare_no_pointers(char *p, size_t n);
633 void undeclare_no_pointers(char *p, size_t n);
634 pointer_safety get_pointer_safety() noexcept;
636 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
643 #include <type_traits>
651 #include <__functional_base>
657 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
661 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
662 #pragma GCC system_header
666 #include <__undef_macros>
669 _LIBCPP_BEGIN_NAMESPACE_STD
671 template <class _ValueType>
672 inline _LIBCPP_ALWAYS_INLINE
673 _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
674 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
675 defined(__ATOMIC_RELAXED) && \
676 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
677 return __atomic_load_n(__value, __ATOMIC_RELAXED);
683 template <class _ValueType>
684 inline _LIBCPP_ALWAYS_INLINE
685 _ValueType __libcpp_acquire_load(_ValueType const* __value) {
686 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
687 defined(__ATOMIC_ACQUIRE) && \
688 (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
689 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
695 // addressof moved to <type_traits>
697 template <class _Tp> class allocator;
700 class _LIBCPP_TEMPLATE_VIS allocator<void>
703 typedef void* pointer;
704 typedef const void* const_pointer;
705 typedef void value_type;
707 template <class _Up> struct rebind {typedef allocator<_Up> other;};
711 class _LIBCPP_TEMPLATE_VIS allocator<const void>
714 typedef const void* pointer;
715 typedef const void* const_pointer;
716 typedef const void value_type;
718 template <class _Up> struct rebind {typedef allocator<_Up> other;};
724 struct __has_element_type
727 struct __two {char __lx; char __lxx;};
728 template <class _Up> static __two __test(...);
729 template <class _Up> static char __test(typename _Up::element_type* = 0);
731 static const bool value = sizeof(__test<_Tp>(0)) == 1;
734 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
735 struct __pointer_traits_element_type;
737 template <class _Ptr>
738 struct __pointer_traits_element_type<_Ptr, true>
740 typedef typename _Ptr::element_type type;
743 #ifndef _LIBCPP_HAS_NO_VARIADICS
745 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
746 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
748 typedef typename _Sp<_Tp, _Args...>::element_type type;
751 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
752 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
757 #else // _LIBCPP_HAS_NO_VARIADICS
759 template <template <class> class _Sp, class _Tp>
760 struct __pointer_traits_element_type<_Sp<_Tp>, true>
762 typedef typename _Sp<_Tp>::element_type type;
765 template <template <class> class _Sp, class _Tp>
766 struct __pointer_traits_element_type<_Sp<_Tp>, false>
771 template <template <class, class> class _Sp, class _Tp, class _A0>
772 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
774 typedef typename _Sp<_Tp, _A0>::element_type type;
777 template <template <class, class> class _Sp, class _Tp, class _A0>
778 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
783 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
784 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
786 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
789 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
790 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
795 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
796 class _A1, class _A2>
797 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
799 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
802 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
803 class _A1, class _A2>
804 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
809 #endif // _LIBCPP_HAS_NO_VARIADICS
812 struct __has_difference_type
815 struct __two {char __lx; char __lxx;};
816 template <class _Up> static __two __test(...);
817 template <class _Up> static char __test(typename _Up::difference_type* = 0);
819 static const bool value = sizeof(__test<_Tp>(0)) == 1;
822 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
823 struct __pointer_traits_difference_type
825 typedef ptrdiff_t type;
828 template <class _Ptr>
829 struct __pointer_traits_difference_type<_Ptr, true>
831 typedef typename _Ptr::difference_type type;
834 template <class _Tp, class _Up>
838 struct __two {char __lx; char __lxx;};
839 template <class _Xp> static __two __test(...);
840 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
842 static const bool value = sizeof(__test<_Tp>(0)) == 1;
845 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
846 struct __pointer_traits_rebind
848 #ifndef _LIBCPP_CXX03_LANG
849 typedef typename _Tp::template rebind<_Up> type;
851 typedef typename _Tp::template rebind<_Up>::other type;
855 #ifndef _LIBCPP_HAS_NO_VARIADICS
857 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
858 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
860 #ifndef _LIBCPP_CXX03_LANG
861 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
863 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
867 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
868 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
870 typedef _Sp<_Up, _Args...> type;
873 #else // _LIBCPP_HAS_NO_VARIADICS
875 template <template <class> class _Sp, class _Tp, class _Up>
876 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
878 #ifndef _LIBCPP_CXX03_LANG
879 typedef typename _Sp<_Tp>::template rebind<_Up> type;
881 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
885 template <template <class> class _Sp, class _Tp, class _Up>
886 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
888 typedef _Sp<_Up> type;
891 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
892 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
894 #ifndef _LIBCPP_CXX03_LANG
895 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
897 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
901 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
902 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
904 typedef _Sp<_Up, _A0> type;
907 template <template <class, class, class> class _Sp, class _Tp, class _A0,
908 class _A1, class _Up>
909 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
911 #ifndef _LIBCPP_CXX03_LANG
912 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
914 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
918 template <template <class, class, class> class _Sp, class _Tp, class _A0,
919 class _A1, class _Up>
920 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
922 typedef _Sp<_Up, _A0, _A1> type;
925 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
926 class _A1, class _A2, class _Up>
927 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
929 #ifndef _LIBCPP_CXX03_LANG
930 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
932 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
936 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
937 class _A1, class _A2, class _Up>
938 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
940 typedef _Sp<_Up, _A0, _A1, _A2> type;
943 #endif // _LIBCPP_HAS_NO_VARIADICS
945 template <class _Ptr>
946 struct _LIBCPP_TEMPLATE_VIS pointer_traits
948 typedef _Ptr pointer;
949 typedef typename __pointer_traits_element_type<pointer>::type element_type;
950 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
952 #ifndef _LIBCPP_CXX03_LANG
953 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
955 template <class _Up> struct rebind
956 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
957 #endif // _LIBCPP_CXX03_LANG
962 _LIBCPP_INLINE_VISIBILITY
963 static pointer pointer_to(typename conditional<is_void<element_type>::value,
964 __nat, element_type>::type& __r)
965 {return pointer::pointer_to(__r);}
969 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
971 typedef _Tp* pointer;
972 typedef _Tp element_type;
973 typedef ptrdiff_t difference_type;
975 #ifndef _LIBCPP_CXX03_LANG
976 template <class _Up> using rebind = _Up*;
978 template <class _Up> struct rebind {typedef _Up* other;};
984 _LIBCPP_INLINE_VISIBILITY
985 static pointer pointer_to(typename conditional<is_void<element_type>::value,
986 __nat, element_type>::type& __r) _NOEXCEPT
987 {return _VSTD::addressof(__r);}
990 template <class _From, class _To>
991 struct __rebind_pointer {
992 #ifndef _LIBCPP_CXX03_LANG
993 typedef typename pointer_traits<_From>::template rebind<_To> type;
995 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
1001 struct __has_pointer_type_imp
1003 template <class _Up> static __two __test(...);
1004 template <class _Up> static char __test(typename _Up::pointer* = 0);
1007 template <class _Tp>
1008 struct __has_pointer_type
1009 : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
1013 namespace __pointer_type_imp
1016 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1017 struct __pointer_type
1019 typedef typename _Dp::pointer type;
1022 template <class _Tp, class _Dp>
1023 struct __pointer_type<_Tp, _Dp, false>
1028 } // __pointer_type_imp
1030 template <class _Tp, class _Dp>
1031 struct __pointer_type
1033 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1036 template <class _Tp>
1037 struct __has_const_pointer
1040 struct __two {char __lx; char __lxx;};
1041 template <class _Up> static __two __test(...);
1042 template <class _Up> static char __test(typename _Up::const_pointer* = 0);
1044 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1047 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1048 struct __const_pointer
1050 typedef typename _Alloc::const_pointer type;
1053 template <class _Tp, class _Ptr, class _Alloc>
1054 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1056 #ifndef _LIBCPP_CXX03_LANG
1057 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1059 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1063 template <class _Tp>
1064 struct __has_void_pointer
1067 struct __two {char __lx; char __lxx;};
1068 template <class _Up> static __two __test(...);
1069 template <class _Up> static char __test(typename _Up::void_pointer* = 0);
1071 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1074 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1075 struct __void_pointer
1077 typedef typename _Alloc::void_pointer type;
1080 template <class _Ptr, class _Alloc>
1081 struct __void_pointer<_Ptr, _Alloc, false>
1083 #ifndef _LIBCPP_CXX03_LANG
1084 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1086 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1090 template <class _Tp>
1091 struct __has_const_void_pointer
1094 struct __two {char __lx; char __lxx;};
1095 template <class _Up> static __two __test(...);
1096 template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
1098 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1101 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1102 struct __const_void_pointer
1104 typedef typename _Alloc::const_void_pointer type;
1107 template <class _Ptr, class _Alloc>
1108 struct __const_void_pointer<_Ptr, _Alloc, false>
1110 #ifndef _LIBCPP_CXX03_LANG
1111 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1113 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1117 template <class _Tp>
1118 inline _LIBCPP_INLINE_VISIBILITY
1120 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1125 template <class _Pointer>
1126 inline _LIBCPP_INLINE_VISIBILITY
1127 typename pointer_traits<_Pointer>::element_type*
1128 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1130 return _VSTD::__to_raw_pointer(__p.operator->());
1133 template <class _Tp>
1134 struct __has_size_type
1137 struct __two {char __lx; char __lxx;};
1138 template <class _Up> static __two __test(...);
1139 template <class _Up> static char __test(typename _Up::size_type* = 0);
1141 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1144 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1147 typedef typename make_unsigned<_DiffType>::type type;
1150 template <class _Alloc, class _DiffType>
1151 struct __size_type<_Alloc, _DiffType, true>
1153 typedef typename _Alloc::size_type type;
1156 template <class _Tp>
1157 struct __has_propagate_on_container_copy_assignment
1160 struct __two {char __lx; char __lxx;};
1161 template <class _Up> static __two __test(...);
1162 template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
1164 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1167 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1168 struct __propagate_on_container_copy_assignment
1170 typedef false_type type;
1173 template <class _Alloc>
1174 struct __propagate_on_container_copy_assignment<_Alloc, true>
1176 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1179 template <class _Tp>
1180 struct __has_propagate_on_container_move_assignment
1183 struct __two {char __lx; char __lxx;};
1184 template <class _Up> static __two __test(...);
1185 template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
1187 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1190 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1191 struct __propagate_on_container_move_assignment
1193 typedef false_type type;
1196 template <class _Alloc>
1197 struct __propagate_on_container_move_assignment<_Alloc, true>
1199 typedef typename _Alloc::propagate_on_container_move_assignment type;
1202 template <class _Tp>
1203 struct __has_propagate_on_container_swap
1206 struct __two {char __lx; char __lxx;};
1207 template <class _Up> static __two __test(...);
1208 template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
1210 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1213 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1214 struct __propagate_on_container_swap
1216 typedef false_type type;
1219 template <class _Alloc>
1220 struct __propagate_on_container_swap<_Alloc, true>
1222 typedef typename _Alloc::propagate_on_container_swap type;
1225 template <class _Tp>
1226 struct __has_is_always_equal
1229 struct __two {char __lx; char __lxx;};
1230 template <class _Up> static __two __test(...);
1231 template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
1233 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1236 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1237 struct __is_always_equal
1239 typedef typename _VSTD::is_empty<_Alloc>::type type;
1242 template <class _Alloc>
1243 struct __is_always_equal<_Alloc, true>
1245 typedef typename _Alloc::is_always_equal type;
1248 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1249 struct __has_rebind_other
1252 struct __two {char __lx; char __lxx;};
1253 template <class _Xp> static __two __test(...);
1254 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1256 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1259 template <class _Tp, class _Up>
1260 struct __has_rebind_other<_Tp, _Up, false>
1262 static const bool value = false;
1265 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1266 struct __allocator_traits_rebind
1268 typedef typename _Tp::template rebind<_Up>::other type;
1271 #ifndef _LIBCPP_HAS_NO_VARIADICS
1273 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1274 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1276 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1279 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1280 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1282 typedef _Alloc<_Up, _Args...> type;
1285 #else // _LIBCPP_HAS_NO_VARIADICS
1287 template <template <class> class _Alloc, class _Tp, class _Up>
1288 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1290 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1293 template <template <class> class _Alloc, class _Tp, class _Up>
1294 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1296 typedef _Alloc<_Up> type;
1299 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1300 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1302 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1305 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1306 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1308 typedef _Alloc<_Up, _A0> type;
1311 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1312 class _A1, class _Up>
1313 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1315 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1318 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1319 class _A1, class _Up>
1320 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1322 typedef _Alloc<_Up, _A0, _A1> type;
1325 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1326 class _A1, class _A2, class _Up>
1327 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1329 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1332 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1333 class _A1, class _A2, class _Up>
1334 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1336 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1339 #endif // _LIBCPP_HAS_NO_VARIADICS
1341 #ifndef _LIBCPP_CXX03_LANG
1343 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1345 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1346 -> decltype(__a.allocate(__sz, __p), true_type());
1348 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1350 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1353 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1354 struct __has_allocate_hint
1355 : integral_constant<bool,
1357 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1358 declval<_SizeType>(),
1359 declval<_ConstVoidPtr>())),
1364 #else // _LIBCPP_CXX03_LANG
1366 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1367 struct __has_allocate_hint
1372 #endif // _LIBCPP_CXX03_LANG
1374 #if !defined(_LIBCPP_CXX03_LANG)
1376 template <class _Alloc, class _Tp, class ..._Args>
1377 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1378 _VSTD::declval<_Args>()...),
1380 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1382 template <class _Alloc, class _Pointer, class ..._Args>
1384 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1386 template <class _Alloc, class _Pointer, class ..._Args>
1387 struct __has_construct
1388 : integral_constant<bool,
1390 decltype(__has_construct_test(declval<_Alloc>(),
1391 declval<_Pointer>(),
1392 declval<_Args>()...)),
1397 template <class _Alloc, class _Pointer>
1399 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1400 -> decltype(__a.destroy(__p), true_type());
1402 template <class _Alloc, class _Pointer>
1404 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1407 template <class _Alloc, class _Pointer>
1408 struct __has_destroy
1409 : integral_constant<bool,
1411 decltype(__has_destroy_test(declval<_Alloc>(),
1412 declval<_Pointer>())),
1417 template <class _Alloc>
1419 __has_max_size_test(_Alloc&& __a)
1420 -> decltype(__a.max_size(), true_type());
1422 template <class _Alloc>
1424 __has_max_size_test(const volatile _Alloc& __a)
1427 template <class _Alloc>
1428 struct __has_max_size
1429 : integral_constant<bool,
1431 decltype(__has_max_size_test(declval<_Alloc&>())),
1436 template <class _Alloc>
1438 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1439 -> decltype(__a.select_on_container_copy_construction(), true_type());
1441 template <class _Alloc>
1443 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1446 template <class _Alloc>
1447 struct __has_select_on_container_copy_construction
1448 : integral_constant<bool,
1450 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1455 #else // _LIBCPP_CXX03_LANG
1457 #ifndef _LIBCPP_HAS_NO_VARIADICS
1459 template <class _Alloc, class _Pointer, class ..._Args>
1460 struct __has_construct
1465 #else // _LIBCPP_HAS_NO_VARIADICS
1467 template <class _Alloc, class _Pointer, class _Args>
1468 struct __has_construct
1473 #endif // _LIBCPP_HAS_NO_VARIADICS
1475 template <class _Alloc, class _Pointer>
1476 struct __has_destroy
1481 template <class _Alloc>
1482 struct __has_max_size
1487 template <class _Alloc>
1488 struct __has_select_on_container_copy_construction
1493 #endif // _LIBCPP_CXX03_LANG
1495 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1496 struct __alloc_traits_difference_type
1498 typedef typename pointer_traits<_Ptr>::difference_type type;
1501 template <class _Alloc, class _Ptr>
1502 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1504 typedef typename _Alloc::difference_type type;
1507 template <class _Alloc>
1508 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1510 typedef _Alloc allocator_type;
1511 typedef typename allocator_type::value_type value_type;
1513 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1514 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1515 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1516 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1518 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1519 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1521 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1522 propagate_on_container_copy_assignment;
1523 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1524 propagate_on_container_move_assignment;
1525 typedef typename __propagate_on_container_swap<allocator_type>::type
1526 propagate_on_container_swap;
1527 typedef typename __is_always_equal<allocator_type>::type
1530 #ifndef _LIBCPP_CXX03_LANG
1531 template <class _Tp> using rebind_alloc =
1532 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1533 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1534 #else // _LIBCPP_CXX03_LANG
1535 template <class _Tp> struct rebind_alloc
1536 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1537 template <class _Tp> struct rebind_traits
1538 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1539 #endif // _LIBCPP_CXX03_LANG
1541 _LIBCPP_INLINE_VISIBILITY
1542 static pointer allocate(allocator_type& __a, size_type __n)
1543 {return __a.allocate(__n);}
1544 _LIBCPP_INLINE_VISIBILITY
1545 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1546 {return __allocate(__a, __n, __hint,
1547 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1549 _LIBCPP_INLINE_VISIBILITY
1550 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1551 {__a.deallocate(__p, __n);}
1553 #ifndef _LIBCPP_HAS_NO_VARIADICS
1554 template <class _Tp, class... _Args>
1555 _LIBCPP_INLINE_VISIBILITY
1556 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1557 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1558 __a, __p, _VSTD::forward<_Args>(__args)...);}
1559 #else // _LIBCPP_HAS_NO_VARIADICS
1560 template <class _Tp>
1561 _LIBCPP_INLINE_VISIBILITY
1562 static void construct(allocator_type&, _Tp* __p)
1564 ::new ((void*)__p) _Tp();
1566 template <class _Tp, class _A0>
1567 _LIBCPP_INLINE_VISIBILITY
1568 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
1570 ::new ((void*)__p) _Tp(__a0);
1572 template <class _Tp, class _A0, class _A1>
1573 _LIBCPP_INLINE_VISIBILITY
1574 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1577 ::new ((void*)__p) _Tp(__a0, __a1);
1579 template <class _Tp, class _A0, class _A1, class _A2>
1580 _LIBCPP_INLINE_VISIBILITY
1581 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1582 const _A1& __a1, const _A2& __a2)
1584 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1586 #endif // _LIBCPP_HAS_NO_VARIADICS
1588 template <class _Tp>
1589 _LIBCPP_INLINE_VISIBILITY
1590 static void destroy(allocator_type& __a, _Tp* __p)
1591 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1593 _LIBCPP_INLINE_VISIBILITY
1594 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1595 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1597 _LIBCPP_INLINE_VISIBILITY
1598 static allocator_type
1599 select_on_container_copy_construction(const allocator_type& __a)
1600 {return __select_on_container_copy_construction(
1601 __has_select_on_container_copy_construction<const allocator_type>(),
1604 template <class _Ptr>
1605 _LIBCPP_INLINE_VISIBILITY
1608 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1610 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1611 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1614 template <class _Tp>
1615 _LIBCPP_INLINE_VISIBILITY
1619 (is_same<allocator_type, allocator<_Tp> >::value
1620 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1621 is_trivially_move_constructible<_Tp>::value,
1624 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1626 ptrdiff_t _Np = __end1 - __begin1;
1629 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1634 template <class _Iter, class _Ptr>
1635 _LIBCPP_INLINE_VISIBILITY
1638 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1640 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1641 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1644 template <class _Tp>
1645 _LIBCPP_INLINE_VISIBILITY
1649 (is_same<allocator_type, allocator<_Tp> >::value
1650 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1651 is_trivially_move_constructible<_Tp>::value,
1654 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1656 typedef typename remove_const<_Tp>::type _Vp;
1657 ptrdiff_t _Np = __end1 - __begin1;
1660 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1665 template <class _Ptr>
1666 _LIBCPP_INLINE_VISIBILITY
1669 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1671 while (__end1 != __begin1)
1673 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1678 template <class _Tp>
1679 _LIBCPP_INLINE_VISIBILITY
1683 (is_same<allocator_type, allocator<_Tp> >::value
1684 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1685 is_trivially_move_constructible<_Tp>::value,
1688 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1690 ptrdiff_t _Np = __end1 - __begin1;
1693 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1698 _LIBCPP_INLINE_VISIBILITY
1699 static pointer __allocate(allocator_type& __a, size_type __n,
1700 const_void_pointer __hint, true_type)
1701 {return __a.allocate(__n, __hint);}
1702 _LIBCPP_INLINE_VISIBILITY
1703 static pointer __allocate(allocator_type& __a, size_type __n,
1704 const_void_pointer, false_type)
1705 {return __a.allocate(__n);}
1707 #ifndef _LIBCPP_HAS_NO_VARIADICS
1708 template <class _Tp, class... _Args>
1709 _LIBCPP_INLINE_VISIBILITY
1710 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1711 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1712 template <class _Tp, class... _Args>
1713 _LIBCPP_INLINE_VISIBILITY
1714 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1716 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1718 #endif // _LIBCPP_HAS_NO_VARIADICS
1720 template <class _Tp>
1721 _LIBCPP_INLINE_VISIBILITY
1722 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1724 template <class _Tp>
1725 _LIBCPP_INLINE_VISIBILITY
1726 static void __destroy(false_type, allocator_type&, _Tp* __p)
1731 _LIBCPP_INLINE_VISIBILITY
1732 static size_type __max_size(true_type, const allocator_type& __a)
1733 {return __a.max_size();}
1734 _LIBCPP_INLINE_VISIBILITY
1735 static size_type __max_size(false_type, const allocator_type&)
1736 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1738 _LIBCPP_INLINE_VISIBILITY
1739 static allocator_type
1740 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1741 {return __a.select_on_container_copy_construction();}
1742 _LIBCPP_INLINE_VISIBILITY
1743 static allocator_type
1744 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1748 template <class _Traits, class _Tp>
1749 struct __rebind_alloc_helper
1751 #ifndef _LIBCPP_CXX03_LANG
1752 typedef typename _Traits::template rebind_alloc<_Tp> type;
1754 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1760 template <class _Tp>
1761 class _LIBCPP_TEMPLATE_VIS allocator
1764 typedef size_t size_type;
1765 typedef ptrdiff_t difference_type;
1766 typedef _Tp* pointer;
1767 typedef const _Tp* const_pointer;
1768 typedef _Tp& reference;
1769 typedef const _Tp& const_reference;
1770 typedef _Tp value_type;
1772 typedef true_type propagate_on_container_move_assignment;
1773 typedef true_type is_always_equal;
1775 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1777 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1778 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1779 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1780 {return _VSTD::addressof(__x);}
1781 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1782 {return _VSTD::addressof(__x);}
1783 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1785 if (__n > max_size())
1786 __throw_length_error("allocator<T>::allocate(size_t n)"
1787 " 'n' exceeds maximum supported size");
1788 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1790 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1791 {_VSTD::__libcpp_deallocate((void*)__p);}
1792 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1793 {return size_type(~0) / sizeof(_Tp);}
1794 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1795 template <class _Up, class... _Args>
1796 _LIBCPP_INLINE_VISIBILITY
1798 construct(_Up* __p, _Args&&... __args)
1800 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1802 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1803 _LIBCPP_INLINE_VISIBILITY
1805 construct(pointer __p)
1807 ::new((void*)__p) _Tp();
1809 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1811 template <class _A0>
1812 _LIBCPP_INLINE_VISIBILITY
1814 construct(pointer __p, _A0& __a0)
1816 ::new((void*)__p) _Tp(__a0);
1818 template <class _A0>
1819 _LIBCPP_INLINE_VISIBILITY
1821 construct(pointer __p, const _A0& __a0)
1823 ::new((void*)__p) _Tp(__a0);
1825 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1826 template <class _A0, class _A1>
1827 _LIBCPP_INLINE_VISIBILITY
1829 construct(pointer __p, _A0& __a0, _A1& __a1)
1831 ::new((void*)__p) _Tp(__a0, __a1);
1833 template <class _A0, class _A1>
1834 _LIBCPP_INLINE_VISIBILITY
1836 construct(pointer __p, const _A0& __a0, _A1& __a1)
1838 ::new((void*)__p) _Tp(__a0, __a1);
1840 template <class _A0, class _A1>
1841 _LIBCPP_INLINE_VISIBILITY
1843 construct(pointer __p, _A0& __a0, const _A1& __a1)
1845 ::new((void*)__p) _Tp(__a0, __a1);
1847 template <class _A0, class _A1>
1848 _LIBCPP_INLINE_VISIBILITY
1850 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1852 ::new((void*)__p) _Tp(__a0, __a1);
1854 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1855 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1858 template <class _Tp>
1859 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1862 typedef size_t size_type;
1863 typedef ptrdiff_t difference_type;
1864 typedef const _Tp* pointer;
1865 typedef const _Tp* const_pointer;
1866 typedef const _Tp& reference;
1867 typedef const _Tp& const_reference;
1868 typedef const _Tp value_type;
1870 typedef true_type propagate_on_container_move_assignment;
1871 typedef true_type is_always_equal;
1873 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1875 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1876 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1877 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1878 {return _VSTD::addressof(__x);}
1879 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1881 if (__n > max_size())
1882 __throw_length_error("allocator<const T>::allocate(size_t n)"
1883 " 'n' exceeds maximum supported size");
1884 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1886 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1887 {_VSTD::__libcpp_deallocate((void*)__p);}
1888 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1889 {return size_type(~0) / sizeof(_Tp);}
1890 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1891 template <class _Up, class... _Args>
1892 _LIBCPP_INLINE_VISIBILITY
1894 construct(_Up* __p, _Args&&... __args)
1896 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1898 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1899 _LIBCPP_INLINE_VISIBILITY
1901 construct(pointer __p)
1903 ::new((void*)__p) _Tp();
1905 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1907 template <class _A0>
1908 _LIBCPP_INLINE_VISIBILITY
1910 construct(pointer __p, _A0& __a0)
1912 ::new((void*)__p) _Tp(__a0);
1914 template <class _A0>
1915 _LIBCPP_INLINE_VISIBILITY
1917 construct(pointer __p, const _A0& __a0)
1919 ::new((void*)__p) _Tp(__a0);
1921 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1922 template <class _A0, class _A1>
1923 _LIBCPP_INLINE_VISIBILITY
1925 construct(pointer __p, _A0& __a0, _A1& __a1)
1927 ::new((void*)__p) _Tp(__a0, __a1);
1929 template <class _A0, class _A1>
1930 _LIBCPP_INLINE_VISIBILITY
1932 construct(pointer __p, const _A0& __a0, _A1& __a1)
1934 ::new((void*)__p) _Tp(__a0, __a1);
1936 template <class _A0, class _A1>
1937 _LIBCPP_INLINE_VISIBILITY
1939 construct(pointer __p, _A0& __a0, const _A1& __a1)
1941 ::new((void*)__p) _Tp(__a0, __a1);
1943 template <class _A0, class _A1>
1944 _LIBCPP_INLINE_VISIBILITY
1946 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1948 ::new((void*)__p) _Tp(__a0, __a1);
1950 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1951 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1954 template <class _Tp, class _Up>
1955 inline _LIBCPP_INLINE_VISIBILITY
1956 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1958 template <class _Tp, class _Up>
1959 inline _LIBCPP_INLINE_VISIBILITY
1960 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1962 template <class _OutputIterator, class _Tp>
1963 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1964 : public iterator<output_iterator_tag,
1965 _Tp, // purposefully not C++03
1966 ptrdiff_t, // purposefully not C++03
1967 _Tp*, // purposefully not C++03
1968 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1971 _OutputIterator __x_;
1973 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1974 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1975 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1976 {::new(&*__x_) _Tp(__element); return *this;}
1977 #if _LIBCPP_STD_VER >= 14
1978 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1979 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1981 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1982 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1983 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1984 #if _LIBCPP_STD_VER >= 14
1985 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1989 template <class _Tp>
1990 pair<_Tp*, ptrdiff_t>
1991 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1993 pair<_Tp*, ptrdiff_t> __r(0, 0);
1994 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1995 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
2001 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
2012 template <class _Tp>
2013 inline _LIBCPP_INLINE_VISIBILITY
2014 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
2016 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2017 template <class _Tp>
2024 class _LIBCPP_TEMPLATE_VIS auto_ptr
2029 typedef _Tp element_type;
2031 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
2032 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
2033 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
2034 : __ptr_(__p.release()) {}
2035 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
2036 {reset(__p.release()); return *this;}
2037 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
2038 {reset(__p.release()); return *this;}
2039 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
2040 {reset(__p.__ptr_); return *this;}
2041 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2043 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2045 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2046 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2047 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2053 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2060 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2061 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2062 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2063 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2064 {return auto_ptr<_Up>(release());}
2068 class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
2071 typedef void element_type;
2075 template <class _Tp, int _Idx,
2076 bool _CanBeEmptyBase =
2077 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2078 struct __compressed_pair_elem {
2079 typedef _Tp _ParamT;
2080 typedef _Tp& reference;
2081 typedef const _Tp& const_reference;
2083 #ifndef _LIBCPP_CXX03_LANG
2084 constexpr __compressed_pair_elem() : __value_() {}
2086 template <class _Up, class = typename enable_if<
2087 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2090 __compressed_pair_elem(_Up&& __u)
2091 : __value_(_VSTD::forward<_Up>(__u)){};
2093 template <class... _Args, size_t... _Indexes>
2094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2095 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2096 __tuple_indices<_Indexes...>)
2097 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2099 __compressed_pair_elem() : __value_() {}
2100 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2103 reference __get() _NOEXCEPT { return __value_; }
2104 const_reference __get() const _NOEXCEPT { return __value_; }
2110 template <class _Tp, int _Idx>
2111 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2112 typedef _Tp _ParamT;
2113 typedef _Tp& reference;
2114 typedef const _Tp& const_reference;
2115 typedef _Tp __value_type;
2117 #ifndef _LIBCPP_CXX03_LANG
2118 constexpr __compressed_pair_elem() = default;
2120 template <class _Up, class = typename enable_if<
2121 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2124 __compressed_pair_elem(_Up&& __u)
2125 : __value_type(_VSTD::forward<_Up>(__u)){};
2127 template <class... _Args, size_t... _Indexes>
2128 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2129 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2130 __tuple_indices<_Indexes...>)
2131 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2133 __compressed_pair_elem() : __value_type() {}
2134 __compressed_pair_elem(_ParamT __p)
2135 : __value_type(std::forward<_ParamT>(__p)) {}
2138 reference __get() _NOEXCEPT { return *this; }
2139 const_reference __get() const _NOEXCEPT { return *this; }
2142 // Tag used to construct the second element of the compressed pair.
2143 struct __second_tag {};
2145 template <class _T1, class _T2>
2146 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2147 private __compressed_pair_elem<_T2, 1> {
2148 typedef __compressed_pair_elem<_T1, 0> _Base1;
2149 typedef __compressed_pair_elem<_T2, 1> _Base2;
2151 // NOTE: This static assert should never fire because __compressed_pair
2152 // is *almost never* used in a scenario where it's possible for T1 == T2.
2153 // (The exception is std::function where it is possible that the function
2154 // object and the allocator have the same type).
2155 static_assert((!is_same<_T1, _T2>::value),
2156 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2157 "The current implementation is NOT ABI-compatible with the previous "
2158 "implementation for this configuration");
2161 #ifndef _LIBCPP_CXX03_LANG
2162 template <bool _Dummy = true,
2163 class = typename enable_if<
2164 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2165 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2168 _LIBCPP_INLINE_VISIBILITY
2169 constexpr __compressed_pair() {}
2171 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2172 __compressed_pair>::value,
2174 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2175 __compressed_pair(_Tp&& __t)
2176 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2178 template <class _Tp>
2179 _LIBCPP_INLINE_VISIBILITY constexpr
2180 __compressed_pair(__second_tag, _Tp&& __t)
2181 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2183 template <class _U1, class _U2>
2184 _LIBCPP_INLINE_VISIBILITY constexpr
2185 __compressed_pair(_U1&& __t1, _U2&& __t2)
2186 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2188 template <class... _Args1, class... _Args2>
2189 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2190 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2191 tuple<_Args2...> __second_args)
2192 : _Base1(__pc, _VSTD::move(__first_args),
2193 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2194 _Base2(__pc, _VSTD::move(__second_args),
2195 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2198 _LIBCPP_INLINE_VISIBILITY
2199 __compressed_pair() {}
2201 _LIBCPP_INLINE_VISIBILITY explicit
2202 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2204 _LIBCPP_INLINE_VISIBILITY
2205 __compressed_pair(__second_tag, _T2 __t2)
2206 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2208 _LIBCPP_INLINE_VISIBILITY
2209 __compressed_pair(_T1 __t1, _T2 __t2)
2210 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2213 _LIBCPP_INLINE_VISIBILITY
2214 typename _Base1::reference first() _NOEXCEPT {
2215 return static_cast<_Base1&>(*this).__get();
2218 _LIBCPP_INLINE_VISIBILITY
2219 typename _Base1::const_reference first() const _NOEXCEPT {
2220 return static_cast<_Base1 const&>(*this).__get();
2223 _LIBCPP_INLINE_VISIBILITY
2224 typename _Base2::reference second() _NOEXCEPT {
2225 return static_cast<_Base2&>(*this).__get();
2228 _LIBCPP_INLINE_VISIBILITY
2229 typename _Base2::const_reference second() const _NOEXCEPT {
2230 return static_cast<_Base2 const&>(*this).__get();
2233 _LIBCPP_INLINE_VISIBILITY
2234 void swap(__compressed_pair& __x)
2235 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2236 __is_nothrow_swappable<_T2>::value)
2239 swap(first(), __x.first());
2240 swap(second(), __x.second());
2244 template <class _T1, class _T2>
2245 inline _LIBCPP_INLINE_VISIBILITY
2246 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2247 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2248 __is_nothrow_swappable<_T2>::value) {
2254 template <class _Tp>
2255 struct _LIBCPP_TEMPLATE_VIS default_delete {
2256 static_assert(!is_function<_Tp>::value,
2257 "default_delete cannot be instantiated for function types");
2258 #ifndef _LIBCPP_CXX03_LANG
2259 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2261 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2263 template <class _Up>
2264 _LIBCPP_INLINE_VISIBILITY
2265 default_delete(const default_delete<_Up>&,
2266 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2269 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2270 static_assert(sizeof(_Tp) > 0,
2271 "default_delete can not delete incomplete type");
2272 static_assert(!is_void<_Tp>::value,
2273 "default_delete can not delete incomplete type");
2278 template <class _Tp>
2279 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2281 template <class _Up>
2282 struct _EnableIfConvertible
2283 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2286 #ifndef _LIBCPP_CXX03_LANG
2287 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2289 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2292 template <class _Up>
2293 _LIBCPP_INLINE_VISIBILITY
2294 default_delete(const default_delete<_Up[]>&,
2295 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2297 template <class _Up>
2298 _LIBCPP_INLINE_VISIBILITY
2299 typename _EnableIfConvertible<_Up>::type
2300 operator()(_Up* __ptr) const _NOEXCEPT {
2301 static_assert(sizeof(_Tp) > 0,
2302 "default_delete can not delete incomplete type");
2303 static_assert(!is_void<_Tp>::value,
2304 "default_delete can not delete void type");
2311 #ifndef _LIBCPP_CXX03_LANG
2312 template <class _Deleter>
2313 struct __unique_ptr_deleter_sfinae {
2314 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2315 typedef const _Deleter& __lval_ref_type;
2316 typedef _Deleter&& __good_rval_ref_type;
2317 typedef true_type __enable_rval_overload;
2320 template <class _Deleter>
2321 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2322 typedef const _Deleter& __lval_ref_type;
2323 typedef const _Deleter&& __bad_rval_ref_type;
2324 typedef false_type __enable_rval_overload;
2327 template <class _Deleter>
2328 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2329 typedef _Deleter& __lval_ref_type;
2330 typedef _Deleter&& __bad_rval_ref_type;
2331 typedef false_type __enable_rval_overload;
2333 #endif // !defined(_LIBCPP_CXX03_LANG)
2335 template <class _Tp, class _Dp = default_delete<_Tp> >
2336 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2338 typedef _Tp element_type;
2339 typedef _Dp deleter_type;
2340 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2342 static_assert(!is_rvalue_reference<deleter_type>::value,
2343 "the specified deleter type cannot be an rvalue reference");
2346 __compressed_pair<pointer, deleter_type> __ptr_;
2348 struct __nat { int __for_bool_; };
2350 #ifndef _LIBCPP_CXX03_LANG
2351 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2353 template <bool _Dummy>
2354 using _LValRefType =
2355 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2357 template <bool _Dummy>
2358 using _GoodRValRefType =
2359 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2361 template <bool _Dummy>
2362 using _BadRValRefType =
2363 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2365 template <bool _Dummy, class _Deleter = typename __dependent_type<
2366 __identity<deleter_type>, _Dummy>::type>
2367 using _EnableIfDeleterDefaultConstructible =
2368 typename enable_if<is_default_constructible<_Deleter>::value &&
2369 !is_pointer<_Deleter>::value>::type;
2371 template <class _ArgType>
2372 using _EnableIfDeleterConstructible =
2373 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2375 template <class _UPtr, class _Up>
2376 using _EnableIfMoveConvertible = typename enable_if<
2377 is_convertible<typename _UPtr::pointer, pointer>::value &&
2378 !is_array<_Up>::value
2381 template <class _UDel>
2382 using _EnableIfDeleterConvertible = typename enable_if<
2383 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2384 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2387 template <class _UDel>
2388 using _EnableIfDeleterAssignable = typename enable_if<
2389 is_assignable<_Dp&, _UDel&&>::value
2393 template <bool _Dummy = true,
2394 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2395 _LIBCPP_INLINE_VISIBILITY
2396 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2398 template <bool _Dummy = true,
2399 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2400 _LIBCPP_INLINE_VISIBILITY
2401 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2403 template <bool _Dummy = true,
2404 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2405 _LIBCPP_INLINE_VISIBILITY
2406 explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2408 template <bool _Dummy = true,
2409 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2410 _LIBCPP_INLINE_VISIBILITY
2411 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2412 : __ptr_(__p, __d) {}
2414 template <bool _Dummy = true,
2415 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2416 _LIBCPP_INLINE_VISIBILITY
2417 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2418 : __ptr_(__p, _VSTD::move(__d)) {
2419 static_assert(!is_reference<deleter_type>::value,
2420 "rvalue deleter bound to reference");
2423 template <bool _Dummy = true,
2424 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2425 _LIBCPP_INLINE_VISIBILITY
2426 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2428 _LIBCPP_INLINE_VISIBILITY
2429 unique_ptr(unique_ptr&& __u) noexcept
2430 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2433 template <class _Up, class _Ep,
2434 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2435 class = _EnableIfDeleterConvertible<_Ep>
2437 _LIBCPP_INLINE_VISIBILITY
2438 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2439 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2441 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2442 template <class _Up>
2443 _LIBCPP_INLINE_VISIBILITY
2444 unique_ptr(auto_ptr<_Up>&& __p,
2445 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2446 is_same<_Dp, default_delete<_Tp>>::value,
2447 __nat>::type = __nat()) _NOEXCEPT
2448 : __ptr_(__p.release()) {}
2451 _LIBCPP_INLINE_VISIBILITY
2452 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2453 reset(__u.release());
2454 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2458 template <class _Up, class _Ep,
2459 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2460 class = _EnableIfDeleterAssignable<_Ep>
2462 _LIBCPP_INLINE_VISIBILITY
2463 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2464 reset(__u.release());
2465 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2469 #else // _LIBCPP_CXX03_LANG
2471 unique_ptr(unique_ptr&);
2472 template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2474 unique_ptr& operator=(unique_ptr&);
2475 template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2478 _LIBCPP_INLINE_VISIBILITY
2479 unique_ptr() : __ptr_(pointer())
2481 static_assert(!is_pointer<deleter_type>::value,
2482 "unique_ptr constructed with null function pointer deleter");
2483 static_assert(is_default_constructible<deleter_type>::value,
2484 "unique_ptr::deleter_type is not default constructible");
2486 _LIBCPP_INLINE_VISIBILITY
2487 unique_ptr(nullptr_t) : __ptr_(pointer())
2489 static_assert(!is_pointer<deleter_type>::value,
2490 "unique_ptr constructed with null function pointer deleter");
2492 _LIBCPP_INLINE_VISIBILITY
2493 explicit unique_ptr(pointer __p)
2494 : __ptr_(_VSTD::move(__p)) {
2495 static_assert(!is_pointer<deleter_type>::value,
2496 "unique_ptr constructed with null function pointer deleter");
2499 _LIBCPP_INLINE_VISIBILITY
2500 operator __rv<unique_ptr>() {
2501 return __rv<unique_ptr>(*this);
2504 _LIBCPP_INLINE_VISIBILITY
2505 unique_ptr(__rv<unique_ptr> __u)
2506 : __ptr_(__u->release(),
2507 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2509 template <class _Up, class _Ep>
2510 _LIBCPP_INLINE_VISIBILITY
2512 !is_array<_Up>::value &&
2513 is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2515 is_assignable<deleter_type&, _Ep&>::value,
2517 operator=(unique_ptr<_Up, _Ep> __u) {
2518 reset(__u.release());
2519 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2523 _LIBCPP_INLINE_VISIBILITY
2524 unique_ptr(pointer __p, deleter_type __d)
2525 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2526 #endif // _LIBCPP_CXX03_LANG
2528 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2529 template <class _Up>
2530 _LIBCPP_INLINE_VISIBILITY
2531 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2532 is_same<_Dp, default_delete<_Tp> >::value,
2534 operator=(auto_ptr<_Up> __p) {
2535 reset(__p.release());
2540 _LIBCPP_INLINE_VISIBILITY
2541 ~unique_ptr() { reset(); }
2543 _LIBCPP_INLINE_VISIBILITY
2544 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2549 _LIBCPP_INLINE_VISIBILITY
2550 typename add_lvalue_reference<_Tp>::type
2552 return *__ptr_.first();
2554 _LIBCPP_INLINE_VISIBILITY
2555 pointer operator->() const _NOEXCEPT {
2556 return __ptr_.first();
2558 _LIBCPP_INLINE_VISIBILITY
2559 pointer get() const _NOEXCEPT {
2560 return __ptr_.first();
2562 _LIBCPP_INLINE_VISIBILITY
2563 deleter_type& get_deleter() _NOEXCEPT {
2564 return __ptr_.second();
2566 _LIBCPP_INLINE_VISIBILITY
2567 const deleter_type& get_deleter() const _NOEXCEPT {
2568 return __ptr_.second();
2570 _LIBCPP_INLINE_VISIBILITY
2571 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2572 return __ptr_.first() != nullptr;
2575 _LIBCPP_INLINE_VISIBILITY
2576 pointer release() _NOEXCEPT {
2577 pointer __t = __ptr_.first();
2578 __ptr_.first() = pointer();
2582 _LIBCPP_INLINE_VISIBILITY
2583 void reset(pointer __p = pointer()) _NOEXCEPT {
2584 pointer __tmp = __ptr_.first();
2585 __ptr_.first() = __p;
2587 __ptr_.second()(__tmp);
2590 _LIBCPP_INLINE_VISIBILITY
2591 void swap(unique_ptr& __u) _NOEXCEPT {
2592 __ptr_.swap(__u.__ptr_);
2597 template <class _Tp, class _Dp>
2598 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2600 typedef _Tp element_type;
2601 typedef _Dp deleter_type;
2602 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2605 __compressed_pair<pointer, deleter_type> __ptr_;
2607 template <class _From>
2608 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2610 template <class _FromElem>
2611 struct _CheckArrayPointerConversion<_FromElem*>
2612 : integral_constant<bool,
2613 is_same<_FromElem*, pointer>::value ||
2614 (is_same<pointer, element_type*>::value &&
2615 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2619 #ifndef _LIBCPP_CXX03_LANG
2620 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2622 template <bool _Dummy>
2623 using _LValRefType =
2624 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2626 template <bool _Dummy>
2627 using _GoodRValRefType =
2628 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2630 template <bool _Dummy>
2631 using _BadRValRefType =
2632 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2634 template <bool _Dummy, class _Deleter = typename __dependent_type<
2635 __identity<deleter_type>, _Dummy>::type>
2636 using _EnableIfDeleterDefaultConstructible =
2637 typename enable_if<is_default_constructible<_Deleter>::value &&
2638 !is_pointer<_Deleter>::value>::type;
2640 template <class _ArgType>
2641 using _EnableIfDeleterConstructible =
2642 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2644 template <class _Pp>
2645 using _EnableIfPointerConvertible = typename enable_if<
2646 _CheckArrayPointerConversion<_Pp>::value
2649 template <class _UPtr, class _Up,
2650 class _ElemT = typename _UPtr::element_type>
2651 using _EnableIfMoveConvertible = typename enable_if<
2652 is_array<_Up>::value &&
2653 is_same<pointer, element_type*>::value &&
2654 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2655 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2658 template <class _UDel>
2659 using _EnableIfDeleterConvertible = typename enable_if<
2660 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2661 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2664 template <class _UDel>
2665 using _EnableIfDeleterAssignable = typename enable_if<
2666 is_assignable<_Dp&, _UDel&&>::value
2670 template <bool _Dummy = true,
2671 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2672 _LIBCPP_INLINE_VISIBILITY
2673 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2675 template <bool _Dummy = true,
2676 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2677 _LIBCPP_INLINE_VISIBILITY
2678 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2680 template <class _Pp, bool _Dummy = true,
2681 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2682 class = _EnableIfPointerConvertible<_Pp>>
2683 _LIBCPP_INLINE_VISIBILITY
2684 explicit unique_ptr(_Pp __p) noexcept
2687 template <class _Pp, bool _Dummy = true,
2688 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2689 class = _EnableIfPointerConvertible<_Pp>>
2690 _LIBCPP_INLINE_VISIBILITY
2691 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2692 : __ptr_(__p, __d) {}
2694 template <bool _Dummy = true,
2695 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2696 _LIBCPP_INLINE_VISIBILITY
2697 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2698 : __ptr_(nullptr, __d) {}
2700 template <class _Pp, bool _Dummy = true,
2701 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2702 class = _EnableIfPointerConvertible<_Pp>>
2703 _LIBCPP_INLINE_VISIBILITY
2704 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2705 : __ptr_(__p, _VSTD::move(__d)) {
2706 static_assert(!is_reference<deleter_type>::value,
2707 "rvalue deleter bound to reference");
2710 template <bool _Dummy = true,
2711 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2712 _LIBCPP_INLINE_VISIBILITY
2713 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2714 : __ptr_(nullptr, _VSTD::move(__d)) {
2715 static_assert(!is_reference<deleter_type>::value,
2716 "rvalue deleter bound to reference");
2719 template <class _Pp, bool _Dummy = true,
2720 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2721 class = _EnableIfPointerConvertible<_Pp>>
2722 _LIBCPP_INLINE_VISIBILITY
2723 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2725 _LIBCPP_INLINE_VISIBILITY
2726 unique_ptr(unique_ptr&& __u) noexcept
2727 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2730 _LIBCPP_INLINE_VISIBILITY
2731 unique_ptr& operator=(unique_ptr&& __u) noexcept {
2732 reset(__u.release());
2733 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2737 template <class _Up, class _Ep,
2738 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2739 class = _EnableIfDeleterConvertible<_Ep>
2741 _LIBCPP_INLINE_VISIBILITY
2742 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
2743 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2746 template <class _Up, class _Ep,
2747 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2748 class = _EnableIfDeleterAssignable<_Ep>
2750 _LIBCPP_INLINE_VISIBILITY
2752 operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2753 reset(__u.release());
2754 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2758 #else // _LIBCPP_CXX03_LANG
2760 template <class _Up> explicit unique_ptr(_Up);
2762 unique_ptr(unique_ptr&);
2763 template <class _Up> unique_ptr(unique_ptr<_Up>&);
2765 unique_ptr& operator=(unique_ptr&);
2766 template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2768 template <class _Up>
2770 typename conditional<
2771 is_reference<deleter_type>::value, deleter_type,
2772 typename add_lvalue_reference<const deleter_type>::type>::type,
2773 typename enable_if<is_convertible<_Up, pointer>::value,
2774 __nat>::type = __nat());
2776 _LIBCPP_INLINE_VISIBILITY
2777 unique_ptr() : __ptr_(pointer()) {
2778 static_assert(!is_pointer<deleter_type>::value,
2779 "unique_ptr constructed with null function pointer deleter");
2781 _LIBCPP_INLINE_VISIBILITY
2782 unique_ptr(nullptr_t) : __ptr_(pointer()) {
2783 static_assert(!is_pointer<deleter_type>::value,
2784 "unique_ptr constructed with null function pointer deleter");
2787 _LIBCPP_INLINE_VISIBILITY
2788 explicit unique_ptr(pointer __p) : __ptr_(__p) {
2789 static_assert(!is_pointer<deleter_type>::value,
2790 "unique_ptr constructed with null function pointer deleter");
2793 _LIBCPP_INLINE_VISIBILITY
2794 unique_ptr(pointer __p, deleter_type __d)
2795 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2797 _LIBCPP_INLINE_VISIBILITY
2798 unique_ptr(nullptr_t, deleter_type __d)
2799 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2801 _LIBCPP_INLINE_VISIBILITY
2802 operator __rv<unique_ptr>() {
2803 return __rv<unique_ptr>(*this);
2806 _LIBCPP_INLINE_VISIBILITY
2807 unique_ptr(__rv<unique_ptr> __u)
2808 : __ptr_(__u->release(),
2809 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2811 _LIBCPP_INLINE_VISIBILITY
2812 unique_ptr& operator=(__rv<unique_ptr> __u) {
2813 reset(__u->release());
2814 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2818 #endif // _LIBCPP_CXX03_LANG
2821 _LIBCPP_INLINE_VISIBILITY
2822 ~unique_ptr() { reset(); }
2824 _LIBCPP_INLINE_VISIBILITY
2825 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2830 _LIBCPP_INLINE_VISIBILITY
2831 typename add_lvalue_reference<_Tp>::type
2832 operator[](size_t __i) const {
2833 return __ptr_.first()[__i];
2835 _LIBCPP_INLINE_VISIBILITY
2836 pointer get() const _NOEXCEPT {
2837 return __ptr_.first();
2840 _LIBCPP_INLINE_VISIBILITY
2841 deleter_type& get_deleter() _NOEXCEPT {
2842 return __ptr_.second();
2845 _LIBCPP_INLINE_VISIBILITY
2846 const deleter_type& get_deleter() const _NOEXCEPT {
2847 return __ptr_.second();
2849 _LIBCPP_INLINE_VISIBILITY
2850 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2851 return __ptr_.first() != nullptr;
2854 _LIBCPP_INLINE_VISIBILITY
2855 pointer release() _NOEXCEPT {
2856 pointer __t = __ptr_.first();
2857 __ptr_.first() = pointer();
2861 template <class _Pp>
2862 _LIBCPP_INLINE_VISIBILITY
2864 _CheckArrayPointerConversion<_Pp>::value
2866 reset(_Pp __p) _NOEXCEPT {
2867 pointer __tmp = __ptr_.first();
2868 __ptr_.first() = __p;
2870 __ptr_.second()(__tmp);
2873 _LIBCPP_INLINE_VISIBILITY
2874 void reset(nullptr_t = nullptr) _NOEXCEPT {
2875 pointer __tmp = __ptr_.first();
2876 __ptr_.first() = nullptr;
2878 __ptr_.second()(__tmp);
2881 _LIBCPP_INLINE_VISIBILITY
2882 void swap(unique_ptr& __u) _NOEXCEPT {
2883 __ptr_.swap(__u.__ptr_);
2888 template <class _Tp, class _Dp>
2889 inline _LIBCPP_INLINE_VISIBILITY
2891 __is_swappable<_Dp>::value,
2894 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2896 template <class _T1, class _D1, class _T2, class _D2>
2897 inline _LIBCPP_INLINE_VISIBILITY
2899 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2901 template <class _T1, class _D1, class _T2, class _D2>
2902 inline _LIBCPP_INLINE_VISIBILITY
2904 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2906 template <class _T1, class _D1, class _T2, class _D2>
2907 inline _LIBCPP_INLINE_VISIBILITY
2909 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2911 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2912 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2913 typedef typename common_type<_P1, _P2>::type _Vp;
2914 return less<_Vp>()(__x.get(), __y.get());
2917 template <class _T1, class _D1, class _T2, class _D2>
2918 inline _LIBCPP_INLINE_VISIBILITY
2920 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2922 template <class _T1, class _D1, class _T2, class _D2>
2923 inline _LIBCPP_INLINE_VISIBILITY
2925 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2927 template <class _T1, class _D1, class _T2, class _D2>
2928 inline _LIBCPP_INLINE_VISIBILITY
2930 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2932 template <class _T1, class _D1>
2933 inline _LIBCPP_INLINE_VISIBILITY
2935 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2940 template <class _T1, class _D1>
2941 inline _LIBCPP_INLINE_VISIBILITY
2943 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2948 template <class _T1, class _D1>
2949 inline _LIBCPP_INLINE_VISIBILITY
2951 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2953 return static_cast<bool>(__x);
2956 template <class _T1, class _D1>
2957 inline _LIBCPP_INLINE_VISIBILITY
2959 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2961 return static_cast<bool>(__x);
2964 template <class _T1, class _D1>
2965 inline _LIBCPP_INLINE_VISIBILITY
2967 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2969 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2970 return less<_P1>()(__x.get(), nullptr);
2973 template <class _T1, class _D1>
2974 inline _LIBCPP_INLINE_VISIBILITY
2976 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2978 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2979 return less<_P1>()(nullptr, __x.get());
2982 template <class _T1, class _D1>
2983 inline _LIBCPP_INLINE_VISIBILITY
2985 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2987 return nullptr < __x;
2990 template <class _T1, class _D1>
2991 inline _LIBCPP_INLINE_VISIBILITY
2993 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2995 return __x < nullptr;
2998 template <class _T1, class _D1>
2999 inline _LIBCPP_INLINE_VISIBILITY
3001 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3003 return !(nullptr < __x);
3006 template <class _T1, class _D1>
3007 inline _LIBCPP_INLINE_VISIBILITY
3009 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3011 return !(__x < nullptr);
3014 template <class _T1, class _D1>
3015 inline _LIBCPP_INLINE_VISIBILITY
3017 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
3019 return !(__x < nullptr);
3022 template <class _T1, class _D1>
3023 inline _LIBCPP_INLINE_VISIBILITY
3025 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
3027 return !(nullptr < __x);
3030 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3032 template <class _Tp, class _Dp>
3033 inline _LIBCPP_INLINE_VISIBILITY
3034 unique_ptr<_Tp, _Dp>
3035 move(unique_ptr<_Tp, _Dp>& __t)
3037 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3042 #if _LIBCPP_STD_VER > 11
3047 typedef unique_ptr<_Tp> __unique_single;
3051 struct __unique_if<_Tp[]>
3053 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3056 template<class _Tp, size_t _Np>
3057 struct __unique_if<_Tp[_Np]>
3059 typedef void __unique_array_known_bound;
3062 template<class _Tp, class... _Args>
3063 inline _LIBCPP_INLINE_VISIBILITY
3064 typename __unique_if<_Tp>::__unique_single
3065 make_unique(_Args&&... __args)
3067 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3071 inline _LIBCPP_INLINE_VISIBILITY
3072 typename __unique_if<_Tp>::__unique_array_unknown_bound
3073 make_unique(size_t __n)
3075 typedef typename remove_extent<_Tp>::type _Up;
3076 return unique_ptr<_Tp>(new _Up[__n]());
3079 template<class _Tp, class... _Args>
3080 typename __unique_if<_Tp>::__unique_array_known_bound
3081 make_unique(_Args&&...) = delete;
3083 #endif // _LIBCPP_STD_VER > 11
3085 template <class _Tp, class _Dp>
3086 #ifdef _LIBCPP_CXX03_LANG
3087 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3089 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3090 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3093 typedef unique_ptr<_Tp, _Dp> argument_type;
3094 typedef size_t result_type;
3095 _LIBCPP_INLINE_VISIBILITY
3096 result_type operator()(const argument_type& __ptr) const
3098 typedef typename argument_type::pointer pointer;
3099 return hash<pointer>()(__ptr.get());
3108 template <class _Tp>
3109 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3110 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3112 template <class _Tp>
3113 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3116 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3118 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3121 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3123 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3126 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3129 template <class _Tp>
3130 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3131 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3133 template <class _Tp>
3134 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3135 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3137 template <class _Tp>
3138 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3139 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3142 template <class _Alloc>
3143 class __allocator_destructor
3145 typedef allocator_traits<_Alloc> __alloc_traits;
3147 typedef typename __alloc_traits::pointer pointer;
3148 typedef typename __alloc_traits::size_type size_type;
3153 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3155 : __alloc_(__a), __s_(__s) {}
3156 _LIBCPP_INLINE_VISIBILITY
3157 void operator()(pointer __p) _NOEXCEPT
3158 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3161 template <class _InputIterator, class _ForwardIterator>
3163 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3165 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3166 #ifndef _LIBCPP_NO_EXCEPTIONS
3167 _ForwardIterator __s = __r;
3171 for (; __f != __l; ++__f, (void) ++__r)
3172 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3173 #ifndef _LIBCPP_NO_EXCEPTIONS
3177 for (; __s != __r; ++__s)
3185 template <class _InputIterator, class _Size, class _ForwardIterator>
3187 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3189 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3190 #ifndef _LIBCPP_NO_EXCEPTIONS
3191 _ForwardIterator __s = __r;
3195 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3196 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3197 #ifndef _LIBCPP_NO_EXCEPTIONS
3201 for (; __s != __r; ++__s)
3209 template <class _ForwardIterator, class _Tp>
3211 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3213 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3214 #ifndef _LIBCPP_NO_EXCEPTIONS
3215 _ForwardIterator __s = __f;
3219 for (; __f != __l; ++__f)
3220 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3221 #ifndef _LIBCPP_NO_EXCEPTIONS
3225 for (; __s != __f; ++__s)
3232 template <class _ForwardIterator, class _Size, class _Tp>
3234 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3236 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3237 #ifndef _LIBCPP_NO_EXCEPTIONS
3238 _ForwardIterator __s = __f;
3242 for (; __n > 0; ++__f, (void) --__n)
3243 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3244 #ifndef _LIBCPP_NO_EXCEPTIONS
3248 for (; __s != __f; ++__s)
3256 #if _LIBCPP_STD_VER > 14
3258 template <class _Tp>
3259 inline _LIBCPP_INLINE_VISIBILITY
3260 void destroy_at(_Tp* __loc) {
3261 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3265 template <class _ForwardIterator>
3266 inline _LIBCPP_INLINE_VISIBILITY
3267 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3268 for (; __first != __last; ++__first)
3269 _VSTD::destroy_at(_VSTD::addressof(*__first));
3272 template <class _ForwardIterator, class _Size>
3273 inline _LIBCPP_INLINE_VISIBILITY
3274 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3275 for (; __n > 0; (void)++__first, --__n)
3276 _VSTD::destroy_at(_VSTD::addressof(*__first));
3280 template <class _ForwardIterator>
3281 inline _LIBCPP_INLINE_VISIBILITY
3282 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3283 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3284 auto __idx = __first;
3285 #ifndef _LIBCPP_NO_EXCEPTIONS
3288 for (; __idx != __last; ++__idx)
3289 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3290 #ifndef _LIBCPP_NO_EXCEPTIONS
3292 _VSTD::destroy(__first, __idx);
3298 template <class _ForwardIterator, class _Size>
3299 inline _LIBCPP_INLINE_VISIBILITY
3300 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3301 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3302 auto __idx = __first;
3303 #ifndef _LIBCPP_NO_EXCEPTIONS
3306 for (; __n > 0; (void)++__idx, --__n)
3307 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3309 #ifndef _LIBCPP_NO_EXCEPTIONS
3311 _VSTD::destroy(__first, __idx);
3318 template <class _ForwardIterator>
3319 inline _LIBCPP_INLINE_VISIBILITY
3320 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3321 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3322 auto __idx = __first;
3323 #ifndef _LIBCPP_NO_EXCEPTIONS
3326 for (; __idx != __last; ++__idx)
3327 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3328 #ifndef _LIBCPP_NO_EXCEPTIONS
3330 _VSTD::destroy(__first, __idx);
3336 template <class _ForwardIterator, class _Size>
3337 inline _LIBCPP_INLINE_VISIBILITY
3338 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3339 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3340 auto __idx = __first;
3341 #ifndef _LIBCPP_NO_EXCEPTIONS
3344 for (; __n > 0; (void)++__idx, --__n)
3345 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3347 #ifndef _LIBCPP_NO_EXCEPTIONS
3349 _VSTD::destroy(__first, __idx);
3356 template <class _InputIt, class _ForwardIt>
3357 inline _LIBCPP_INLINE_VISIBILITY
3358 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3359 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3360 auto __idx = __first_res;
3361 #ifndef _LIBCPP_NO_EXCEPTIONS
3364 for (; __first != __last; (void)++__idx, ++__first)
3365 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3367 #ifndef _LIBCPP_NO_EXCEPTIONS
3369 _VSTD::destroy(__first_res, __idx);
3375 template <class _InputIt, class _Size, class _ForwardIt>
3376 inline _LIBCPP_INLINE_VISIBILITY
3377 pair<_InputIt, _ForwardIt>
3378 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3379 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3380 auto __idx = __first_res;
3381 #ifndef _LIBCPP_NO_EXCEPTIONS
3384 for (; __n > 0; ++__idx, (void)++__first, --__n)
3385 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3386 return {__first, __idx};
3387 #ifndef _LIBCPP_NO_EXCEPTIONS
3389 _VSTD::destroy(__first_res, __idx);
3396 #endif // _LIBCPP_STD_VER > 14
3398 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3399 // should be sufficient for thread safety.
3400 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3401 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3402 && defined(__ATOMIC_RELAXED) \
3403 && defined(__ATOMIC_ACQ_REL)
3404 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3405 #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3406 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3409 template <class _Tp>
3410 inline _LIBCPP_INLINE_VISIBILITY _Tp
3411 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3413 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3414 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3420 template <class _Tp>
3421 inline _LIBCPP_INLINE_VISIBILITY _Tp
3422 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3424 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3425 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3431 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3432 : public std::exception
3435 virtual ~bad_weak_ptr() _NOEXCEPT;
3436 virtual const char* what() const _NOEXCEPT;
3439 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3440 void __throw_bad_weak_ptr()
3442 #ifndef _LIBCPP_NO_EXCEPTIONS
3443 throw bad_weak_ptr();
3449 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3451 class _LIBCPP_TYPE_VIS __shared_count
3453 __shared_count(const __shared_count&);
3454 __shared_count& operator=(const __shared_count&);
3457 long __shared_owners_;
3458 virtual ~__shared_count();
3460 virtual void __on_zero_shared() _NOEXCEPT = 0;
3463 _LIBCPP_INLINE_VISIBILITY
3464 explicit __shared_count(long __refs = 0) _NOEXCEPT
3465 : __shared_owners_(__refs) {}
3467 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3468 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3469 void __add_shared() _NOEXCEPT;
3470 bool __release_shared() _NOEXCEPT;
3472 _LIBCPP_INLINE_VISIBILITY
3473 void __add_shared() _NOEXCEPT {
3474 __libcpp_atomic_refcount_increment(__shared_owners_);
3476 _LIBCPP_INLINE_VISIBILITY
3477 bool __release_shared() _NOEXCEPT {
3478 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3485 _LIBCPP_INLINE_VISIBILITY
3486 long use_count() const _NOEXCEPT {
3487 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3491 class _LIBCPP_TYPE_VIS __shared_weak_count
3492 : private __shared_count
3494 long __shared_weak_owners_;
3497 _LIBCPP_INLINE_VISIBILITY
3498 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3499 : __shared_count(__refs),
3500 __shared_weak_owners_(__refs) {}
3502 virtual ~__shared_weak_count();
3505 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3506 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3507 void __add_shared() _NOEXCEPT;
3508 void __add_weak() _NOEXCEPT;
3509 void __release_shared() _NOEXCEPT;
3511 _LIBCPP_INLINE_VISIBILITY
3512 void __add_shared() _NOEXCEPT {
3513 __shared_count::__add_shared();
3515 _LIBCPP_INLINE_VISIBILITY
3516 void __add_weak() _NOEXCEPT {
3517 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3519 _LIBCPP_INLINE_VISIBILITY
3520 void __release_shared() _NOEXCEPT {
3521 if (__shared_count::__release_shared())
3525 void __release_weak() _NOEXCEPT;
3526 _LIBCPP_INLINE_VISIBILITY
3527 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3528 __shared_weak_count* lock() _NOEXCEPT;
3530 // Define the function out only if we build static libc++ without RTTI.
3531 // Otherwise we may break clients who need to compile their projects with
3532 // -fno-rtti and yet link against a libc++.dylib compiled
3533 // without -fno-rtti.
3534 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3535 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3538 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3541 template <class _Tp, class _Dp, class _Alloc>
3542 class __shared_ptr_pointer
3543 : public __shared_weak_count
3545 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3547 _LIBCPP_INLINE_VISIBILITY
3548 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3549 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3551 #ifndef _LIBCPP_NO_RTTI
3552 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3556 virtual void __on_zero_shared() _NOEXCEPT;
3557 virtual void __on_zero_shared_weak() _NOEXCEPT;
3560 #ifndef _LIBCPP_NO_RTTI
3562 template <class _Tp, class _Dp, class _Alloc>
3564 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3566 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3569 #endif // _LIBCPP_NO_RTTI
3571 template <class _Tp, class _Dp, class _Alloc>
3573 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3575 __data_.first().second()(__data_.first().first());
3576 __data_.first().second().~_Dp();
3579 template <class _Tp, class _Dp, class _Alloc>
3581 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3583 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3584 typedef allocator_traits<_Al> _ATraits;
3585 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3587 _Al __a(__data_.second());
3588 __data_.second().~_Alloc();
3589 __a.deallocate(_PTraits::pointer_to(*this), 1);
3592 template <class _Tp, class _Alloc>
3593 class __shared_ptr_emplace
3594 : public __shared_weak_count
3596 __compressed_pair<_Alloc, _Tp> __data_;
3598 #ifndef _LIBCPP_HAS_NO_VARIADICS
3600 _LIBCPP_INLINE_VISIBILITY
3601 __shared_ptr_emplace(_Alloc __a)
3602 : __data_(_VSTD::move(__a)) {}
3604 template <class ..._Args>
3605 _LIBCPP_INLINE_VISIBILITY
3606 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3607 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3608 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3610 #else // _LIBCPP_HAS_NO_VARIADICS
3612 _LIBCPP_INLINE_VISIBILITY
3613 __shared_ptr_emplace(_Alloc __a)
3616 template <class _A0>
3617 _LIBCPP_INLINE_VISIBILITY
3618 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3619 : __data_(__a, _Tp(__a0)) {}
3621 template <class _A0, class _A1>
3622 _LIBCPP_INLINE_VISIBILITY
3623 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3624 : __data_(__a, _Tp(__a0, __a1)) {}
3626 template <class _A0, class _A1, class _A2>
3627 _LIBCPP_INLINE_VISIBILITY
3628 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3629 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3631 #endif // _LIBCPP_HAS_NO_VARIADICS
3634 virtual void __on_zero_shared() _NOEXCEPT;
3635 virtual void __on_zero_shared_weak() _NOEXCEPT;
3637 _LIBCPP_INLINE_VISIBILITY
3638 _Tp* get() _NOEXCEPT {return &__data_.second();}
3641 template <class _Tp, class _Alloc>
3643 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3645 __data_.second().~_Tp();
3648 template <class _Tp, class _Alloc>
3650 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3652 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3653 typedef allocator_traits<_Al> _ATraits;
3654 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3655 _Al __a(__data_.first());
3656 __data_.first().~_Alloc();
3657 __a.deallocate(_PTraits::pointer_to(*this), 1);
3660 struct __shared_ptr_dummy_rebind_allocator_type;
3662 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3665 template <class _Other>
3668 typedef allocator<_Other> other;
3672 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3675 class _LIBCPP_TEMPLATE_VIS shared_ptr
3678 typedef _Tp element_type;
3680 #if _LIBCPP_STD_VER > 14
3681 typedef weak_ptr<_Tp> weak_type;
3684 element_type* __ptr_;
3685 __shared_weak_count* __cntrl_;
3687 struct __nat {int __for_bool_;};
3689 _LIBCPP_INLINE_VISIBILITY
3690 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3691 _LIBCPP_INLINE_VISIBILITY
3692 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3694 explicit shared_ptr(_Yp* __p,
3695 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3696 template<class _Yp, class _Dp>
3697 shared_ptr(_Yp* __p, _Dp __d,
3698 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3699 template<class _Yp, class _Dp, class _Alloc>
3700 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3701 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3702 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3703 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3704 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3705 _LIBCPP_INLINE_VISIBILITY
3706 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3708 _LIBCPP_INLINE_VISIBILITY
3709 shared_ptr(const shared_ptr<_Yp>& __r,
3710 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3712 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3713 _LIBCPP_INLINE_VISIBILITY
3714 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3715 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3716 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3718 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3719 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3720 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3721 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3722 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3724 shared_ptr(auto_ptr<_Yp>&& __r,
3725 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3728 shared_ptr(auto_ptr<_Yp> __r,
3729 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3732 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3733 template <class _Yp, class _Dp>
3734 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3737 !is_lvalue_reference<_Dp>::value &&
3738 !is_array<_Yp>::value &&
3739 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3742 template <class _Yp, class _Dp>
3743 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3746 is_lvalue_reference<_Dp>::value &&
3747 !is_array<_Yp>::value &&
3748 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3751 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3752 template <class _Yp, class _Dp>
3753 shared_ptr(unique_ptr<_Yp, _Dp>,
3756 !is_lvalue_reference<_Dp>::value &&
3757 !is_array<_Yp>::value &&
3758 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3761 template <class _Yp, class _Dp>
3762 shared_ptr(unique_ptr<_Yp, _Dp>,
3765 is_lvalue_reference<_Dp>::value &&
3766 !is_array<_Yp>::value &&
3767 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3770 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3774 _LIBCPP_INLINE_VISIBILITY
3775 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3779 is_convertible<_Yp*, element_type*>::value,
3782 _LIBCPP_INLINE_VISIBILITY
3783 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3784 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3785 _LIBCPP_INLINE_VISIBILITY
3786 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3790 is_convertible<_Yp*, element_type*>::value,
3793 _LIBCPP_INLINE_VISIBILITY
3794 operator=(shared_ptr<_Yp>&& __r);
3795 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3797 _LIBCPP_INLINE_VISIBILITY
3800 !is_array<_Yp>::value &&
3801 is_convertible<_Yp*, element_type*>::value,
3804 operator=(auto_ptr<_Yp>&& __r);
3806 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3807 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3809 _LIBCPP_INLINE_VISIBILITY
3812 !is_array<_Yp>::value &&
3813 is_convertible<_Yp*, element_type*>::value,
3816 operator=(auto_ptr<_Yp> __r);
3819 template <class _Yp, class _Dp>
3822 !is_array<_Yp>::value &&
3823 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3826 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3827 _LIBCPP_INLINE_VISIBILITY
3828 operator=(unique_ptr<_Yp, _Dp>&& __r);
3829 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3830 _LIBCPP_INLINE_VISIBILITY
3831 operator=(unique_ptr<_Yp, _Dp> __r);
3834 _LIBCPP_INLINE_VISIBILITY
3835 void swap(shared_ptr& __r) _NOEXCEPT;
3836 _LIBCPP_INLINE_VISIBILITY
3837 void reset() _NOEXCEPT;
3841 is_convertible<_Yp*, element_type*>::value,
3844 _LIBCPP_INLINE_VISIBILITY
3846 template<class _Yp, class _Dp>
3849 is_convertible<_Yp*, element_type*>::value,
3852 _LIBCPP_INLINE_VISIBILITY
3853 reset(_Yp* __p, _Dp __d);
3854 template<class _Yp, class _Dp, class _Alloc>
3857 is_convertible<_Yp*, element_type*>::value,
3860 _LIBCPP_INLINE_VISIBILITY
3861 reset(_Yp* __p, _Dp __d, _Alloc __a);
3863 _LIBCPP_INLINE_VISIBILITY
3864 element_type* get() const _NOEXCEPT {return __ptr_;}
3865 _LIBCPP_INLINE_VISIBILITY
3866 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3868 _LIBCPP_INLINE_VISIBILITY
3869 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3870 _LIBCPP_INLINE_VISIBILITY
3871 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3872 _LIBCPP_INLINE_VISIBILITY
3873 bool unique() const _NOEXCEPT {return use_count() == 1;}
3874 _LIBCPP_INLINE_VISIBILITY
3875 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3876 template <class _Up>
3877 _LIBCPP_INLINE_VISIBILITY
3878 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3879 {return __cntrl_ < __p.__cntrl_;}
3880 template <class _Up>
3881 _LIBCPP_INLINE_VISIBILITY
3882 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3883 {return __cntrl_ < __p.__cntrl_;}
3884 _LIBCPP_INLINE_VISIBILITY
3886 __owner_equivalent(const shared_ptr& __p) const
3887 {return __cntrl_ == __p.__cntrl_;}
3889 #ifndef _LIBCPP_NO_RTTI
3890 template <class _Dp>
3891 _LIBCPP_INLINE_VISIBILITY
3892 _Dp* __get_deleter() const _NOEXCEPT
3893 {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
3894 #endif // _LIBCPP_NO_RTTI
3896 #ifndef _LIBCPP_HAS_NO_VARIADICS
3898 template<class ..._Args>
3901 make_shared(_Args&& ...__args);
3903 template<class _Alloc, class ..._Args>
3906 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3908 #else // _LIBCPP_HAS_NO_VARIADICS
3910 static shared_ptr<_Tp> make_shared();
3913 static shared_ptr<_Tp> make_shared(_A0&);
3915 template<class _A0, class _A1>
3916 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3918 template<class _A0, class _A1, class _A2>
3919 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3921 template<class _Alloc>
3922 static shared_ptr<_Tp>
3923 allocate_shared(const _Alloc& __a);
3925 template<class _Alloc, class _A0>
3926 static shared_ptr<_Tp>
3927 allocate_shared(const _Alloc& __a, _A0& __a0);
3929 template<class _Alloc, class _A0, class _A1>
3930 static shared_ptr<_Tp>
3931 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3933 template<class _Alloc, class _A0, class _A1, class _A2>
3934 static shared_ptr<_Tp>
3935 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3937 #endif // _LIBCPP_HAS_NO_VARIADICS
3940 template <class _Yp, bool = is_function<_Yp>::value>
3941 struct __shared_ptr_default_allocator
3943 typedef allocator<_Yp> type;
3946 template <class _Yp>
3947 struct __shared_ptr_default_allocator<_Yp, true>
3949 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3952 template <class _Yp, class _OrigPtr>
3953 _LIBCPP_INLINE_VISIBILITY
3954 typename enable_if<is_convertible<_OrigPtr*,
3955 const enable_shared_from_this<_Yp>*
3958 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3959 _OrigPtr* __ptr) _NOEXCEPT
3961 typedef typename remove_cv<_Yp>::type _RawYp;
3962 if (__e && __e->__weak_this_.expired())
3964 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3965 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
3969 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
3971 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3972 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
3979 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3988 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
3996 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3997 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4000 unique_ptr<_Yp> __hold(__p);
4001 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4002 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
4003 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
4005 __enable_weak_this(__p, __p);
4009 template<class _Yp, class _Dp>
4010 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
4011 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4014 #ifndef _LIBCPP_NO_EXCEPTIONS
4017 #endif // _LIBCPP_NO_EXCEPTIONS
4018 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4019 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4020 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4021 __enable_weak_this(__p, __p);
4022 #ifndef _LIBCPP_NO_EXCEPTIONS
4029 #endif // _LIBCPP_NO_EXCEPTIONS
4034 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
4037 #ifndef _LIBCPP_NO_EXCEPTIONS
4040 #endif // _LIBCPP_NO_EXCEPTIONS
4041 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4042 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4043 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4044 #ifndef _LIBCPP_NO_EXCEPTIONS
4051 #endif // _LIBCPP_NO_EXCEPTIONS
4055 template<class _Yp, class _Dp, class _Alloc>
4056 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4057 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4060 #ifndef _LIBCPP_NO_EXCEPTIONS
4063 #endif // _LIBCPP_NO_EXCEPTIONS
4064 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4065 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4066 typedef __allocator_destructor<_A2> _D2;
4068 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4069 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4070 _CntrlBlk(__p, __d, __a);
4071 __cntrl_ = _VSTD::addressof(*__hold2.release());
4072 __enable_weak_this(__p, __p);
4073 #ifndef _LIBCPP_NO_EXCEPTIONS
4080 #endif // _LIBCPP_NO_EXCEPTIONS
4084 template<class _Dp, class _Alloc>
4085 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4088 #ifndef _LIBCPP_NO_EXCEPTIONS
4091 #endif // _LIBCPP_NO_EXCEPTIONS
4092 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4093 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4094 typedef __allocator_destructor<_A2> _D2;
4096 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4097 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4098 _CntrlBlk(__p, __d, __a);
4099 __cntrl_ = _VSTD::addressof(*__hold2.release());
4100 #ifndef _LIBCPP_NO_EXCEPTIONS
4107 #endif // _LIBCPP_NO_EXCEPTIONS
4113 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4115 __cntrl_(__r.__cntrl_)
4118 __cntrl_->__add_shared();
4123 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4124 : __ptr_(__r.__ptr_),
4125 __cntrl_(__r.__cntrl_)
4128 __cntrl_->__add_shared();
4134 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4135 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4137 : __ptr_(__r.__ptr_),
4138 __cntrl_(__r.__cntrl_)
4141 __cntrl_->__add_shared();
4144 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4148 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4149 : __ptr_(__r.__ptr_),
4150 __cntrl_(__r.__cntrl_)
4159 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4160 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4162 : __ptr_(__r.__ptr_),
4163 __cntrl_(__r.__cntrl_)
4169 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4171 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4174 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4175 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4177 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4179 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4182 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4183 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4184 __enable_weak_this(__r.get(), __r.get());
4190 template <class _Yp, class _Dp>
4191 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4192 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4194 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4198 !is_lvalue_reference<_Dp>::value &&
4199 !is_array<_Yp>::value &&
4200 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4205 #if _LIBCPP_STD_VER > 11
4206 if (__ptr_ == nullptr)
4211 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4212 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4213 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4214 __enable_weak_this(__r.get(), __r.get());
4220 template <class _Yp, class _Dp>
4221 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4222 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4224 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4228 is_lvalue_reference<_Dp>::value &&
4229 !is_array<_Yp>::value &&
4230 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4235 #if _LIBCPP_STD_VER > 11
4236 if (__ptr_ == nullptr)
4241 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4242 typedef __shared_ptr_pointer<_Yp*,
4243 reference_wrapper<typename remove_reference<_Dp>::type>,
4244 _AllocT > _CntrlBlk;
4245 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4246 __enable_weak_this(__r.get(), __r.get());
4251 #ifndef _LIBCPP_HAS_NO_VARIADICS
4254 template<class ..._Args>
4256 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4258 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4259 typedef allocator<_CntrlBlk> _A2;
4260 typedef __allocator_destructor<_A2> _D2;
4262 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4263 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4264 shared_ptr<_Tp> __r;
4265 __r.__ptr_ = __hold2.get()->get();
4266 __r.__cntrl_ = __hold2.release();
4267 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4272 template<class _Alloc, class ..._Args>
4274 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4276 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4277 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4278 typedef __allocator_destructor<_A2> _D2;
4280 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4281 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4282 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4283 shared_ptr<_Tp> __r;
4284 __r.__ptr_ = __hold2.get()->get();
4285 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4286 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4290 #else // _LIBCPP_HAS_NO_VARIADICS
4294 shared_ptr<_Tp>::make_shared()
4296 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4297 typedef allocator<_CntrlBlk> _Alloc2;
4298 typedef __allocator_destructor<_Alloc2> _D2;
4300 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4301 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4302 shared_ptr<_Tp> __r;
4303 __r.__ptr_ = __hold2.get()->get();
4304 __r.__cntrl_ = __hold2.release();
4305 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4312 shared_ptr<_Tp>::make_shared(_A0& __a0)
4314 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4315 typedef allocator<_CntrlBlk> _Alloc2;
4316 typedef __allocator_destructor<_Alloc2> _D2;
4318 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4319 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4320 shared_ptr<_Tp> __r;
4321 __r.__ptr_ = __hold2.get()->get();
4322 __r.__cntrl_ = __hold2.release();
4323 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4328 template<class _A0, class _A1>
4330 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4332 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4333 typedef allocator<_CntrlBlk> _Alloc2;
4334 typedef __allocator_destructor<_Alloc2> _D2;
4336 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4337 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4338 shared_ptr<_Tp> __r;
4339 __r.__ptr_ = __hold2.get()->get();
4340 __r.__cntrl_ = __hold2.release();
4341 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4346 template<class _A0, class _A1, class _A2>
4348 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4350 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4351 typedef allocator<_CntrlBlk> _Alloc2;
4352 typedef __allocator_destructor<_Alloc2> _D2;
4354 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4355 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4356 shared_ptr<_Tp> __r;
4357 __r.__ptr_ = __hold2.get()->get();
4358 __r.__cntrl_ = __hold2.release();
4359 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4364 template<class _Alloc>
4366 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4368 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4369 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4370 typedef __allocator_destructor<_Alloc2> _D2;
4371 _Alloc2 __alloc2(__a);
4372 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4373 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4375 shared_ptr<_Tp> __r;
4376 __r.__ptr_ = __hold2.get()->get();
4377 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4378 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4383 template<class _Alloc, class _A0>
4385 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4387 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4388 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4389 typedef __allocator_destructor<_Alloc2> _D2;
4390 _Alloc2 __alloc2(__a);
4391 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4392 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4393 _CntrlBlk(__a, __a0);
4394 shared_ptr<_Tp> __r;
4395 __r.__ptr_ = __hold2.get()->get();
4396 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4397 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4402 template<class _Alloc, class _A0, class _A1>
4404 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4406 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4407 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4408 typedef __allocator_destructor<_Alloc2> _D2;
4409 _Alloc2 __alloc2(__a);
4410 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4411 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4412 _CntrlBlk(__a, __a0, __a1);
4413 shared_ptr<_Tp> __r;
4414 __r.__ptr_ = __hold2.get()->get();
4415 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4416 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4421 template<class _Alloc, class _A0, class _A1, class _A2>
4423 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
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, __a2);
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_);
4439 #endif // _LIBCPP_HAS_NO_VARIADICS
4442 shared_ptr<_Tp>::~shared_ptr()
4445 __cntrl_->__release_shared();
4451 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4453 shared_ptr(__r).swap(*this);
4462 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4465 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4467 shared_ptr(__r).swap(*this);
4471 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4476 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4478 shared_ptr(_VSTD::move(__r)).swap(*this);
4487 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4490 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4492 shared_ptr(_VSTD::move(__r)).swap(*this);
4496 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4502 !is_array<_Yp>::value &&
4503 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4506 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4508 shared_ptr(_VSTD::move(__r)).swap(*this);
4514 template <class _Yp, class _Dp>
4518 !is_array<_Yp>::value &&
4519 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4520 typename shared_ptr<_Tp>::element_type*>::value,
4523 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4525 shared_ptr(_VSTD::move(__r)).swap(*this);
4529 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4531 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4534 inline _LIBCPP_INLINE_VISIBILITY
4537 !is_array<_Yp>::value &&
4538 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4541 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4543 shared_ptr(__r).swap(*this);
4549 template <class _Yp, class _Dp>
4550 inline _LIBCPP_INLINE_VISIBILITY
4553 !is_array<_Yp>::value &&
4554 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4555 typename shared_ptr<_Tp>::element_type*>::value,
4558 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4560 shared_ptr(_VSTD::move(__r)).swap(*this);
4564 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4569 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4571 _VSTD::swap(__ptr_, __r.__ptr_);
4572 _VSTD::swap(__cntrl_, __r.__cntrl_);
4578 shared_ptr<_Tp>::reset() _NOEXCEPT
4580 shared_ptr().swap(*this);
4588 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4591 shared_ptr<_Tp>::reset(_Yp* __p)
4593 shared_ptr(__p).swap(*this);
4597 template<class _Yp, class _Dp>
4601 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4604 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4606 shared_ptr(__p, __d).swap(*this);
4610 template<class _Yp, class _Dp, class _Alloc>
4614 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4617 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4619 shared_ptr(__p, __d, __a).swap(*this);
4622 #ifndef _LIBCPP_HAS_NO_VARIADICS
4624 template<class _Tp, class ..._Args>
4625 inline _LIBCPP_INLINE_VISIBILITY
4628 !is_array<_Tp>::value,
4631 make_shared(_Args&& ...__args)
4633 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4636 template<class _Tp, class _Alloc, class ..._Args>
4637 inline _LIBCPP_INLINE_VISIBILITY
4640 !is_array<_Tp>::value,
4643 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4645 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4648 #else // _LIBCPP_HAS_NO_VARIADICS
4651 inline _LIBCPP_INLINE_VISIBILITY
4655 return shared_ptr<_Tp>::make_shared();
4658 template<class _Tp, class _A0>
4659 inline _LIBCPP_INLINE_VISIBILITY
4661 make_shared(_A0& __a0)
4663 return shared_ptr<_Tp>::make_shared(__a0);
4666 template<class _Tp, class _A0, class _A1>
4667 inline _LIBCPP_INLINE_VISIBILITY
4669 make_shared(_A0& __a0, _A1& __a1)
4671 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4674 template<class _Tp, class _A0, class _A1, class _A2>
4675 inline _LIBCPP_INLINE_VISIBILITY
4677 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4679 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4682 template<class _Tp, class _Alloc>
4683 inline _LIBCPP_INLINE_VISIBILITY
4685 allocate_shared(const _Alloc& __a)
4687 return shared_ptr<_Tp>::allocate_shared(__a);
4690 template<class _Tp, class _Alloc, class _A0>
4691 inline _LIBCPP_INLINE_VISIBILITY
4693 allocate_shared(const _Alloc& __a, _A0& __a0)
4695 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4698 template<class _Tp, class _Alloc, class _A0, class _A1>
4699 inline _LIBCPP_INLINE_VISIBILITY
4701 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4703 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4706 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4707 inline _LIBCPP_INLINE_VISIBILITY
4709 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4711 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4714 #endif // _LIBCPP_HAS_NO_VARIADICS
4716 template<class _Tp, class _Up>
4717 inline _LIBCPP_INLINE_VISIBILITY
4719 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4721 return __x.get() == __y.get();
4724 template<class _Tp, class _Up>
4725 inline _LIBCPP_INLINE_VISIBILITY
4727 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4729 return !(__x == __y);
4732 template<class _Tp, class _Up>
4733 inline _LIBCPP_INLINE_VISIBILITY
4735 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4737 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4738 return less<_Vp>()(__x.get(), __y.get());
4741 template<class _Tp, class _Up>
4742 inline _LIBCPP_INLINE_VISIBILITY
4744 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4749 template<class _Tp, class _Up>
4750 inline _LIBCPP_INLINE_VISIBILITY
4752 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4754 return !(__y < __x);
4757 template<class _Tp, class _Up>
4758 inline _LIBCPP_INLINE_VISIBILITY
4760 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4762 return !(__x < __y);
4766 inline _LIBCPP_INLINE_VISIBILITY
4768 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4774 inline _LIBCPP_INLINE_VISIBILITY
4776 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4782 inline _LIBCPP_INLINE_VISIBILITY
4784 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4786 return static_cast<bool>(__x);
4790 inline _LIBCPP_INLINE_VISIBILITY
4792 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4794 return static_cast<bool>(__x);
4798 inline _LIBCPP_INLINE_VISIBILITY
4800 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4802 return less<_Tp*>()(__x.get(), nullptr);
4806 inline _LIBCPP_INLINE_VISIBILITY
4808 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4810 return less<_Tp*>()(nullptr, __x.get());
4814 inline _LIBCPP_INLINE_VISIBILITY
4816 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4818 return nullptr < __x;
4822 inline _LIBCPP_INLINE_VISIBILITY
4824 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4826 return __x < nullptr;
4830 inline _LIBCPP_INLINE_VISIBILITY
4832 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4834 return !(nullptr < __x);
4838 inline _LIBCPP_INLINE_VISIBILITY
4840 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4842 return !(__x < nullptr);
4846 inline _LIBCPP_INLINE_VISIBILITY
4848 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4850 return !(__x < nullptr);
4854 inline _LIBCPP_INLINE_VISIBILITY
4856 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4858 return !(nullptr < __x);
4862 inline _LIBCPP_INLINE_VISIBILITY
4864 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4869 template<class _Tp, class _Up>
4870 inline _LIBCPP_INLINE_VISIBILITY
4873 !is_array<_Tp>::value && !is_array<_Up>::value,
4876 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4878 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4881 template<class _Tp, class _Up>
4882 inline _LIBCPP_INLINE_VISIBILITY
4885 !is_array<_Tp>::value && !is_array<_Up>::value,
4888 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4890 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4891 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4894 template<class _Tp, class _Up>
4897 is_array<_Tp>::value == is_array<_Up>::value,
4900 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4902 typedef typename remove_extent<_Tp>::type _RTp;
4903 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4906 #ifndef _LIBCPP_NO_RTTI
4908 template<class _Dp, class _Tp>
4909 inline _LIBCPP_INLINE_VISIBILITY
4911 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4913 return __p.template __get_deleter<_Dp>();
4916 #endif // _LIBCPP_NO_RTTI
4919 class _LIBCPP_TEMPLATE_VIS weak_ptr
4922 typedef _Tp element_type;
4924 element_type* __ptr_;
4925 __shared_weak_count* __cntrl_;
4928 _LIBCPP_INLINE_VISIBILITY
4929 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4930 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4931 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4933 _LIBCPP_INLINE_VISIBILITY
4934 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4935 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
4936 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4939 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4940 _LIBCPP_INLINE_VISIBILITY
4941 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4942 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
4943 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4945 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4948 _LIBCPP_INLINE_VISIBILITY
4949 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4953 is_convertible<_Yp*, element_type*>::value,
4956 _LIBCPP_INLINE_VISIBILITY
4957 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4959 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4961 _LIBCPP_INLINE_VISIBILITY
4962 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4966 is_convertible<_Yp*, element_type*>::value,
4969 _LIBCPP_INLINE_VISIBILITY
4970 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4972 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4977 is_convertible<_Yp*, element_type*>::value,
4980 _LIBCPP_INLINE_VISIBILITY
4981 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4983 _LIBCPP_INLINE_VISIBILITY
4984 void swap(weak_ptr& __r) _NOEXCEPT;
4985 _LIBCPP_INLINE_VISIBILITY
4986 void reset() _NOEXCEPT;
4988 _LIBCPP_INLINE_VISIBILITY
4989 long use_count() const _NOEXCEPT
4990 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4991 _LIBCPP_INLINE_VISIBILITY
4992 bool expired() const _NOEXCEPT
4993 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4994 shared_ptr<_Tp> lock() const _NOEXCEPT;
4996 _LIBCPP_INLINE_VISIBILITY
4997 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
4998 {return __cntrl_ < __r.__cntrl_;}
5000 _LIBCPP_INLINE_VISIBILITY
5001 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
5002 {return __cntrl_ < __r.__cntrl_;}
5004 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
5005 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
5011 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
5019 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
5020 : __ptr_(__r.__ptr_),
5021 __cntrl_(__r.__cntrl_)
5024 __cntrl_->__add_weak();
5030 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
5031 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5033 : __ptr_(__r.__ptr_),
5034 __cntrl_(__r.__cntrl_)
5037 __cntrl_->__add_weak();
5043 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5044 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5046 : __ptr_(__r.__ptr_),
5047 __cntrl_(__r.__cntrl_)
5050 __cntrl_->__add_weak();
5053 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5057 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5058 : __ptr_(__r.__ptr_),
5059 __cntrl_(__r.__cntrl_)
5068 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5069 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5071 : __ptr_(__r.__ptr_),
5072 __cntrl_(__r.__cntrl_)
5078 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5081 weak_ptr<_Tp>::~weak_ptr()
5084 __cntrl_->__release_weak();
5090 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5092 weak_ptr(__r).swap(*this);
5101 is_convertible<_Yp*, _Tp*>::value,
5104 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5106 weak_ptr(__r).swap(*this);
5110 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5115 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5117 weak_ptr(_VSTD::move(__r)).swap(*this);
5126 is_convertible<_Yp*, _Tp*>::value,
5129 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5131 weak_ptr(_VSTD::move(__r)).swap(*this);
5135 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5142 is_convertible<_Yp*, _Tp*>::value,
5145 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5147 weak_ptr(__r).swap(*this);
5154 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5156 _VSTD::swap(__ptr_, __r.__ptr_);
5157 _VSTD::swap(__cntrl_, __r.__cntrl_);
5161 inline _LIBCPP_INLINE_VISIBILITY
5163 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5171 weak_ptr<_Tp>::reset() _NOEXCEPT
5173 weak_ptr().swap(*this);
5178 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5179 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5180 : __ptr_(__r.__ptr_),
5181 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5184 __throw_bad_weak_ptr();
5189 weak_ptr<_Tp>::lock() const _NOEXCEPT
5191 shared_ptr<_Tp> __r;
5192 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5194 __r.__ptr_ = __ptr_;
5198 #if _LIBCPP_STD_VER > 14
5199 template <class _Tp = void> struct owner_less;
5201 template <class _Tp> struct owner_less;
5204 template <class _Tp>
5205 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5206 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5208 typedef bool result_type;
5209 _LIBCPP_INLINE_VISIBILITY
5210 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5211 {return __x.owner_before(__y);}
5212 _LIBCPP_INLINE_VISIBILITY
5213 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5214 {return __x.owner_before(__y);}
5215 _LIBCPP_INLINE_VISIBILITY
5216 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5217 {return __x.owner_before(__y);}
5220 template <class _Tp>
5221 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5222 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5224 typedef bool result_type;
5225 _LIBCPP_INLINE_VISIBILITY
5226 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5227 {return __x.owner_before(__y);}
5228 _LIBCPP_INLINE_VISIBILITY
5229 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5230 {return __x.owner_before(__y);}
5231 _LIBCPP_INLINE_VISIBILITY
5232 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5233 {return __x.owner_before(__y);}
5236 #if _LIBCPP_STD_VER > 14
5238 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5240 template <class _Tp, class _Up>
5241 _LIBCPP_INLINE_VISIBILITY
5242 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5243 {return __x.owner_before(__y);}
5244 template <class _Tp, class _Up>
5245 _LIBCPP_INLINE_VISIBILITY
5246 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5247 {return __x.owner_before(__y);}
5248 template <class _Tp, class _Up>
5249 _LIBCPP_INLINE_VISIBILITY
5250 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5251 {return __x.owner_before(__y);}
5252 template <class _Tp, class _Up>
5253 _LIBCPP_INLINE_VISIBILITY
5254 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5255 {return __x.owner_before(__y);}
5256 typedef void is_transparent;
5261 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5263 mutable weak_ptr<_Tp> __weak_this_;
5265 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5266 enable_shared_from_this() _NOEXCEPT {}
5267 _LIBCPP_INLINE_VISIBILITY
5268 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5269 _LIBCPP_INLINE_VISIBILITY
5270 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5272 _LIBCPP_INLINE_VISIBILITY
5273 ~enable_shared_from_this() {}
5275 _LIBCPP_INLINE_VISIBILITY
5276 shared_ptr<_Tp> shared_from_this()
5277 {return shared_ptr<_Tp>(__weak_this_);}
5278 _LIBCPP_INLINE_VISIBILITY
5279 shared_ptr<_Tp const> shared_from_this() const
5280 {return shared_ptr<const _Tp>(__weak_this_);}
5282 #if _LIBCPP_STD_VER > 14
5283 _LIBCPP_INLINE_VISIBILITY
5284 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5285 { return __weak_this_; }
5287 _LIBCPP_INLINE_VISIBILITY
5288 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5289 { return __weak_this_; }
5290 #endif // _LIBCPP_STD_VER > 14
5292 template <class _Up> friend class shared_ptr;
5295 template <class _Tp>
5296 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5298 typedef shared_ptr<_Tp> argument_type;
5299 typedef size_t result_type;
5301 _LIBCPP_INLINE_VISIBILITY
5302 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5304 return hash<_Tp*>()(__ptr.get());
5308 template<class _CharT, class _Traits, class _Yp>
5309 inline _LIBCPP_INLINE_VISIBILITY
5310 basic_ostream<_CharT, _Traits>&
5311 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5314 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5316 class _LIBCPP_TYPE_VIS __sp_mut
5320 void lock() _NOEXCEPT;
5321 void unlock() _NOEXCEPT;
5324 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5325 __sp_mut(const __sp_mut&);
5326 __sp_mut& operator=(const __sp_mut&);
5328 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5331 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5332 __sp_mut& __get_sp_mut(const void*);
5334 template <class _Tp>
5335 inline _LIBCPP_INLINE_VISIBILITY
5337 atomic_is_lock_free(const shared_ptr<_Tp>*)
5342 template <class _Tp>
5343 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5345 atomic_load(const shared_ptr<_Tp>* __p)
5347 __sp_mut& __m = __get_sp_mut(__p);
5349 shared_ptr<_Tp> __q = *__p;
5354 template <class _Tp>
5355 inline _LIBCPP_INLINE_VISIBILITY
5356 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5358 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5360 return atomic_load(__p);
5363 template <class _Tp>
5364 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5366 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5368 __sp_mut& __m = __get_sp_mut(__p);
5374 template <class _Tp>
5375 inline _LIBCPP_INLINE_VISIBILITY
5376 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5378 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5380 atomic_store(__p, __r);
5383 template <class _Tp>
5384 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5386 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5388 __sp_mut& __m = __get_sp_mut(__p);
5395 template <class _Tp>
5396 inline _LIBCPP_INLINE_VISIBILITY
5397 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5399 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5401 return atomic_exchange(__p, __r);
5404 template <class _Tp>
5405 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5407 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5409 shared_ptr<_Tp> __temp;
5410 __sp_mut& __m = __get_sp_mut(__p);
5412 if (__p->__owner_equivalent(*__v))
5414 _VSTD::swap(__temp, *__p);
5419 _VSTD::swap(__temp, *__v);
5425 template <class _Tp>
5426 inline _LIBCPP_INLINE_VISIBILITY
5427 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5429 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5431 return atomic_compare_exchange_strong(__p, __v, __w);
5434 template <class _Tp>
5435 inline _LIBCPP_INLINE_VISIBILITY
5436 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5438 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5439 shared_ptr<_Tp> __w, memory_order, memory_order)
5441 return atomic_compare_exchange_strong(__p, __v, __w);
5444 template <class _Tp>
5445 inline _LIBCPP_INLINE_VISIBILITY
5446 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5448 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5449 shared_ptr<_Tp> __w, memory_order, memory_order)
5451 return atomic_compare_exchange_weak(__p, __v, __w);
5454 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5457 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5458 # ifndef _LIBCPP_CXX03_LANG
5459 enum class pointer_safety : unsigned char {
5466 struct _LIBCPP_TYPE_VIS pointer_safety
5477 _LIBCPP_INLINE_VISIBILITY
5478 pointer_safety() : __v_() {}
5480 _LIBCPP_INLINE_VISIBILITY
5481 pointer_safety(__lx __v) : __v_(__v) {}
5482 _LIBCPP_INLINE_VISIBILITY
5483 operator int() const {return __v_;}
5487 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5488 defined(_LIBCPP_BUILDING_MEMORY)
5489 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5491 // This function is only offered in C++03 under ABI v1.
5492 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5493 inline _LIBCPP_INLINE_VISIBILITY
5494 pointer_safety get_pointer_safety() _NOEXCEPT {
5495 return pointer_safety::relaxed;
5501 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5502 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5503 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5504 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5506 template <class _Tp>
5507 inline _LIBCPP_INLINE_VISIBILITY
5509 undeclare_reachable(_Tp* __p)
5511 return static_cast<_Tp*>(__undeclare_reachable(__p));
5514 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5516 // --- Helper for container swap --
5517 template <typename _Alloc>
5518 inline _LIBCPP_INLINE_VISIBILITY
5519 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5520 #if _LIBCPP_STD_VER >= 14
5523 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5526 __swap_allocator(__a1, __a2,
5527 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5530 template <typename _Alloc>
5531 _LIBCPP_INLINE_VISIBILITY
5532 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5533 #if _LIBCPP_STD_VER >= 14
5536 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5543 template <typename _Alloc>
5544 inline _LIBCPP_INLINE_VISIBILITY
5545 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5547 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5548 struct __noexcept_move_assign_container : public integral_constant<bool,
5549 _Traits::propagate_on_container_move_assignment::value
5550 #if _LIBCPP_STD_VER > 14
5551 || _Traits::is_always_equal::value
5553 && is_nothrow_move_assignable<_Alloc>::value
5558 #ifndef _LIBCPP_HAS_NO_VARIADICS
5559 template <class _Tp, class _Alloc>
5560 struct __temp_value {
5561 typedef allocator_traits<_Alloc> _Traits;
5563 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5566 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5567 _Tp & get() { return *__addr(); }
5569 template<class... _Args>
5570 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5571 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5573 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5577 _LIBCPP_END_NAMESPACE_STD
5581 #endif // _LIBCPP_MEMORY