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;};
723 template <class _Tp, class = void>
724 struct __has_element_type : false_type {};
727 struct __has_element_type<_Tp,
728 typename __void_t<typename _Tp::element_type>::type> : true_type {};
730 template <class _Ptr, bool = __has_element_type<_Ptr>::value>
731 struct __pointer_traits_element_type;
733 template <class _Ptr>
734 struct __pointer_traits_element_type<_Ptr, true>
736 typedef typename _Ptr::element_type type;
739 #ifndef _LIBCPP_HAS_NO_VARIADICS
741 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
742 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
744 typedef typename _Sp<_Tp, _Args...>::element_type type;
747 template <template <class, class...> class _Sp, class _Tp, class ..._Args>
748 struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
753 #else // _LIBCPP_HAS_NO_VARIADICS
755 template <template <class> class _Sp, class _Tp>
756 struct __pointer_traits_element_type<_Sp<_Tp>, true>
758 typedef typename _Sp<_Tp>::element_type type;
761 template <template <class> class _Sp, class _Tp>
762 struct __pointer_traits_element_type<_Sp<_Tp>, false>
767 template <template <class, class> class _Sp, class _Tp, class _A0>
768 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
770 typedef typename _Sp<_Tp, _A0>::element_type type;
773 template <template <class, class> class _Sp, class _Tp, class _A0>
774 struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
779 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
780 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
782 typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
785 template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
786 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
791 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
792 class _A1, class _A2>
793 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
795 typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
798 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
799 class _A1, class _A2>
800 struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
805 #endif // _LIBCPP_HAS_NO_VARIADICS
807 template <class _Tp, class = void>
808 struct __has_difference_type : false_type {};
811 struct __has_difference_type<_Tp,
812 typename __void_t<typename _Tp::difference_type>::type> : true_type {};
814 template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
815 struct __pointer_traits_difference_type
817 typedef ptrdiff_t type;
820 template <class _Ptr>
821 struct __pointer_traits_difference_type<_Ptr, true>
823 typedef typename _Ptr::difference_type type;
826 template <class _Tp, class _Up>
830 struct __two {char __lx; char __lxx;};
831 template <class _Xp> static __two __test(...);
832 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
834 static const bool value = sizeof(__test<_Tp>(0)) == 1;
837 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
838 struct __pointer_traits_rebind
840 #ifndef _LIBCPP_CXX03_LANG
841 typedef typename _Tp::template rebind<_Up> type;
843 typedef typename _Tp::template rebind<_Up>::other type;
847 #ifndef _LIBCPP_HAS_NO_VARIADICS
849 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
850 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
852 #ifndef _LIBCPP_CXX03_LANG
853 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
855 typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
859 template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
860 struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
862 typedef _Sp<_Up, _Args...> type;
865 #else // _LIBCPP_HAS_NO_VARIADICS
867 template <template <class> class _Sp, class _Tp, class _Up>
868 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
870 #ifndef _LIBCPP_CXX03_LANG
871 typedef typename _Sp<_Tp>::template rebind<_Up> type;
873 typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
877 template <template <class> class _Sp, class _Tp, class _Up>
878 struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
880 typedef _Sp<_Up> type;
883 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
884 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
886 #ifndef _LIBCPP_CXX03_LANG
887 typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
889 typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
893 template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
894 struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
896 typedef _Sp<_Up, _A0> type;
899 template <template <class, class, class> class _Sp, class _Tp, class _A0,
900 class _A1, class _Up>
901 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
903 #ifndef _LIBCPP_CXX03_LANG
904 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
906 typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
910 template <template <class, class, class> class _Sp, class _Tp, class _A0,
911 class _A1, class _Up>
912 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
914 typedef _Sp<_Up, _A0, _A1> type;
917 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
918 class _A1, class _A2, class _Up>
919 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
921 #ifndef _LIBCPP_CXX03_LANG
922 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
924 typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
928 template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
929 class _A1, class _A2, class _Up>
930 struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
932 typedef _Sp<_Up, _A0, _A1, _A2> type;
935 #endif // _LIBCPP_HAS_NO_VARIADICS
937 template <class _Ptr>
938 struct _LIBCPP_TEMPLATE_VIS pointer_traits
940 typedef _Ptr pointer;
941 typedef typename __pointer_traits_element_type<pointer>::type element_type;
942 typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
944 #ifndef _LIBCPP_CXX03_LANG
945 template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
947 template <class _Up> struct rebind
948 {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
949 #endif // _LIBCPP_CXX03_LANG
954 _LIBCPP_INLINE_VISIBILITY
955 static pointer pointer_to(typename conditional<is_void<element_type>::value,
956 __nat, element_type>::type& __r)
957 {return pointer::pointer_to(__r);}
961 struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
963 typedef _Tp* pointer;
964 typedef _Tp element_type;
965 typedef ptrdiff_t difference_type;
967 #ifndef _LIBCPP_CXX03_LANG
968 template <class _Up> using rebind = _Up*;
970 template <class _Up> struct rebind {typedef _Up* other;};
976 _LIBCPP_INLINE_VISIBILITY
977 static pointer pointer_to(typename conditional<is_void<element_type>::value,
978 __nat, element_type>::type& __r) _NOEXCEPT
979 {return _VSTD::addressof(__r);}
982 template <class _From, class _To>
983 struct __rebind_pointer {
984 #ifndef _LIBCPP_CXX03_LANG
985 typedef typename pointer_traits<_From>::template rebind<_To> type;
987 typedef typename pointer_traits<_From>::template rebind<_To>::other type;
993 template <class _Tp, class = void>
994 struct __has_pointer_type : false_type {};
997 struct __has_pointer_type<_Tp,
998 typename __void_t<typename _Tp::pointer>::type> : true_type {};
1000 namespace __pointer_type_imp
1003 template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
1004 struct __pointer_type
1006 typedef typename _Dp::pointer type;
1009 template <class _Tp, class _Dp>
1010 struct __pointer_type<_Tp, _Dp, false>
1015 } // __pointer_type_imp
1017 template <class _Tp, class _Dp>
1018 struct __pointer_type
1020 typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
1023 template <class _Tp, class = void>
1024 struct __has_const_pointer : false_type {};
1026 template <class _Tp>
1027 struct __has_const_pointer<_Tp,
1028 typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
1030 template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
1031 struct __const_pointer
1033 typedef typename _Alloc::const_pointer type;
1036 template <class _Tp, class _Ptr, class _Alloc>
1037 struct __const_pointer<_Tp, _Ptr, _Alloc, false>
1039 #ifndef _LIBCPP_CXX03_LANG
1040 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
1042 typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
1046 template <class _Tp, class = void>
1047 struct __has_void_pointer : false_type {};
1049 template <class _Tp>
1050 struct __has_void_pointer<_Tp,
1051 typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
1053 template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
1054 struct __void_pointer
1056 typedef typename _Alloc::void_pointer type;
1059 template <class _Ptr, class _Alloc>
1060 struct __void_pointer<_Ptr, _Alloc, false>
1062 #ifndef _LIBCPP_CXX03_LANG
1063 typedef typename pointer_traits<_Ptr>::template rebind<void> type;
1065 typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
1069 template <class _Tp, class = void>
1070 struct __has_const_void_pointer : false_type {};
1072 template <class _Tp>
1073 struct __has_const_void_pointer<_Tp,
1074 typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
1076 template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
1077 struct __const_void_pointer
1079 typedef typename _Alloc::const_void_pointer type;
1082 template <class _Ptr, class _Alloc>
1083 struct __const_void_pointer<_Ptr, _Alloc, false>
1085 #ifndef _LIBCPP_CXX03_LANG
1086 typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
1088 typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
1092 template <class _Tp>
1093 inline _LIBCPP_INLINE_VISIBILITY
1095 __to_raw_pointer(_Tp* __p) _NOEXCEPT
1100 template <class _Pointer>
1101 inline _LIBCPP_INLINE_VISIBILITY
1102 typename pointer_traits<_Pointer>::element_type*
1103 __to_raw_pointer(_Pointer __p) _NOEXCEPT
1105 return _VSTD::__to_raw_pointer(__p.operator->());
1108 template <class _Tp, class = void>
1109 struct __has_size_type : false_type {};
1111 template <class _Tp>
1112 struct __has_size_type<_Tp,
1113 typename __void_t<typename _Tp::size_type>::type> : true_type {};
1115 template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
1118 typedef typename make_unsigned<_DiffType>::type type;
1121 template <class _Alloc, class _DiffType>
1122 struct __size_type<_Alloc, _DiffType, true>
1124 typedef typename _Alloc::size_type type;
1127 template <class _Tp, class = void>
1128 struct __has_propagate_on_container_copy_assignment : false_type {};
1130 template <class _Tp>
1131 struct __has_propagate_on_container_copy_assignment<_Tp,
1132 typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
1135 template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
1136 struct __propagate_on_container_copy_assignment
1138 typedef false_type type;
1141 template <class _Alloc>
1142 struct __propagate_on_container_copy_assignment<_Alloc, true>
1144 typedef typename _Alloc::propagate_on_container_copy_assignment type;
1147 template <class _Tp, class = void>
1148 struct __has_propagate_on_container_move_assignment : false_type {};
1150 template <class _Tp>
1151 struct __has_propagate_on_container_move_assignment<_Tp,
1152 typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
1155 template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
1156 struct __propagate_on_container_move_assignment
1158 typedef false_type type;
1161 template <class _Alloc>
1162 struct __propagate_on_container_move_assignment<_Alloc, true>
1164 typedef typename _Alloc::propagate_on_container_move_assignment type;
1167 template <class _Tp, class = void>
1168 struct __has_propagate_on_container_swap : false_type {};
1170 template <class _Tp>
1171 struct __has_propagate_on_container_swap<_Tp,
1172 typename __void_t<typename _Tp::propagate_on_container_swap>::type>
1175 template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
1176 struct __propagate_on_container_swap
1178 typedef false_type type;
1181 template <class _Alloc>
1182 struct __propagate_on_container_swap<_Alloc, true>
1184 typedef typename _Alloc::propagate_on_container_swap type;
1187 template <class _Tp, class = void>
1188 struct __has_is_always_equal : false_type {};
1190 template <class _Tp>
1191 struct __has_is_always_equal<_Tp,
1192 typename __void_t<typename _Tp::is_always_equal>::type>
1195 template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
1196 struct __is_always_equal
1198 typedef typename _VSTD::is_empty<_Alloc>::type type;
1201 template <class _Alloc>
1202 struct __is_always_equal<_Alloc, true>
1204 typedef typename _Alloc::is_always_equal type;
1207 template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
1208 struct __has_rebind_other
1211 struct __two {char __lx; char __lxx;};
1212 template <class _Xp> static __two __test(...);
1213 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
1215 static const bool value = sizeof(__test<_Tp>(0)) == 1;
1218 template <class _Tp, class _Up>
1219 struct __has_rebind_other<_Tp, _Up, false>
1221 static const bool value = false;
1224 template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
1225 struct __allocator_traits_rebind
1227 typedef typename _Tp::template rebind<_Up>::other type;
1230 #ifndef _LIBCPP_HAS_NO_VARIADICS
1232 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1233 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
1235 typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
1238 template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
1239 struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
1241 typedef _Alloc<_Up, _Args...> type;
1244 #else // _LIBCPP_HAS_NO_VARIADICS
1246 template <template <class> class _Alloc, class _Tp, class _Up>
1247 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
1249 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
1252 template <template <class> class _Alloc, class _Tp, class _Up>
1253 struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
1255 typedef _Alloc<_Up> type;
1258 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1259 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
1261 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
1264 template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
1265 struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
1267 typedef _Alloc<_Up, _A0> type;
1270 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1271 class _A1, class _Up>
1272 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
1274 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
1277 template <template <class, class, class> class _Alloc, class _Tp, class _A0,
1278 class _A1, class _Up>
1279 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
1281 typedef _Alloc<_Up, _A0, _A1> type;
1284 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1285 class _A1, class _A2, class _Up>
1286 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
1288 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
1291 template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
1292 class _A1, class _A2, class _Up>
1293 struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
1295 typedef _Alloc<_Up, _A0, _A1, _A2> type;
1298 #endif // _LIBCPP_HAS_NO_VARIADICS
1300 #ifndef _LIBCPP_CXX03_LANG
1302 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1304 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1305 -> decltype(__a.allocate(__sz, __p), true_type());
1307 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1309 __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
1312 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1313 struct __has_allocate_hint
1314 : integral_constant<bool,
1316 decltype(__has_allocate_hint_test(declval<_Alloc>(),
1317 declval<_SizeType>(),
1318 declval<_ConstVoidPtr>())),
1323 #else // _LIBCPP_CXX03_LANG
1325 template <class _Alloc, class _SizeType, class _ConstVoidPtr>
1326 struct __has_allocate_hint
1331 #endif // _LIBCPP_CXX03_LANG
1333 #if !defined(_LIBCPP_CXX03_LANG)
1335 template <class _Alloc, class _Tp, class ..._Args>
1336 decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
1337 _VSTD::declval<_Args>()...),
1339 __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
1341 template <class _Alloc, class _Pointer, class ..._Args>
1343 __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
1345 template <class _Alloc, class _Pointer, class ..._Args>
1346 struct __has_construct
1347 : integral_constant<bool,
1349 decltype(__has_construct_test(declval<_Alloc>(),
1350 declval<_Pointer>(),
1351 declval<_Args>()...)),
1356 template <class _Alloc, class _Pointer>
1358 __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
1359 -> decltype(__a.destroy(__p), true_type());
1361 template <class _Alloc, class _Pointer>
1363 __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
1366 template <class _Alloc, class _Pointer>
1367 struct __has_destroy
1368 : integral_constant<bool,
1370 decltype(__has_destroy_test(declval<_Alloc>(),
1371 declval<_Pointer>())),
1376 template <class _Alloc>
1378 __has_max_size_test(_Alloc&& __a)
1379 -> decltype(__a.max_size(), true_type());
1381 template <class _Alloc>
1383 __has_max_size_test(const volatile _Alloc& __a)
1386 template <class _Alloc>
1387 struct __has_max_size
1388 : integral_constant<bool,
1390 decltype(__has_max_size_test(declval<_Alloc&>())),
1395 template <class _Alloc>
1397 __has_select_on_container_copy_construction_test(_Alloc&& __a)
1398 -> decltype(__a.select_on_container_copy_construction(), true_type());
1400 template <class _Alloc>
1402 __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
1405 template <class _Alloc>
1406 struct __has_select_on_container_copy_construction
1407 : integral_constant<bool,
1409 decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
1414 #else // _LIBCPP_CXX03_LANG
1416 #ifndef _LIBCPP_HAS_NO_VARIADICS
1418 template <class _Alloc, class _Pointer, class ..._Args>
1419 struct __has_construct
1424 #else // _LIBCPP_HAS_NO_VARIADICS
1426 template <class _Alloc, class _Pointer, class _Args>
1427 struct __has_construct
1432 #endif // _LIBCPP_HAS_NO_VARIADICS
1434 template <class _Alloc, class _Pointer>
1435 struct __has_destroy
1440 template <class _Alloc>
1441 struct __has_max_size
1446 template <class _Alloc>
1447 struct __has_select_on_container_copy_construction
1452 #endif // _LIBCPP_CXX03_LANG
1454 template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
1455 struct __alloc_traits_difference_type
1457 typedef typename pointer_traits<_Ptr>::difference_type type;
1460 template <class _Alloc, class _Ptr>
1461 struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
1463 typedef typename _Alloc::difference_type type;
1466 template <class _Alloc>
1467 struct _LIBCPP_TEMPLATE_VIS allocator_traits
1469 typedef _Alloc allocator_type;
1470 typedef typename allocator_type::value_type value_type;
1472 typedef typename __pointer_type<value_type, allocator_type>::type pointer;
1473 typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
1474 typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
1475 typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
1477 typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
1478 typedef typename __size_type<allocator_type, difference_type>::type size_type;
1480 typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
1481 propagate_on_container_copy_assignment;
1482 typedef typename __propagate_on_container_move_assignment<allocator_type>::type
1483 propagate_on_container_move_assignment;
1484 typedef typename __propagate_on_container_swap<allocator_type>::type
1485 propagate_on_container_swap;
1486 typedef typename __is_always_equal<allocator_type>::type
1489 #ifndef _LIBCPP_CXX03_LANG
1490 template <class _Tp> using rebind_alloc =
1491 typename __allocator_traits_rebind<allocator_type, _Tp>::type;
1492 template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
1493 #else // _LIBCPP_CXX03_LANG
1494 template <class _Tp> struct rebind_alloc
1495 {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
1496 template <class _Tp> struct rebind_traits
1497 {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
1498 #endif // _LIBCPP_CXX03_LANG
1500 _LIBCPP_INLINE_VISIBILITY
1501 static pointer allocate(allocator_type& __a, size_type __n)
1502 {return __a.allocate(__n);}
1503 _LIBCPP_INLINE_VISIBILITY
1504 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
1505 {return __allocate(__a, __n, __hint,
1506 __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
1508 _LIBCPP_INLINE_VISIBILITY
1509 static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
1510 {__a.deallocate(__p, __n);}
1512 #ifndef _LIBCPP_HAS_NO_VARIADICS
1513 template <class _Tp, class... _Args>
1514 _LIBCPP_INLINE_VISIBILITY
1515 static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
1516 {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
1517 __a, __p, _VSTD::forward<_Args>(__args)...);}
1518 #else // _LIBCPP_HAS_NO_VARIADICS
1519 template <class _Tp>
1520 _LIBCPP_INLINE_VISIBILITY
1521 static void construct(allocator_type&, _Tp* __p)
1523 ::new ((void*)__p) _Tp();
1525 template <class _Tp, class _A0>
1526 _LIBCPP_INLINE_VISIBILITY
1527 static void construct(allocator_type&, _Tp* __p, const _A0& __a0)
1529 ::new ((void*)__p) _Tp(__a0);
1531 template <class _Tp, class _A0, class _A1>
1532 _LIBCPP_INLINE_VISIBILITY
1533 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1536 ::new ((void*)__p) _Tp(__a0, __a1);
1538 template <class _Tp, class _A0, class _A1, class _A2>
1539 _LIBCPP_INLINE_VISIBILITY
1540 static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
1541 const _A1& __a1, const _A2& __a2)
1543 ::new ((void*)__p) _Tp(__a0, __a1, __a2);
1545 #endif // _LIBCPP_HAS_NO_VARIADICS
1547 template <class _Tp>
1548 _LIBCPP_INLINE_VISIBILITY
1549 static void destroy(allocator_type& __a, _Tp* __p)
1550 {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
1552 _LIBCPP_INLINE_VISIBILITY
1553 static size_type max_size(const allocator_type& __a) _NOEXCEPT
1554 {return __max_size(__has_max_size<const allocator_type>(), __a);}
1556 _LIBCPP_INLINE_VISIBILITY
1557 static allocator_type
1558 select_on_container_copy_construction(const allocator_type& __a)
1559 {return __select_on_container_copy_construction(
1560 __has_select_on_container_copy_construction<const allocator_type>(),
1563 template <class _Ptr>
1564 _LIBCPP_INLINE_VISIBILITY
1567 __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
1569 for (; __begin1 != __end1; ++__begin1, ++__begin2)
1570 construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
1573 template <class _Tp>
1574 _LIBCPP_INLINE_VISIBILITY
1578 (is_same<allocator_type, allocator<_Tp> >::value
1579 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1580 is_trivially_move_constructible<_Tp>::value,
1583 __construct_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1585 ptrdiff_t _Np = __end1 - __begin1;
1588 _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
1593 template <class _Iter, class _Ptr>
1594 _LIBCPP_INLINE_VISIBILITY
1597 __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
1599 for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
1600 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
1603 template <class _Tp>
1604 _LIBCPP_INLINE_VISIBILITY
1608 (is_same<allocator_type, allocator<_Tp> >::value
1609 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1610 is_trivially_move_constructible<_Tp>::value,
1613 __construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
1615 typedef typename remove_const<_Tp>::type _Vp;
1616 ptrdiff_t _Np = __end1 - __begin1;
1619 _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
1624 template <class _Ptr>
1625 _LIBCPP_INLINE_VISIBILITY
1628 __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
1630 while (__end1 != __begin1)
1632 construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
1637 template <class _Tp>
1638 _LIBCPP_INLINE_VISIBILITY
1642 (is_same<allocator_type, allocator<_Tp> >::value
1643 || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
1644 is_trivially_move_constructible<_Tp>::value,
1647 __construct_backward(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
1649 ptrdiff_t _Np = __end1 - __begin1;
1652 _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
1657 _LIBCPP_INLINE_VISIBILITY
1658 static pointer __allocate(allocator_type& __a, size_type __n,
1659 const_void_pointer __hint, true_type)
1660 {return __a.allocate(__n, __hint);}
1661 _LIBCPP_INLINE_VISIBILITY
1662 static pointer __allocate(allocator_type& __a, size_type __n,
1663 const_void_pointer, false_type)
1664 {return __a.allocate(__n);}
1666 #ifndef _LIBCPP_HAS_NO_VARIADICS
1667 template <class _Tp, class... _Args>
1668 _LIBCPP_INLINE_VISIBILITY
1669 static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
1670 {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
1671 template <class _Tp, class... _Args>
1672 _LIBCPP_INLINE_VISIBILITY
1673 static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
1675 ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
1677 #endif // _LIBCPP_HAS_NO_VARIADICS
1679 template <class _Tp>
1680 _LIBCPP_INLINE_VISIBILITY
1681 static void __destroy(true_type, allocator_type& __a, _Tp* __p)
1683 template <class _Tp>
1684 _LIBCPP_INLINE_VISIBILITY
1685 static void __destroy(false_type, allocator_type&, _Tp* __p)
1690 _LIBCPP_INLINE_VISIBILITY
1691 static size_type __max_size(true_type, const allocator_type& __a)
1692 {return __a.max_size();}
1693 _LIBCPP_INLINE_VISIBILITY
1694 static size_type __max_size(false_type, const allocator_type&)
1695 {return numeric_limits<size_type>::max() / sizeof(value_type);}
1697 _LIBCPP_INLINE_VISIBILITY
1698 static allocator_type
1699 __select_on_container_copy_construction(true_type, const allocator_type& __a)
1700 {return __a.select_on_container_copy_construction();}
1701 _LIBCPP_INLINE_VISIBILITY
1702 static allocator_type
1703 __select_on_container_copy_construction(false_type, const allocator_type& __a)
1707 template <class _Traits, class _Tp>
1708 struct __rebind_alloc_helper
1710 #ifndef _LIBCPP_CXX03_LANG
1711 typedef typename _Traits::template rebind_alloc<_Tp> type;
1713 typedef typename _Traits::template rebind_alloc<_Tp>::other type;
1719 template <class _Tp>
1720 class _LIBCPP_TEMPLATE_VIS allocator
1723 typedef size_t size_type;
1724 typedef ptrdiff_t difference_type;
1725 typedef _Tp* pointer;
1726 typedef const _Tp* const_pointer;
1727 typedef _Tp& reference;
1728 typedef const _Tp& const_reference;
1729 typedef _Tp value_type;
1731 typedef true_type propagate_on_container_move_assignment;
1732 typedef true_type is_always_equal;
1734 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1736 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1737 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1738 _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
1739 {return _VSTD::addressof(__x);}
1740 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1741 {return _VSTD::addressof(__x);}
1742 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1744 if (__n > max_size())
1745 __throw_length_error("allocator<T>::allocate(size_t n)"
1746 " 'n' exceeds maximum supported size");
1747 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1749 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1750 {_VSTD::__libcpp_deallocate((void*)__p);}
1751 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1752 {return size_type(~0) / sizeof(_Tp);}
1753 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1754 template <class _Up, class... _Args>
1755 _LIBCPP_INLINE_VISIBILITY
1757 construct(_Up* __p, _Args&&... __args)
1759 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1761 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1762 _LIBCPP_INLINE_VISIBILITY
1764 construct(pointer __p)
1766 ::new((void*)__p) _Tp();
1768 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1770 template <class _A0>
1771 _LIBCPP_INLINE_VISIBILITY
1773 construct(pointer __p, _A0& __a0)
1775 ::new((void*)__p) _Tp(__a0);
1777 template <class _A0>
1778 _LIBCPP_INLINE_VISIBILITY
1780 construct(pointer __p, const _A0& __a0)
1782 ::new((void*)__p) _Tp(__a0);
1784 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1785 template <class _A0, class _A1>
1786 _LIBCPP_INLINE_VISIBILITY
1788 construct(pointer __p, _A0& __a0, _A1& __a1)
1790 ::new((void*)__p) _Tp(__a0, __a1);
1792 template <class _A0, class _A1>
1793 _LIBCPP_INLINE_VISIBILITY
1795 construct(pointer __p, const _A0& __a0, _A1& __a1)
1797 ::new((void*)__p) _Tp(__a0, __a1);
1799 template <class _A0, class _A1>
1800 _LIBCPP_INLINE_VISIBILITY
1802 construct(pointer __p, _A0& __a0, const _A1& __a1)
1804 ::new((void*)__p) _Tp(__a0, __a1);
1806 template <class _A0, class _A1>
1807 _LIBCPP_INLINE_VISIBILITY
1809 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1811 ::new((void*)__p) _Tp(__a0, __a1);
1813 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1814 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1817 template <class _Tp>
1818 class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
1821 typedef size_t size_type;
1822 typedef ptrdiff_t difference_type;
1823 typedef const _Tp* pointer;
1824 typedef const _Tp* const_pointer;
1825 typedef const _Tp& reference;
1826 typedef const _Tp& const_reference;
1827 typedef const _Tp value_type;
1829 typedef true_type propagate_on_container_move_assignment;
1830 typedef true_type is_always_equal;
1832 template <class _Up> struct rebind {typedef allocator<_Up> other;};
1834 _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
1835 template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
1836 _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
1837 {return _VSTD::addressof(__x);}
1838 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
1840 if (__n > max_size())
1841 __throw_length_error("allocator<const T>::allocate(size_t n)"
1842 " 'n' exceeds maximum supported size");
1843 return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
1845 _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
1846 {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
1847 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
1848 {return size_type(~0) / sizeof(_Tp);}
1849 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1850 template <class _Up, class... _Args>
1851 _LIBCPP_INLINE_VISIBILITY
1853 construct(_Up* __p, _Args&&... __args)
1855 ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
1857 #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1858 _LIBCPP_INLINE_VISIBILITY
1860 construct(pointer __p)
1862 ::new((void*) const_cast<_Tp *>(__p)) _Tp();
1864 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1866 template <class _A0>
1867 _LIBCPP_INLINE_VISIBILITY
1869 construct(pointer __p, _A0& __a0)
1871 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1873 template <class _A0>
1874 _LIBCPP_INLINE_VISIBILITY
1876 construct(pointer __p, const _A0& __a0)
1878 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
1880 # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
1881 template <class _A0, class _A1>
1882 _LIBCPP_INLINE_VISIBILITY
1884 construct(pointer __p, _A0& __a0, _A1& __a1)
1886 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1888 template <class _A0, class _A1>
1889 _LIBCPP_INLINE_VISIBILITY
1891 construct(pointer __p, const _A0& __a0, _A1& __a1)
1893 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1895 template <class _A0, class _A1>
1896 _LIBCPP_INLINE_VISIBILITY
1898 construct(pointer __p, _A0& __a0, const _A1& __a1)
1900 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1902 template <class _A0, class _A1>
1903 _LIBCPP_INLINE_VISIBILITY
1905 construct(pointer __p, const _A0& __a0, const _A1& __a1)
1907 ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
1909 #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
1910 _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
1913 template <class _Tp, class _Up>
1914 inline _LIBCPP_INLINE_VISIBILITY
1915 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
1917 template <class _Tp, class _Up>
1918 inline _LIBCPP_INLINE_VISIBILITY
1919 bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
1921 template <class _OutputIterator, class _Tp>
1922 class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
1923 : public iterator<output_iterator_tag,
1924 _Tp, // purposefully not C++03
1925 ptrdiff_t, // purposefully not C++03
1926 _Tp*, // purposefully not C++03
1927 raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
1930 _OutputIterator __x_;
1932 _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
1933 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
1934 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
1935 {::new(&*__x_) _Tp(__element); return *this;}
1936 #if _LIBCPP_STD_VER >= 14
1937 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
1938 {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
1940 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
1941 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
1942 {raw_storage_iterator __t(*this); ++__x_; return __t;}
1943 #if _LIBCPP_STD_VER >= 14
1944 _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
1948 template <class _Tp>
1949 pair<_Tp*, ptrdiff_t>
1950 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
1952 pair<_Tp*, ptrdiff_t> __r(0, 0);
1953 const ptrdiff_t __m = (~ptrdiff_t(0) ^
1954 ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
1960 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
1971 template <class _Tp>
1972 inline _LIBCPP_INLINE_VISIBILITY
1973 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
1975 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
1976 template <class _Tp>
1983 class _LIBCPP_TEMPLATE_VIS auto_ptr
1988 typedef _Tp element_type;
1990 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
1991 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
1992 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
1993 : __ptr_(__p.release()) {}
1994 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
1995 {reset(__p.release()); return *this;}
1996 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
1997 {reset(__p.release()); return *this;}
1998 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
1999 {reset(__p.__ptr_); return *this;}
2000 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
2002 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
2004 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
2005 _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
2006 _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
2012 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
2019 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
2020 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
2021 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
2022 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
2023 {return auto_ptr<_Up>(release());}
2027 class _LIBCPP_TEMPLATE_VIS auto_ptr<void>
2030 typedef void element_type;
2034 template <class _Tp, int _Idx,
2035 bool _CanBeEmptyBase =
2036 is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
2037 struct __compressed_pair_elem {
2038 typedef _Tp _ParamT;
2039 typedef _Tp& reference;
2040 typedef const _Tp& const_reference;
2042 #ifndef _LIBCPP_CXX03_LANG
2043 constexpr __compressed_pair_elem() : __value_() {}
2045 template <class _Up, class = typename enable_if<
2046 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2049 __compressed_pair_elem(_Up&& __u)
2050 : __value_(_VSTD::forward<_Up>(__u)){};
2052 template <class... _Args, size_t... _Indexes>
2053 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2054 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2055 __tuple_indices<_Indexes...>)
2056 : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2058 __compressed_pair_elem() : __value_() {}
2059 __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
2062 reference __get() _NOEXCEPT { return __value_; }
2063 const_reference __get() const _NOEXCEPT { return __value_; }
2069 template <class _Tp, int _Idx>
2070 struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
2071 typedef _Tp _ParamT;
2072 typedef _Tp& reference;
2073 typedef const _Tp& const_reference;
2074 typedef _Tp __value_type;
2076 #ifndef _LIBCPP_CXX03_LANG
2077 constexpr __compressed_pair_elem() = default;
2079 template <class _Up, class = typename enable_if<
2080 !is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
2083 __compressed_pair_elem(_Up&& __u)
2084 : __value_type(_VSTD::forward<_Up>(__u)){};
2086 template <class... _Args, size_t... _Indexes>
2087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2088 __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
2089 __tuple_indices<_Indexes...>)
2090 : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
2092 __compressed_pair_elem() : __value_type() {}
2093 __compressed_pair_elem(_ParamT __p)
2094 : __value_type(std::forward<_ParamT>(__p)) {}
2097 reference __get() _NOEXCEPT { return *this; }
2098 const_reference __get() const _NOEXCEPT { return *this; }
2101 // Tag used to construct the second element of the compressed pair.
2102 struct __second_tag {};
2104 template <class _T1, class _T2>
2105 class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
2106 private __compressed_pair_elem<_T2, 1> {
2107 typedef __compressed_pair_elem<_T1, 0> _Base1;
2108 typedef __compressed_pair_elem<_T2, 1> _Base2;
2110 // NOTE: This static assert should never fire because __compressed_pair
2111 // is *almost never* used in a scenario where it's possible for T1 == T2.
2112 // (The exception is std::function where it is possible that the function
2113 // object and the allocator have the same type).
2114 static_assert((!is_same<_T1, _T2>::value),
2115 "__compressed_pair cannot be instantated when T1 and T2 are the same type; "
2116 "The current implementation is NOT ABI-compatible with the previous "
2117 "implementation for this configuration");
2120 #ifndef _LIBCPP_CXX03_LANG
2121 template <bool _Dummy = true,
2122 class = typename enable_if<
2123 __dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
2124 __dependent_type<is_default_constructible<_T2>, _Dummy>::value
2127 _LIBCPP_INLINE_VISIBILITY
2128 constexpr __compressed_pair() {}
2130 template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
2131 __compressed_pair>::value,
2133 _LIBCPP_INLINE_VISIBILITY constexpr explicit
2134 __compressed_pair(_Tp&& __t)
2135 : _Base1(std::forward<_Tp>(__t)), _Base2() {}
2137 template <class _Tp>
2138 _LIBCPP_INLINE_VISIBILITY constexpr
2139 __compressed_pair(__second_tag, _Tp&& __t)
2140 : _Base1(), _Base2(std::forward<_Tp>(__t)) {}
2142 template <class _U1, class _U2>
2143 _LIBCPP_INLINE_VISIBILITY constexpr
2144 __compressed_pair(_U1&& __t1, _U2&& __t2)
2145 : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
2147 template <class... _Args1, class... _Args2>
2148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
2149 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
2150 tuple<_Args2...> __second_args)
2151 : _Base1(__pc, _VSTD::move(__first_args),
2152 typename __make_tuple_indices<sizeof...(_Args1)>::type()),
2153 _Base2(__pc, _VSTD::move(__second_args),
2154 typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
2157 _LIBCPP_INLINE_VISIBILITY
2158 __compressed_pair() {}
2160 _LIBCPP_INLINE_VISIBILITY explicit
2161 __compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
2163 _LIBCPP_INLINE_VISIBILITY
2164 __compressed_pair(__second_tag, _T2 __t2)
2165 : _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
2167 _LIBCPP_INLINE_VISIBILITY
2168 __compressed_pair(_T1 __t1, _T2 __t2)
2169 : _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
2172 _LIBCPP_INLINE_VISIBILITY
2173 typename _Base1::reference first() _NOEXCEPT {
2174 return static_cast<_Base1&>(*this).__get();
2177 _LIBCPP_INLINE_VISIBILITY
2178 typename _Base1::const_reference first() const _NOEXCEPT {
2179 return static_cast<_Base1 const&>(*this).__get();
2182 _LIBCPP_INLINE_VISIBILITY
2183 typename _Base2::reference second() _NOEXCEPT {
2184 return static_cast<_Base2&>(*this).__get();
2187 _LIBCPP_INLINE_VISIBILITY
2188 typename _Base2::const_reference second() const _NOEXCEPT {
2189 return static_cast<_Base2 const&>(*this).__get();
2192 _LIBCPP_INLINE_VISIBILITY
2193 void swap(__compressed_pair& __x)
2194 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2195 __is_nothrow_swappable<_T2>::value)
2198 swap(first(), __x.first());
2199 swap(second(), __x.second());
2203 template <class _T1, class _T2>
2204 inline _LIBCPP_INLINE_VISIBILITY
2205 void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
2206 _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
2207 __is_nothrow_swappable<_T2>::value) {
2213 template <class _Tp>
2214 struct _LIBCPP_TEMPLATE_VIS default_delete {
2215 static_assert(!is_function<_Tp>::value,
2216 "default_delete cannot be instantiated for function types");
2217 #ifndef _LIBCPP_CXX03_LANG
2218 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2220 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2222 template <class _Up>
2223 _LIBCPP_INLINE_VISIBILITY
2224 default_delete(const default_delete<_Up>&,
2225 typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
2228 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
2229 static_assert(sizeof(_Tp) > 0,
2230 "default_delete can not delete incomplete type");
2231 static_assert(!is_void<_Tp>::value,
2232 "default_delete can not delete incomplete type");
2237 template <class _Tp>
2238 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
2240 template <class _Up>
2241 struct _EnableIfConvertible
2242 : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
2245 #ifndef _LIBCPP_CXX03_LANG
2246 _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default;
2248 _LIBCPP_INLINE_VISIBILITY default_delete() {}
2251 template <class _Up>
2252 _LIBCPP_INLINE_VISIBILITY
2253 default_delete(const default_delete<_Up[]>&,
2254 typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
2256 template <class _Up>
2257 _LIBCPP_INLINE_VISIBILITY
2258 typename _EnableIfConvertible<_Up>::type
2259 operator()(_Up* __ptr) const _NOEXCEPT {
2260 static_assert(sizeof(_Tp) > 0,
2261 "default_delete can not delete incomplete type");
2262 static_assert(!is_void<_Tp>::value,
2263 "default_delete can not delete void type");
2270 #ifndef _LIBCPP_CXX03_LANG
2271 template <class _Deleter>
2272 struct __unique_ptr_deleter_sfinae {
2273 static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
2274 typedef const _Deleter& __lval_ref_type;
2275 typedef _Deleter&& __good_rval_ref_type;
2276 typedef true_type __enable_rval_overload;
2279 template <class _Deleter>
2280 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
2281 typedef const _Deleter& __lval_ref_type;
2282 typedef const _Deleter&& __bad_rval_ref_type;
2283 typedef false_type __enable_rval_overload;
2286 template <class _Deleter>
2287 struct __unique_ptr_deleter_sfinae<_Deleter&> {
2288 typedef _Deleter& __lval_ref_type;
2289 typedef _Deleter&& __bad_rval_ref_type;
2290 typedef false_type __enable_rval_overload;
2292 #endif // !defined(_LIBCPP_CXX03_LANG)
2294 template <class _Tp, class _Dp = default_delete<_Tp> >
2295 class _LIBCPP_TEMPLATE_VIS unique_ptr {
2297 typedef _Tp element_type;
2298 typedef _Dp deleter_type;
2299 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2301 static_assert(!is_rvalue_reference<deleter_type>::value,
2302 "the specified deleter type cannot be an rvalue reference");
2305 __compressed_pair<pointer, deleter_type> __ptr_;
2307 struct __nat { int __for_bool_; };
2309 #ifndef _LIBCPP_CXX03_LANG
2310 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2312 template <bool _Dummy>
2313 using _LValRefType =
2314 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2316 template <bool _Dummy>
2317 using _GoodRValRefType =
2318 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2320 template <bool _Dummy>
2321 using _BadRValRefType =
2322 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2324 template <bool _Dummy, class _Deleter = typename __dependent_type<
2325 __identity<deleter_type>, _Dummy>::type>
2326 using _EnableIfDeleterDefaultConstructible =
2327 typename enable_if<is_default_constructible<_Deleter>::value &&
2328 !is_pointer<_Deleter>::value>::type;
2330 template <class _ArgType>
2331 using _EnableIfDeleterConstructible =
2332 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2334 template <class _UPtr, class _Up>
2335 using _EnableIfMoveConvertible = typename enable_if<
2336 is_convertible<typename _UPtr::pointer, pointer>::value &&
2337 !is_array<_Up>::value
2340 template <class _UDel>
2341 using _EnableIfDeleterConvertible = typename enable_if<
2342 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2343 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2346 template <class _UDel>
2347 using _EnableIfDeleterAssignable = typename enable_if<
2348 is_assignable<_Dp&, _UDel&&>::value
2352 template <bool _Dummy = true,
2353 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2354 _LIBCPP_INLINE_VISIBILITY
2355 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2357 template <bool _Dummy = true,
2358 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2359 _LIBCPP_INLINE_VISIBILITY
2360 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2362 template <bool _Dummy = true,
2363 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2364 _LIBCPP_INLINE_VISIBILITY
2365 explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {}
2367 template <bool _Dummy = true,
2368 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2369 _LIBCPP_INLINE_VISIBILITY
2370 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept
2371 : __ptr_(__p, __d) {}
2373 template <bool _Dummy = true,
2374 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2375 _LIBCPP_INLINE_VISIBILITY
2376 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept
2377 : __ptr_(__p, _VSTD::move(__d)) {
2378 static_assert(!is_reference<deleter_type>::value,
2379 "rvalue deleter bound to reference");
2382 template <bool _Dummy = true,
2383 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>>
2384 _LIBCPP_INLINE_VISIBILITY
2385 unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
2387 _LIBCPP_INLINE_VISIBILITY
2388 unique_ptr(unique_ptr&& __u) noexcept
2389 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2392 template <class _Up, class _Ep,
2393 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2394 class = _EnableIfDeleterConvertible<_Ep>
2396 _LIBCPP_INLINE_VISIBILITY
2397 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
2398 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
2400 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2401 template <class _Up>
2402 _LIBCPP_INLINE_VISIBILITY
2403 unique_ptr(auto_ptr<_Up>&& __p,
2404 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2405 is_same<_Dp, default_delete<_Tp>>::value,
2406 __nat>::type = __nat()) _NOEXCEPT
2407 : __ptr_(__p.release()) {}
2410 _LIBCPP_INLINE_VISIBILITY
2411 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
2412 reset(__u.release());
2413 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2417 template <class _Up, class _Ep,
2418 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2419 class = _EnableIfDeleterAssignable<_Ep>
2421 _LIBCPP_INLINE_VISIBILITY
2422 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
2423 reset(__u.release());
2424 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2428 #else // _LIBCPP_CXX03_LANG
2430 unique_ptr(unique_ptr&);
2431 template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&);
2433 unique_ptr& operator=(unique_ptr&);
2434 template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
2437 _LIBCPP_INLINE_VISIBILITY
2438 unique_ptr() : __ptr_(pointer())
2440 static_assert(!is_pointer<deleter_type>::value,
2441 "unique_ptr constructed with null function pointer deleter");
2442 static_assert(is_default_constructible<deleter_type>::value,
2443 "unique_ptr::deleter_type is not default constructible");
2445 _LIBCPP_INLINE_VISIBILITY
2446 unique_ptr(nullptr_t) : __ptr_(pointer())
2448 static_assert(!is_pointer<deleter_type>::value,
2449 "unique_ptr constructed with null function pointer deleter");
2451 _LIBCPP_INLINE_VISIBILITY
2452 explicit unique_ptr(pointer __p)
2453 : __ptr_(_VSTD::move(__p)) {
2454 static_assert(!is_pointer<deleter_type>::value,
2455 "unique_ptr constructed with null function pointer deleter");
2458 _LIBCPP_INLINE_VISIBILITY
2459 operator __rv<unique_ptr>() {
2460 return __rv<unique_ptr>(*this);
2463 _LIBCPP_INLINE_VISIBILITY
2464 unique_ptr(__rv<unique_ptr> __u)
2465 : __ptr_(__u->release(),
2466 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2468 template <class _Up, class _Ep>
2469 _LIBCPP_INLINE_VISIBILITY
2471 !is_array<_Up>::value &&
2472 is_convertible<typename unique_ptr<_Up, _Ep>::pointer,
2474 is_assignable<deleter_type&, _Ep&>::value,
2476 operator=(unique_ptr<_Up, _Ep> __u) {
2477 reset(__u.release());
2478 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2482 _LIBCPP_INLINE_VISIBILITY
2483 unique_ptr(pointer __p, deleter_type __d)
2484 : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
2485 #endif // _LIBCPP_CXX03_LANG
2487 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
2488 template <class _Up>
2489 _LIBCPP_INLINE_VISIBILITY
2490 typename enable_if<is_convertible<_Up*, _Tp*>::value &&
2491 is_same<_Dp, default_delete<_Tp> >::value,
2493 operator=(auto_ptr<_Up> __p) {
2494 reset(__p.release());
2499 _LIBCPP_INLINE_VISIBILITY
2500 ~unique_ptr() { reset(); }
2502 _LIBCPP_INLINE_VISIBILITY
2503 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2508 _LIBCPP_INLINE_VISIBILITY
2509 typename add_lvalue_reference<_Tp>::type
2511 return *__ptr_.first();
2513 _LIBCPP_INLINE_VISIBILITY
2514 pointer operator->() const _NOEXCEPT {
2515 return __ptr_.first();
2517 _LIBCPP_INLINE_VISIBILITY
2518 pointer get() const _NOEXCEPT {
2519 return __ptr_.first();
2521 _LIBCPP_INLINE_VISIBILITY
2522 deleter_type& get_deleter() _NOEXCEPT {
2523 return __ptr_.second();
2525 _LIBCPP_INLINE_VISIBILITY
2526 const deleter_type& get_deleter() const _NOEXCEPT {
2527 return __ptr_.second();
2529 _LIBCPP_INLINE_VISIBILITY
2530 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2531 return __ptr_.first() != nullptr;
2534 _LIBCPP_INLINE_VISIBILITY
2535 pointer release() _NOEXCEPT {
2536 pointer __t = __ptr_.first();
2537 __ptr_.first() = pointer();
2541 _LIBCPP_INLINE_VISIBILITY
2542 void reset(pointer __p = pointer()) _NOEXCEPT {
2543 pointer __tmp = __ptr_.first();
2544 __ptr_.first() = __p;
2546 __ptr_.second()(__tmp);
2549 _LIBCPP_INLINE_VISIBILITY
2550 void swap(unique_ptr& __u) _NOEXCEPT {
2551 __ptr_.swap(__u.__ptr_);
2556 template <class _Tp, class _Dp>
2557 class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
2559 typedef _Tp element_type;
2560 typedef _Dp deleter_type;
2561 typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
2564 __compressed_pair<pointer, deleter_type> __ptr_;
2566 template <class _From>
2567 struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
2569 template <class _FromElem>
2570 struct _CheckArrayPointerConversion<_FromElem*>
2571 : integral_constant<bool,
2572 is_same<_FromElem*, pointer>::value ||
2573 (is_same<pointer, element_type*>::value &&
2574 is_convertible<_FromElem(*)[], element_type(*)[]>::value)
2578 #ifndef _LIBCPP_CXX03_LANG
2579 typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
2581 template <bool _Dummy>
2582 using _LValRefType =
2583 typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
2585 template <bool _Dummy>
2586 using _GoodRValRefType =
2587 typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
2589 template <bool _Dummy>
2590 using _BadRValRefType =
2591 typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
2593 template <bool _Dummy, class _Deleter = typename __dependent_type<
2594 __identity<deleter_type>, _Dummy>::type>
2595 using _EnableIfDeleterDefaultConstructible =
2596 typename enable_if<is_default_constructible<_Deleter>::value &&
2597 !is_pointer<_Deleter>::value>::type;
2599 template <class _ArgType>
2600 using _EnableIfDeleterConstructible =
2601 typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
2603 template <class _Pp>
2604 using _EnableIfPointerConvertible = typename enable_if<
2605 _CheckArrayPointerConversion<_Pp>::value
2608 template <class _UPtr, class _Up,
2609 class _ElemT = typename _UPtr::element_type>
2610 using _EnableIfMoveConvertible = typename enable_if<
2611 is_array<_Up>::value &&
2612 is_same<pointer, element_type*>::value &&
2613 is_same<typename _UPtr::pointer, _ElemT*>::value &&
2614 is_convertible<_ElemT(*)[], element_type(*)[]>::value
2617 template <class _UDel>
2618 using _EnableIfDeleterConvertible = typename enable_if<
2619 (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
2620 (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
2623 template <class _UDel>
2624 using _EnableIfDeleterAssignable = typename enable_if<
2625 is_assignable<_Dp&, _UDel&&>::value
2629 template <bool _Dummy = true,
2630 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2631 _LIBCPP_INLINE_VISIBILITY
2632 constexpr unique_ptr() noexcept : __ptr_(pointer()) {}
2634 template <bool _Dummy = true,
2635 class = _EnableIfDeleterDefaultConstructible<_Dummy>>
2636 _LIBCPP_INLINE_VISIBILITY
2637 constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {}
2639 template <class _Pp, bool _Dummy = true,
2640 class = _EnableIfDeleterDefaultConstructible<_Dummy>,
2641 class = _EnableIfPointerConvertible<_Pp>>
2642 _LIBCPP_INLINE_VISIBILITY
2643 explicit unique_ptr(_Pp __p) noexcept
2646 template <class _Pp, bool _Dummy = true,
2647 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>,
2648 class = _EnableIfPointerConvertible<_Pp>>
2649 _LIBCPP_INLINE_VISIBILITY
2650 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept
2651 : __ptr_(__p, __d) {}
2653 template <bool _Dummy = true,
2654 class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>>
2655 _LIBCPP_INLINE_VISIBILITY
2656 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept
2657 : __ptr_(nullptr, __d) {}
2659 template <class _Pp, bool _Dummy = true,
2660 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>,
2661 class = _EnableIfPointerConvertible<_Pp>>
2662 _LIBCPP_INLINE_VISIBILITY
2663 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept
2664 : __ptr_(__p, _VSTD::move(__d)) {
2665 static_assert(!is_reference<deleter_type>::value,
2666 "rvalue deleter bound to reference");
2669 template <bool _Dummy = true,
2670 class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>>
2671 _LIBCPP_INLINE_VISIBILITY
2672 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept
2673 : __ptr_(nullptr, _VSTD::move(__d)) {
2674 static_assert(!is_reference<deleter_type>::value,
2675 "rvalue deleter bound to reference");
2678 template <class _Pp, bool _Dummy = true,
2679 class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>,
2680 class = _EnableIfPointerConvertible<_Pp>>
2681 _LIBCPP_INLINE_VISIBILITY
2682 unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
2684 _LIBCPP_INLINE_VISIBILITY
2685 unique_ptr(unique_ptr&& __u) noexcept
2686 : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
2689 _LIBCPP_INLINE_VISIBILITY
2690 unique_ptr& operator=(unique_ptr&& __u) noexcept {
2691 reset(__u.release());
2692 __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
2696 template <class _Up, class _Ep,
2697 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2698 class = _EnableIfDeleterConvertible<_Ep>
2700 _LIBCPP_INLINE_VISIBILITY
2701 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
2702 : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
2705 template <class _Up, class _Ep,
2706 class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
2707 class = _EnableIfDeleterAssignable<_Ep>
2709 _LIBCPP_INLINE_VISIBILITY
2711 operator=(unique_ptr<_Up, _Ep>&& __u) noexcept {
2712 reset(__u.release());
2713 __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
2717 #else // _LIBCPP_CXX03_LANG
2719 template <class _Up> explicit unique_ptr(_Up);
2721 unique_ptr(unique_ptr&);
2722 template <class _Up> unique_ptr(unique_ptr<_Up>&);
2724 unique_ptr& operator=(unique_ptr&);
2725 template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&);
2727 template <class _Up>
2729 typename conditional<
2730 is_reference<deleter_type>::value, deleter_type,
2731 typename add_lvalue_reference<const deleter_type>::type>::type,
2732 typename enable_if<is_convertible<_Up, pointer>::value,
2733 __nat>::type = __nat());
2735 _LIBCPP_INLINE_VISIBILITY
2736 unique_ptr() : __ptr_(pointer()) {
2737 static_assert(!is_pointer<deleter_type>::value,
2738 "unique_ptr constructed with null function pointer deleter");
2740 _LIBCPP_INLINE_VISIBILITY
2741 unique_ptr(nullptr_t) : __ptr_(pointer()) {
2742 static_assert(!is_pointer<deleter_type>::value,
2743 "unique_ptr constructed with null function pointer deleter");
2746 _LIBCPP_INLINE_VISIBILITY
2747 explicit unique_ptr(pointer __p) : __ptr_(__p) {
2748 static_assert(!is_pointer<deleter_type>::value,
2749 "unique_ptr constructed with null function pointer deleter");
2752 _LIBCPP_INLINE_VISIBILITY
2753 unique_ptr(pointer __p, deleter_type __d)
2754 : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
2756 _LIBCPP_INLINE_VISIBILITY
2757 unique_ptr(nullptr_t, deleter_type __d)
2758 : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
2760 _LIBCPP_INLINE_VISIBILITY
2761 operator __rv<unique_ptr>() {
2762 return __rv<unique_ptr>(*this);
2765 _LIBCPP_INLINE_VISIBILITY
2766 unique_ptr(__rv<unique_ptr> __u)
2767 : __ptr_(__u->release(),
2768 _VSTD::forward<deleter_type>(__u->get_deleter())) {}
2770 _LIBCPP_INLINE_VISIBILITY
2771 unique_ptr& operator=(__rv<unique_ptr> __u) {
2772 reset(__u->release());
2773 __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
2777 #endif // _LIBCPP_CXX03_LANG
2780 _LIBCPP_INLINE_VISIBILITY
2781 ~unique_ptr() { reset(); }
2783 _LIBCPP_INLINE_VISIBILITY
2784 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
2789 _LIBCPP_INLINE_VISIBILITY
2790 typename add_lvalue_reference<_Tp>::type
2791 operator[](size_t __i) const {
2792 return __ptr_.first()[__i];
2794 _LIBCPP_INLINE_VISIBILITY
2795 pointer get() const _NOEXCEPT {
2796 return __ptr_.first();
2799 _LIBCPP_INLINE_VISIBILITY
2800 deleter_type& get_deleter() _NOEXCEPT {
2801 return __ptr_.second();
2804 _LIBCPP_INLINE_VISIBILITY
2805 const deleter_type& get_deleter() const _NOEXCEPT {
2806 return __ptr_.second();
2808 _LIBCPP_INLINE_VISIBILITY
2809 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2810 return __ptr_.first() != nullptr;
2813 _LIBCPP_INLINE_VISIBILITY
2814 pointer release() _NOEXCEPT {
2815 pointer __t = __ptr_.first();
2816 __ptr_.first() = pointer();
2820 template <class _Pp>
2821 _LIBCPP_INLINE_VISIBILITY
2823 _CheckArrayPointerConversion<_Pp>::value
2825 reset(_Pp __p) _NOEXCEPT {
2826 pointer __tmp = __ptr_.first();
2827 __ptr_.first() = __p;
2829 __ptr_.second()(__tmp);
2832 _LIBCPP_INLINE_VISIBILITY
2833 void reset(nullptr_t = nullptr) _NOEXCEPT {
2834 pointer __tmp = __ptr_.first();
2835 __ptr_.first() = nullptr;
2837 __ptr_.second()(__tmp);
2840 _LIBCPP_INLINE_VISIBILITY
2841 void swap(unique_ptr& __u) _NOEXCEPT {
2842 __ptr_.swap(__u.__ptr_);
2847 template <class _Tp, class _Dp>
2848 inline _LIBCPP_INLINE_VISIBILITY
2850 __is_swappable<_Dp>::value,
2853 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
2855 template <class _T1, class _D1, class _T2, class _D2>
2856 inline _LIBCPP_INLINE_VISIBILITY
2858 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
2860 template <class _T1, class _D1, class _T2, class _D2>
2861 inline _LIBCPP_INLINE_VISIBILITY
2863 operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
2865 template <class _T1, class _D1, class _T2, class _D2>
2866 inline _LIBCPP_INLINE_VISIBILITY
2868 operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
2870 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2871 typedef typename unique_ptr<_T2, _D2>::pointer _P2;
2872 typedef typename common_type<_P1, _P2>::type _Vp;
2873 return less<_Vp>()(__x.get(), __y.get());
2876 template <class _T1, class _D1, class _T2, class _D2>
2877 inline _LIBCPP_INLINE_VISIBILITY
2879 operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
2881 template <class _T1, class _D1, class _T2, class _D2>
2882 inline _LIBCPP_INLINE_VISIBILITY
2884 operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
2886 template <class _T1, class _D1, class _T2, class _D2>
2887 inline _LIBCPP_INLINE_VISIBILITY
2889 operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
2891 template <class _T1, class _D1>
2892 inline _LIBCPP_INLINE_VISIBILITY
2894 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2899 template <class _T1, class _D1>
2900 inline _LIBCPP_INLINE_VISIBILITY
2902 operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2907 template <class _T1, class _D1>
2908 inline _LIBCPP_INLINE_VISIBILITY
2910 operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
2912 return static_cast<bool>(__x);
2915 template <class _T1, class _D1>
2916 inline _LIBCPP_INLINE_VISIBILITY
2918 operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
2920 return static_cast<bool>(__x);
2923 template <class _T1, class _D1>
2924 inline _LIBCPP_INLINE_VISIBILITY
2926 operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2928 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2929 return less<_P1>()(__x.get(), nullptr);
2932 template <class _T1, class _D1>
2933 inline _LIBCPP_INLINE_VISIBILITY
2935 operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2937 typedef typename unique_ptr<_T1, _D1>::pointer _P1;
2938 return less<_P1>()(nullptr, __x.get());
2941 template <class _T1, class _D1>
2942 inline _LIBCPP_INLINE_VISIBILITY
2944 operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2946 return nullptr < __x;
2949 template <class _T1, class _D1>
2950 inline _LIBCPP_INLINE_VISIBILITY
2952 operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2954 return __x < nullptr;
2957 template <class _T1, class _D1>
2958 inline _LIBCPP_INLINE_VISIBILITY
2960 operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2962 return !(nullptr < __x);
2965 template <class _T1, class _D1>
2966 inline _LIBCPP_INLINE_VISIBILITY
2968 operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2970 return !(__x < nullptr);
2973 template <class _T1, class _D1>
2974 inline _LIBCPP_INLINE_VISIBILITY
2976 operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
2978 return !(__x < nullptr);
2981 template <class _T1, class _D1>
2982 inline _LIBCPP_INLINE_VISIBILITY
2984 operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
2986 return !(nullptr < __x);
2989 #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2991 template <class _Tp, class _Dp>
2992 inline _LIBCPP_INLINE_VISIBILITY
2993 unique_ptr<_Tp, _Dp>
2994 move(unique_ptr<_Tp, _Dp>& __t)
2996 return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
3001 #if _LIBCPP_STD_VER > 11
3006 typedef unique_ptr<_Tp> __unique_single;
3010 struct __unique_if<_Tp[]>
3012 typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
3015 template<class _Tp, size_t _Np>
3016 struct __unique_if<_Tp[_Np]>
3018 typedef void __unique_array_known_bound;
3021 template<class _Tp, class... _Args>
3022 inline _LIBCPP_INLINE_VISIBILITY
3023 typename __unique_if<_Tp>::__unique_single
3024 make_unique(_Args&&... __args)
3026 return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
3030 inline _LIBCPP_INLINE_VISIBILITY
3031 typename __unique_if<_Tp>::__unique_array_unknown_bound
3032 make_unique(size_t __n)
3034 typedef typename remove_extent<_Tp>::type _Up;
3035 return unique_ptr<_Tp>(new _Up[__n]());
3038 template<class _Tp, class... _Args>
3039 typename __unique_if<_Tp>::__unique_array_known_bound
3040 make_unique(_Args&&...) = delete;
3042 #endif // _LIBCPP_STD_VER > 11
3044 template <class _Tp, class _Dp>
3045 #ifdef _LIBCPP_CXX03_LANG
3046 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
3048 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
3049 unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>>
3052 typedef unique_ptr<_Tp, _Dp> argument_type;
3053 typedef size_t result_type;
3054 _LIBCPP_INLINE_VISIBILITY
3055 result_type operator()(const argument_type& __ptr) const
3057 typedef typename argument_type::pointer pointer;
3058 return hash<pointer>()(__ptr.get());
3067 template <class _Tp>
3068 _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
3069 {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
3071 template <class _Tp>
3072 _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
3075 _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
3077 _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
3080 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
3082 _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
3085 _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
3088 template <class _Tp>
3089 _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
3090 {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3092 template <class _Tp>
3093 _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
3094 {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3096 template <class _Tp>
3097 _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
3098 {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
3101 template <class _Alloc>
3102 class __allocator_destructor
3104 typedef allocator_traits<_Alloc> __alloc_traits;
3106 typedef typename __alloc_traits::pointer pointer;
3107 typedef typename __alloc_traits::size_type size_type;
3112 _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
3114 : __alloc_(__a), __s_(__s) {}
3115 _LIBCPP_INLINE_VISIBILITY
3116 void operator()(pointer __p) _NOEXCEPT
3117 {__alloc_traits::deallocate(__alloc_, __p, __s_);}
3120 template <class _InputIterator, class _ForwardIterator>
3122 uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
3124 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3125 #ifndef _LIBCPP_NO_EXCEPTIONS
3126 _ForwardIterator __s = __r;
3130 for (; __f != __l; ++__f, (void) ++__r)
3131 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3132 #ifndef _LIBCPP_NO_EXCEPTIONS
3136 for (; __s != __r; ++__s)
3144 template <class _InputIterator, class _Size, class _ForwardIterator>
3146 uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
3148 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3149 #ifndef _LIBCPP_NO_EXCEPTIONS
3150 _ForwardIterator __s = __r;
3154 for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
3155 ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
3156 #ifndef _LIBCPP_NO_EXCEPTIONS
3160 for (; __s != __r; ++__s)
3168 template <class _ForwardIterator, class _Tp>
3170 uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
3172 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3173 #ifndef _LIBCPP_NO_EXCEPTIONS
3174 _ForwardIterator __s = __f;
3178 for (; __f != __l; ++__f)
3179 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3180 #ifndef _LIBCPP_NO_EXCEPTIONS
3184 for (; __s != __f; ++__s)
3191 template <class _ForwardIterator, class _Size, class _Tp>
3193 uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
3195 typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
3196 #ifndef _LIBCPP_NO_EXCEPTIONS
3197 _ForwardIterator __s = __f;
3201 for (; __n > 0; ++__f, (void) --__n)
3202 ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
3203 #ifndef _LIBCPP_NO_EXCEPTIONS
3207 for (; __s != __f; ++__s)
3215 #if _LIBCPP_STD_VER > 14
3217 template <class _Tp>
3218 inline _LIBCPP_INLINE_VISIBILITY
3219 void destroy_at(_Tp* __loc) {
3220 _LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
3224 template <class _ForwardIterator>
3225 inline _LIBCPP_INLINE_VISIBILITY
3226 void destroy(_ForwardIterator __first, _ForwardIterator __last) {
3227 for (; __first != __last; ++__first)
3228 _VSTD::destroy_at(_VSTD::addressof(*__first));
3231 template <class _ForwardIterator, class _Size>
3232 inline _LIBCPP_INLINE_VISIBILITY
3233 _ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
3234 for (; __n > 0; (void)++__first, --__n)
3235 _VSTD::destroy_at(_VSTD::addressof(*__first));
3239 template <class _ForwardIterator>
3240 inline _LIBCPP_INLINE_VISIBILITY
3241 void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
3242 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3243 auto __idx = __first;
3244 #ifndef _LIBCPP_NO_EXCEPTIONS
3247 for (; __idx != __last; ++__idx)
3248 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3249 #ifndef _LIBCPP_NO_EXCEPTIONS
3251 _VSTD::destroy(__first, __idx);
3257 template <class _ForwardIterator, class _Size>
3258 inline _LIBCPP_INLINE_VISIBILITY
3259 _ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
3260 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3261 auto __idx = __first;
3262 #ifndef _LIBCPP_NO_EXCEPTIONS
3265 for (; __n > 0; (void)++__idx, --__n)
3266 ::new((void*)_VSTD::addressof(*__idx)) _Vt;
3268 #ifndef _LIBCPP_NO_EXCEPTIONS
3270 _VSTD::destroy(__first, __idx);
3277 template <class _ForwardIterator>
3278 inline _LIBCPP_INLINE_VISIBILITY
3279 void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
3280 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3281 auto __idx = __first;
3282 #ifndef _LIBCPP_NO_EXCEPTIONS
3285 for (; __idx != __last; ++__idx)
3286 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3287 #ifndef _LIBCPP_NO_EXCEPTIONS
3289 _VSTD::destroy(__first, __idx);
3295 template <class _ForwardIterator, class _Size>
3296 inline _LIBCPP_INLINE_VISIBILITY
3297 _ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
3298 using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
3299 auto __idx = __first;
3300 #ifndef _LIBCPP_NO_EXCEPTIONS
3303 for (; __n > 0; (void)++__idx, --__n)
3304 ::new((void*)_VSTD::addressof(*__idx)) _Vt();
3306 #ifndef _LIBCPP_NO_EXCEPTIONS
3308 _VSTD::destroy(__first, __idx);
3315 template <class _InputIt, class _ForwardIt>
3316 inline _LIBCPP_INLINE_VISIBILITY
3317 _ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
3318 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3319 auto __idx = __first_res;
3320 #ifndef _LIBCPP_NO_EXCEPTIONS
3323 for (; __first != __last; (void)++__idx, ++__first)
3324 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3326 #ifndef _LIBCPP_NO_EXCEPTIONS
3328 _VSTD::destroy(__first_res, __idx);
3334 template <class _InputIt, class _Size, class _ForwardIt>
3335 inline _LIBCPP_INLINE_VISIBILITY
3336 pair<_InputIt, _ForwardIt>
3337 uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
3338 using _Vt = typename iterator_traits<_ForwardIt>::value_type;
3339 auto __idx = __first_res;
3340 #ifndef _LIBCPP_NO_EXCEPTIONS
3343 for (; __n > 0; ++__idx, (void)++__first, --__n)
3344 ::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
3345 return {__first, __idx};
3346 #ifndef _LIBCPP_NO_EXCEPTIONS
3348 _VSTD::destroy(__first_res, __idx);
3355 #endif // _LIBCPP_STD_VER > 14
3357 // NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
3358 // should be sufficient for thread safety.
3359 // See https://bugs.llvm.org/show_bug.cgi?id=22803
3360 #if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
3361 && defined(__ATOMIC_RELAXED) \
3362 && defined(__ATOMIC_ACQ_REL)
3363 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3364 #elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
3365 # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
3368 template <class _Tp>
3369 inline _LIBCPP_INLINE_VISIBILITY _Tp
3370 __libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
3372 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3373 return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
3379 template <class _Tp>
3380 inline _LIBCPP_INLINE_VISIBILITY _Tp
3381 __libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
3383 #if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
3384 return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
3390 class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
3391 : public std::exception
3394 virtual ~bad_weak_ptr() _NOEXCEPT;
3395 virtual const char* what() const _NOEXCEPT;
3398 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
3399 void __throw_bad_weak_ptr()
3401 #ifndef _LIBCPP_NO_EXCEPTIONS
3402 throw bad_weak_ptr();
3408 template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
3410 class _LIBCPP_TYPE_VIS __shared_count
3412 __shared_count(const __shared_count&);
3413 __shared_count& operator=(const __shared_count&);
3416 long __shared_owners_;
3417 virtual ~__shared_count();
3419 virtual void __on_zero_shared() _NOEXCEPT = 0;
3422 _LIBCPP_INLINE_VISIBILITY
3423 explicit __shared_count(long __refs = 0) _NOEXCEPT
3424 : __shared_owners_(__refs) {}
3426 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3427 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3428 void __add_shared() _NOEXCEPT;
3429 bool __release_shared() _NOEXCEPT;
3431 _LIBCPP_INLINE_VISIBILITY
3432 void __add_shared() _NOEXCEPT {
3433 __libcpp_atomic_refcount_increment(__shared_owners_);
3435 _LIBCPP_INLINE_VISIBILITY
3436 bool __release_shared() _NOEXCEPT {
3437 if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
3444 _LIBCPP_INLINE_VISIBILITY
3445 long use_count() const _NOEXCEPT {
3446 return __libcpp_relaxed_load(&__shared_owners_) + 1;
3450 class _LIBCPP_TYPE_VIS __shared_weak_count
3451 : private __shared_count
3453 long __shared_weak_owners_;
3456 _LIBCPP_INLINE_VISIBILITY
3457 explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
3458 : __shared_count(__refs),
3459 __shared_weak_owners_(__refs) {}
3461 virtual ~__shared_weak_count();
3464 #if defined(_LIBCPP_BUILDING_MEMORY) && \
3465 defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
3466 void __add_shared() _NOEXCEPT;
3467 void __add_weak() _NOEXCEPT;
3468 void __release_shared() _NOEXCEPT;
3470 _LIBCPP_INLINE_VISIBILITY
3471 void __add_shared() _NOEXCEPT {
3472 __shared_count::__add_shared();
3474 _LIBCPP_INLINE_VISIBILITY
3475 void __add_weak() _NOEXCEPT {
3476 __libcpp_atomic_refcount_increment(__shared_weak_owners_);
3478 _LIBCPP_INLINE_VISIBILITY
3479 void __release_shared() _NOEXCEPT {
3480 if (__shared_count::__release_shared())
3484 void __release_weak() _NOEXCEPT;
3485 _LIBCPP_INLINE_VISIBILITY
3486 long use_count() const _NOEXCEPT {return __shared_count::use_count();}
3487 __shared_weak_count* lock() _NOEXCEPT;
3489 // Define the function out only if we build static libc++ without RTTI.
3490 // Otherwise we may break clients who need to compile their projects with
3491 // -fno-rtti and yet link against a libc++.dylib compiled
3492 // without -fno-rtti.
3493 #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
3494 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3497 virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
3500 template <class _Tp, class _Dp, class _Alloc>
3501 class __shared_ptr_pointer
3502 : public __shared_weak_count
3504 __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
3506 _LIBCPP_INLINE_VISIBILITY
3507 __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
3508 : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
3510 #ifndef _LIBCPP_NO_RTTI
3511 virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
3515 virtual void __on_zero_shared() _NOEXCEPT;
3516 virtual void __on_zero_shared_weak() _NOEXCEPT;
3519 #ifndef _LIBCPP_NO_RTTI
3521 template <class _Tp, class _Dp, class _Alloc>
3523 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
3525 return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
3528 #endif // _LIBCPP_NO_RTTI
3530 template <class _Tp, class _Dp, class _Alloc>
3532 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
3534 __data_.first().second()(__data_.first().first());
3535 __data_.first().second().~_Dp();
3538 template <class _Tp, class _Dp, class _Alloc>
3540 __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3542 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
3543 typedef allocator_traits<_Al> _ATraits;
3544 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3546 _Al __a(__data_.second());
3547 __data_.second().~_Alloc();
3548 __a.deallocate(_PTraits::pointer_to(*this), 1);
3551 template <class _Tp, class _Alloc>
3552 class __shared_ptr_emplace
3553 : public __shared_weak_count
3555 __compressed_pair<_Alloc, _Tp> __data_;
3557 #ifndef _LIBCPP_HAS_NO_VARIADICS
3559 _LIBCPP_INLINE_VISIBILITY
3560 __shared_ptr_emplace(_Alloc __a)
3561 : __data_(_VSTD::move(__a)) {}
3563 template <class ..._Args>
3564 _LIBCPP_INLINE_VISIBILITY
3565 __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
3566 : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
3567 _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
3569 #else // _LIBCPP_HAS_NO_VARIADICS
3571 _LIBCPP_INLINE_VISIBILITY
3572 __shared_ptr_emplace(_Alloc __a)
3575 template <class _A0>
3576 _LIBCPP_INLINE_VISIBILITY
3577 __shared_ptr_emplace(_Alloc __a, _A0& __a0)
3578 : __data_(__a, _Tp(__a0)) {}
3580 template <class _A0, class _A1>
3581 _LIBCPP_INLINE_VISIBILITY
3582 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
3583 : __data_(__a, _Tp(__a0, __a1)) {}
3585 template <class _A0, class _A1, class _A2>
3586 _LIBCPP_INLINE_VISIBILITY
3587 __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
3588 : __data_(__a, _Tp(__a0, __a1, __a2)) {}
3590 #endif // _LIBCPP_HAS_NO_VARIADICS
3593 virtual void __on_zero_shared() _NOEXCEPT;
3594 virtual void __on_zero_shared_weak() _NOEXCEPT;
3596 _LIBCPP_INLINE_VISIBILITY
3597 _Tp* get() _NOEXCEPT {return &__data_.second();}
3600 template <class _Tp, class _Alloc>
3602 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
3604 __data_.second().~_Tp();
3607 template <class _Tp, class _Alloc>
3609 __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
3611 typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
3612 typedef allocator_traits<_Al> _ATraits;
3613 typedef pointer_traits<typename _ATraits::pointer> _PTraits;
3614 _Al __a(__data_.first());
3615 __data_.first().~_Alloc();
3616 __a.deallocate(_PTraits::pointer_to(*this), 1);
3619 struct __shared_ptr_dummy_rebind_allocator_type;
3621 class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
3624 template <class _Other>
3627 typedef allocator<_Other> other;
3631 template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
3634 class _LIBCPP_TEMPLATE_VIS shared_ptr
3637 typedef _Tp element_type;
3639 #if _LIBCPP_STD_VER > 14
3640 typedef weak_ptr<_Tp> weak_type;
3643 element_type* __ptr_;
3644 __shared_weak_count* __cntrl_;
3646 struct __nat {int __for_bool_;};
3648 _LIBCPP_INLINE_VISIBILITY
3649 _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
3650 _LIBCPP_INLINE_VISIBILITY
3651 _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
3653 explicit shared_ptr(_Yp* __p,
3654 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3655 template<class _Yp, class _Dp>
3656 shared_ptr(_Yp* __p, _Dp __d,
3657 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3658 template<class _Yp, class _Dp, class _Alloc>
3659 shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
3660 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3661 template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
3662 template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
3663 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
3664 _LIBCPP_INLINE_VISIBILITY
3665 shared_ptr(const shared_ptr& __r) _NOEXCEPT;
3667 _LIBCPP_INLINE_VISIBILITY
3668 shared_ptr(const shared_ptr<_Yp>& __r,
3669 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3671 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3672 _LIBCPP_INLINE_VISIBILITY
3673 shared_ptr(shared_ptr&& __r) _NOEXCEPT;
3674 template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
3675 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
3677 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3678 template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
3679 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
3680 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3681 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3683 shared_ptr(auto_ptr<_Yp>&& __r,
3684 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3687 shared_ptr(auto_ptr<_Yp> __r,
3688 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
3691 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3692 template <class _Yp, class _Dp>
3693 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3696 !is_lvalue_reference<_Dp>::value &&
3697 !is_array<_Yp>::value &&
3698 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3701 template <class _Yp, class _Dp>
3702 shared_ptr(unique_ptr<_Yp, _Dp>&&,
3705 is_lvalue_reference<_Dp>::value &&
3706 !is_array<_Yp>::value &&
3707 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3710 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3711 template <class _Yp, class _Dp>
3712 shared_ptr(unique_ptr<_Yp, _Dp>,
3715 !is_lvalue_reference<_Dp>::value &&
3716 !is_array<_Yp>::value &&
3717 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3720 template <class _Yp, class _Dp>
3721 shared_ptr(unique_ptr<_Yp, _Dp>,
3724 is_lvalue_reference<_Dp>::value &&
3725 !is_array<_Yp>::value &&
3726 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3729 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3733 _LIBCPP_INLINE_VISIBILITY
3734 shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
3738 is_convertible<_Yp*, element_type*>::value,
3741 _LIBCPP_INLINE_VISIBILITY
3742 operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
3743 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3744 _LIBCPP_INLINE_VISIBILITY
3745 shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
3749 is_convertible<_Yp*, element_type*>::value,
3752 _LIBCPP_INLINE_VISIBILITY
3753 operator=(shared_ptr<_Yp>&& __r);
3754 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3756 _LIBCPP_INLINE_VISIBILITY
3759 !is_array<_Yp>::value &&
3760 is_convertible<_Yp*, element_type*>::value,
3763 operator=(auto_ptr<_Yp>&& __r);
3765 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3766 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
3768 _LIBCPP_INLINE_VISIBILITY
3771 !is_array<_Yp>::value &&
3772 is_convertible<_Yp*, element_type*>::value,
3775 operator=(auto_ptr<_Yp> __r);
3778 template <class _Yp, class _Dp>
3781 !is_array<_Yp>::value &&
3782 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
3785 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3786 _LIBCPP_INLINE_VISIBILITY
3787 operator=(unique_ptr<_Yp, _Dp>&& __r);
3788 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3789 _LIBCPP_INLINE_VISIBILITY
3790 operator=(unique_ptr<_Yp, _Dp> __r);
3793 _LIBCPP_INLINE_VISIBILITY
3794 void swap(shared_ptr& __r) _NOEXCEPT;
3795 _LIBCPP_INLINE_VISIBILITY
3796 void reset() _NOEXCEPT;
3800 is_convertible<_Yp*, element_type*>::value,
3803 _LIBCPP_INLINE_VISIBILITY
3805 template<class _Yp, class _Dp>
3808 is_convertible<_Yp*, element_type*>::value,
3811 _LIBCPP_INLINE_VISIBILITY
3812 reset(_Yp* __p, _Dp __d);
3813 template<class _Yp, class _Dp, class _Alloc>
3816 is_convertible<_Yp*, element_type*>::value,
3819 _LIBCPP_INLINE_VISIBILITY
3820 reset(_Yp* __p, _Dp __d, _Alloc __a);
3822 _LIBCPP_INLINE_VISIBILITY
3823 element_type* get() const _NOEXCEPT {return __ptr_;}
3824 _LIBCPP_INLINE_VISIBILITY
3825 typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
3827 _LIBCPP_INLINE_VISIBILITY
3828 element_type* operator->() const _NOEXCEPT {return __ptr_;}
3829 _LIBCPP_INLINE_VISIBILITY
3830 long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
3831 _LIBCPP_INLINE_VISIBILITY
3832 bool unique() const _NOEXCEPT {return use_count() == 1;}
3833 _LIBCPP_INLINE_VISIBILITY
3834 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
3835 template <class _Up>
3836 _LIBCPP_INLINE_VISIBILITY
3837 bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
3838 {return __cntrl_ < __p.__cntrl_;}
3839 template <class _Up>
3840 _LIBCPP_INLINE_VISIBILITY
3841 bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
3842 {return __cntrl_ < __p.__cntrl_;}
3843 _LIBCPP_INLINE_VISIBILITY
3845 __owner_equivalent(const shared_ptr& __p) const
3846 {return __cntrl_ == __p.__cntrl_;}
3848 #ifndef _LIBCPP_NO_RTTI
3849 template <class _Dp>
3850 _LIBCPP_INLINE_VISIBILITY
3851 _Dp* __get_deleter() const _NOEXCEPT
3852 {return static_cast<_Dp*>(__cntrl_
3853 ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
3855 #endif // _LIBCPP_NO_RTTI
3857 #ifndef _LIBCPP_HAS_NO_VARIADICS
3859 template<class ..._Args>
3862 make_shared(_Args&& ...__args);
3864 template<class _Alloc, class ..._Args>
3867 allocate_shared(const _Alloc& __a, _Args&& ...__args);
3869 #else // _LIBCPP_HAS_NO_VARIADICS
3871 static shared_ptr<_Tp> make_shared();
3874 static shared_ptr<_Tp> make_shared(_A0&);
3876 template<class _A0, class _A1>
3877 static shared_ptr<_Tp> make_shared(_A0&, _A1&);
3879 template<class _A0, class _A1, class _A2>
3880 static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
3882 template<class _Alloc>
3883 static shared_ptr<_Tp>
3884 allocate_shared(const _Alloc& __a);
3886 template<class _Alloc, class _A0>
3887 static shared_ptr<_Tp>
3888 allocate_shared(const _Alloc& __a, _A0& __a0);
3890 template<class _Alloc, class _A0, class _A1>
3891 static shared_ptr<_Tp>
3892 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
3894 template<class _Alloc, class _A0, class _A1, class _A2>
3895 static shared_ptr<_Tp>
3896 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
3898 #endif // _LIBCPP_HAS_NO_VARIADICS
3901 template <class _Yp, bool = is_function<_Yp>::value>
3902 struct __shared_ptr_default_allocator
3904 typedef allocator<_Yp> type;
3907 template <class _Yp>
3908 struct __shared_ptr_default_allocator<_Yp, true>
3910 typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
3913 template <class _Yp, class _OrigPtr>
3914 _LIBCPP_INLINE_VISIBILITY
3915 typename enable_if<is_convertible<_OrigPtr*,
3916 const enable_shared_from_this<_Yp>*
3919 __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
3920 _OrigPtr* __ptr) _NOEXCEPT
3922 typedef typename remove_cv<_Yp>::type _RawYp;
3923 if (__e && __e->__weak_this_.expired())
3925 __e->__weak_this_ = shared_ptr<_RawYp>(*this,
3926 const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
3930 _LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
3932 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
3933 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
3940 shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
3949 shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
3957 shared_ptr<_Tp>::shared_ptr(_Yp* __p,
3958 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3961 unique_ptr<_Yp> __hold(__p);
3962 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3963 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
3964 __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
3966 __enable_weak_this(__p, __p);
3970 template<class _Yp, class _Dp>
3971 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
3972 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
3975 #ifndef _LIBCPP_NO_EXCEPTIONS
3978 #endif // _LIBCPP_NO_EXCEPTIONS
3979 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
3980 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
3981 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
3982 __enable_weak_this(__p, __p);
3983 #ifndef _LIBCPP_NO_EXCEPTIONS
3990 #endif // _LIBCPP_NO_EXCEPTIONS
3995 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
3998 #ifndef _LIBCPP_NO_EXCEPTIONS
4001 #endif // _LIBCPP_NO_EXCEPTIONS
4002 typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
4003 typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
4004 __cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
4005 #ifndef _LIBCPP_NO_EXCEPTIONS
4012 #endif // _LIBCPP_NO_EXCEPTIONS
4016 template<class _Yp, class _Dp, class _Alloc>
4017 shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
4018 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4021 #ifndef _LIBCPP_NO_EXCEPTIONS
4024 #endif // _LIBCPP_NO_EXCEPTIONS
4025 typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
4026 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4027 typedef __allocator_destructor<_A2> _D2;
4029 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4030 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4031 _CntrlBlk(__p, __d, __a);
4032 __cntrl_ = _VSTD::addressof(*__hold2.release());
4033 __enable_weak_this(__p, __p);
4034 #ifndef _LIBCPP_NO_EXCEPTIONS
4041 #endif // _LIBCPP_NO_EXCEPTIONS
4045 template<class _Dp, class _Alloc>
4046 shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
4049 #ifndef _LIBCPP_NO_EXCEPTIONS
4052 #endif // _LIBCPP_NO_EXCEPTIONS
4053 typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
4054 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4055 typedef __allocator_destructor<_A2> _D2;
4057 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4058 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4059 _CntrlBlk(__p, __d, __a);
4060 __cntrl_ = _VSTD::addressof(*__hold2.release());
4061 #ifndef _LIBCPP_NO_EXCEPTIONS
4068 #endif // _LIBCPP_NO_EXCEPTIONS
4074 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
4076 __cntrl_(__r.__cntrl_)
4079 __cntrl_->__add_shared();
4084 shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
4085 : __ptr_(__r.__ptr_),
4086 __cntrl_(__r.__cntrl_)
4089 __cntrl_->__add_shared();
4095 shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
4096 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4098 : __ptr_(__r.__ptr_),
4099 __cntrl_(__r.__cntrl_)
4102 __cntrl_->__add_shared();
4105 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4109 shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
4110 : __ptr_(__r.__ptr_),
4111 __cntrl_(__r.__cntrl_)
4120 shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
4121 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4123 : __ptr_(__r.__ptr_),
4124 __cntrl_(__r.__cntrl_)
4130 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4132 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4135 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4136 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
4138 shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
4140 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
4143 typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
4144 __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
4145 __enable_weak_this(__r.get(), __r.get());
4151 template <class _Yp, class _Dp>
4152 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4153 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4155 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4159 !is_lvalue_reference<_Dp>::value &&
4160 !is_array<_Yp>::value &&
4161 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4166 #if _LIBCPP_STD_VER > 11
4167 if (__ptr_ == nullptr)
4172 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4173 typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
4174 __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
4175 __enable_weak_this(__r.get(), __r.get());
4181 template <class _Yp, class _Dp>
4182 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4183 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
4185 shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
4189 is_lvalue_reference<_Dp>::value &&
4190 !is_array<_Yp>::value &&
4191 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
4196 #if _LIBCPP_STD_VER > 11
4197 if (__ptr_ == nullptr)
4202 typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
4203 typedef __shared_ptr_pointer<_Yp*,
4204 reference_wrapper<typename remove_reference<_Dp>::type>,
4205 _AllocT > _CntrlBlk;
4206 __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
4207 __enable_weak_this(__r.get(), __r.get());
4212 #ifndef _LIBCPP_HAS_NO_VARIADICS
4215 template<class ..._Args>
4217 shared_ptr<_Tp>::make_shared(_Args&& ...__args)
4219 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4220 typedef allocator<_CntrlBlk> _A2;
4221 typedef __allocator_destructor<_A2> _D2;
4223 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4224 ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
4225 shared_ptr<_Tp> __r;
4226 __r.__ptr_ = __hold2.get()->get();
4227 __r.__cntrl_ = __hold2.release();
4228 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4233 template<class _Alloc, class ..._Args>
4235 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
4237 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4238 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
4239 typedef __allocator_destructor<_A2> _D2;
4241 unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
4242 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4243 _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
4244 shared_ptr<_Tp> __r;
4245 __r.__ptr_ = __hold2.get()->get();
4246 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4247 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4251 #else // _LIBCPP_HAS_NO_VARIADICS
4255 shared_ptr<_Tp>::make_shared()
4257 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4258 typedef allocator<_CntrlBlk> _Alloc2;
4259 typedef __allocator_destructor<_Alloc2> _D2;
4261 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4262 ::new(__hold2.get()) _CntrlBlk(__alloc2);
4263 shared_ptr<_Tp> __r;
4264 __r.__ptr_ = __hold2.get()->get();
4265 __r.__cntrl_ = __hold2.release();
4266 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4273 shared_ptr<_Tp>::make_shared(_A0& __a0)
4275 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4276 typedef allocator<_CntrlBlk> _Alloc2;
4277 typedef __allocator_destructor<_Alloc2> _D2;
4279 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4280 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
4281 shared_ptr<_Tp> __r;
4282 __r.__ptr_ = __hold2.get()->get();
4283 __r.__cntrl_ = __hold2.release();
4284 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4289 template<class _A0, class _A1>
4291 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
4293 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4294 typedef allocator<_CntrlBlk> _Alloc2;
4295 typedef __allocator_destructor<_Alloc2> _D2;
4297 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4298 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
4299 shared_ptr<_Tp> __r;
4300 __r.__ptr_ = __hold2.get()->get();
4301 __r.__cntrl_ = __hold2.release();
4302 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4307 template<class _A0, class _A1, class _A2>
4309 shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4311 typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
4312 typedef allocator<_CntrlBlk> _Alloc2;
4313 typedef __allocator_destructor<_Alloc2> _D2;
4315 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4316 ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
4317 shared_ptr<_Tp> __r;
4318 __r.__ptr_ = __hold2.get()->get();
4319 __r.__cntrl_ = __hold2.release();
4320 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4325 template<class _Alloc>
4327 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
4329 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4330 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4331 typedef __allocator_destructor<_Alloc2> _D2;
4332 _Alloc2 __alloc2(__a);
4333 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4334 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4336 shared_ptr<_Tp> __r;
4337 __r.__ptr_ = __hold2.get()->get();
4338 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4339 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4344 template<class _Alloc, class _A0>
4346 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
4348 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4349 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4350 typedef __allocator_destructor<_Alloc2> _D2;
4351 _Alloc2 __alloc2(__a);
4352 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4353 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4354 _CntrlBlk(__a, __a0);
4355 shared_ptr<_Tp> __r;
4356 __r.__ptr_ = __hold2.get()->get();
4357 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4358 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4363 template<class _Alloc, class _A0, class _A1>
4365 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4367 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4368 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4369 typedef __allocator_destructor<_Alloc2> _D2;
4370 _Alloc2 __alloc2(__a);
4371 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4372 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4373 _CntrlBlk(__a, __a0, __a1);
4374 shared_ptr<_Tp> __r;
4375 __r.__ptr_ = __hold2.get()->get();
4376 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4377 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4382 template<class _Alloc, class _A0, class _A1, class _A2>
4384 shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4386 typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
4387 typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
4388 typedef __allocator_destructor<_Alloc2> _D2;
4389 _Alloc2 __alloc2(__a);
4390 unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
4391 ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
4392 _CntrlBlk(__a, __a0, __a1, __a2);
4393 shared_ptr<_Tp> __r;
4394 __r.__ptr_ = __hold2.get()->get();
4395 __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
4396 __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
4400 #endif // _LIBCPP_HAS_NO_VARIADICS
4403 shared_ptr<_Tp>::~shared_ptr()
4406 __cntrl_->__release_shared();
4412 shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
4414 shared_ptr(__r).swap(*this);
4423 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4426 shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
4428 shared_ptr(__r).swap(*this);
4432 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4437 shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
4439 shared_ptr(_VSTD::move(__r)).swap(*this);
4448 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4451 shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
4453 shared_ptr(_VSTD::move(__r)).swap(*this);
4457 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4463 !is_array<_Yp>::value &&
4464 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4467 shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
4469 shared_ptr(_VSTD::move(__r)).swap(*this);
4475 template <class _Yp, class _Dp>
4479 !is_array<_Yp>::value &&
4480 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4481 typename shared_ptr<_Tp>::element_type*>::value,
4484 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
4486 shared_ptr(_VSTD::move(__r)).swap(*this);
4490 #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4492 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
4495 inline _LIBCPP_INLINE_VISIBILITY
4498 !is_array<_Yp>::value &&
4499 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4502 shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
4504 shared_ptr(__r).swap(*this);
4510 template <class _Yp, class _Dp>
4511 inline _LIBCPP_INLINE_VISIBILITY
4514 !is_array<_Yp>::value &&
4515 is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
4516 typename shared_ptr<_Tp>::element_type*>::value,
4519 shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
4521 shared_ptr(_VSTD::move(__r)).swap(*this);
4525 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4530 shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
4532 _VSTD::swap(__ptr_, __r.__ptr_);
4533 _VSTD::swap(__cntrl_, __r.__cntrl_);
4539 shared_ptr<_Tp>::reset() _NOEXCEPT
4541 shared_ptr().swap(*this);
4549 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4552 shared_ptr<_Tp>::reset(_Yp* __p)
4554 shared_ptr(__p).swap(*this);
4558 template<class _Yp, class _Dp>
4562 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4565 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
4567 shared_ptr(__p, __d).swap(*this);
4571 template<class _Yp, class _Dp, class _Alloc>
4575 is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
4578 shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
4580 shared_ptr(__p, __d, __a).swap(*this);
4583 #ifndef _LIBCPP_HAS_NO_VARIADICS
4585 template<class _Tp, class ..._Args>
4586 inline _LIBCPP_INLINE_VISIBILITY
4589 !is_array<_Tp>::value,
4592 make_shared(_Args&& ...__args)
4594 return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
4597 template<class _Tp, class _Alloc, class ..._Args>
4598 inline _LIBCPP_INLINE_VISIBILITY
4601 !is_array<_Tp>::value,
4604 allocate_shared(const _Alloc& __a, _Args&& ...__args)
4606 return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
4609 #else // _LIBCPP_HAS_NO_VARIADICS
4612 inline _LIBCPP_INLINE_VISIBILITY
4616 return shared_ptr<_Tp>::make_shared();
4619 template<class _Tp, class _A0>
4620 inline _LIBCPP_INLINE_VISIBILITY
4622 make_shared(_A0& __a0)
4624 return shared_ptr<_Tp>::make_shared(__a0);
4627 template<class _Tp, class _A0, class _A1>
4628 inline _LIBCPP_INLINE_VISIBILITY
4630 make_shared(_A0& __a0, _A1& __a1)
4632 return shared_ptr<_Tp>::make_shared(__a0, __a1);
4635 template<class _Tp, class _A0, class _A1, class _A2>
4636 inline _LIBCPP_INLINE_VISIBILITY
4638 make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
4640 return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
4643 template<class _Tp, class _Alloc>
4644 inline _LIBCPP_INLINE_VISIBILITY
4646 allocate_shared(const _Alloc& __a)
4648 return shared_ptr<_Tp>::allocate_shared(__a);
4651 template<class _Tp, class _Alloc, class _A0>
4652 inline _LIBCPP_INLINE_VISIBILITY
4654 allocate_shared(const _Alloc& __a, _A0& __a0)
4656 return shared_ptr<_Tp>::allocate_shared(__a, __a0);
4659 template<class _Tp, class _Alloc, class _A0, class _A1>
4660 inline _LIBCPP_INLINE_VISIBILITY
4662 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
4664 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
4667 template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
4668 inline _LIBCPP_INLINE_VISIBILITY
4670 allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
4672 return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
4675 #endif // _LIBCPP_HAS_NO_VARIADICS
4677 template<class _Tp, class _Up>
4678 inline _LIBCPP_INLINE_VISIBILITY
4680 operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4682 return __x.get() == __y.get();
4685 template<class _Tp, class _Up>
4686 inline _LIBCPP_INLINE_VISIBILITY
4688 operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4690 return !(__x == __y);
4693 template<class _Tp, class _Up>
4694 inline _LIBCPP_INLINE_VISIBILITY
4696 operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4698 typedef typename common_type<_Tp*, _Up*>::type _Vp;
4699 return less<_Vp>()(__x.get(), __y.get());
4702 template<class _Tp, class _Up>
4703 inline _LIBCPP_INLINE_VISIBILITY
4705 operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4710 template<class _Tp, class _Up>
4711 inline _LIBCPP_INLINE_VISIBILITY
4713 operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4715 return !(__y < __x);
4718 template<class _Tp, class _Up>
4719 inline _LIBCPP_INLINE_VISIBILITY
4721 operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
4723 return !(__x < __y);
4727 inline _LIBCPP_INLINE_VISIBILITY
4729 operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4735 inline _LIBCPP_INLINE_VISIBILITY
4737 operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4743 inline _LIBCPP_INLINE_VISIBILITY
4745 operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4747 return static_cast<bool>(__x);
4751 inline _LIBCPP_INLINE_VISIBILITY
4753 operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4755 return static_cast<bool>(__x);
4759 inline _LIBCPP_INLINE_VISIBILITY
4761 operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4763 return less<_Tp*>()(__x.get(), nullptr);
4767 inline _LIBCPP_INLINE_VISIBILITY
4769 operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4771 return less<_Tp*>()(nullptr, __x.get());
4775 inline _LIBCPP_INLINE_VISIBILITY
4777 operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4779 return nullptr < __x;
4783 inline _LIBCPP_INLINE_VISIBILITY
4785 operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4787 return __x < nullptr;
4791 inline _LIBCPP_INLINE_VISIBILITY
4793 operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4795 return !(nullptr < __x);
4799 inline _LIBCPP_INLINE_VISIBILITY
4801 operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4803 return !(__x < nullptr);
4807 inline _LIBCPP_INLINE_VISIBILITY
4809 operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
4811 return !(__x < nullptr);
4815 inline _LIBCPP_INLINE_VISIBILITY
4817 operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
4819 return !(nullptr < __x);
4823 inline _LIBCPP_INLINE_VISIBILITY
4825 swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
4830 template<class _Tp, class _Up>
4831 inline _LIBCPP_INLINE_VISIBILITY
4834 !is_array<_Tp>::value && !is_array<_Up>::value,
4837 static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4839 return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
4842 template<class _Tp, class _Up>
4843 inline _LIBCPP_INLINE_VISIBILITY
4846 !is_array<_Tp>::value && !is_array<_Up>::value,
4849 dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4851 _Tp* __p = dynamic_cast<_Tp*>(__r.get());
4852 return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
4855 template<class _Tp, class _Up>
4858 is_array<_Tp>::value == is_array<_Up>::value,
4861 const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
4863 typedef typename remove_extent<_Tp>::type _RTp;
4864 return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
4867 #ifndef _LIBCPP_NO_RTTI
4869 template<class _Dp, class _Tp>
4870 inline _LIBCPP_INLINE_VISIBILITY
4872 get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
4874 return __p.template __get_deleter<_Dp>();
4877 #endif // _LIBCPP_NO_RTTI
4880 class _LIBCPP_TEMPLATE_VIS weak_ptr
4883 typedef _Tp element_type;
4885 element_type* __ptr_;
4886 __shared_weak_count* __cntrl_;
4889 _LIBCPP_INLINE_VISIBILITY
4890 _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
4891 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
4892 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4894 _LIBCPP_INLINE_VISIBILITY
4895 weak_ptr(weak_ptr const& __r) _NOEXCEPT;
4896 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
4897 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4900 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4901 _LIBCPP_INLINE_VISIBILITY
4902 weak_ptr(weak_ptr&& __r) _NOEXCEPT;
4903 template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
4904 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
4906 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4909 _LIBCPP_INLINE_VISIBILITY
4910 weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
4914 is_convertible<_Yp*, element_type*>::value,
4917 _LIBCPP_INLINE_VISIBILITY
4918 operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
4920 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4922 _LIBCPP_INLINE_VISIBILITY
4923 weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
4927 is_convertible<_Yp*, element_type*>::value,
4930 _LIBCPP_INLINE_VISIBILITY
4931 operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
4933 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4938 is_convertible<_Yp*, element_type*>::value,
4941 _LIBCPP_INLINE_VISIBILITY
4942 operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
4944 _LIBCPP_INLINE_VISIBILITY
4945 void swap(weak_ptr& __r) _NOEXCEPT;
4946 _LIBCPP_INLINE_VISIBILITY
4947 void reset() _NOEXCEPT;
4949 _LIBCPP_INLINE_VISIBILITY
4950 long use_count() const _NOEXCEPT
4951 {return __cntrl_ ? __cntrl_->use_count() : 0;}
4952 _LIBCPP_INLINE_VISIBILITY
4953 bool expired() const _NOEXCEPT
4954 {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
4955 shared_ptr<_Tp> lock() const _NOEXCEPT;
4957 _LIBCPP_INLINE_VISIBILITY
4958 bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
4959 {return __cntrl_ < __r.__cntrl_;}
4961 _LIBCPP_INLINE_VISIBILITY
4962 bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
4963 {return __cntrl_ < __r.__cntrl_;}
4965 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
4966 template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
4972 weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
4980 weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
4981 : __ptr_(__r.__ptr_),
4982 __cntrl_(__r.__cntrl_)
4985 __cntrl_->__add_weak();
4991 weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
4992 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
4994 : __ptr_(__r.__ptr_),
4995 __cntrl_(__r.__cntrl_)
4998 __cntrl_->__add_weak();
5004 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
5005 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5007 : __ptr_(__r.__ptr_),
5008 __cntrl_(__r.__cntrl_)
5011 __cntrl_->__add_weak();
5014 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5018 weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
5019 : __ptr_(__r.__ptr_),
5020 __cntrl_(__r.__cntrl_)
5029 weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
5030 typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
5032 : __ptr_(__r.__ptr_),
5033 __cntrl_(__r.__cntrl_)
5039 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5042 weak_ptr<_Tp>::~weak_ptr()
5045 __cntrl_->__release_weak();
5051 weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
5053 weak_ptr(__r).swap(*this);
5062 is_convertible<_Yp*, _Tp*>::value,
5065 weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
5067 weak_ptr(__r).swap(*this);
5071 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
5076 weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
5078 weak_ptr(_VSTD::move(__r)).swap(*this);
5087 is_convertible<_Yp*, _Tp*>::value,
5090 weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
5092 weak_ptr(_VSTD::move(__r)).swap(*this);
5096 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
5103 is_convertible<_Yp*, _Tp*>::value,
5106 weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
5108 weak_ptr(__r).swap(*this);
5115 weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
5117 _VSTD::swap(__ptr_, __r.__ptr_);
5118 _VSTD::swap(__cntrl_, __r.__cntrl_);
5122 inline _LIBCPP_INLINE_VISIBILITY
5124 swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
5132 weak_ptr<_Tp>::reset() _NOEXCEPT
5134 weak_ptr().swap(*this);
5139 shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
5140 typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
5141 : __ptr_(__r.__ptr_),
5142 __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
5145 __throw_bad_weak_ptr();
5150 weak_ptr<_Tp>::lock() const _NOEXCEPT
5152 shared_ptr<_Tp> __r;
5153 __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
5155 __r.__ptr_ = __ptr_;
5159 #if _LIBCPP_STD_VER > 14
5160 template <class _Tp = void> struct owner_less;
5162 template <class _Tp> struct owner_less;
5165 template <class _Tp>
5166 struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
5167 : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
5169 typedef bool result_type;
5170 _LIBCPP_INLINE_VISIBILITY
5171 bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5172 {return __x.owner_before(__y);}
5173 _LIBCPP_INLINE_VISIBILITY
5174 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5175 {return __x.owner_before(__y);}
5176 _LIBCPP_INLINE_VISIBILITY
5177 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5178 {return __x.owner_before(__y);}
5181 template <class _Tp>
5182 struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
5183 : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
5185 typedef bool result_type;
5186 _LIBCPP_INLINE_VISIBILITY
5187 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5188 {return __x.owner_before(__y);}
5189 _LIBCPP_INLINE_VISIBILITY
5190 bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
5191 {return __x.owner_before(__y);}
5192 _LIBCPP_INLINE_VISIBILITY
5193 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
5194 {return __x.owner_before(__y);}
5197 #if _LIBCPP_STD_VER > 14
5199 struct _LIBCPP_TEMPLATE_VIS owner_less<void>
5201 template <class _Tp, class _Up>
5202 _LIBCPP_INLINE_VISIBILITY
5203 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5204 {return __x.owner_before(__y);}
5205 template <class _Tp, class _Up>
5206 _LIBCPP_INLINE_VISIBILITY
5207 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5208 {return __x.owner_before(__y);}
5209 template <class _Tp, class _Up>
5210 _LIBCPP_INLINE_VISIBILITY
5211 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
5212 {return __x.owner_before(__y);}
5213 template <class _Tp, class _Up>
5214 _LIBCPP_INLINE_VISIBILITY
5215 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
5216 {return __x.owner_before(__y);}
5217 typedef void is_transparent;
5222 class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
5224 mutable weak_ptr<_Tp> __weak_this_;
5226 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
5227 enable_shared_from_this() _NOEXCEPT {}
5228 _LIBCPP_INLINE_VISIBILITY
5229 enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
5230 _LIBCPP_INLINE_VISIBILITY
5231 enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
5233 _LIBCPP_INLINE_VISIBILITY
5234 ~enable_shared_from_this() {}
5236 _LIBCPP_INLINE_VISIBILITY
5237 shared_ptr<_Tp> shared_from_this()
5238 {return shared_ptr<_Tp>(__weak_this_);}
5239 _LIBCPP_INLINE_VISIBILITY
5240 shared_ptr<_Tp const> shared_from_this() const
5241 {return shared_ptr<const _Tp>(__weak_this_);}
5243 #if _LIBCPP_STD_VER > 14
5244 _LIBCPP_INLINE_VISIBILITY
5245 weak_ptr<_Tp> weak_from_this() _NOEXCEPT
5246 { return __weak_this_; }
5248 _LIBCPP_INLINE_VISIBILITY
5249 weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
5250 { return __weak_this_; }
5251 #endif // _LIBCPP_STD_VER > 14
5253 template <class _Up> friend class shared_ptr;
5256 template <class _Tp>
5257 struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
5259 typedef shared_ptr<_Tp> argument_type;
5260 typedef size_t result_type;
5262 _LIBCPP_INLINE_VISIBILITY
5263 result_type operator()(const argument_type& __ptr) const _NOEXCEPT
5265 return hash<_Tp*>()(__ptr.get());
5269 template<class _CharT, class _Traits, class _Yp>
5270 inline _LIBCPP_INLINE_VISIBILITY
5271 basic_ostream<_CharT, _Traits>&
5272 operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
5275 #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5277 class _LIBCPP_TYPE_VIS __sp_mut
5281 void lock() _NOEXCEPT;
5282 void unlock() _NOEXCEPT;
5285 _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
5286 __sp_mut(const __sp_mut&);
5287 __sp_mut& operator=(const __sp_mut&);
5289 friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
5292 _LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5293 __sp_mut& __get_sp_mut(const void*);
5295 template <class _Tp>
5296 inline _LIBCPP_INLINE_VISIBILITY
5298 atomic_is_lock_free(const shared_ptr<_Tp>*)
5303 template <class _Tp>
5304 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5306 atomic_load(const shared_ptr<_Tp>* __p)
5308 __sp_mut& __m = __get_sp_mut(__p);
5310 shared_ptr<_Tp> __q = *__p;
5315 template <class _Tp>
5316 inline _LIBCPP_INLINE_VISIBILITY
5317 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5319 atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
5321 return atomic_load(__p);
5324 template <class _Tp>
5325 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5327 atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5329 __sp_mut& __m = __get_sp_mut(__p);
5335 template <class _Tp>
5336 inline _LIBCPP_INLINE_VISIBILITY
5337 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5339 atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5341 atomic_store(__p, __r);
5344 template <class _Tp>
5345 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5347 atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
5349 __sp_mut& __m = __get_sp_mut(__p);
5356 template <class _Tp>
5357 inline _LIBCPP_INLINE_VISIBILITY
5358 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5360 atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
5362 return atomic_exchange(__p, __r);
5365 template <class _Tp>
5366 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5368 atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5370 shared_ptr<_Tp> __temp;
5371 __sp_mut& __m = __get_sp_mut(__p);
5373 if (__p->__owner_equivalent(*__v))
5375 _VSTD::swap(__temp, *__p);
5380 _VSTD::swap(__temp, *__v);
5386 template <class _Tp>
5387 inline _LIBCPP_INLINE_VISIBILITY
5388 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5390 atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
5392 return atomic_compare_exchange_strong(__p, __v, __w);
5395 template <class _Tp>
5396 inline _LIBCPP_INLINE_VISIBILITY
5397 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5399 atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5400 shared_ptr<_Tp> __w, memory_order, memory_order)
5402 return atomic_compare_exchange_strong(__p, __v, __w);
5405 template <class _Tp>
5406 inline _LIBCPP_INLINE_VISIBILITY
5407 _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
5409 atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
5410 shared_ptr<_Tp> __w, memory_order, memory_order)
5412 return atomic_compare_exchange_weak(__p, __v, __w);
5415 #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
5418 #if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
5419 # ifndef _LIBCPP_CXX03_LANG
5420 enum class pointer_safety : unsigned char {
5427 struct _LIBCPP_TYPE_VIS pointer_safety
5438 _LIBCPP_INLINE_VISIBILITY
5439 pointer_safety() : __v_() {}
5441 _LIBCPP_INLINE_VISIBILITY
5442 pointer_safety(__lx __v) : __v_(__v) {}
5443 _LIBCPP_INLINE_VISIBILITY
5444 operator int() const {return __v_;}
5448 #if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
5449 defined(_LIBCPP_BUILDING_MEMORY)
5450 _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
5452 // This function is only offered in C++03 under ABI v1.
5453 # if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
5454 inline _LIBCPP_INLINE_VISIBILITY
5455 pointer_safety get_pointer_safety() _NOEXCEPT {
5456 return pointer_safety::relaxed;
5462 _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
5463 _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
5464 _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
5465 _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
5467 template <class _Tp>
5468 inline _LIBCPP_INLINE_VISIBILITY
5470 undeclare_reachable(_Tp* __p)
5472 return static_cast<_Tp*>(__undeclare_reachable(__p));
5475 _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
5477 // --- Helper for container swap --
5478 template <typename _Alloc>
5479 inline _LIBCPP_INLINE_VISIBILITY
5480 void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
5481 #if _LIBCPP_STD_VER >= 14
5484 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5487 __swap_allocator(__a1, __a2,
5488 integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
5491 template <typename _Alloc>
5492 _LIBCPP_INLINE_VISIBILITY
5493 void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
5494 #if _LIBCPP_STD_VER >= 14
5497 _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
5504 template <typename _Alloc>
5505 inline _LIBCPP_INLINE_VISIBILITY
5506 void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
5508 template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
5509 struct __noexcept_move_assign_container : public integral_constant<bool,
5510 _Traits::propagate_on_container_move_assignment::value
5511 #if _LIBCPP_STD_VER > 14
5512 || _Traits::is_always_equal::value
5514 && is_nothrow_move_assignable<_Alloc>::value
5519 #ifndef _LIBCPP_HAS_NO_VARIADICS
5520 template <class _Tp, class _Alloc>
5521 struct __temp_value {
5522 typedef allocator_traits<_Alloc> _Traits;
5524 typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
5527 _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
5528 _Tp & get() { return *__addr(); }
5530 template<class... _Args>
5531 __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
5532 { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
5534 ~__temp_value() { _Traits::destroy(__a, __addr()); }
5538 _LIBCPP_END_NAMESPACE_STD
5542 #endif // _LIBCPP_MEMORY